List of usage examples for java.util Collections addAll
@SafeVarargs public static <T> boolean addAll(Collection<? super T> c, T... elements)
From source file:Main.java
/** * Returns data converted into list./*w ww. ja v a 2 s. c o m*/ * * @param data data * @param <T> data type * @return data list */ public static <T> ArrayList<T> copy(final T... data) { final ArrayList<T> list = new ArrayList<T>(data.length); Collections.addAll(list, data); return list; }
From source file:edu.umich.robot.util.Configs.java
public static void toLog(Log logger, Config config) { if (!logger.isDebugEnabled()) return;// w w w .j av a 2s.com List<String> keys = new LinkedList<String>(); Collections.addAll(keys, config.getKeys()); Collections.sort(keys); for (String key : keys) logger.debug(String.format("%s = %s", key, Arrays.toString(config.getStrings(key)))); }
From source file:Main.java
public static <E> List<E> asList(E... elements) { if (elements == null || elements.length == 0) { return Collections.emptyList(); }/* ww w .ja v a 2 s . c o m*/ // Avoid integer overflow when a large array is passed in int capacity = (int) Math.min(5L + elements.length + (elements.length / 10), Integer.MAX_VALUE); ArrayList<E> list = new ArrayList<E>(capacity); Collections.addAll(list, elements); return list; }
From source file:Main.java
public static <T> T[] intersection(@NonNull final T[] array1, @NonNull final T[] array2) { final List<T> list1 = new ArrayList<>(); Collections.addAll(list1, array1); final List<T> list2 = new ArrayList<>(); Collections.addAll(list2, array2); list1.retainAll(list2);//from w ww. j av a 2s . com //noinspection unchecked return list1.toArray((T[]) Array.newInstance(array1.getClass().getComponentType(), list1.size())); }
From source file:Main.java
public static void innerListFiles(Collection<File> files, File directory, FileFilter filter) { File[] found = directory.listFiles(); if (found != null) { for (File aFound : found) { if (aFound.isDirectory()) { innerListFiles(files, aFound, filter); } else { File[] found2 = directory.listFiles(filter); Collections.addAll(files, found2); }//w w w. j a v a 2s . c o m } } }
From source file:Main.java
/** * Create a hashed set from an array.// ww w. j a v a2s.c om * * @param <T> * type * @param elements * elements in the set. * @return the set. * @see Arrays#asList(Object[]) */ public static <T> HashSet<T> asHashSet(@SuppressWarnings("unchecked") T... elements) { HashSet<T> result = new HashSet<T>(); Collections.addAll(result, elements); return result; }
From source file:Main.java
/** * Helper function that takes an object and returns a list representation * of it://from w w w. j av a 2 s.c om * * o == null => [] * o is a list => o * else => [o] * * @param o * @return */ public static List<Object> toList(final Object o) { if (o == null) return Collections.emptyList(); else if (o instanceof List) return (List<Object>) o; else if (o.getClass().isArray()) { final List<Object> l = new ArrayList<Object>(); Collections.addAll(l, (int[]) o); return l; } else return Collections.singletonList(o); }
From source file:jease.site.Authorizations.java
/** * Returns guarding Access object for given content or null, if content is * not guarded./*from w ww . j av a 2s . com*/ */ public static Access[] getGuards(Content content) { if (content == null) { return null; } Map<Content, Access[]> cache = Database.query(accessByContent); if (!cache.containsKey(content)) { List<Access> allGuards = new ArrayList<>(); Access[] accessGuards = content.getGuards(Access.class); if (ArrayUtils.isNotEmpty(accessGuards)) { Collections.addAll(allGuards, accessGuards); } else { Reference[] referenceGuards = content.getGuards(Reference.class); if (ArrayUtils.isNotEmpty(referenceGuards)) { for (Reference reference : referenceGuards) { if (reference.getContent() instanceof Access) { allGuards.add((Access) reference.getContent()); } } } } cache.put(content, allGuards.toArray(new Access[allGuards.size()])); } List<Access> activeGuards = new ArrayList<>(); for (Access access : cache.get(content)) { if (access.isGuarding()) { activeGuards.add(access); } } if (!activeGuards.isEmpty()) { return activeGuards.toArray(new Access[activeGuards.size()]); } else { return getGuards((Content) content.getParent()); } }
From source file:Main.java
static String composeFilesString(final String dirPath, final List<String> subDirPaths, final String pattern, int skip) { final StringBuilder sb = new StringBuilder(); final List<File> allFiles = new ArrayList<>(); final FilenameFilter filter = new FilenameFilter() { @Override/* w ww .ja va 2s. c o m*/ public boolean accept(File dir, String name) { return name.matches(pattern); } }; for (final String subDirPath : subDirPaths) { final File subDir = new File(dirPath, subDirPath); final File[] files = subDir.listFiles(filter); if (files == null) { throw new RuntimeException(String.format("%s directory does not exist", subDir.getPath())); } Arrays.sort(files); Collections.addAll(allFiles, files); } final int m; final int n; if (skip >= 0) { m = skip; n = allFiles.size(); } else { m = 0; n = allFiles.size() + skip; } for (int i = m; i < n; i++) { final File file = allFiles.get(i); if (sb.length() > 0) { sb.append(' '); } sb.append(file.getPath()); } return sb.toString(); }
From source file:Main.java
/** * Creates a {@link List} from incoming {@literal "varargs"}. Currently * uses {@link ArrayList} as the {@code List} implementation. * //from ww w . j a va 2 s. c o m * <p>Used like so: * {@code List<String> listy = list("y", "helo", "thar");} * * @param elements Items that will make up the elements of the returned * {@code List}. * * @return A {@code List} whose elements are each item within {@code elements}. */ public static <E> List<E> list(E... elements) { List<E> newList = arrList(elements.length); Collections.addAll(newList, elements); return newList; }