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:org.lockss.config.TdbTitle.java

/**
 * Return the TdbAus for with the specified TdbAu volume.
 * /*  ww w.  ja  v a  2s . c om*/
 * @param tdbAuVolume the volume of the AU to select
 * @return the TdbAu for the specified name
 */
public Collection<TdbAu> getTdbAusByVolume(String tdbAuVolume) {
    ArrayList<TdbAu> aus = new ArrayList<TdbAu>();
    for (TdbAu tdbAu : tdbAus.values()) {
        if ((tdbAuVolume == null) || tdbAu.includesVolume(tdbAuVolume)) {
            aus.add(tdbAu);
        }
    }
    aus.trimToSize();
    return aus;
}

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

/**
 * Returns a <code>List</code> of all <code>LexUnits</code> in which
 * <code>orthForm</code> occurs as main orthographical form -- in case
 * <code>considerAllOrthForms</code> is true. Else returns a
 * <code>List</code> of all <code>LexUnits</code> in which
 * <code>orthForm</code> occurs as main orthographical form, as
 * orthographical variant, as old orthographical form, or as old
 * orthographic variant -- in case/*from w w w.  j  av a  2s.c om*/
 * <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>LexUnits</code> containing
 * <code>orthForm</code>. If no <code>LexUnits</code> were found, this is a
 * <code>List</code> containing no <code>LexUnits</code>.
 */
public List<LexUnit> getLexUnits(String orthForm, boolean considerMainOrthFormOnly) {
    ArrayList<LexUnit> rval = new ArrayList<LexUnit>();

    // get LexUnits from each word class
    for (WordCategory wc : WordCategory.values()) {
        rval.addAll(getLexUnits(orthForm, wc, considerMainOrthFormOnly));
    }
    rval.trimToSize();
    return rval;
}

From source file:com.flexive.ejb.beans.ACLEngineBean.java

/**
 * {@inheritDoc}// www . j  av a 2  s .c  o  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<ACLAssignment> loadAssignments(Long aclId, Long groupId) throws FxApplicationException {
    Connection con = null;
    Statement stmt = null;
    String curSql;
    UserTicket ticket = FxContext.getUserTicket();

    // Permission & Exists check
    checkPermissions(ticket, groupId, aclId, false);
    try {
        // Obtain a database connection
        con = Database.getDbConnection();

        // load assignments
        //                   1             2       3         4         5           6           7
        curSql = "SELECT ass.USERGROUP,ass.ACL,ass.PREAD,ass.PEDIT,ass.PREMOVE,ass.PEXPORT,ass.PREL," +
        //   8        ,      9        10             11             12              13
                "ass.PCREATE,acl.CAT_TYPE,ass.CREATED_BY,ass.CREATED_AT,ass.MODIFIED_BY,ass.MODIFIED_AT "
                + "FROM " + TBL_ACLS_ASSIGNMENT + " ass, " + TBL_ACLS + " acl WHERE " + "ass.ACL=acl.ID AND "
                + ((groupId != null) ? "USERGROUP=" + groupId : "")
                + ((groupId != null && aclId != null) ? " AND " : "") + ((aclId != null) ? "ACL=" + aclId : "");

        stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(curSql);

        // Read the data
        ArrayList<ACLAssignment> result = new ArrayList<ACLAssignment>(20);
        while (rs != null && rs.next())
            result.add(new ACLAssignment(rs.getLong(2), rs.getLong(1), rs.getBoolean(3), rs.getBoolean(4),
                    rs.getBoolean(7), rs.getBoolean(5), rs.getBoolean(6), rs.getBoolean(8),
                    ACLCategory.getById(rs.getByte(9)), LifeCycleInfoImpl.load(rs, 10, 11, 12, 13)));

        // Return the found entries
        result.trimToSize();
        return result;
    } catch (SQLException exc) {
        throw new FxLoadException(LOG, exc, "ex.aclAssignment.loadFailed");
    } finally {
        Database.closeObjects(ACLEngineBean.class, con, stmt);
    }
}

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

protected List<String> convertUrlList(List<String> printfStrings, String key) {
    if (printfStrings == null) {
        return null;
    }//from ww w  .  j a v  a2 s .c o  m
    // Just a guess; each printf may generate more than one URL
    ArrayList<String> res = new ArrayList<String>(printfStrings.size());
    for (String pattern : printfStrings) {
        if (StringUtil.isNullString(pattern)) {
            log.warning("Null pattern string in " + key);
            continue;
        }
        List<String> lst = convertUrlList(pattern);
        if (lst == null) {
            log.warning("Null converted string in " + key + ", from " + pattern);
            continue;
        }
        res.addAll(lst);
    }
    res.trimToSize();
    return res;
}

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

/**
 * Returns a <code>List</code> of all <code>LexUnits</code> in the specified
 * <code>wordCategory</code>.
 * @param wordCategory the <code>WordCategory</code>, (e.g.
 * <code>WordCategory.verben</code>)
 * @return a <code>List</code> of all <code>LexUnits</code> in the specified
 * <code>wordCategory</code>. If no <code>LexUnits</code> were found, this
 * is a <code>List</code> containing no <code>LexUnits</code>.
 *//*from   w ww.j  a  va2  s  .c  o  m*/
