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.zaproxy.zap.control.AddOnLoader.java

/**
 * Gets the active scan rules of all the loaded add-ons.
 * <p>//from   www .j a va 2 s . com
 * The discovery of active scan rules is done by resorting to {@code ZapAddOn.xml} file bundled in the add-ons.
 *
 * @return an unmodifiable {@code List} with all the active scan rules, never {@code null}
 * @since 2.4.0
 * @see AbstractPlugin
 */
public List<AbstractPlugin> getActiveScanRules() {
    ArrayList<AbstractPlugin> list = new ArrayList<>();
    for (AddOn addOn : getAddOnCollection().getAddOns()) {
        AddOnClassLoader addOnClassLoader = this.addOnLoaders.get(addOn.getId());
        if (addOnClassLoader != null) {
            list.addAll(AddOnLoaderUtils.getActiveScanRules(addOn, addOnClassLoader));
        }
    }
    list.trimToSize();
    return Collections.unmodifiableList(list);
}

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

/**
 * Gets the passive scan rules of all the loaded add-ons.
 * <p>/*from w  w w  .  j  av  a 2 s .  c o  m*/
 * The discovery of passive scan rules is done by resorting to {@code ZapAddOn.xml} file bundled in the add-ons.
 *
 * @return an unmodifiable {@code List} with all the passive scan rules, never {@code null}
 * @since 2.4.0
 * @see PluginPassiveScanner
 */
public List<PluginPassiveScanner> getPassiveScanRules() {
    ArrayList<PluginPassiveScanner> list = new ArrayList<>();
    for (AddOn addOn : getAddOnCollection().getAddOns()) {
        AddOnClassLoader addOnClassLoader = this.addOnLoaders.get(addOn.getId());
        if (addOnClassLoader != null) {
            list.addAll(AddOnLoaderUtils.getPassiveScanRules(addOn, addOnClassLoader));
        }
    }
    list.trimToSize();
    return Collections.unmodifiableList(list);
}

From source file:net.sf.farrago.namespace.sfdc.SfdcDataServer.java

private Object[] updateRowType(FarragoTypeFactory typeFactory, RelDataType currRowType,
        RelDataType srcRowType) {/*from w  w w  .j a  v  a2 s  .c  o  m*/
    String fieldNames = "";
    String typeNames = "";
    ArrayList fieldsVector = new ArrayList();
    ArrayList typesVector = new ArrayList();

    HashMap<String, RelDataType> srcMap = new HashMap();
    for (RelDataTypeField srcField : srcRowType.getFieldList()) {
        srcMap.put(srcField.getName(), srcField.getType());
    }

    for (RelDataTypeField currField : currRowType.getFieldList()) {
        RelDataType type;
        if (((type = srcMap.get(currField.getName())) != null)
                && SqlTypeUtil.canCastFrom(currField.getType(), type, true)) {
            if (fieldNames.equals("")) {
                fieldNames = currField.getName();
                typeNames = type.toString();
            } else {
                fieldNames = fieldNames.concat(",").concat(currField.getName());
                typeNames = typeNames.concat(",").concat(type.toString());
            }
            fieldsVector.add(currField.getName());
            typesVector.add(type);
        }
    }

    typesVector.trimToSize();
    fieldsVector.trimToSize();
    RelDataType[] types = (RelDataType[]) typesVector.toArray(new RelDataType[typesVector.size()]);
    String[] fields = (String[]) fieldsVector.toArray(new String[fieldsVector.size()]);

    RelDataType rowType = createRowType(typeFactory, types, fields);
    return new Object[] { rowType, fieldNames, typeNames };
}

From source file:org.zaproxy.zap.extension.replacer.ReplacerParam.java

