Example usage for java.util ArrayList trimToSize

List of usage examples for java.util ArrayList trimToSize

Introduction

In this page you can find the example usage for java.util ArrayList trimToSize.

Prototype

public void trimToSize() 

Source Link

Document

Trims the capacity of this ArrayList instance to be the list's current size.

Usage

From source file:de.tuebingen.uni.sfs.germanet.api.GermaNet.java

/**
 * Returns a <code>List</code> of all <code>Synsets</code> in which
 * <code>orthForm</code> occurs as main orthographical form in one of its
 * <code>LexUnits</code> -- in case <code>considerAllOrthForms</code> is
 * true. Else returns a <code>List</code> of all <code>Synsets</code> in
 * which <code>orthForm</code> occurs as main orthographical form, as
 * orthographical variant, as old orthographical form, or as old
 * orthographic variant in one of its <code>LexUnits</code> -- in case
 * <code>considerAllOrthForms</code> is false. It uses the
 * <code>ignoreCase</code> flag as set in the constructor.
 * @param orthForm the <code>orthForm</code> to search for
 * @param considerMainOrthFormOnly considering main orthographical form only
 * (<code>true</code>) or all variants (<code>false</code>)
 * @return a <code>List</code> of all <code>Synsets</code> containing
 * orthForm. If no <code>Synsets</code> were found, this is a
 * <code>List</code> containing no <code>Synsets</code>
 *//*from w w w.ja v  a2 s  . co m*/
public List<Synset> getSynsets(String orthForm, boolean considerMainOrthFormOnly) {
    ArrayList<Synset> rval = new ArrayList<Synset>();
    HashMap<String, ArrayList<LexUnit>> map;
    List<LexUnit> tmpList;
    String mapForm = orthForm;

    if (ignoreCase) {
        mapForm = orthForm.toLowerCase();
    }

    for (WordCategory wc : WordCategory.values()) {
        if (considerMainOrthFormOnly) {
            map = wordCategoryMap.get(wc);
        } else {
            map = wordCategoryMapAllOrthForms.get(wc);
        }
        tmpList = map.get(mapForm);
        if (tmpList != null) {
            for (LexUnit lu : tmpList) {
                if (!rval.contains(lu.getSynset())) {
                    rval.add(lu.getSynset());
                }
            }
        }
    }
    rval.trimToSize();
    return rval;
}

From source file:org.lockss.config.Tdb.java

/**
 * Returns a collection of TdbTitles for the specified title name
 * across all publishers./*  w w w.  j  a  v a2 s .  c  o m*/
 *  
 * @param titleName the title name
 * @return a collection of TdbTitles that match the title name
 */
public Collection<TdbTitle> getTdbTitlesByName(String titleName) {
    ArrayList<TdbTitle> titles = new ArrayList<TdbTitle>();
    getTdbTitlesByName(titleName, titles);
    titles.trimToSize();
    return titles;
}

From source file:org.lockss.config.Tdb.java

/**
 * Returns a collection of TdbTitles like (starts with) the 
 * specified title name across all publishers.
 *  /*from ww  w. j  a va 2  s  .c om*/
 * @param titleName the title name
 * @return a collection of TdbTitles that match the title name
 */
public Collection<TdbTitle> getTdbTitlesLikeName(String titleName) {
    ArrayList<TdbTitle> titles = new ArrayList<TdbTitle>();
    getTdbTitlesLikeName(titleName, titles);
    titles.trimToSize();
    return titles;
}

From source file:com.flexive.faces.components.content.FxWrappedContent.java

/**
 * Returns possible workflow steps as select items.
 *
 * @return possible workflow steps as select items.
 *//*w w  w. j a v  a 2s  .c  o m*/
public List<SelectItem> getPossibleWorkflowSteps() {
    FxEnvironment environment = CacheAdmin.getFilteredEnvironment();
    UserTicket ticket = FxContext.getUserTicket();
    FxType fxType = environment.getType(content.getTypeId());

    List<Step> steps;
    boolean isNew = content.getPk().isNew();
    if (isNew) {
        steps = fxType.getWorkflow().getSteps();
    } else {
        steps = fxType.getWorkflow().getTargets(content.getStepId());
        if (steps.size() == 0 || !steps.contains(environment.getStep(content.getStepId())))
            steps.add(environment.getStep(content.getStepId()));
    }
    ArrayList<SelectItem> result = new ArrayList<SelectItem>(steps.size());
    for (Step step : steps) {
        if (!fxType.isUseStepPermissions()
                || (isNew ? ticket.mayCreateACL(step.getAclId(), content.getLifeCycleInfo().getCreatorId())
                        : ticket.mayEditACL(step.getAclId(), content.getLifeCycleInfo().getCreatorId()))) {
            StepDefinition def = environment.getStepDefinition(step.getStepDefinitionId());
            result.add(new SelectItem(String.valueOf(step.getId()), def.getLabel().getDefaultTranslation()));
        }
    }
    result.trimToSize();
    return result;
}

From source file:it.unibo.alchemist.language.EnvironmentBuilder.java

