List of usage examples for com.google.common.collect Iterables size
public static int size(Iterable<?> iterable)
From source file:org.eclipse.osee.executor.admin.WorkUtility.java
public static <INPUT, OUTPUT> List<Callable<Collection<OUTPUT>>> partitionWork(Iterable<INPUT> work, PartitionFactory<INPUT, OUTPUT> factory) throws Exception { List<Callable<Collection<OUTPUT>>> callables = new LinkedList<Callable<Collection<OUTPUT>>>(); int size = Iterables.size(work); if (size > 0) { int partitionSize = Math.max(1, size / NUM_PARTITIONS); List<INPUT> subList = new LinkedList<INPUT>(); int index = 0; Iterator<INPUT> iterator = work.iterator(); while (iterator.hasNext()) { subList.add(iterator.next()); if (index != 0 && partitionSize != 0 && (index % partitionSize == 0)) { Callable<Collection<OUTPUT>> worker = factory.createWorker(subList); callables.add(worker);/* ww w.ja v a 2 s . c o m*/ subList = new LinkedList<INPUT>(); } index++; } // Anything left over ? if (!subList.isEmpty()) { Callable<Collection<OUTPUT>> worker = factory.createWorker(subList); callables.add(worker); } } return callables; }
From source file:playground.michalm.taxi.util.TaxicabUtils.java
public static int countVehicles(Iterable<? extends Vehicle> vehicles, Predicate<Vehicle> predicate) { return Iterables.size(Iterables.filter(vehicles, predicate)); }
From source file:org.jclouds.openstack.nova.v2_0.domain.zonescoped.RegionAndId.java
public static RegionAndId fromSlashEncoded(String id) { Iterable<String> parts = Splitter.on('/').split(checkNotNull(id, "id")); checkArgument(Iterables.size(parts) == 2, "id must be in format regionId/id"); return new RegionAndId(Iterables.get(parts, 0), Iterables.get(parts, 1)); }
From source file:springfox.documentation.spring.web.plugins.DuplicateGroupsDetector.java
public static void ensureNoDuplicateGroups(List<DocumentationPlugin> allPlugins) throws IllegalStateException { Multimap<String, DocumentationPlugin> plugins = Multimaps.index(allPlugins, byGroupName()); Iterable<String> duplicateGroups = from(plugins.asMap().entrySet()).filter(duplicates()) .transform(toGroupNames());// w w w. ja va 2 s. co m if (Iterables.size(duplicateGroups) > 0) { throw new IllegalStateException(String.format( "Multiple Dockets with the same group name are not supported. " + "The following duplicate groups were discovered. %s", Joiner.on(',').join(duplicateGroups))); } }
From source file:org.jclouds.aliyun.ecs.compute.functions.internal.OperatingSystems.java
private static String parseVersion(Image image) { String sequence = image.osName().trim().replaceAll("\\s+", " "); int offset = 2; if (isWindows(image)) { sequence = image.platform();/*from w ww. j a v a 2s .co m*/ offset = 1; } Iterable<String> splitted = Splitter.on(" ").split(sequence); return Iterables.get(splitted, Iterables.size(splitted) - offset); }
From source file:co.cask.cdap.logging.gateway.handlers.FormattedLogEvent.java
public static LogOffset parseLogOffset(String offsetStr) { if (offsetStr.isEmpty()) { return LogOffset.LATEST_OFFSET; }/*from w w w.j a v a2s. c om*/ Iterable<String> splits = Splitter.on(SEPARATOR).split(offsetStr); Preconditions.checkArgument(Iterables.size(splits) == 2, "Invalid offset provided: %s", offsetStr); return new LogOffset(Long.valueOf(Iterables.get(splits, 0)), Long.valueOf(Iterables.get(splits, 1))); }
From source file:net.sourceforge.cilib.util.selection.WeightedSelection.java
private static <T> WeightedObject[] copyOfInternal(Iterable<T> iterable) { checkArgument(Iterables.size(iterable) >= 1, "Attempting to create a " + "selection on an empty collection is not valid."); List<T> list = Lists.newArrayList(iterable); List<WeightedObject> result = Lists.newArrayListWithExpectedSize(list.size()); for (T t : list) { result.add(new WeightedObject(t, 0.0)); }/*from w w w .j a v a2 s . co m*/ return result.toArray(new WeightedObject[] {}); }
From source file:sf.net.experimaestro.utils.graphs.Sort.java
/** * Topological sort of a set of nodes//from ww w.j a v a2 s.c o m * * @param nodes The nodes to be sorted * @return An ordered list of nodes */ static public <T extends Node> ArrayList<T> topologicalSort(List<T> nodes) { ArrayList<T> ordered = new ArrayList<>(); HashSet<NodeRef<T>> dandling = new HashSet<>(); Map<NodeRef<T>, MutableInt> remaining = new HashMap<>(); for (Node node : nodes) { final Iterable<? extends Node> children = node.getChildren(); int size = Iterables.size(children); if (size == 0) dandling.add(new NodeRef(node)); else remaining.put(new NodeRef(node), new MutableInt(size)); } while (!remaining.isEmpty() || !dandling.isEmpty()) { if (dandling.isEmpty()) throw new XPMRuntimeException("Graph contains cycle"); HashSet<NodeRef<T>> newDandling = new HashSet<>(); for (NodeRef<T> ref : dandling) { ordered.add(ref.node); remaining.remove(ref); } for (NodeRef<T> ref : dandling) { for (Node parent : ref.node.getParents()) { final MutableInt children = remaining.get(new NodeRef<>(parent)); children.decrement(); assert children.intValue() >= 0; if (children.intValue() == 0) newDandling.add(new NodeRef(parent)); } } dandling = newDandling; } return ordered; }
From source file:org.janusgraph.testutil.JanusGraphAssert.java
public static int size(Object obj) { Preconditions.checkArgument(obj != null); if (obj instanceof Traversal) return size(((Traversal) obj).toList()); else if (obj instanceof Collection) return ((Collection) obj).size(); else if (obj instanceof Iterable) return Iterables.size((Iterable) obj); else if (obj instanceof Iterator) return Iterators.size((Iterator) obj); else if (obj.getClass().isArray()) return Array.getLength(obj); throw new IllegalArgumentException("Cannot determine size of: " + obj); }
From source file:com.thinkbiganalytics.security.service.user.UserModelTransform.java
/** * Transforms Metadata groups to Security groups. * * @return the Security groups// w w w. j av a 2 s. co m */ @Nonnull public static Function<com.thinkbiganalytics.metadata.api.user.UserGroup, UserGroup> toGroupPrincipal() { return (com.thinkbiganalytics.metadata.api.user.UserGroup group) -> { final UserGroup principal = new UserGroup(); principal.setDescription(group.getDescription()); principal.setMemberCount(Iterables.size(group.getGroups()) + Iterables.size(group.getUsers())); principal.setTitle(group.getTitle()); principal.setSystemName(group.getSystemName()); return principal; }; }