private void saveRules() {

    ((HierarchicalConfiguration) getConfig()).clearTree(ALL_RULES_KEY);

    ArrayList<String> enabledTokens = new ArrayList<>(rules.size());
    for (int i = 0, size = rules.size(); i < size; ++i) {
        String elementBaseKey = ALL_RULES_KEY + "(" + i + ").";
        ReplacerParamRule rule = rules.get(i);

        getConfig().setProperty(elementBaseKey + RULE_DESCRIPTION_KEY, rule.getDescription());
        getConfig().setProperty(elementBaseKey + RULE_ENABLED_KEY, Boolean.valueOf(rule.isEnabled()));
        getConfig().setProperty(elementBaseKey + RULE_MATCH_TYPE_KEY, rule.getMatchType().name());
        getConfig().setProperty(elementBaseKey + RULE_MATCH_STRING_KEY, rule.getMatchString());
        getConfig().setProperty(elementBaseKey + RULE_REGEX_KEY, Boolean.valueOf(rule.isMatchRegex()));
        getConfig().setProperty(elementBaseKey + RULE_REPLACEMENT_KEY, rule.getReplacement());
        List<Integer> initiators = rule.getInitiators();
        if (initiators == null || initiators.isEmpty()) {
            getConfig().setProperty(elementBaseKey + RULE_INITIATORS_KEY, "");
        } else {/* w  w w.j ava2 s  .c om*/
            getConfig().setProperty(elementBaseKey + RULE_INITIATORS_KEY, initiators.toString());
        }

        if (rule.isEnabled()) {
            enabledTokens.add(rule.getDescription());
        }
    }

    enabledTokens.trimToSize();
}

From source file:org.parosproxy.paros.network.ConnectionParam.java

/**
 * Sets the domains that will be excluded from the outgoing proxy.
 * /*  w  w  w.j av  a 2  s  .  co m*/
 * @param proxyExcludedDomains the domains that will be excluded.
 * @since 2.3.0
 * @see #getProxyExcludedDomains()
 * @see #getProxyExcludedDomainsEnabled()
 */
public void setProxyExcludedDomains(List<ProxyExcludedDomainMatcher> proxyExcludedDomains) {
    if (proxyExcludedDomains == null || proxyExcludedDomains.isEmpty()) {
        ((HierarchicalConfiguration) getConfig()).clearTree(ALL_PROXY_EXCLUDED_DOMAINS_KEY);

        this.proxyExcludedDomains = Collections.emptyList();
        this.proxyExcludedDomainsEnabled = Collections.emptyList();
        return;
    }

    this.proxyExcludedDomains = new ArrayList<>(proxyExcludedDomains);

    ((HierarchicalConfiguration) getConfig()).clearTree(ALL_PROXY_EXCLUDED_DOMAINS_KEY);

    int size = proxyExcludedDomains.size();
    ArrayList<ProxyExcludedDomainMatcher> enabledExcludedDomains = new ArrayList<>(size);
    for (int i = 0; i < size; ++i) {
        String elementBaseKey = ALL_PROXY_EXCLUDED_DOMAINS_KEY + "(" + i + ").";
        ProxyExcludedDomainMatcher excludedDomain = proxyExcludedDomains.get(i);

        getConfig().setProperty(elementBaseKey + PROXY_EXCLUDED_DOMAIN_VALUE_KEY, excludedDomain.getValue());
        getConfig().setProperty(elementBaseKey + PROXY_EXCLUDED_DOMAIN_REGEX_KEY,
                Boolean.valueOf(excludedDomain.isRegex()));
        getConfig().setProperty(elementBaseKey + PROXY_EXCLUDED_DOMAIN_ENABLED_KEY,
                Boolean.valueOf(excludedDomain.isEnabled()));

        if (excludedDomain.isEnabled()) {
            enabledExcludedDomains.add(excludedDomain);
        }
    }

    enabledExcludedDomains.trimToSize();
    this.proxyExcludedDomainsEnabled = enabledExcludedDomains;
}

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

