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

/**
 * Trims all <code>Lists</code> (takes ~0.3 seconds and frees up 2mb).
 *//* www.  j  a  v a 2 s  . co  m*/
protected void trimAll() {
    // trim Synsets, which trim LexUnits
    for (Synset sset : synsets) {
        sset.trimAll();
    }

    // trim lists in wordCategoryMap
    HashMap<String, ArrayList<LexUnit>> map;
    for (WordCategory wc : WordCategory.values()) {
        map = wordCategoryMap.get(wc);
        for (ArrayList<LexUnit> luList : map.values()) {
            luList.trimToSize();
        }
    }
}

From source file:org.parosproxy.paros.db.paros.ParosTableHistory.java

/**
 * Gets all the history record IDs of the given session and with the given history types.
 *
 * @param sessionId the ID of session of the history records
 * @param histTypes the history types of the history records that should be returned
 * @return a {@code List} with all the history IDs of the given session and history types, never {@code null}
 * @throws DatabaseException if an error occurred while getting the history IDs
 * @since 2.3.0//from   w  w  w .  j  a v  a2  s.co  m
 * @see #getHistoryIds(long)
 * @see #getHistoryIdsExceptOfHistType(long, int...)
 */
@Override
public List<Integer> getHistoryIdsOfHistType(long sessionId, int... histTypes) throws DatabaseException {
    try {
        boolean hasHistTypes = histTypes != null && histTypes.length > 0;
        int strLength = hasHistTypes ? 97 : 68;
        StringBuilder strBuilder = new StringBuilder(strLength);
        strBuilder.append("SELECT ").append(HISTORYID);
        strBuilder.append(" FROM ").append(TABLE_NAME).append(" WHERE ").append(SESSIONID).append(" = ?");
        if (hasHistTypes) {
            strBuilder.append(" AND ").append(HISTTYPE).append(" IN ( UNNEST(?) )");
        }
        strBuilder.append(" ORDER BY ").append(HISTORYID);

        try (PreparedStatement psReadSession = getConnection().prepareStatement(strBuilder.toString())) {

            psReadSession.setLong(1, sessionId);
            if (hasHistTypes) {
                Array arrayHistTypes = getConnection().createArrayOf("INTEGER", ArrayUtils.toObject(histTypes));
                psReadSession.setArray(2, arrayHistTypes);
            }
            try (ResultSet rs = psReadSession.executeQuery()) {
                ArrayList<Integer> ids = new ArrayList<>();
                while (rs.next()) {
                    ids.add(Integer.valueOf(rs.getInt(HISTORYID)));
                }
                ids.trimToSize();

                return ids;
            }
        }
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}

From source file:org.parosproxy.paros.db.paros.ParosTableHistory.java

/**
 * Returns all the history record IDs of the given session except the ones with the given history types.
 ** /*from   ww  w  .java 2s  .  c o m*/
 * @param sessionId the ID of session of the history records
 * @param histTypes the history types of the history records that should be excluded
 * @return a {@code List} with all the history IDs of the given session and history types, never {@code null}
 * @throws DatabaseException if an error occurred while getting the history IDs
 * @since 2.3.0
 * @see #getHistoryIdsOfHistType(long, int...)
 */
@Override
public List<Integer> getHistoryIdsExceptOfHistType(long sessionId, int... histTypes) throws DatabaseException {
    try {
        boolean hasHistTypes = histTypes != null && histTypes.length > 0;
        int strLength = hasHistTypes ? 102 : 68;
        StringBuilder sb = new StringBuilder(strLength);
        sb.append("SELECT ").append(HISTORYID);
        sb.append(" FROM ").append(TABLE_NAME).append(" WHERE ").append(SESSIONID).append(" = ?");
        if (hasHistTypes) {
            sb.append(" AND ").append(HISTTYPE).append(" NOT IN ( UNNEST(?) )");
        }
        sb.append(" ORDER BY ").append(HISTORYID);

        try (PreparedStatement psReadSession = getConnection().prepareStatement(sb.toString())) {

            psReadSession.setLong(1, sessionId);
            if (hasHistTypes) {
                Array arrayHistTypes = getConnection().createArrayOf("INTEGER", ArrayUtils.toObject(histTypes));
                psReadSession.setArray(2, arrayHistTypes);
            }
            try (ResultSet rs = psReadSession.executeQuery()) {
                ArrayList<Integer> ids = new ArrayList<>();
                while (rs.next()) {
                    ids.add(Integer.valueOf(rs.getInt(HISTORYID)));
                }
                ids.trimToSize();

                return ids;
            }
        }
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}

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

/**
 * Returns a <code>List</code> of all <code>LexUnits</code>.
 * @return a <code>List</code> of all <code>LexUnits</code>
 *//*from w w  w.  j av a  2 s .co m*/
public List<LexUnit> getLexUnits() {
    ArrayList<LexUnit> rval = new ArrayList<LexUnit>();

    for (WordCategory wc : WordCategory.values()) {
        rval.addAll(getLexUnits(wc));
    }
    rval.trimToSize();
    return rval;
}

From source file:org.lockss.plugin.definable.DefinableArchivalUnit.java

CrawlRule makeRule0() throws LockssRegexpException {
    Object rule = definitionMap.getMapElement(KEY_AU_CRAWL_RULES);

    if (rule instanceof String) {
        CrawlRuleFromAuFactory fact = (CrawlRuleFromAuFactory) newAuxClass((String) rule,
                CrawlRuleFromAuFactory.class);
        return fact.createCrawlRule(this);
    }/*from www. ja  va  2s .c o  m*/
    ArrayList rules = null;
    if (rule instanceof List) {
        List<String> templates = (List<String>) rule;
        rules = new ArrayList(templates.size());
        for (String rule_template : templates) {
            CrawlRule cr = convertRule(rule_template, isCaseIndependentCrawlRules());
            if (cr != null) {
                rules.add(cr);
            }
        }
        rules.trimToSize();

        if (rules.size() > 0) {
            return new CrawlRules.FirstMatch(rules);
        } else {
            log.error("No crawl rules found for plugin: " + makeName());
            return null;
        }
    }
    return null;
}

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

/**
 * Returns a <code>List</code> of all <code>Synsets</code> in the specified
 * <code>wordClass</code>.//from   ww w .  ja v  a2s  . co  m
 * @param wordClass the <code>WordClass</code>, for example
 * <code>WordCategory.Menge</code>
 * @return a <code>List</code> of all <code>Synsets</code> in the specified
 * <code>wordClass</code>. If no <code>Synsets</code> were found, this is
 * a <code>List</code> containing no <code>Synsets</code>.
 */
public List<Synset> getSynsets(WordClass wordClass) {

    ArrayList<Synset> rval = new ArrayList<Synset>();

    for (Synset syn : synsets) {
        if (syn.getWordClass() == wordClass) {
            rval.add(syn);
        }
    }
    rval.trimToSize();
    return rval;
}

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

/**
 * Returns a <code>List</code> of all <code>Synsets</code> in the specified
 * <code>wordCategory</code>.
 * @param wordCategory the <code>WordCategory</code>, for example
 * <code>WordCategory.nomen</code>
 * @return a <code>List</code> of all <code>Synsets</code> in the specified
 * <code>wordCategory</code>. If no <code>Synsets</code> were found, this is
 * a <code>List</code> containing no <code>Synsets</code>.
 *///from  ww w.  j  ava2 s  .c  o  m
public List<Synset> getSynsets(WordCategory wordCategory) {

    ArrayList<Synset> rval = new ArrayList<Synset>();

    for (Synset syn : synsets) {
        if (syn.getWordCategory() == wordCategory) {
            rval.add(syn);
        }
    }
    rval.trimToSize();
    return rval;
}

From source file:pltag.parser.Chart.java

public void compressSlice(int i) {
    if (i < 0) {
        return;//w w  w . ja v  a 2s.  co  m
    }
    ArrayList<ChartEntry> slice = treeStateListArray.get(i);
    int size = slice.size();
    for (int j = size - 1; j >= 0; j--) {
        ChartEntry ce = slice.get(j);
        if (!ce.wasUsed()) {
            for (BuildBlock b : ce.getBuildBlocks()) {
                b = null;
            }
            slice.remove(ce);
            //chartEntrySorter.remove(ce);
        } else {
            ce.minimizeSpace();
        }
    }
    slice.trimToSize();
    if (opts.aggregate) {
        chartEntrySorter.clear();
    }
}

From source file:pcgen.core.Globals.java

/**
 * Finds all PObjects that match the passed in type.  All the types listed
 * in aType must match for the object to be returned.
 * @param aPObjectList List of PObjects to search
 * @param aType A "." separated list of TYPEs to match
 * @return List of PObjects matching all TYPEs
 *//* w  ww  .j  a va 2 s.c om*/
public static <T extends CDOMObject> List<T> getPObjectsOfType(final Collection<T> aPObjectList,
        final String aType) {
    final ArrayList<T> ret = new ArrayList<T>(aPObjectList.size());

    List<String> typeList = new ArrayList<String>();
    StringTokenizer tok = new StringTokenizer(aType, ".");
    while (tok.hasMoreTokens()) {
        typeList.add(tok.nextToken());
    }

    for (T anObject : aPObjectList) {
        boolean match = false;
        for (String type : typeList) {
            final boolean sense = !(type.charAt(0) == '!');
            if (anObject.isType(type) == sense) {
                match = true;
            } else {
                match = false;
                break;
            }
        }
        if (match) {
            ret.add(anObject);
        }
    }
    ret.trimToSize();
    return ret;
}

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

/**
 * Return the TdbAu for with the specified TdbAu volume.
 * //from w  w  w. java2  s. c om
 * @param tdbAuYear the year of the AU to select
 * @return the TdbAu for the specified name
 */
public Collection<TdbAu> getTdbAusByYear(String tdbAuYear) {
    ArrayList<TdbAu> aus = new ArrayList<TdbAu>();
    for (TdbAu tdbAu : tdbAus.values()) {
        if ((tdbAuYear == null) || tdbAu.includesYear(tdbAuYear)) {
            aus.add(tdbAu);
        }
    }
    aus.trimToSize();
    return aus;
}