List of usage examples for java.util Collection add
boolean add(E e);
From source file:org.joinfaces.security.AuthenticationFactory.java
private static Collection<? extends GrantedAuthority> grantedAuthorities(String... authorities) { Collection<SimpleGrantedAuthority> result = new HashSet<SimpleGrantedAuthority>(); for (String authority : authorities) { result.add(new SimpleGrantedAuthority(authority)); }// w w w .ja v a 2s . c om return result; }
From source file:Main.java
/** * Adds all elements of the given array to the collector, starting from the given index. * /*w w w.j a va 2 s .c o m*/ * @param sourceArray * is the source array to copy from * @param startIndex * is an index in the array from which the copying shall start * @param collector * collects the copied elements */ private static <T> void copyRemainder(final T[] sourceArray, final int startIndex, final Collection<T> collector) { for (int index = startIndex; index < sourceArray.length; index++) { collector.add(sourceArray[index]); } }
From source file:Main.java
/** * This function filters the input collection and returns a collection of elements containing the specified input (Ignore Case). * @param coll// w ww.j a v a 2s .co m * @param str * @return Filtered Collection<String> */ public static Collection<String> containsStringIgnoreCase(Collection<String> coll, final String str) { Collection<String> list = new ArrayList<String>(); for (String item : coll) { if (item.toLowerCase().contains(str.toLowerCase())) { list.add(item); } } return list; }
From source file:Main.java
/** * This function filters the input collection and returns a collection of elements ending with specified input (Ignore Case). * @param coll/*from ww w. ja v a 2 s .c om*/ * @param str * @return Filtered Collection<String> */ public static Collection<String> endsWithStringIgnoreCase(Collection<String> coll, final String str) { Collection<String> list = new ArrayList<String>(); for (String item : coll) { if (item.toLowerCase().endsWith(str.toLowerCase())) { list.add(item); } } return list; }
From source file:Main.java
/** * add a unique value to a collection. If the value already exists, it will * return <code>false</code>. * //from w ww.j a va 2s .co m * @param collection * the collection. * @param value * the value. * @return boolean. * @since 0.1 */ public static boolean addUnique(final Collection collection, final Object value) { if (collection.contains(value)) { return false; } return collection.add(value); }
From source file:Main.java
private static Collection<String> convertToCollection(final NodeList nodes) { final Collection<String> result = new ArrayList<String>(); if (nodes != null) { for (int i = 0; i < nodes.getLength(); i++) { result.add(nodes.item(i).getNodeValue()); }/*from ww w. ja va 2s. c o m*/ } return result; }
From source file:Main.java
public static <T> Collection<T> filter(final Collection<?> objects, final Class<T> filterType) { final Collection<T> filtered = new ArrayList<T>(); for (final Object object : objects) { if (filterType.isInstance(object)) { filtered.add(filterType.cast(object)); }// w w w. j a va2 s . com } return filtered; }
From source file:Main.java
public static <E> boolean addAll(Collection<E> addTo, Iterable<? extends E> elementsToAdd) { boolean modified = false; for (E e : elementsToAdd) { modified |= addTo.add(e); }//from w w w .j av a 2 s . c om return modified; }
From source file:Main.java
/** * Copy the source collection into the destination one filtering source elements by the given type. * // w ww . j ava2 s. co m * @param source * the source collection * @param destination * the destination collection * @param clazz * the filtering type */ @SuppressWarnings("unchecked") public static <T, E extends T> void filterCollectionByType(Collection<T> source, Collection<E> destination, Class<E> clazz) { for (T element : source) { if (clazz.isInstance(element)) { destination.add((E) element); } } }
From source file:com.sonatype.nexus.perftest.PerformanceTestAsserter.java
public static void assertTest(String name, List<Metric> metrics) throws InterruptedException { TestExecution baseline = null;//from w ww. j a va2 s. c om if (baselineId != null) { baseline = TestExecutions.select(name, baselineId); if (baseline == null) { throw new RuntimeException(String.format("Baseline build %s is not found", baselineId)); } } System.out.println("Baseline " + baselineId + " " + baseline); TestExecution execution = null; if (buildId != null) { execution = TestExecutions.select(name, buildId); if (execution == null) { throw new RuntimeException(String.format("Build ID execution %s is not found", buildId)); } } System.out.println("Execution " + buildId + " " + execution); Collection<PerformanceMetricDescriptor> descriptors = new ArrayList<>(); for (Metric metric : metrics) { descriptors.add(new PerformanceMetricDescriptor(metric.getName() + ".successCount", 0.9f, 1.1f)); descriptors.add(new PerformanceMetricDescriptor(metric.getName() + ".successDuration", 0.9f, 1.1f)); descriptors.add(new PerformanceMetricDescriptor(metric.getName() + ".failureCount", 0.9f, 1.1f)); } TestExecutions.assertPerformance(descriptors, baseline, execution); }