List of usage examples for java.util List addAll
boolean addAll(Collection<? extends E> c);
From source file:com.technofovea.packbsp.packaging.BspZipController.java
public static void writePackingList(Map<String, File> packItems, Writer dest) throws IOException { final String newline = "\r\n"; List<String> keys = new ArrayList<String>(); keys.addAll(packItems.keySet()); Collections.sort(keys);//from w w w . j a v a2 s . c om for (String inner : keys) { File outer = packItems.get(inner); dest.write(inner); dest.write(newline); dest.write(outer.getAbsolutePath()); dest.write(newline); } }
From source file:Main.java
/** * Add a varargs list of items to the specified list. If the list or items array are null, then no action is * performed. Note that the destination list has no requirements other than it must be a List of the source item's * type. This allows the destination to be used, for example, as an accumulator.<br> * <br>/* ww w . j ava2 s . c o m*/ * Note that this method is not thread safe. Users of this method will need to maintain type safety against the * list. * * @param list * A list to which items will be added * @param items * A list of items to add */ public static final <T, U extends T> List<T> addToList(List<T> list, List<U> items) { if (list != null && items != null) { list.addAll(items); } return list; }
From source file:de.tudarmstadt.ukp.csniper.resbuild.stuff.BncLocalCorpusBuilder.java
public static CollectionReader buildCollectionReader() throws ResourceInitializationException { List<String> patterns = new ArrayList<String>(); try {//from ww w .j av a 2 s. c o m patterns.addAll(read(INCLUSION_FILE, "[+]**/")); System.out.println("Including documents specified in [" + INCLUSION_FILE + "]."); } catch (IOException e) { patterns.add("[+]**/*.xml"); System.out.println("No inclusions specified, parsing all BNC documents."); } try { patterns.addAll(read(EXCLUSION_FILE, "[-]**/")); System.out.println("Excluding documents specified in [" + EXCLUSION_FILE + "]."); } catch (IOException e) { System.out.println("No exclusions specified, parsing all specified BNC documents."); } CollectionReader reader = createCollectionReader(BncReaderReloaded.class, BncReaderReloaded.PARAM_PATH, INPUT_BNC_PATH, BncReaderReloaded.PARAM_PATTERNS, patterns.toArray(new String[0]), BncReaderReloaded.PARAM_LANGUAGE, "en"); return reader; }
From source file:Main.java
public static void resize(List list, int newSize) { if (newSize < list.size()) { list.subList(newSize, list.size()).clear(); } else {//from ww w .j a v a2s.c o m list.addAll(Collections.nCopies(newSize - list.size(), null)); } }
From source file:Main.java
public static <T> List<T> innerJoin(List<List<T>> list, BiFunction<T, T, T> function) { if (list == null || function == null) { throw new NullPointerException("list or function must not be null"); }//www . j av a 2 s . c o m if (list.isEmpty()) { return Collections.emptyList(); } if (list.size() == 1) { return list.get(0); } List<List<T>> result = innerJoin(list.get(0), list.get(1), function); if (list.size() == 2) { return merge(result); } else { for (int i = 2; i < list.size(); i++) { List<T> l1 = list.get(i); List<List<T>> temp = new ArrayList<>(); result.stream().forEach(l -> temp.addAll(innerJoin(l, l1, function))); result = temp; } return merge(result); } }
From source file:Main.java
public static <E> List<E> concatList(List<E>... array) { if (array == null || array.length < 1) { return Collections.emptyList(); }/* w ww . j a v a2 s. c o m*/ List<E> newList = new ArrayList<E>(); for (List<E> e : array) { if (isNotEmpty(e)) { newList.addAll(e); } } return newList; }
From source file:Main.java
/** * This method returns a new ArrayList which is the intersection of the two List parameters, based on {@link Object#equals(Object) equality} * of their elements.//from w w w . j a v a2 s. c o m * The intersection list will contain elements in the order they have in list1 and any references in the resultant list will be * to elements within list1 also. * * @return a new ArrayList whose values represent the intersection of the two Lists. */ public static <T> List<T> intersect(List<? extends T> list1, List<? extends T> list2) { if (list1 == null || list1.isEmpty() || list2 == null || list2.isEmpty()) { return Collections.emptyList(); } List<T> result = new ArrayList<T>(); result.addAll(list1); result.retainAll(list2); return result; }
From source file:com.github.jmnarloch.spring.jaxrs.client.support.JaxRsClientRegistrar.java
/** * Ads all values to the value list./*w w w . j a v a2 s. c om*/ * * @param list the list of values * @param values the values */ private static void addAll(List<String> list, String[] values) { list.addAll(Arrays.asList(values)); }
From source file:eu.eubrazilcc.lvl.core.util.TestUtils.java
public static Collection<File> getTextFiles() { final List<File> files = newArrayList(); files.addAll(getGenBankFlatFiles()); files.addAll(getGBSeqXMLFiles());//from w w w .ja va2 s . com files.addAll(getGBSeqXMLSetFiles()); files.addAll(getPubMedXMLSetFiles()); files.addAll(getGeoJsonFiles()); return files; }
From source file:Main.java
/** * Returns a three-element array of mutable {@code List}s: * <ol>// w ww.j a v a 2s .com * </li> * the intersection of {@code a} and {@code b} * <li> * </li> * the {@code a} - {@code b} difference * <li> * </li> * the {@code b} - {@code a} difference * <li> * </ol> * * @param comparator * a comparator to sort results, or {@code null} to remain * unsorted */ public static <T> List<T>[] getIntersectAndDiffs(Collection<? extends T> a, Collection<? extends T> b, Comparator<T> comparator) { int aSize = a.size(); List<T> aDiff = new ArrayList<T>(aSize); aDiff.addAll(a); int bSize = b.size(); List<T> bDiff = new ArrayList<T>(bSize); bDiff.addAll(b); if (comparator != null) { Collections.sort(aDiff, comparator); Collections.sort(bDiff, comparator); } List<T> abInter = new ArrayList<T>(Math.min(aSize, bSize)); for (int i = aDiff.size() - 1; i >= 0; i--) { T element = aDiff.get(i); int index = comparator == null ? bDiff.indexOf(element) : Collections.binarySearch(bDiff, element, comparator); if (index != -1) { bDiff.remove(index); aDiff.remove(i); abInter.add(element); } } @SuppressWarnings({ "unchecked" }) List<T>[] array = (List<T>[]) new List[] { abInter, aDiff, bDiff }; return array; }