当前位置: 首页>>代码示例>>Java>>正文


Java ArrayList.trimToSize方法代码示例

本文整理汇总了Java中java.util.ArrayList.trimToSize方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayList.trimToSize方法的具体用法?Java ArrayList.trimToSize怎么用?Java ArrayList.trimToSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.ArrayList的用法示例。


在下文中一共展示了ArrayList.trimToSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: leastOf

import java.util.ArrayList; //导入方法依赖的package包/类
/**
 * Returns the {@code k} least elements from the given iterator according to this ordering, in
 * order from least to greatest. If there are fewer than {@code k} elements present, all will be
 * included.
 *
 * <p>The implementation does not necessarily use a <i>stable</i> sorting algorithm; when multiple
 * elements are equivalent, it is undefined which will come first.
 *
 * <p><b>Java 8 users:</b> Continue to use this method for now. After the next release of Guava,
 * use {@code Streams.stream(iterator).collect(Comparators.least(k, thisComparator))} instead.
 *
 * @return an immutable {@code RandomAccess} list of the {@code k} least elements in ascending
 *     order
 * @throws IllegalArgumentException if {@code k} is negative
 * @since 14.0
 */
public <E extends T> List<E> leastOf(Iterator<E> iterator, int k) {
  checkNotNull(iterator);
  checkNonnegative(k, "k");

  if (k == 0 || !iterator.hasNext()) {
    return ImmutableList.of();
  } else if (k >= Integer.MAX_VALUE / 2) {
    // k is really large; just do a straightforward sorted-copy-and-sublist
    ArrayList<E> list = Lists.newArrayList(iterator);
    Collections.sort(list, this);
    if (list.size() > k) {
      list.subList(k, list.size()).clear();
    }
    list.trimToSize();
    return Collections.unmodifiableList(list);
  } else {
    TopKSelector<E> selector = TopKSelector.least(k, this);
    selector.offerAll(iterator);
    return selector.topK();
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:38,代码来源:Ordering.java

示例2: filter

import java.util.ArrayList; //导入方法依赖的package包/类
@Override
public Entry filter(Entry entry) {
  NavigableMap<byte[], Integer> scopes = entry.getKey().getScopes();
  if (scopes == null || scopes.isEmpty()) {
    return null;
  }
  ArrayList<Cell> cells = entry.getEdit().getCells();
  int size = cells.size();
  for (int i = size - 1; i >= 0; i--) {
    Cell cell = cells.get(i);
    // The scope will be null or empty if
    // there's nothing to replicate in that WALEdit
    if (!scopes.containsKey(cell.getFamily())
        || scopes.get(cell.getFamily()) == HConstants.REPLICATION_SCOPE_LOCAL) {
      cells.remove(i);
    }
  }
  if (cells.size() < size / 2) {
    cells.trimToSize();
  }
  return entry;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:23,代码来源:ScopeWALEntryFilter.java

示例3: trimToSize

import java.util.ArrayList; //导入方法依赖的package包/类
public void trimToSize() {
    if (attributes == null) {
        return;
    }
    if (attributes.isEmpty()) {
        attributes = null;
        return;
    }
    if (attributes instanceof ArrayList) {
        ArrayList<Attribute> al = (ArrayList<Attribute>)attributes;
        al.trimToSize();
        boolean allCanon = true;
        for (Attribute a : al) {
            if (!a.isCanonical()) {
                allCanon = false;
            }
            if (a.fixups != null) {
                assert(!a.isCanonical());
                a.fixups = Fixups.trimToSize(a.fixups);
            }
        }
        if (allCanon) {
            // Replace private writable attribute list
            // with only trivial entries by public unique
            // immutable attribute list with the same entries.
            attributes = getCanonList(al);
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:Attribute.java

示例4: concatPhases

import java.util.ArrayList; //导入方法依赖的package包/类
private static List<CompilationPhase> concatPhases(final CompilationPhases[] bases) {
    final ArrayList<CompilationPhase> l = new ArrayList<>();
    for(final CompilationPhases base: bases) {
        l.addAll(base.phases);
    }
    l.trimToSize();
    return l;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:Compiler.java

示例5: trimToSize

import java.util.ArrayList; //导入方法依赖的package包/类
/**
 * Reduces the memory used by this {@code ArrayListMultimap}, if feasible.
 */
public void trimToSize() {
  for (Collection<V> collection : backingMap().values()) {
    ArrayList<V> arrayList = (ArrayList<V>) collection;
    arrayList.trimToSize();
  }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:10,代码来源:ArrayListMultimap.java

示例6: filter

import java.util.ArrayList; //导入方法依赖的package包/类
public static <T> List<T> filter(List<T> list, ListUtilsHook<T> hook) {
    ArrayList<T> r = new ArrayList<T>();
    for (T t : list) {
        if (hook.Result(t)) {
            r.add(t);
        }
    }
    r.trimToSize();
    return r;
}
 
开发者ID:Zyj163,项目名称:yyox,代码行数:11,代码来源:ListUtils.java

示例7: getContextInjectionFields

import java.util.ArrayList; //导入方法依赖的package包/类
/**
 * Get {@link ViewContext} annotated fields of class and its superclasses
 * @param cls Class to inspect
 * @return ViewContext annotated fields
 * @throws ViewConfigurationException Invalid Context injection type
 */
public static Collection<ViewContextField> getContextInjectionFields(Class<?> cls)
		throws ViewConfigurationException {
	ArrayList<ViewContextField> fields = new ArrayList<>();

	Class<?> currentClass = cls;
	while (currentClass != null) {
		final Field[] declaredFields = currentClass.getDeclaredFields();
		for (final Field field : declaredFields) {
			if (field.isAnnotationPresent(ViewContext.class)) {
				// check not final
				if (Modifier.isFinal(field.getModifiers())) {
					throw new ViewConfigurationException("Context injection field " + field.getName()
							+ " must not be declared as final in class " + cls.getName());
				}
				ViewContext vc = field.getAnnotation(ViewContext.class);

				fields.add(
						ViewContextField.build(AnnotationUtils.getStringValue(vc.value()), vc.required(), field));
			}
		}
		currentClass = currentClass.getSuperclass();
	}

	fields.trimToSize();
	return fields;
}
 
开发者ID:holon-platform,项目名称:holon-vaadin,代码行数:33,代码来源:ViewNavigationUtils.java

示例8: readColumnInfoViaReflection

import java.util.ArrayList; //导入方法依赖的package包/类
private ColumnMapping readColumnInfoViaReflection(Class<?> clazz) {
    Field[] fieldArray = clazz.getDeclaredFields();
    ArrayList<ColumnInfo> list = new ArrayList<>(fieldArray.length);
    ColumnInfo rowNumberColumn = null;
    for (Field field: fieldArray) {

        RowNumber rowNumberAnnotation = field.getAnnotation(RowNumber.class);

        if (! Objects.isNull(rowNumberAnnotation)) {
            rowNumberColumn = new ColumnInfo("__id__", field.getName(), -1, null,Integer.class, NoopConverter.class);
            continue;
        }

        Column annotation = field.getAnnotation(Column.class);
        if (! Objects.isNull(annotation)) {
            Class<?> converter = annotation.convertorClass();
            list.add(new ColumnInfo(annotation.name().trim(),
                    field.getName(),
                    annotation.index(),
                    annotation.dataFormat(),
                    field.getType(),
                    converter));
        }
    }

    if (list.isEmpty()) {
        throw new ZeroCellException(String.format("Class %s does not have @Column annotations", clazz.getName()));
    }
    list.trimToSize();
    return new ColumnMapping(rowNumberColumn, list);
}
 
开发者ID:creditdatamw,项目名称:zerocell,代码行数:32,代码来源:EntityHandler.java

示例9: addEquivalents

import java.util.ArrayList; //导入方法依赖的package包/类
/**
 * Replaces all isomorphic clusters in the given list by a single cluster
 * with weight given by their sum.  The resulting list is also sorted by #
 * of connections.  Both the list and the the weights of the clusters it
 * contains may be altered by this method.
 */
public static void addEquivalents(ArrayList<ClusterDiagram> list) {
    if (list.size() < 2) {
        return;
    }
    reduce(list);
    ClusterDiagram cluster1 = null;
    for (int i=0; i<list.size(); i++) {
        cluster1 = list.get(i);
        for (int j=i+1; j<list.size(); j++) {
            ClusterDiagram cluster2 = list.get(j);
            if (cluster1.getNumConnections() != cluster2.getNumConnections()) {
                break;
            }
            if(cluster2.getWeight().numerator() == 0) {
                continue;
            }
            if(cluster1.isIsomorphOf(cluster2)) {
                int[] score1 = new int[cluster1.mNumBody/2+1];
                cluster1.calcScore(score1);
                if(cluster2.scoreGreaterThan(score1)) {
                    cluster2.setWeight(cluster1.getWeight().plus(cluster2.getWeight()));
                    cluster1.setWeight(Rational.ZERO);
                    break;
                }
                cluster1.setWeight(cluster1.getWeight().plus(cluster2.getWeight()));
                cluster2.setWeight(Rational.ZERO);
            }
        }
    }
    //remove clusters having zero weight
    for (int i=0; i<list.size(); i++) {
        ClusterDiagram cluster = list.get(i);
        if(cluster.getWeight().numerator() == 0) {
            list.remove(i);
            i--;
        }
    }
    list.trimToSize();
}
 
开发者ID:etomica,项目名称:etomica,代码行数:46,代码来源:ClusterOperations.java

示例10: optimizeList

import java.util.ArrayList; //导入方法依赖的package包/类
private static <T> List<T> optimizeList(final ArrayList<T> list) {
    switch(list.size()) {
        case 0: {
            return Collections.emptyList();
        }
        case 1: {
            return Collections.singletonList(list.get(0));
        }
        default: {
            list.trimToSize();
            return list;
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:Parser.java

示例11: filterDefinitions

import java.util.ArrayList; //导入方法依赖的package包/类
/**
 * Utility function for returning the subset of the availableDefinitions in availableDefinitions
 * order, with categories named in the allowedDefinitionNames.  If availableDefinitions is
 * empty, no filtering is performed.
 * @param allowedDefinitionNames
 * @param availableDefinitions
 * @return
 */
protected static List<SuiteDefinition> filterDefinitions(
  Set<String> allowedDefinitionNames, List<SuiteDefinition> availableDefinitions)
{    
  if (allowedDefinitionNames.isEmpty())
  {
    return availableDefinitions;
  }
  else
  {
    ArrayList<SuiteDefinition> definitions = new ArrayList<SuiteDefinition>();
    
    for (String category : allowedDefinitionNames)
    {
      SuiteDefinition allowedDefinition = _getSuitedDefinitionByCategory(availableDefinitions, category);
      
      if (allowedDefinition != null)
      {
        definitions.add(allowedDefinition);
      }
      else
      {
        _LOG.warning("Unabled to find test category named:" + category);
      }
    }

    definitions.trimToSize();
    return Collections.unmodifiableList(definitions);
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:38,代码来源:RenderKitTestCase.java

示例12: getPath

import java.util.ArrayList; //导入方法依赖的package包/类
private List getPath (String pathName) {
    String cp = saVM.getSystemProperty(pathName);
    String pathSep = saVM.getSystemProperty("path.separator");
    ArrayList al = new ArrayList();
    StringTokenizer st = new StringTokenizer(cp, pathSep);
    while (st.hasMoreTokens()) {
        al.add(st.nextToken());
    }
    al.trimToSize();
    return al;
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:12,代码来源:VirtualMachineImpl.java

示例13: create

import java.util.ArrayList; //导入方法依赖的package包/类
@Override
public Object create() {
    ArrayList list = new ArrayList();
    for (int i = 0; i < 1000; i++) {
        Integer x = new Integer(i);
        list.add(x);
    }
    list.trimToSize();
    return list;
}
 
开发者ID:JetBrains,项目名称:intellij-deps-trove4j,代码行数:11,代码来源:MemoryUsage.java

示例14: getHeaderFields

import java.util.ArrayList; //导入方法依赖的package包/类
/**
 * Returns an unmodifiable Map of the header fields.
 */
@Override
public Map<String,List<String>> getHeaderFields() {

  if (!connected) {
      // Try to connect (silently)
      try {
          connect();
      } catch (IOException e) {
          //Ignore
      }
  }

  if (attributes == null)
      return (Collections.emptyMap());

  HashMap<String,List<String>> headerFields =
      new HashMap<String,List<String>>(attributes.size());
  NamingEnumeration<String> attributeEnum = attributes.getIDs();
  try {
      while (attributeEnum.hasMore()) {
          String attributeID = attributeEnum.next();
          Attribute attribute = attributes.get(attributeID);
          if (attribute == null) continue;
          ArrayList<String> attributeValueList =
              new ArrayList<String>(attribute.size());
          NamingEnumeration<?> attributeValues = attribute.getAll();
          while (attributeValues.hasMore()) {
              Object attrValue = attributeValues.next();
              attributeValueList.add(getHeaderValueAsString(attrValue));
          }
          attributeValueList.trimToSize(); // should be a no-op if attribute.size() didn't lie
          headerFields.put(attributeID, Collections.unmodifiableList(attributeValueList));
      }
  } catch (NamingException ne) {
        // Shouldn't happen
  }

  return Collections.unmodifiableMap(headerFields);

}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:44,代码来源:DirContextURLConnection.java

示例15: buildAndValidateAcl

import java.util.ArrayList; //导入方法依赖的package包/类
/**
 * Builds the final list of ACL entries to return by trimming, sorting and
 * validating the ACL entries that have been added.
 *
 * @param aclBuilder ArrayList<AclEntry> containing entries to build
 * @return List<AclEntry> unmodifiable, sorted list of ACL entries
 * @throws AclException if validation fails
 */
private static List<AclEntry> buildAndValidateAcl(
    ArrayList<AclEntry> aclBuilder) throws AclException {
  if (aclBuilder.size() > MAX_ENTRIES) {
    throw new AclException("Invalid ACL: ACL has " + aclBuilder.size() +
      " entries, which exceeds maximum of " + MAX_ENTRIES + ".");
  }
  aclBuilder.trimToSize();
  Collections.sort(aclBuilder, ACL_ENTRY_COMPARATOR);
  // Full iteration to check for duplicates and invalid named entries.
  AclEntry prevEntry = null;
  for (AclEntry entry: aclBuilder) {
    if (prevEntry != null &&
        ACL_ENTRY_COMPARATOR.compare(prevEntry, entry) == 0) {
      throw new AclException(
        "Invalid ACL: multiple entries with same scope, type and name.");
    }
    if (entry.getName() != null && (entry.getType() == MASK ||
        entry.getType() == OTHER)) {
      throw new AclException(
        "Invalid ACL: this entry type must not have a name: " + entry + ".");
    }
    prevEntry = entry;
  }
  // Search for the required base access entries.  If there is a default ACL,
  // then do the same check on the default entries.
  ScopedAclEntries scopedEntries = new ScopedAclEntries(aclBuilder);
  for (AclEntryType type: EnumSet.of(USER, GROUP, OTHER)) {
    AclEntry accessEntryKey = new AclEntry.Builder().setScope(ACCESS)
      .setType(type).build();
    if (Collections.binarySearch(scopedEntries.getAccessEntries(),
        accessEntryKey, ACL_ENTRY_COMPARATOR) < 0) {
      throw new AclException(
        "Invalid ACL: the user, group and other entries are required.");
    }
    if (!scopedEntries.getDefaultEntries().isEmpty()) {
      AclEntry defaultEntryKey = new AclEntry.Builder().setScope(DEFAULT)
        .setType(type).build();
      if (Collections.binarySearch(scopedEntries.getDefaultEntries(),
          defaultEntryKey, ACL_ENTRY_COMPARATOR) < 0) {
        throw new AclException(
          "Invalid default ACL: the user, group and other entries are required.");
      }
    }
  }
  return Collections.unmodifiableList(aclBuilder);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:55,代码来源:AclTransformation.java


注:本文中的java.util.ArrayList.trimToSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。