public List<LexUnit> getLexUnits(WordCategory wordCategory) {
    ArrayList<LexUnit> rval = new ArrayList<LexUnit>();
    HashMap<String, ArrayList<LexUnit>> map;
    map = wordCategoryMap.get(wordCategory);

    for (ArrayList<LexUnit> luList : map.values()) {
        rval.addAll((ArrayList<LexUnit>) luList.clone());
    }
    rval.trimToSize();
    return rval;
}

From source file:org.zaproxy.zap.extension.invoke.InvokeParam.java

public void setListInvoke(List<InvokableApp> listInvoke) {
    this.listInvoke = listInvoke;

    ((HierarchicalConfiguration) getConfig()).clearTree(ALL_APPS_KEY);

    ArrayList<InvokableApp> enabledApps = new ArrayList<>(listInvoke.size());
    for (int i = 0, size = listInvoke.size(); i < size; ++i) {
        String elementBaseKey = ALL_APPS_KEY + "(" + i + ").";
        InvokableApp app = listInvoke.get(i);

        getConfig().setProperty(elementBaseKey + APP_NAME_KEY, app.getDisplayName());
        File file = app.getWorkingDirectory();
        getConfig().setProperty(elementBaseKey + APP_DIRECTORY_KEY, file != null ? file.getAbsolutePath() : "");
        getConfig().setProperty(elementBaseKey + APP_COMMAND_KEY, app.getFullCommand());
        getConfig().setProperty(elementBaseKey + APP_PARAMS_KEY, app.getParameters());
        getConfig().setProperty(elementBaseKey + APP_OUTPUT_KEY, Boolean.valueOf(app.isCaptureOutput()));
        getConfig().setProperty(elementBaseKey + APP_NOTE_KEY, Boolean.valueOf(app.isOutputNote()));

        getConfig().setProperty(elementBaseKey + APP_ENABLED_KEY, Boolean.valueOf(app.isEnabled()));

        if (app.isEnabled()) {
            enabledApps.add(app);/* w  w w . jav  a 2 s  .c  om*/
        }
    }

    enabledApps.trimToSize();
    this.listInvokeEnabled = enabledApps;
}

From source file:FastArrayList.java

/**
 * Trim the capacity of this <code>ArrayList</code> instance to be the
 * list's current size.  An application can use this operation to minimize
 * the storage of an <code>ArrayList</code> instance.
 *///w  w w  .j av a2s .co m
public void trimToSize() {

    if (fast) {
        synchronized (this) {
            ArrayList temp = (ArrayList) list.clone();
            temp.trimToSize();
            list = temp;
        }
    } else {
        synchronized (list) {
            list.trimToSize();
        }
    }

}

From source file:org.apache.hadoop.hbase.replication.TableCfWALEntryFilter.java