@Override
protected void parse() {
    listInvoke.clear();//w w  w .  j  a v a  2  s . co  m

    ArrayList<InvokableApp> enabledApps = null;
    try {
        List<HierarchicalConfiguration> fields = ((HierarchicalConfiguration) getConfig())
                .configurationsAt(ALL_APPS_KEY);
        this.listInvoke = new ArrayList<>(fields.size());
        enabledApps = new ArrayList<>(fields.size());
        List<String> tempListNames = new ArrayList<>(fields.size());
        for (HierarchicalConfiguration sub : fields) {
            String name = sub.getString(APP_NAME_KEY, "");
            if (!"".equals(name) && !tempListNames.contains(name)) {
                tempListNames.add(name);

                File dir = null;
                String directory = sub.getString(APP_DIRECTORY_KEY, "");
                if (directory.length() > 0) {
                    dir = new File(directory);
                }

                InvokableApp app = new InvokableApp(name, dir, sub.getString(APP_COMMAND_KEY),
                        sub.getString(APP_PARAMS_KEY), sub.getBoolean(APP_OUTPUT_KEY, true),
                        sub.getBoolean(APP_NOTE_KEY, false));

                app.setEnabled(sub.getBoolean(APP_ENABLED_KEY, true));

                listInvoke.add(app);

                if (app.isEnabled()) {
                    enabledApps.add(app);
                }
            }
        }
        enabledApps.trimToSize();
        this.listInvokeEnabled = enabledApps;
    } catch (ConversionException e) {
        logger.error("Error while loading invoke applications: " + e.getMessage(), e);
    }

    try {
        this.confirmRemoveApp = getConfig().getBoolean(CONFIRM_REMOVE_APP_KEY, true);
    } catch (ConversionException e) {
        logger.error("Error while loading the confirm remove option: " + e.getMessage(), e);
    }
}

From source file:org.zaproxy.zap.extension.websocket.db.TableWebSocket.java

private List<WebSocketChannelDTO> buildChannelDTOs(ResultSet rs) throws SQLException {
    ArrayList<WebSocketChannelDTO> channels = new ArrayList<>();
    try {//from   ww  w . ja v a 2  s.c o m
        while (rs.next()) {
            WebSocketChannelDTO channel = new WebSocketChannelDTO();
            channel.id = rs.getInt("channel_id");
            channel.host = rs.getString("host");
            channel.port = rs.getInt("port");
            channel.url = rs.getString("url");
            channel.startTimestamp = rs.getTimestamp("start_timestamp").getTime();

            Time endTs = rs.getTime("end_timestamp");
            channel.endTimestamp = (endTs != null) ? endTs.getTime() : null;

            channel.historyId = rs.getInt("history_id");

            channels.add(channel);
        }
    } finally {
        rs.close();
    }

    channels.trimToSize();

    return channels;
}

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

/**
 * Returns a <code>List</code> of all <code>Synsets</code> with the
 * specified <code>WordCategory</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 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 be found
 * @param wordCategory the <code>WordCategory</code> of the
 * <code>Synsets</code> to be found (e.g. <code>WordCategory.adj</code>)
 * @param considerMainOrthFormOnly considering main orthographical form only
 * (<code>true</code>) or all variants (<code>false</code>)
 * @return a <code>List</code> of <code>Synsets</code> with the specified
 * <code>orthForm</code> and <code>wordCategory</code>.
 *///from   w  ww.java  2  s .  co m