private void populateReaction(final Map<String, Object> subenv, final Reaction<T> res, final Node rootReact)
        throws InstantiationException, IllegalAccessException, InvocationTargetException,
        ClassNotFoundException {//from  w  w w  .j  a v a2s  .  com
    final NodeList children = rootReact.getChildNodes();
    final ArrayList<Condition<T>> conditions = new ArrayList<Condition<T>>();
    final ArrayList<Action<T>> actions = new ArrayList<Action<T>>();
    for (int i = 0; i < children.getLength(); i++) {
        final Node son = children.item(i);
        final String kind = son.getNodeName();
        if (!kind.equals(TEXT)) {
            final Node sonNameAttr = son.getAttributes().getNamedItem(NAME);
            final String sonName = sonNameAttr == null ? "" : sonNameAttr.getNodeValue();
            Object sonInstance = null;
            if (kind.equals("condition")) {
                final Condition<T> cond = buildCondition(son, subenv);
                conditions.add(cond);
                sonInstance = cond;
            } else if (kind.equals("action")) {
                final Action<T> act = buildAction(son, subenv);
                actions.add(act);
                sonInstance = act;
            }
            if (sonInstance != null) {
                subenv.put(sonName, sonInstance);
            }
        }
    }
    conditions.trimToSize();
    actions.trimToSize();
    if (!conditions.isEmpty()) {
        res.setConditions(conditions);
    }
    if (!actions.isEmpty()) {
        res.setActions(actions);
    }
}

From source file:org.apereo.portal.io.xml.JaxbPortalDataHandlerService.java

/**
 * Order in which data types should be imported.
 *//*from  ww w . j  a  v  a  2  s .c  o  m*/
@javax.annotation.Resource(name = "dataTypeImportOrder")
public void setDataTypeImportOrder(List<IPortalDataType> dataTypeImportOrder) {
    final ArrayList<PortalDataKey> dataKeyImportOrder = new ArrayList<PortalDataKey>(
            dataTypeImportOrder.size() * 2);
    final Map<PortalDataKey, IPortalDataType> dataKeyTypes = new LinkedHashMap<PortalDataKey, IPortalDataType>(
            dataTypeImportOrder.size() * 2);

    for (final IPortalDataType portalDataType : dataTypeImportOrder) {
        final List<PortalDataKey> supportedDataKeys = portalDataType.getDataKeyImportOrder();
        for (final PortalDataKey portalDataKey : supportedDataKeys) {
            dataKeyImportOrder.add(portalDataKey);
            dataKeyTypes.put(portalDataKey, portalDataType);
        }
    }

    dataKeyImportOrder.trimToSize();
    this.dataKeyImportOrder = Collections.unmodifiableList(dataKeyImportOrder);
    this.dataKeyTypes = Collections.unmodifiableMap(dataKeyTypes);
}

From source file:org.zaproxy.zap.control.AddOn.java

/**
 * Gets the extensions of this add-on that have dependencies and were loaded.
 *
 * @return an unmodifiable {@code List} with the extensions of this add-on that have dependencies and were loaded
 * @since 2.4.0//w w  w .  j  a va 2s .co  m
 */
public List<Extension> getLoadedExtensionsWithDeps() {
    List<String> classnames = getExtensionsWithDeps();
    ArrayList<Extension> loadedExtensions = new ArrayList<>(extensionsWithDeps.size());
    for (Extension extension : getLoadedExtensions()) {
        if (classnames.contains(extension.getClass().getCanonicalName())) {
            loadedExtensions.add(extension);
        }
    }
    loadedExtensions.trimToSize();
    return loadedExtensions;
}

From source file:org.opentripplanner.routing.edgetype.factory.InterliningTrip.java

private List<ShapePoint> getUniqueShapePointsForShapeId(AgencyAndId shapeId) {
    List<ShapePoint> points = _dao.getShapePointsForShapeId(shapeId);
    ArrayList<ShapePoint> filtered = new ArrayList<ShapePoint>(points.size());
    ShapePoint last = null;/*from w  ww.  ja  v  a2 s. com*/
    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;
    }
}

From source file:org.lockss.config.Tdb.java

/**
 * Get the linked titles for the specified link type.
 * //from   w  w w  .j  a  va 2  s .c om
 * @param linkType the link type (see {@link TdbTitle} for description of
 * link types)
 * @param title the TdbTitle with links
 * @return a collection of linked titles for the specified type 
 */
public Collection<TdbTitle> getLinkedTdbTitlesForType(TdbTitle.LinkType linkType, TdbTitle title) {
    if (linkType == null) {
        throw new IllegalArgumentException("linkType cannot be null");
    }
    if (title == null) {
        throw new IllegalArgumentException("title cannot be null");
    }
    Collection<String> titleIds = title.getLinkedTdbTitleIdsForType(linkType);
    if (titleIds.isEmpty()) {
        return Collections.emptyList();
    }
    ArrayList<TdbTitle> titles = new ArrayList<TdbTitle>();
    for (String titleId : titleIds) {
        TdbTitle aTitle = getTdbTitleById(titleId);
        if (aTitle != null) {
            titles.add(aTitle);
        }
    }
    titles.trimToSize();
    return titles;
}

From source file:org.zaproxy.zap.extension.zest.ExtensionZest.java

private List<Path> getDefaultTemplates() {
    AddOn addOn = getAddOn();/*from w ww. ja  va2 s  .c o m*/
    if (addOn == null) {
        // Probably running from source...
        return Collections.emptyList();
    }

    List<String> files = addOn.getFiles();
    if (files == null || files.isEmpty()) {
        return Collections.emptyList();
    }

    ArrayList<Path> defaultTemplates = new ArrayList<>(files.size());
    Path zapHome = Paths.get(Constant.getZapHome());
    for (String file : files) {
        if (file.startsWith(ExtensionScript.TEMPLATES_DIR)) {
            defaultTemplates.add(zapHome.resolve(file));
        }
    }
    defaultTemplates.trimToSize();
    return defaultTemplates;
}