List of usage examples for java.util Collection size
int size();
From source file:com.flexive.shared.search.FxSQLFunctions.java
/** * Return the FxSQL function names for the given list of {@link com.flexive.shared.search.FxSQLFunction} * objects, i.e. project the result of {@link FxSQLFunction#getSqlName()}. * * @param functions the FxSQL function object * @return the FxSQL function names as used in FxSQL *///from w w w. j av a2 s.com public static List<String> getSqlNames(Collection<? extends FxSQLFunction> functions) { final List<String> result = new ArrayList<String>(functions.size()); for (FxSQLFunction function : functions) { result.add(function.getSqlName()); } return result; }
From source file:com.bigdata.dastor.streaming.StreamOut.java
/** * Split out files for all tables on disk locally for each range and then stream them to the target endpoint. *//*from w w w. j a v a 2 s.co m*/ public static void transferRanges(InetAddress target, String tableName, Collection<Range> ranges, Runnable callback) { assert ranges.size() > 0; logger.debug("Beginning transfer process to " + target + " for ranges " + StringUtils.join(ranges, ", ")); /* * (1) dump all the memtables to disk. * (2) anticompaction -- split out the keys in the range specified * (3) transfer the data. */ try { Table table = Table.open(tableName); logger.info("Flushing memtables for " + tableName + "..."); for (Future f : table.flush()) { try { f.get(); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (ExecutionException e) { throw new RuntimeException(e); } } logger.info("Performing anticompaction ..."); /* Get the list of files that need to be streamed */ transferSSTables(target, table.forceAntiCompaction(ranges, target), tableName); // SSTR GC deletes the file when done } catch (IOException e) { throw new IOError(e); } finally { StreamOutManager.remove(target); } if (callback != null) callback.run(); }
From source file:Main.java
public static boolean equalsSet(Collection c1, Collection c2) { boolean equals; if (c1 == null) { equals = (c2 == null);/*from w ww .jav a 2 s . com*/ } else if (c2 == null) { equals = false; } else if (c1.size() == c2.size()) { equals = true; Iterator iterC1 = c1.iterator(); while (equals && iterC1.hasNext()) { Object o1 = iterC1.next(); equals = c2.contains(o1); } } else { equals = false; } return equals; }
From source file:Main.java
/** * Returns a three-element array of mutable {@code List}s: * <ol>/*ww w.ja v a2 s . c o m*/ * </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; }
From source file:de.chludwig.websec.saml2sp.springconfig.CurrentUserHandlerMethodArgumentResolver.java
private static Set<RoleId> getUserRoles(Authentication auth) { Collection<? extends GrantedAuthority> authorities = auth.getAuthorities(); Set<RoleId> roles = new HashSet<>(authorities.size()); for (GrantedAuthority authority : authorities) { RoleId roleId = RoleId.valueById(authority.getAuthority()); if (roleId != null) { roles.add(roleId);/*from w ww. ja v a 2 s .com*/ } } return roles; }
From source file:br.ufpe.cin.srmqnlp.CarrotConsoleFormatter.java
public static void displayDocuments(final Collection<Document> documents) { System.out.println("Collected " + documents.size() + " documents\n"); for (final Document document : documents) { displayDocument(0, document);//from w w w.jav a2s .c o m } }
From source file:Main.java
public static <V> V getRandom(Collection<V> collection) { if (collection.isEmpty()) { return null; }/*from w ww.ja v a2s . c o m*/ int randIdx = (int) Math.round(Math.random() * (collection.size() - 1)); int count = 0; Iterator<V> iterator = collection.iterator(); while (iterator.hasNext()) { V current = iterator.next(); if (count == randIdx) { return current; } count++; } throw new RuntimeException("Shouldn't happen"); }
From source file:example.springdata.mongodb.util.ConsoleResultPrinter.java
public static void printResult(Collection<BlogPost> blogPosts, CriteriaDefinition criteria) { System.out.println(String.format("XXXXXXXXXXXX -- Found %s blogPosts matching '%s' --XXXXXXXXXXXX", blogPosts.size(), criteria != null ? criteria.getCriteriaObject() : "")); for (BlogPost blogPost : blogPosts) { System.out.println(blogPost); }/* w ww.j ava2 s. c o m*/ System.out.println("XXXXXXXXXXXX -- XXXXXXXXXXXX -- XXXXXXXXXXXX\r\n"); }
From source file:Main.java
/** * Return the last element of a collection. This method iterates over the complete collection to found * the last element.// ww w . j a v a 2s. c o m * * @param collection The collection to get the last element from. * @param <T> The type of value. * @return The last element of the collection. If there is no element, the method return null. */ public static <T> T last(Collection<T> collection) { if (collection.isEmpty()) { return null; } Iterator<T> iterator = collection.iterator(); for (int i = 0; i < collection.size() - 1; i++) { iterator.next(); } return iterator.next(); }
From source file:Main.java
/** * Return the first N items in a collection. * *//*from w w w . j a v a2 s . c o m*/ public static <T> List<T> head(Collection<T> input, int count) { List<T> result = Lists.newArrayList(); ArrayList<T> tmp = Lists.newArrayList(); tmp.addAll(input); for (int i = 0; i < input.size(); i++) { if (result.size() == count) break; result.add(tmp.get(i)); } return result; }