當前位置: 首頁>>代碼示例>>Java>>正文


Java ArrayList.ensureCapacity方法代碼示例

本文整理匯總了Java中java.util.ArrayList.ensureCapacity方法的典型用法代碼示例。如果您正苦於以下問題:Java ArrayList.ensureCapacity方法的具體用法?Java ArrayList.ensureCapacity怎麽用?Java ArrayList.ensureCapacity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.ArrayList的用法示例。


在下文中一共展示了ArrayList.ensureCapacity方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getQueue

import java.util.ArrayList; //導入方法依賴的package包/類
public ArrayList<MusicPlaybackTrack> getQueue() {
    ArrayList<MusicPlaybackTrack> results = new ArrayList<>();

    Cursor cursor = null;
    try {
        cursor = mMusicDatabase.getReadableDatabase().query(PlaybackQueueColumns.NAME, null,
                null, null, null, null, null);

        if (cursor != null && cursor.moveToFirst()) {
            results.ensureCapacity(cursor.getCount());

            do {
                results.add(new MusicPlaybackTrack(cursor.getLong(0), cursor.getLong(1),
                        TimberUtils.IdType.getTypeById(cursor.getInt(2)), cursor.getInt(3)));
            } while (cursor.moveToNext());
        }

        return results;
    } finally {
        if (cursor != null) {
            cursor.close();
            cursor = null;
        }
    }
}
 
開發者ID:Vinetos,項目名稱:Hello-Music-droid,代碼行數:26,代碼來源:MusicPlaybackState.java

示例2: getQueue

import java.util.ArrayList; //導入方法依賴的package包/類
public ArrayList<MusicPlaybackTrack> getQueue() {
    ArrayList<MusicPlaybackTrack> results = new ArrayList<>();

    Cursor cursor = null;
    try {
        cursor = mMusicDatabase.getReadableDatabase().query(PlaybackQueueColumns.NAME, null,
                null, null, null, null, null);

        if (cursor != null && cursor.moveToFirst()) {
            results.ensureCapacity(cursor.getCount());

            do {
                results.add(new MusicPlaybackTrack(cursor.getLong(0), cursor.getLong(1),
                        cursor.getInt(3)));
            } while (cursor.moveToNext());
        }

        return results;
    } finally {
        if (cursor != null) {
            cursor.close();
            cursor = null;
        }
    }
}
 
開發者ID:komamj,項目名稱:KomaMusic,代碼行數:26,代碼來源:MusicPlaybackState.java

示例3: addParameterValues

