List of usage examples for java.util ArrayList trimToSize
public void trimToSize()
From source file:Main.java
private static List<Object> recursiveAggregateTree(List<Object> items, int maxPerList) { if (items.size() > maxPerList) { ArrayList<Object> aggregateList = new ArrayList<Object>(maxPerList); ArrayList<Object> childList = null; for (Object item : items) { if (childList == null || childList.size() == maxPerList) { childList = new ArrayList<Object>(maxPerList); aggregateList.add(childList); }//w w w. j a v a 2 s.co m childList.add(item); } childList.trimToSize(); aggregateList.addAll(recursiveAggregateTree(aggregateList, maxPerList)); aggregateList.trimToSize(); return aggregateList; } else { // This is a safe blind cast since only subsequent calls of this method will end up here // and this method always uses ArrayList<Object> return items; } }
From source file:Main.java
private static List<Object> recursiveAggregateTree(List<Object> items, int maxPerList) { if (items.size() > maxPerList) { ArrayList<Object> aggregateList = new ArrayList<Object>(maxPerList); ArrayList<Object> childList = null; for (Object item : items) { if (childList == null || childList.size() == maxPerList) { childList = new ArrayList<Object>(maxPerList); aggregateList.add(childList); }/*from w w w . j av a 2 s . com*/ childList.add(item); } if (childList != null) { childList.trimToSize(); } aggregateList.addAll(recursiveAggregateTree(aggregateList, maxPerList)); aggregateList.trimToSize(); return aggregateList; } else { // This is a safe blind cast since only subsequent calls of this method will end up here // and this method always uses ArrayList<Object> return items; } }
From source file:org.tinygroup.commons.tools.CollectionUtil.java
/** <code>ArrayList</code> */ public static <T> ArrayList<T> createArrayList(Iterable<? extends T> c) { ArrayList<T> list; if (c instanceof Collection<?>) { list = new ArrayList<T>((Collection<? extends T>) c); } else {//from w w w .j a v a 2s.c om list = new ArrayList<T>(); iterableToCollection(c, list); list.trimToSize(); } return list; }
From source file:org.n52.test.mock.MockUtil.java
public static Collection<String> getParserPropertyValues(Class<? extends IParser> clazz, String propertyName) { String clazzName = clazz.getName(); ArrayList<String> propertyList = new ArrayList<String>(); try {/*ww w. ja va2 s. co m*/ WPSConfig mockConfig = MockUtil.getMockConfig(); PropertyDocument.Property properties[] = mockConfig.getPropertiesForParserClass(clazzName); for (Property property : properties) { if (propertyName.equals(property.getName())) { propertyList.add(property.getStringValue()); } } propertyList.trimToSize(); } catch (Exception e) { System.err.println("ERROR parsing property " + propertyName + " for Parser class " + clazzName); } return propertyList; }
From source file:org.n52.test.mock.MockUtil.java
public static Collection<String> getGeneratorPropertyValues(Class<? extends IGenerator> clazz, String propertyName) {//from ww w . j a v a 2s . co m String clazzName = clazz.getName(); ArrayList<String> propertyList = new ArrayList<String>(); try { WPSConfig mockConfig = MockUtil.getMockConfig(); PropertyDocument.Property properties[] = mockConfig.getPropertiesForGeneratorClass(clazzName); for (Property property : properties) { if (propertyName.equals(property.getName())) { propertyList.add(property.getStringValue()); } } } catch (Exception e) { System.err.println("ERROR parsing property " + propertyName + " for Generator class " + clazzName); } propertyList.trimToSize(); return propertyList; }
From source file:com.silverwrist.util.StringUtils.java
/** * Splits the provided text into a list, based on a given separator. The separator is not included in the * returned String list. The maximum number of splits to perfom can be controlled. * * @param text The string to parse./* ww w .j ava 2 s . c o m*/ * @param separator Character used as the delimiter. * @param limit The maximum number of elements to include in the list. A zero or negative value implies no limit. * @return A list of parsed Strings. */ public static final List split1List(String text, char separator, int limit) { if (text == null) return Collections.EMPTY_LIST; if (limit <= 0) limit = Integer.MAX_VALUE; ArrayList rc = new ArrayList(); String work = text; int p = work.indexOf(separator); while ((work.length() > 0) && (p >= 0) && (--limit > 0)) { // add elements to the ArrayList if (p == 0) rc.add(""); else rc.add(work.substring(0, p)); work = work.substring(p + 1); p = work.indexOf(separator); } // end while rc.add(work); rc.trimToSize(); return rc; }
From source file:it.unibo.alchemist.language.EnvironmentBuilder.java
@SuppressWarnings("unchecked") private static <E> E coreOperations(final Map<String, Object> environment, final Node root, final String type, final RandomGenerator random) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException { final NamedNodeMap atts = root.getAttributes(); final Node nameNode = atts.getNamedItem(NAME); final String name = nameNode == null ? "" : nameNode.getNodeValue(); if (!name.equals("") && atts.getLength() == 1 && environment.containsKey(name)) { return (E) environment.get(name); }/*from ww w . j a v a 2 s .c o m*/ final Class<?> objClass = (Class<?>) Class.forName(type); final List<Constructor<E>> consList = unsafeExtractConstructors(objClass); final ArrayList<String> params = new ArrayList<String>(); int index = 0; for (Node param = atts.getNamedItem("p0"); param != null; param = atts.getNamedItem("p" + (++index))) { params.add(param.getNodeValue()); } params.trimToSize(); final E res = tryToBuild(consList, params, environment, random); environment.put(name, res); return res; }
From source file:org.parosproxy.paros.network.SSLConnector.java
private static String[] extractSupportedProtocols(String[] enabledProtocols) { if (enabledProtocols == null || enabledProtocols.length == 0) { throw new IllegalArgumentException("Protocol(s) required but no protocol set."); }/* w w w . j av a 2 s . c om*/ String[] supportedProtocols = getSupportedProtocols(); ArrayList<String> enabledSupportedProtocols = new ArrayList<>(supportedProtocols.length); for (String protocol : enabledProtocols) { if (protocol != null && Arrays.binarySearch(supportedProtocols, protocol) >= 0) { enabledSupportedProtocols.add(protocol); } } enabledSupportedProtocols.trimToSize(); if (enabledSupportedProtocols.isEmpty()) { throw new IllegalArgumentException("No supported protocol(s) set."); } String[] extractedSupportedProtocols = new String[enabledSupportedProtocols.size()]; enabledSupportedProtocols.toArray(extractedSupportedProtocols); return extractedSupportedProtocols; }
From source file:com.romanenco.gitt.git.GitHelper.java
/** * Read log messages, up to maxRecords/* w ww. ja v a2s .c o m*/ * * @param repoPath * @param maxRecords * @return */ public static List<LogEntry> readRepoHistory(String repoPath, int maxRecords) { ArrayList<LogEntry> result = new ArrayList<GitHelper.LogEntry>(maxRecords); try { Git git = Git.open(new File(repoPath)); Iterable<RevCommit> logs = git.log().call(); for (RevCommit commit : logs) { result.add(new LogEntry(commit)); if (--maxRecords == 0) break; } } catch (IOException e) { Log.e(TAG, "IO", e); } catch (NoHeadException e) { Log.e(TAG, "NoHead", e); } catch (GitAPIException e) { Log.e(TAG, "GitApi", e); } if (maxRecords > 0) { result.trimToSize(); } return result; }
From source file:org.bultreebank.labpipe.converters.LineConverter.java
/** * Returns a converted Line encoded data from a <code>String</code> to a * {@link Conll} object.//from w w w .ja v a 2 s . co m * * @param lines Line encoded data * @param eosToken end of sentence token * @param conllMap <code>Map</code> containing connections between full * BTB tags and their respective CoNLL forms. * @return {@link Conll} */ public static Conll toConll(String lines, String eosToken, Properties conllMap) { Conll conll = new Conll(); int num = 1; ArrayList<String> sentence = new ArrayList(100); for (String line : lines.split("\n")) { line = line.trim(); if (line.startsWith("##") || (!(line.contains(" ") || line.contains("\t")) && !line.contains(eosToken))) { continue; } if (line.contains(eosToken)) { num = 1; sentence.trimToSize(); conll.add(sentence); sentence = new ArrayList(100); } else { sentence.add(DataUtils.lineTokenToConllToken(line, num, conllMap)); num++; } } sentence.trimToSize(); if (sentence.size() > 0) { conll.add(sentence); } conll.trimToSize(); return conll; }