List of usage examples for java.util Collection size
int size();
From source file:com.goncalomb.bukkit.bkglib.namemaps.PotionEffectsMap.java
public static List<String> getNamez(Collection<PotionEffect> effects) { ArrayList<String> names = new ArrayList<String>(effects.size()); for (PotionEffect effect : effects) { names.add(getName(effect.getType())); }/*from w w w. ja v a 2 s . c o m*/ return names; }
From source file:edu.harvard.med.screensaver.util.CollectionUtils.java
@SuppressWarnings("unchecked") public static <I> Set<I> entityIds(Collection<? extends Entity> entities) { Set<I> ids = new HashSet<I>(entities.size()); for (Entity entity : entities) { ids.add((I) entity.getEntityId()); }//from w ww . j av a 2 s . com return ids; }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> T[] toArray(Collection<T> c) { if (c == null) { return null; } else {// ww w .ja v a 2 s . co m T[] result = (T[]) Array.newInstance(c.getClass().getComponentType(), c.size()); int i = 0; for (T r : c) { result[i] = r; i++; } return result; } }
From source file:com.vrem.util.EnumUtils.java
public static <T extends Enum, U> Predicate<U> predicate(@NonNull Class<T> enumType, @NonNull Collection<T> input, @NonNull Transformer<T, Predicate<U>> transformer) { if (input.size() >= values(enumType).size()) { return PredicateUtils.truePredicate(); }/*ww w . ja v a 2 s . co m*/ return PredicateUtils.anyPredicate(CollectionUtils.collect(input, transformer)); }
From source file:Main.java
public static <T extends Comparable<T>> int compareAsSet(Collection<? extends T> set1, Collection<? extends T> set2) { int res = Ints.compare(set1.size(), set2.size()); if (res != 0) return res; SortedSet<? extends T> sortedSet1 = toNaturalSortedSet(set1); SortedSet<? extends T> sortedSet2 = toNaturalSortedSet(set2); Iterator<? extends T> elements2 = set2.iterator(); for (T element1 : set1) { res = element1.compareTo(elements2.next()); if (res != 0) return res; }//from w ww. j a v a 2 s. c o m return 0; }
From source file:Main.java
/** * <p>//from w ww .j av a2 s.com * Checks if the given two {@link Collection}s contains the same elements * in any order. * </p> * <p> * Empty {@link Collection}s and {@code null} parameters are treated as equal. * </p> * @param first The first {@link Collection}. * @param second The second {@link Collection}. * @return {@code true} both {@link Collection}s contains same elements, {@code false} {@link Collection}s are different. */ public static <T> boolean containsSame(Collection<T> first, Collection<T> second) { if (first != null) { if (second != null) { if (first.size() == second.size()) { Collection<T> firstCopy = new LinkedList<T>(first); boolean same = true; Iterator<T> secondIter = second.iterator(); while (same && secondIter.hasNext()) { T secondNext = secondIter.next(); same = firstCopy.remove(secondNext); } return same; } else { return false; } } else { return first.size() == 0; } } else { return second == null || second.size() == 0; } }
From source file:Main.java
public static <T> int compareAsSet(@Nonnull Comparator<? super T> elementComparator, @Nonnull Collection<? extends T> list1, @Nonnull Collection<? extends T> list2) { int res = Ints.compare(list1.size(), list2.size()); if (res != 0) return res; SortedSet<? extends T> set1 = toSortedSet(elementComparator, list1); SortedSet<? extends T> set2 = toSortedSet(elementComparator, list2); Iterator<? extends T> elements2 = set2.iterator(); for (T element1 : set1) { res = elementComparator.compare(element1, elements2.next()); if (res != 0) return res; }/*from w w w . j a v a2 s . co m*/ return 0; }
From source file:com.ebay.logstorm.server.utils.LogStormServerDebug.java
private static File findAssemblyJarFile() { String projectRootDir = System.getProperty("user.dir"); String assemblyModuleTargeDirPath = projectRootDir + "/assembly/target/"; File assemblyTargeDirFile = new File(assemblyModuleTargeDirPath); if (!assemblyTargeDirFile.exists()) { throw new IllegalStateException( assemblyModuleTargeDirPath + " not found, please execute 'mvn install -DskipTests' under " + projectRootDir + " to build the project firstly and retry"); }/* w ww.jav a 2 s .c om*/ String jarFileNameWildCard = "logstorm-assembly-*.jar"; Collection<File> jarFiles = FileUtils.listFiles(assemblyTargeDirFile, new WildcardFileFilter(jarFileNameWildCard), TrueFileFilter.INSTANCE); if (jarFiles.size() == 0) { throw new IllegalStateException( "jar is not found, please execute 'mvn install -DskipTests' from project root firstly and retry"); } File jarFile = jarFiles.iterator().next(); LOG.debug("Found pipeline.jar: {}", jarFile.getAbsolutePath()); return jarFile; }
From source file:Main.java
public static <T> int compareAsSet(Comparator<? super T> elementComparator, Collection<? extends T> list1, Collection<? extends T> list2) { int res = Ints.compare(list1.size(), list2.size()); if (res != 0) return res; SortedSet<? extends T> set1 = toSortedSet(elementComparator, list1); SortedSet<? extends T> set2 = toSortedSet(elementComparator, list2); Iterator<? extends T> elements2 = set2.iterator(); for (T element1 : set1) { res = elementComparator.compare(element1, elements2.next()); if (res != 0) return res; }/*from ww w . j a v a2 s. c o m*/ return 0; }
From source file:com.goncalomb.bukkit.bkglib.namemaps.PotionEffectsMap.java
public static List<String> getNames(Collection<PotionEffectType> effects) { ArrayList<String> names = new ArrayList<String>(effects.size()); for (PotionEffectType effect : effects) { names.add(getName(effect));/*w w w . j ava 2 s . c o m*/ } return names; }