import java.util.ArrayList; //導入方法依賴的package包/類
@Deprecated
public void addParameterValues(String key, String[] newValues) {
    if (key == null) {
        return;
    }
    ArrayList<String> values = paramHashValues.get(key);
    if (values == null) {
        values = new ArrayList<String>(newValues.length);
        paramHashValues.put(key, values);
    } else {
        values.ensureCapacity(values.size() + newValues.length);
    }
    for (String newValue : newValues) {
        values.add(newValue);
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:17,代碼來源:Parameters.java

示例4: getEpisodeList

import java.util.ArrayList; //導入方法依賴的package包/類
/**
 * Get the list of episodes in the DB for the given show
 * @param showId
 * @return
 */
private List<EpisodeTags> getEpisodeList(long showId) {
    ArrayList<EpisodeTags> result = new ArrayList<EpisodeTags>();
    // get EpisodeTags by ShowId
    final Uri uri = VideoStore.Video.Media.EXTERNAL_CONTENT_URI;
    final String selection = VideoStore.Video.VideoColumns.SCRAPER_SHOW_ID + "=?";
    final String[] selectionArgs = new String[] { String.valueOf(showId) };
    final String sortOrder = VideoStore.Video.VideoColumns.SCRAPER_E_SEASON+", "+VideoStore.Video.VideoColumns.SCRAPER_E_EPISODE;
    Cursor c = mContext.getContentResolver().query(uri, TagsFactory.VIDEO_COLUMNS, selection, selectionArgs, sortOrder);
    List<BaseTags> tagsList = TagsFactory.buildTagsFromVideoCursor(c);
    if (c != null)
        c.close();
    // add every EpisodeTags (should be all) to result list
    if (tagsList != null) {
        result.ensureCapacity(tagsList.size());
        for (BaseTags bTag : tagsList) {
            if (bTag instanceof EpisodeTags) {
                EpisodeTags epTag = (EpisodeTags) bTag;
                result.add(epTag);
            }
        }
    }
    return result;
}
 
開發者ID:archos-sa,項目名稱:aos-Video,代碼行數:29,代碼來源:ManualShowScrappingSearchFragment.java

示例5: convert

import java.util.ArrayList; //導入方法依賴的package包/類
/**
 * General conversion method to convert collection contents to the specified
 * type. Wrapper around the Collection version for arrays.
 * 
 * @param propertyType - the target property type
 * @param values - the value to be converted
 * @return - the converted value as the correct type
 * @throws DictionaryException if the property type's registered java class is invalid
 * @throws TypeConversionException if the conversion cannot be performed
 */
public final Collection<?> convert(DataTypeDefinition propertyType, Object[] values)
{
   if(values == null) {
      return convert(propertyType, (Collection<?>)null);
   } else {
      // Turn the array into a Collection, then convert as that
      ArrayList<Object> c = new ArrayList<Object>();
      c.ensureCapacity(values.length);
      for(Object v : values) {
         c.add(v);
      }
      // Convert
      return convert(propertyType, c);
   }
}
 
開發者ID:Alfresco,項目名稱:alfresco-data-model,代碼行數:26,代碼來源:TypeConverter.java

示例6: copyProbandListEntryTagValuesInToJson

import java.util.ArrayList; //導入方法依賴的package包/類
public static void copyProbandListEntryTagValuesInToJson(ArrayList<ProbandListEntryTagValueJsonVO> tagValuesOut, ArrayList<ProbandListEntryTagValueInVO> tagValuesIn,
		HashMap<Long, ProbandListEntryTagOutVO> tagVOsMap) {
	if (tagValuesOut != null) {
		tagValuesOut.clear();
		if (tagValuesIn != null && tagVOsMap != null) {
			tagValuesOut.ensureCapacity(tagValuesIn.size());
			Iterator<ProbandListEntryTagValueInVO> it = tagValuesIn.iterator();
			while (it.hasNext()) {
				ProbandListEntryTagValueInVO in = it.next();
				if (tagVOsMap.containsKey(in.getTagId())) {
					ProbandListEntryTagValueJsonVO out = new ProbandListEntryTagValueJsonVO();
					CommonUtil.copyProbandListEntryTagValueInToJson(out, in, tagVOsMap.get(in.getTagId()));
					tagValuesOut.add(out);
				}
			}
		}
	}
}
 
開發者ID:phoenixctms,項目名稱:ctsms,代碼行數:19,代碼來源:ProbandListEntryTagValueBean.java

示例7: addParameterValues

import java.util.ArrayList; //導入方法依賴的package包/類
@Deprecated
public void addParameterValues(String key, String[] newValues) {
	if (key == null) {
		return;
	}
	ArrayList<String> values = paramHashValues.get(key);
	if (values == null) {
		values = new ArrayList<String>(newValues.length);
		paramHashValues.put(key, values);
	} else {
		values.ensureCapacity(values.size() + newValues.length);
	}
	for (String newValue : newValues) {
		values.add(newValue);
	}
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:17,代碼來源:Parameters.java

示例8: copyEcrfFieldValuesInToJson

import java.util.ArrayList; //導入方法依賴的package包/類
public static void copyEcrfFieldValuesInToJson(ArrayList<ECRFFieldValueJsonVO> ecrfFieldValuesOut, ArrayList<ECRFFieldValueInVO> ecrfFieldValuesIn,
		HashMap<Long, ECRFFieldOutVO> ecrfFieldVOsMap) {
	if (ecrfFieldValuesOut != null) {
		ecrfFieldValuesOut.clear();
		if (ecrfFieldValuesIn != null && ecrfFieldVOsMap != null) {
			ecrfFieldValuesOut.ensureCapacity(ecrfFieldValuesIn.size());
			Iterator<ECRFFieldValueInVO> it = ecrfFieldValuesIn.iterator();
			while (it.hasNext()) {
				ECRFFieldValueInVO in = it.next();
				if (ecrfFieldVOsMap.containsKey(in.getEcrfFieldId())) {
					ECRFFieldValueJsonVO out = new ECRFFieldValueJsonVO();
					CommonUtil.copyEcrfFieldValueInToJson(out, in, ecrfFieldVOsMap.get(in.getEcrfFieldId()));
					ecrfFieldValuesOut.add(out);
				}
			}
		}
	}
}
 
開發者ID:phoenixctms,項目名稱:ctsms,代碼行數:19,代碼來源:EcrfFieldValueBean.java

示例9: resize

import java.util.ArrayList; //導入方法依賴的package包/類
@Override
public Object resize( final Object object ,  final int newSize ){
  ArrayList list = (ArrayList) object;
  list.ensureCapacity(newSize);
  while (list.size() < newSize) {
    list.add(null);
  }
  while (list.size() > newSize) {
    list.remove(list.size() - 1);
  }
  return list;
}
 
開發者ID:yahoojapan,項目名稱:multiple-dimension-spread,代碼行數:13,代碼來源:MDSListObjectInspector.java

示例10: getTargetTypes

import java.util.ArrayList; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public List<Class<?>> getTargetTypes(Class<?> sourceType)
{
  ArrayList<Class<?>> list = new ArrayList<Class<?>>(1);
  if (Date.class.isAssignableFrom(sourceType))
  {
    list.add(Calendar.class);
  }
  else if (Calendar.class.isAssignableFrom(sourceType))
  {
    list.add(Date.class);
  }
  else if (Number.class.isAssignableFrom(sourceType))
  {
    list.ensureCapacity(14);
    list.add(Byte.class);
    list.add(Double.class);
    list.add(Float.class);
    list.add(Integer.class);
    list.add(Long.class);
    list.add(Short.class);
    list.add(BigDecimal.class);      
    list.add(Byte.TYPE);
    list.add(Double.TYPE);
    list.add(Float.TYPE); // bug 4891181
    list.add(Integer.TYPE);
    list.add(Long.TYPE);
    list.add(Short.TYPE);
    list.add (BigInteger.class);
  }
  
  return list;
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:35,代碼來源:BaseConverter.java

示例11: _expandListToIndex

import java.util.ArrayList; //導入方法依賴的package包/類
static private void _expandListToIndex(ArrayList<PropertyKey> list, int count)
{
  list.ensureCapacity(count + 1);
  int addCount = (count + 1) - list.size();
  for (int i = 0; i < addCount; i++)
    list.add(null);
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:8,代碼來源:FacesBean.java

示例12: __toList

import java.util.ArrayList; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
static List<Object> __toList(Object o)
{
  if (o == null)
    return null;

  ArrayList<Object> listCopy = new ArrayList<Object>();
  if (o instanceof Collection)
  {
    listCopy.addAll((Collection<Object>) o);
  }
  // Use java.lang.reflect.Array, etc. to support primitive Object arrays
  else if (o.getClass().isArray())
  {
    int length = Array.getLength(o);
    listCopy.ensureCapacity(length);
    for (int i = 0; i < length; i++)
    {
      listCopy.add(Array.get(o, i));
    }
  }
  else
  {
    // Already logged in __getSize(), so let it slide here
    ;
  }

  return listCopy;
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:30,代碼來源:UIXSelectManyTemplate.java

示例13: readFromParcel

import java.util.ArrayList; //導入方法依賴的package包/類
public static ArrayList<DataEntity> readFromParcel(Parcel src) {
    ArrayList<DataEntity> result = new ArrayList();
    try {
        int size = src.readInt();
        result.ensureCapacity(size);
        for (int i = 0; i < size; i++) {
            result.add(i, new DataEntity(src));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return result;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:14,代碼來源:DataEntity.java

示例14: getEpisodeList

import java.util.ArrayList; //導入方法依賴的package包/類
private List<EpisodeTags> getEpisodeList(ShowTags sTag) {
    ArrayList<EpisodeTags> result = new ArrayList<EpisodeTags>();
    if (sTag != null) {
        // get EpisodeTags by ShowId
        long sId = sTag.getId();
        ContentResolver cr = mContext.getContentResolver();
        Uri uri = VideoStore.Video.Media.EXTERNAL_CONTENT_URI;
        String selection = VideoStore.Video.VideoColumns.SCRAPER_SHOW_ID + "=?";
        String[] selectionArgs = new String[] {
                String.valueOf(sId)
        };
        String sortOrder = null;
        Cursor c = cr.query(uri, TagsFactory.VIDEO_COLUMNS, selection, selectionArgs, sortOrder);
        List<BaseTags> tagsList = TagsFactory.buildTagsFromVideoCursor(c);
        if (c != null)
            c.close();
        // add every EpisodeTags (should be all) to result list
        if (tagsList != null) {
            result.ensureCapacity(tagsList.size());
            for (BaseTags bTag : tagsList) {
                if (bTag instanceof EpisodeTags) {
                    EpisodeTags epTag = (EpisodeTags) bTag;
                    result.add(epTag);
                }
            }
        }
    }
    return result;
}
 
開發者ID:archos-sa,項目名稱:aos-Video,代碼行數:30,代碼來源:VideoInfoShowScraperFragment.java

示例15: testArrayList

import java.util.ArrayList; //導入方法依賴的package包/類
private static void testArrayList() {
    ArrayList<String> al = new ArrayList<String>();
    al.add("abc");
    al.ensureCapacity(Integer.MIN_VALUE);

    // there is no method to query the capacity of ArrayList
    // so before and after capacity are not checked
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:EnsureCapacity.java


注:本文中的java.util.ArrayList.ensureCapacity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。