public List<Synset> getSynsets(String orthForm, WordCategory wordCategory, boolean considerMainOrthFormOnly) {
    /*
     * This method can probably be removed since it is very rare that
     * an orthForm is contained in more than one word class
     */
    ArrayList<Synset> rval = new ArrayList<Synset>();
    HashMap<String, ArrayList<LexUnit>> map;
    List<LexUnit> tmpList;

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

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

From source file:org.zaproxy.zap.spider.SpiderParam.java

/**
 * Sets the domains that will be always in scope.
 * //w ww  .j a va  2s  .co  m
 * @param domainsAlwaysInScope the domains that will be excluded.
 * @since 2.3.0
 */
public void setDomainsAlwaysInScope(List<DomainAlwaysInScopeMatcher> domainsAlwaysInScope) {
    if (domainsAlwaysInScope == null || domainsAlwaysInScope.isEmpty()) {
        ((HierarchicalConfiguration) getConfig()).clearTree(ALL_DOMAINS_ALWAYS_IN_SCOPE_KEY);

        this.domainsAlwaysInScope = Collections.emptyList();
        this.domainsAlwaysInScopeEnabled = Collections.emptyList();
        return;
    }

    this.domainsAlwaysInScope = new ArrayList<>(domainsAlwaysInScope);

    ((HierarchicalConfiguration) getConfig()).clearTree(ALL_DOMAINS_ALWAYS_IN_SCOPE_KEY);

    int size = domainsAlwaysInScope.size();
    ArrayList<DomainAlwaysInScopeMatcher> enabledExcludedDomains = new ArrayList<>(size);
    for (int i = 0; i < size; ++i) {
        String elementBaseKey = ALL_DOMAINS_ALWAYS_IN_SCOPE_KEY + "(" + i + ").";
        DomainAlwaysInScopeMatcher excludedDomain = domainsAlwaysInScope.get(i);

        getConfig().setProperty(elementBaseKey + DOMAIN_ALWAYS_IN_SCOPE_VALUE_KEY, excludedDomain.getValue());
        getConfig().setProperty(elementBaseKey + DOMAIN_ALWAYS_IN_SCOPE_REGEX_KEY,
                Boolean.valueOf(excludedDomain.isRegex()));
        getConfig().setProperty(elementBaseKey + DOMAIN_ALWAYS_IN_SCOPE_ENABLED_KEY,
                Boolean.valueOf(excludedDomain.isEnabled()));

        if (excludedDomain.isEnabled()) {
            enabledExcludedDomains.add(excludedDomain);
        }
    }

    enabledExcludedDomains.trimToSize();
    this.domainsAlwaysInScopeEnabled = enabledExcludedDomains;
}

From source file:org.apache.zeppelin.spark.SparkInterpreter.java

private void setupConfForPySpark(SparkConf conf) {
    String pysparkBasePath = new InterpreterProperty("SPARK_HOME", null, null, null).getValue();
    File pysparkPath;// w w  w  . jav a 2s . c  om
    if (null == pysparkBasePath) {
        pysparkBasePath = new InterpreterProperty("ZEPPELIN_HOME", "zeppelin.home", "../", null).getValue();
        pysparkPath = new File(pysparkBasePath,
                "interpreter" + File.separator + "spark" + File.separator + "pyspark");
    } else {
        pysparkPath = new File(pysparkBasePath, "python" + File.separator + "lib");
    }

    //Only one of py4j-0.9-src.zip and py4j-0.8.2.1-src.zip should exist
    //TODO(zjffdu), this is not maintainable when new version is added.
    String[] pythonLibs = new String[] { "pyspark.zip", "py4j-0.9-src.zip", "py4j-0.8.2.1-src.zip",
            "py4j-0.10.1-src.zip", "py4j-0.10.3-src.zip", "py4j-0.10.4-src.zip" };
    ArrayList<String> pythonLibUris = new ArrayList<>();
    for (String lib : pythonLibs) {
        File libFile = new File(pysparkPath, lib);
        if (libFile.exists()) {
            pythonLibUris.add(libFile.toURI().toString());
        }
    }
    pythonLibUris.trimToSize();

    // Distribute two libraries(pyspark.zip and py4j-*.zip) to workers
    // when spark version is less than or equal to 1.4.1
    if (pythonLibUris.size() == 2) {
        try {
            String confValue = conf.get("spark.yarn.dist.files");
            conf.set("spark.yarn.dist.files", confValue + "," + Joiner.on(",").join(pythonLibUris));
        } catch (NoSuchElementException e) {
            conf.set("spark.yarn.dist.files", Joiner.on(",").join(pythonLibUris));
        }
        if (!useSparkSubmit()) {
            conf.set("spark.files", conf.get("spark.yarn.dist.files"));
        }
        conf.set("spark.submit.pyArchives", Joiner.on(":").join(pythonLibs));
        conf.set("spark.submit.pyFiles", Joiner.on(",").join(pythonLibUris));
    }

    // Distributes needed libraries to workers
    // when spark version is greater than or equal to 1.5.0
    if (isYarnMode()) {
        conf.set("spark.yarn.isPython", "true");
    }
}