当前位置: 首页>>代码示例>>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;未经允许,请勿转载。