當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。