Tabnine Logo
ArrayList.trimToSize
Code IndexAdd Tabnine to your IDE (free)

How to use
trimToSize
method
in
java.util.ArrayList

Best Java code snippets using java.util.ArrayList.trimToSize (Showing top 20 results out of 3,501)

Refine searchRefine arrow

  • ArrayList.add
origin: org.freemarker/freemarker

private static final List removeDuplicates(List list) {
  int s = list.size();
  ArrayList ulist = new ArrayList(s);
  Set set = new HashSet(s * 4 / 3, .75f);
  Iterator it = list.iterator();
  while (it.hasNext()) {
    Object o = it.next();
    if (set.add(o))
      ulist.add(o);
  }
  ulist.trimToSize();
  return ulist;
}
origin: konsoletyper/teavm

List<ConsumerWithNode> getConsumers() {
  if (consumers == null) {
    consumers = new ArrayList<>();
    for (DependencyNode node : domain) {
      if (node.followers != null) {
        consumers.add(new ConsumerWithNode(node.followers.toArray(new DependencyConsumer[0]), node));
      }
    }
    consumers.trimToSize();
  }
  return consumers;
}
origin: wildfly/wildfly

static <T> List<T> loadServices(Class<T> type, ClassLoader classLoader) {
  return doPrivileged((PrivilegedAction<List<T>>) () -> {
    ArrayList<T> list = new ArrayList<>();
    Iterator<T> iterator = ServiceLoader.load(type, classLoader).iterator();
    for (;;) try {
      if (! iterator.hasNext()) break;
      final T contextFactory = iterator.next();
      list.add(contextFactory);
    } catch (ServiceConfigurationError error) {
      Messages.log.serviceConfigFailed(error);
    }
    list.trimToSize();
    return list;
  });
}
origin: stanfordnlp/CoreNLP

/**
 * Returns text as a List of tokens.
 *
 * @return A list of all tokens remaining in the underlying Reader
 */
@Override
public List<T> tokenize() {
 ArrayList<T> result = new ArrayList<>(DEFAULT_TOKENIZE_LIST_SIZE);
 while (hasNext()) {
  result.add(next());
 }
 // log.info("tokenize() produced " + result);
 // if it was tiny, reallocate small
 if (result.size() <= DEFAULT_TOKENIZE_LIST_SIZE / 4) {
  result.trimToSize();
 }
 return result;
}
origin: wildfly/wildfly

/**
 * Construct a new instance.  The given class loader is scanned for transaction providers.
 *
 * @param classLoader the class loader to scan for transaction providers ({@code null} indicates the application or bootstrap class loader)
 */
public RemoteTransactionContext(final ClassLoader classLoader) {
  this(doPrivileged((PrivilegedAction<List<RemoteTransactionProvider>>) () -> {
    final ServiceLoader<RemoteTransactionProvider> loader = ServiceLoader.load(RemoteTransactionProvider.class, classLoader);
    final ArrayList<RemoteTransactionProvider> providers = new ArrayList<RemoteTransactionProvider>();
    final Iterator<RemoteTransactionProvider> iterator = loader.iterator();
    for (;;) try {
      if (! iterator.hasNext()) break;
      providers.add(iterator.next());
    } catch (ServiceConfigurationError e) {
      Log.log.serviceConfigurationFailed(e);
    }
    providers.trimToSize();
    return providers;
  }), false);
}
origin: hibernate/hibernate-orm