@Override
public Entry filter(Entry entry) {
    TableName tabName = entry.getKey().getTablename();
    ArrayList<Cell> cells = entry.getEdit().getCells();
    Map<TableName, List<String>> tableCFs = null;

    try {//  w  ww. j  a v a  2  s .  c  o m
        tableCFs = this.peer.getTableCFs();
    } catch (IllegalArgumentException e) {
        LOG.error("should not happen: can't get tableCFs for peer " + peer.getId()
                + ", degenerate as if it's not configured by keeping tableCFs==null");
    }
    int size = cells.size();

    // return null(prevent replicating) if logKey's table isn't in this peer's
    // replicable table list (empty tableCFs means all table are replicable)
    if (tableCFs != null && !tableCFs.containsKey(tabName)) {
        return null;
    } else {
        List<String> cfs = (tableCFs == null) ? null : tableCFs.get(tabName);
        for (int i = size - 1; i >= 0; i--) {
            Cell cell = cells.get(i);
            // ignore(remove) kv if its cf isn't in the replicable cf list
            // (empty cfs means all cfs of this table are replicable)
            if ((cfs != null && !cfs.contains(Bytes.toString(CellUtil.cloneFamily(cell))))) {
                cells.remove(i);
            }
        }
    }
    if (cells.size() < size / 2) {
        cells.trimToSize();
    }
    return entry;
}

From source file:gov.nih.nci.caintegrator.application.gpvisualizer.CaIntegratorRunVisualizer.java

protected String[] doCommandLineSubstitutions() throws IOException {
    // do input argument substitution in command line
    String commandLine = (String) params.get(RunVisualizerConstants.COMMAND_LINE);

    HashMap hmDownloadables = downloadInputURLs();

    StringTokenizer stCmd = new StringTokenizer(commandLine, " ");
    ArrayList cmdArray = new ArrayList(stCmd.countTokens());
    int c = 0;//  ww  w . j a va  2  s.com
    while (stCmd.hasMoreTokens()) {
        cmdArray.add(stCmd.nextToken());
    }

    // replace variables in the command line from System.properties and the
    // params HashMap
    for (c = 0; c < cmdArray.size(); c++) {
        String cmd = (String) cmdArray.get(c);
        cmd = variableSubstitution(cmd, hmDownloadables);
        cmdArray.set(c, cmd);
        // if there is nothing in a slot after substitutions, delete the
        // slot entirely
        if (cmd.length() == 0) {
            cmdArray.remove(c);
            c--;
        }
    }
    cmdArray.trimToSize();
    return (String[]) cmdArray.toArray(new String[0]);
}

From source file:org.apache.hadoop.hbase.replication.ScopeWALEntryFilter.java

@Override
public Entry filter(Entry entry) {
    NavigableMap<byte[], Integer> scopes = entry.getKey().getReplicationScopes();
    if (scopes == null || scopes.isEmpty()) {
        return null;
    }//from w w w .j av a  2s.c o  m
    ArrayList<Cell> cells = entry.getEdit().getCells();
    int size = cells.size();
    byte[] fam;
    for (int i = size - 1; i >= 0; i--) {
        Cell cell = cells.get(i);
        // If a bulk load entry has a scope then that means user has enabled replication for bulk load
        // hfiles.
        // TODO There is a similar logic in TableCfWALEntryFilter but data structures are different so
        // cannot refactor into one now, can revisit and see if any way to unify them.
        if (CellUtil.matchingColumn(cell, WALEdit.METAFAMILY, WALEdit.BULK_LOAD)) {
            Cell filteredBulkLoadEntryCell = filterBulkLoadEntries(scopes, cell);
            if (filteredBulkLoadEntryCell != null) {
                cells.set(i, filteredBulkLoadEntryCell);
            } else {
                cells.remove(i);
            }
        } else {
            // The scope will be null or empty if
            // there's nothing to replicate in that WALEdit
            fam = CellUtil.cloneFamily(cell);
            if (!scopes.containsKey(fam) || scopes.get(fam) == HConstants.REPLICATION_SCOPE_LOCAL) {
                cells.remove(i);
            }
        }
    }
    if (cells.size() < size / 2) {
        cells.trimToSize();
    }
    return entry;
}