List of usage examples for java.util ArrayList trimToSize
public void trimToSize()
From source file:phex.host.CaughtHostsContainer.java
public List<CaughtHost> getFreeUltrapeerSlotHosts() { synchronized (freeUltrapeerSlotSet) { ArrayList<CaughtHost> freeHosts = new ArrayList<>(freeUltrapeerSlotSet); freeHosts.trimToSize(); return freeHosts; }/*w ww . ja v a2 s. co m*/ }
From source file:org.lockss.config.TdbProvider.java
/** * Return the collection of TdbTitles for this provider * with the specified title name./*from w ww .java 2s. co m*/ * * @param titleName the title name * @return the set of TdbTitles with the specified title name */ public Collection<TdbTitle> getTdbTitlesByName(String titleName) { ArrayList<TdbTitle> matchTitles = new ArrayList<TdbTitle>(); getTdbTitlesByName(titleName, matchTitles); matchTitles.trimToSize(); return matchTitles; }
From source file:phex.common.Ip2CountryManager.java
private void loadIp2CountryDB() { InputStream inStream = ClassLoader.getSystemResourceAsStream("phex/resources/ip2country.csv"); if (inStream == null) { Logger.logMessage(Logger.FINE, Logger.NETWORK, "Default GWebCache file not found."); return;//from w ww . j a v a 2 s .c om } BufferedReader reader = new BufferedReader(new InputStreamReader(inStream)); ArrayList initialList = new ArrayList(5000); IpCountryRange range; String line; try { line = reader.readLine(); while (line != null) { range = new IpCountryRange(line); initialList.add(range); line = reader.readLine(); } } catch (IOException exp) { NLogger.error(NLoggerNames.GLOBAL, exp, exp); } finally { IOUtil.closeQuietly(reader); } initialList.trimToSize(); Collections.sort(initialList); ipCountryRangeList = UnmodifiableList.decorate(initialList); isLoaded = true; }
From source file:org.zaproxy.zap.extension.anticsrf.AntiCsrfParam.java
@ZapApiIgnore public void setTokens(List<AntiCsrfParamToken> tokens) { this.tokens = new ArrayList<>(tokens); ((HierarchicalConfiguration) getConfig()).clearTree(ALL_TOKENS_KEY); ArrayList<String> enabledTokens = new ArrayList<>(tokens.size()); for (int i = 0, size = tokens.size(); i < size; ++i) { String elementBaseKey = ALL_TOKENS_KEY + "(" + i + ")."; AntiCsrfParamToken token = tokens.get(i); getConfig().setProperty(elementBaseKey + TOKEN_NAME_KEY, token.getName()); getConfig().setProperty(elementBaseKey + TOKEN_ENABLED_KEY, Boolean.valueOf(token.isEnabled())); if (token.isEnabled()) { enabledTokens.add(token.getName()); }//ww w .j a v a 2s . c o m } enabledTokens.trimToSize(); this.enabledTokensNames = enabledTokens; }
From source file:org.zaproxy.zap.extension.httpsessions.HttpSessionsParam.java
/** * Sets the default tokens./*from w w w .ja va 2s . c o m*/ * * @param tokens the new default tokens */ public void setDefaultTokens(final List<HttpSessionToken> tokens) { this.defaultTokens = tokens; ((HierarchicalConfiguration) getConfig()).clearTree(ALL_DEFAULT_TOKENS_KEY); ArrayList<String> enabledTokens = new ArrayList<>(tokens.size()); for (int i = 0, size = tokens.size(); i < size; ++i) { String elementBaseKey = ALL_DEFAULT_TOKENS_KEY + "(" + i + ")."; HttpSessionToken token = tokens.get(i); getConfig().setProperty(elementBaseKey + TOKEN_NAME_KEY, token.getName()); getConfig().setProperty(elementBaseKey + TOKEN_ENABLED_KEY, Boolean.valueOf(token.isEnabled())); if (token.isEnabled()) { enabledTokens.add(token.getName()); } } enabledTokens.trimToSize(); this.defaultTokensEnabled = enabledTokens; }
From source file:org.zaproxy.zap.spider.SpiderParam.java
private static List<DomainAlwaysInScopeMatcher> convertOldDomainsInScopeOption(String oldDomainsInScope) { if (oldDomainsInScope == null || oldDomainsInScope.isEmpty()) { return Collections.emptyList(); }/*from ww w. jav a 2 s . c om*/ ArrayList<DomainAlwaysInScopeMatcher> domainsInScope = new ArrayList<>(); String[] names = oldDomainsInScope.split(";"); for (String name : names) { String domain = name.trim(); if (!domain.isEmpty()) { if (domain.contains("*")) { domain = domain.replace(".", "\\.").replace("+", "\\+").replace("*", ".*?"); try { Pattern pattern = Pattern.compile(name, Pattern.CASE_INSENSITIVE); domainsInScope.add(new DomainAlwaysInScopeMatcher(pattern)); } catch (IllegalArgumentException e) { log.error("Failed to migrate a domain always in scope, name: " + name, e); } } else { domainsInScope.add(new DomainAlwaysInScopeMatcher(domain)); } } } domainsInScope.trimToSize(); return domainsInScope; }
From source file:org.zaproxy.zap.control.BaseZapAddOnXmlData.java
protected List<String> getStrings(HierarchicalConfiguration zapAddOnXml, String element, String elementName) { String[] fields = zapAddOnXml.getStringArray(element); if (fields.length == 0) { return Collections.emptyList(); }// w w w. ja v a2 s .com ArrayList<String> strings = new ArrayList<>(fields.length); for (String field : fields) { if (!field.isEmpty()) { strings.add(field); } else { LOGGER.warn("Ignoring empty \"" + elementName + "\" entry in add-on \"" + name + "\"."); } } if (strings.isEmpty()) { return Collections.emptyList(); } strings.trimToSize(); return strings; }
From source file:edu.umn.se.trap.rule.businessrule.PersonalAndRentalCarRule.java
/** * @param expenses// ww w. j a va2s . c o m * @throws TrapException */ protected void checkCarRentals(List<Expense> expenses) throws TrapException { ArrayList<TransportationExpense> personal = new ArrayList<TransportationExpense>(expenses.size()); ArrayList<TransportationExpense> rental = new ArrayList<TransportationExpense>(expenses.size()); for (Expense expense : expenses) { if (expense.getType().equals(ExpenseType.TRANSPORTATION)) { if (StringUtils.equalsIgnoreCase(((TransportationExpense) expense).getTranportationType(), "Car")) { if (((TransportationExpense) expense).isRental()) { rental.add(((TransportationExpense) expense)); } else { personal.add(((TransportationExpense) expense)); } } } } personal.trimToSize(); rental.trimToSize(); if (rental.size() != 0 && personal.size() != 0) { for (TransportationExpense pcar : personal) { for (TransportationExpense rcar : rental) { if (TrapDateUtil.sameDay(pcar.getDate(), rcar.getDate())) { throw new TrapException(TrapErrors.PERSONAL_RENTAL_CAR); } } } } }
From source file:de.unisb.cs.st.javaslicer.traceResult.TraceResult.java
public TraceResult(File filename) throws IOException { final MultiplexedFileReader file = new MultiplexedFileReader(filename); if (file.getStreamIds().size() < 2) throw new IOException("corrupted data"); final MultiplexInputStream readClassesStream = file.getInputStream(0); if (readClassesStream == null) throw new IOException("corrupted data"); PushbackInputStream pushBackInput = new PushbackInputStream( new BufferedInputStream(new GZIPInputStream(readClassesStream, 512), 512), 1); final DataInputStream readClassesInputStream = new DataInputStream(pushBackInput); final ArrayList<ReadClass> readClasses0 = new ArrayList<ReadClass>(); final StringCacheInput stringCache = new StringCacheInput(); int testRead; while ((testRead = pushBackInput.read()) != -1) { pushBackInput.unread(testRead);/* w w w . j a v a 2 s . c o m*/ readClasses0.add(ReadClass.readFrom(readClassesInputStream, stringCache)); } readClasses0.trimToSize(); Collections.sort(readClasses0); this.readClasses = readClasses0; this.instructions = getInstructionArray(readClasses0); final MultiplexInputStream threadTracersStream = file.getInputStream(1); if (threadTracersStream == null) throw new IOException("corrupted data"); pushBackInput = new PushbackInputStream( new BufferedInputStream(new GZIPInputStream(threadTracersStream, 512), 512), 1); final DataInputStream threadTracersInputStream = new DataInputStream(pushBackInput); final ArrayList<ThreadTraceResult> threadTraces0 = new ArrayList<ThreadTraceResult>(); while ((testRead = pushBackInput.read()) != -1) { pushBackInput.unread(testRead); threadTraces0.add(ThreadTraceResult.readFrom(threadTracersInputStream, this, file)); } threadTraces0.trimToSize(); Collections.sort(threadTraces0); this.threadTraces = threadTraces0; }
From source file:org.zaproxy.zap.extension.globalexcludeurl.GlobalExcludeURLParam.java
public void setTokens(List<GlobalExcludeURLParamToken> tokens) { this.tokens = new ArrayList<>(tokens); ((HierarchicalConfiguration) getConfig()).clearTree(ALL_TOKENS_KEY); ArrayList<String> enabledTokens = new ArrayList<>(tokens.size()); for (int i = 0, size = tokens.size(); i < size; ++i) { String elementBaseKey = ALL_TOKENS_KEY + "(" + i + ")."; GlobalExcludeURLParamToken token = tokens.get(i); getConfig().setProperty(elementBaseKey + TOKEN_REGEX_KEY, token.getRegex()); getConfig().setProperty(elementBaseKey + TOKEN_DESCRIPTION_KEY, token.getDescription()); getConfig().setProperty(elementBaseKey + TOKEN_ENABLED_KEY, Boolean.valueOf(token.isEnabled())); if (token.isEnabled()) { enabledTokens.add(token.getRegex()); }/*from ww w . jav a2 s . c om*/ } enabledTokens.trimToSize(); this.enabledTokensNames = enabledTokens; }