private static List<StandardServiceInitiator> buildStandardServiceInitiatorList() {
  final ArrayList<StandardServiceInitiator> serviceInitiators = new ArrayList<StandardServiceInitiator>();
  serviceInitiators.add( CfgXmlAccessServiceInitiator.INSTANCE );
  serviceInitiators.add( ConfigurationServiceInitiator.INSTANCE );
  serviceInitiators.add( PropertyAccessStrategyResolverInitiator.INSTANCE );
  serviceInitiators.add( ImportSqlCommandExtractorInitiator.INSTANCE );
  serviceInitiators.add( EntityCopyObserverFactoryInitiator.INSTANCE );
  serviceInitiators.trimToSize();
origin: nutzam/nutz

List<LinkField> getList(String regex) {
  ArrayList<LinkField> list;
  if (Strings.isBlank(regex)) {
    list = lnks;
  } else {
    list = cache.get(regex);
    if (null == list) {
      synchronized (cache) {
        list = cache.get(regex);
        if (null == list) {
          list = new ArrayList<LinkField>(lnks.size());
          for (LinkField lnk : lnks)
            if (Pattern.matches(regex, lnk.getName()))
              list.add(lnk);
          list.trimToSize();
          cache.put(regex, list);
        }
      }
    }
  }
  return list;
}
origin: org.freemarker/freemarker

/**
 * Constructs a simple sequence from the passed collection model, which shouldn't be added to later. The internal
 * list will be build immediately (not lazily). The resulting sequence shouldn't be extended with
 * {@link #add(Object)}, because the appropriate {@link ObjectWrapper} won't be available; use
 * {@link #SimpleSequence(Collection, ObjectWrapper)} instead, if you need that.
 */
public SimpleSequence(TemplateCollectionModel tcm) throws TemplateModelException {
  ArrayList alist = new ArrayList();
  for (TemplateModelIterator it = tcm.iterator(); it.hasNext(); ) {
    alist.add(it.next());
  }
  alist.trimToSize();
  list = alist;
}
origin: Sable/soot

 @Override
 public Collection<Unit> load(SootMethod m) throws Exception {
  ArrayList<Unit> res = new ArrayList<Unit>();
  // only retain callers that are explicit call sites or
  // Thread.start()
  Iterator<Edge> edgeIter = new EdgeFilter().wrap(cg.edgesInto(m));
  while (edgeIter.hasNext()) {
   Edge edge = edgeIter.next();
   res.add(edge.srcUnit());
  }
  res.trimToSize();
  return res;
 }
};
origin: wildfly/wildfly

protected List<PoolConfiguration> getMatchingPoolConfigs(String poolName, ManagementRepository repository) {
  ArrayList<PoolConfiguration> result = new ArrayList<PoolConfiguration>(repository.getDataSources().size());
  if (repository.getDataSources() != null) {
    for (DataSource ds : repository.getDataSources()) {
      if (poolName.equalsIgnoreCase(ds.getPool().getName())) {
        result.add(ds.getPoolConfiguration());
      }
    }
  }
  result.trimToSize();
  return result;
}
origin: org.apache.commons/commons-collections4

  final O item = iterator.next();
  if (lastItem == null || !lastItem.equals(item)) {
    mergedList.add(item);
mergedList.trimToSize();
return mergedList;
origin: wildfly/wildfly

  public List<Pool> match(String jndiName, ManagementRepository repository) {
    ArrayList<org.jboss.jca.core.api.connectionmanager.pool.Pool> result = new ArrayList<Pool>(repository
        .getDataSources().size());
    if (repository.getDataSources() != null) {
      for (DataSource ds : repository.getDataSources()) {
        if (jndiName.equalsIgnoreCase(ds.getJndiName()) && ds.getPool() != null) {
          result.add(ds.getPool());
        }
      }
    }
    result.trimToSize();
    return result;
  }
}
origin: Sable/soot

 successors.add(nextUnit);
  successors.add(target);
successors.trimToSize();
unitToSuccs.put(currentUnit, successors);
origin: Sable/soot

 @Override
 public Collection<SootMethod> load(Unit u) throws Exception {
  ArrayList<SootMethod> res = null;
  // only retain callers that are explicit call sites or
  // Thread.start()
  Iterator<Edge> edgeIter = new EdgeFilter().wrap(cg.edgesOutOf(u));
  while (edgeIter.hasNext()) {
   Edge edge = edgeIter.next();
   SootMethod m = edge.getTgt().method();
   if (includePhantomCallees || m.hasActiveBody()) {
    if (res == null) {
     res = new ArrayList<SootMethod>();
    }
    res.add(m);
   } else if (IDESolver.DEBUG) {
    logger.error(String.format("Method %s is referenced but has no body!", m.getSignature(), new Exception()));
   }
  }
  if (res != null) {
   res.trimToSize();
   return res;
  } else {
   return Collections.emptySet();
  }
 }
};
origin: wildfly/wildfly

protected List<PoolConfiguration> getMatchingPoolConfigs(String poolName, ManagementRepository repository) {
  ArrayList<PoolConfiguration> result = new ArrayList<PoolConfiguration>(repository.getConnectors().size());
  if (repository.getConnectors() != null) {
    for (Connector conn : repository.getConnectors()) {
      if (conn.getConnectionFactories() == null || conn.getConnectionFactories().get(0) == null
          || conn.getConnectionFactories().get(0).getPool() == null)
        continue;
      ConnectionFactory connectionFactory = conn.getConnectionFactories().get(0);
      if (poolName.equals(connectionFactory.getPool().getName())) {
        PoolConfiguration pc = conn.getConnectionFactories().get(0).getPoolConfiguration();
        result.add(pc);
      }
    }
  }
  result.trimToSize();
  return result;
}
origin: opentripplanner/OpenTripPlanner

private List<ShapePoint> getUniqueShapePointsForShapeId(FeedScopedId shapeId) {
  List<ShapePoint> points = transitService.getShapePointsForShapeId(shapeId);
  ArrayList<ShapePoint> filtered = new ArrayList<ShapePoint>(points.size());
  ShapePoint last = null;
  for (ShapePoint sp : points) {
    if (last == null || last.getSequence() != sp.getSequence()) {
      if (last != null && 
        last.getLat() == sp.getLat() && 
        last.getLon() == sp.getLon()) {
        LOG.trace("pair of identical shape points (skipping): {} {}", last, sp);
      } else {
        filtered.add(sp);
      }
    }
    last = sp;
  }
  if (filtered.size() != points.size()) {
    filtered.trimToSize();
    return filtered;
  } else {
    return points;
  }
}
origin: apache/ignite

    keyCols.add(keyCol);
  else {
    for (String propName : type.fields().keySet()) {
        Column col = tbl.getColumn(propName);
        keyCols.add(tbl.indexColumn(col.getColumnId(), SortOrder.ASCENDING));
      keyCols.add(keyCol);
  keyCols.add(affCol);
else
  keyCols.trimToSize();
origin: qiujuer/Genius-Android

    break;
  } else {
    routes.add(container.toString());
    prevIP = container.mIP;
routes.trimToSize();
mRoutes = routes;
origin: spring-projects/spring-security

  attrs.add(pre);
  attrs.add(post);
attrs.trimToSize();
origin: robovm/robovm

private void decodeValueCollection(ASN1ValueCollection collection) throws IOException {
  int begOffset = offset;
  int endOffset = begOffset + length;
  ASN1Type type = collection.type;
  if (isVerify) {
    while (endOffset > offset) {
      next();
      type.decode(this);
    }
  } else {
    int seqTagOffset = tagOffset; //store tag offset
    ArrayList<Object> values = new ArrayList<Object>();
    while (endOffset > offset) {
      next();
      values.add(type.decode(this));
    }
    values.trimToSize();
    content = values;
    tagOffset = seqTagOffset; //retrieve tag offset
  }
  if (offset != endOffset) {
    throw new ASN1Exception("Wrong encoding at [" + begOffset + "]. Content's length and encoded length are not the same");
  }
}
java.utilArrayListtrimToSize

Javadoc

Sets the capacity of this ArrayList to be the same as the current size.

Popular methods of ArrayList

  • <init>
  • add
  • size
    Returns the number of elements in this ArrayList.
  • get
    Returns the element at the specified position in this list.
  • toArray
    Returns an array containing all of the elements in this list in proper sequence (from first to last
  • addAll
    Adds the objects in the specified collection to this ArrayList.
  • remove
    Removes the first occurrence of the specified element from this list, if it is present. If the list
  • clear
    Removes all elements from this ArrayList, leaving it empty.
  • isEmpty
    Returns true if this list contains no elements.
  • iterator
    Returns an iterator over the elements in this list in proper sequence.The returned iterator is fail-
  • contains
    Searches this ArrayList for the specified object.
  • set
    Replaces the element at the specified position in this list with the specified element.
  • contains,
  • set,
  • indexOf,
  • clone,
  • subList,
  • stream,
  • ensureCapacity,
  • removeAll,
  • toString

Popular in Java

  • Start an intent from android
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getExternalFilesDir (Context)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • ArrayList (java.util)
    ArrayList is an implementation of List, backed by an array. All optional operations including adding
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now