List of usage examples for com.google.common.collect Iterables size
public static int size(Iterable<?> iterable)
From source file:org.apache.mahout.math.als.AlternatingLeastSquaresSolver.java
static Matrix createMiIi(Iterable<Vector> featureVectors, int numFeatures) { double[][] MiIi = new double[numFeatures][Iterables.size(featureVectors)]; int n = 0;/*ww w .j av a 2s . c o m*/ for (Vector featureVector : featureVectors) { for (int m = 0; m < numFeatures; m++) { MiIi[m][n] = featureVector.getQuick(m); } n++; } return new DenseMatrix(MiIi, true); }
From source file:com.b2international.index.lucene.QueryBuilderBase.java
private Query build(final Occur occur, Iterable<Query> queries) { final int size = Iterables.size(queries); checkArgument(size > 0, "At least one clause must be specified to build a query"); if (size == 1) { return Iterables.getOnlyElement(queries); } else {/*ww w.ja v a2 s . c o m*/ final BooleanQuery.Builder query = new BooleanQuery.Builder(); for (Query q : queries) { query.add(q, occur); } return query.build(); } }
From source file:org.eclipse.xtext.common.types.ui.query.JavaSearchHelper.java
public void search(URI uri, IProgressMonitor monitor) { int numResources = Iterables.size(resourceDescriptions.getAllResourceDescriptions()); SubMonitor subMonitor = SubMonitor.convert(monitor, numResources / 10); subMonitor.subTask("Find references in EMF resources"); try {/*from w ww . j a v a 2 s . co m*/ int i = 0; for (IResourceDescription resourceDescription : resourceDescriptions.getAllResourceDescriptions()) { URI resourceURI = resourceDescription.getURI(); IResourceServiceProvider resourceServiceProvider = serviceProviderRegistry .getResourceServiceProvider(resourceURI); if (resourceServiceProvider != null) { IJavaSearchParticipation javaSearchParticipation = resourceServiceProvider .get(IJavaSearchParticipation.class); if (javaSearchParticipation == null || javaSearchParticipation.canContainJvmReferences(resourceURI)) searchIn(uri, resourceDescription); } if (++i % 10 == 0) { if (subMonitor.isCanceled()) { return; // not throwing OperationCanceledException, as the client in JDT doesn't seem to handle it properly } subMonitor.worked(1); } } for (ResourceSet resourceSet : projectToResourceSet.values()) { resourceSet.getResources().clear(); resourceSet.eAdapters().clear(); } } finally { subMonitor.done(); } }
From source file:org.yakindu.base.expressions.linking.OperationOverloadingLinkingService.java
public List<EObject> getLinkedOperation(ArgumentExpression context, EReference ref, INode node) { final EClass requiredType = ref.getEReferenceType(); if (requiredType == null) { return Collections.<EObject>emptyList(); }/* w w w. j a v a 2 s . c o m*/ final String crossRefString = getCrossRefNodeAsString(node); if (crossRefString == null || crossRefString.equals("")) { return Collections.<EObject>emptyList(); } final IScope scope = getScope(context, ref); final QualifiedName qualifiedLinkName = qualifiedNameConverter.toQualifiedName(crossRefString); // Adoption to super class implementation here to return multi elements final Iterable<IEObjectDescription> eObjectDescription = scope.getElements(qualifiedLinkName); int size = Iterables.size(eObjectDescription); if (size == 0) return Collections.emptyList(); if (size == 1) return Collections.singletonList(Iterables.getFirst(eObjectDescription, null).getEObjectOrProxy()); // Two operation with same name found here List<IEObjectDescription> candidates = new ArrayList<>(); for (IEObjectDescription currentDescription : eObjectDescription) { if (currentDescription.getEClass().isSuperTypeOf(TypesPackage.Literals.OPERATION)) { candidates.add(currentDescription); } } Optional<Operation> operation = operationsLinker.linkOperation(candidates, context); if (operation.isPresent()) { return Collections.singletonList(operation.get()); } //Link to first operation to get parameter errors instead of linking errors return Collections.singletonList(Iterables.getFirst(eObjectDescription, null).getEObjectOrProxy()); }
From source file:org.eclipse.elk.alg.mrtree.intermediate.LevelHeightProcessor.java
/** * Set the height property for each node in the current level and for their children. The height * is the height of the tallest node in the level. * //from w ww.j a v a 2s . c o m * @param currentLevel * the list of TNode at the same level, for which the neighbors and siblings should * be determined * @param progressMonitor * the current progress monitor */ private void setNeighbors(final Iterable<TNode> currentLevel, final IElkProgressMonitor progressMonitor) { /** only do something in filled levels */ if (!Iterables.isEmpty(currentLevel)) { /** create subtask for recursive descent */ IElkProgressMonitor sT = progressMonitor.subTask(Iterables.size(currentLevel) / numberOfNodes); sT.begin("Set neighbors in level", 1f); /** build empty iterator */ Iterable<TNode> nextLevel = new Iterable<TNode>() { public Iterator<TNode> iterator() { return Iterators.emptyIterator(); } }; double height = 0d; for (TNode cN : currentLevel) { /** append the children of the current node to the next level */ nextLevel = Iterables.concat(nextLevel, cN.getChildren()); /** check if the node is the tallest node so far */ if (height < cN.getSize().y) { height = cN.getSize().y; } } for (TNode cN : currentLevel) { /** set the level height for the node */ cN.setProperty(InternalProperties.LEVELHEIGHT, height); } /** add amount of work units to the whole task */ sT.done(); /** determine neighbors by bfs and for the whole graph */ setNeighbors(nextLevel, progressMonitor); } }
From source file:org.summer.dsl.model.ui.query.JavaSearchHelper.java
public void search(URI uri, IProgressMonitor monitor) { int numResources = Iterables.size(resourceDescriptions.getAllResourceDescriptions()); SubMonitor subMonitor = SubMonitor.convert(monitor, numResources); subMonitor.subTask("Find references in EMF resources"); try {/*from ww w .j a va2s. co m*/ for (IResourceDescription resourceDescription : resourceDescriptions.getAllResourceDescriptions()) { URI resourceURI = resourceDescription.getURI(); IResourceServiceProvider resourceServiceProvider = serviceProviderRegistry .getResourceServiceProvider(resourceURI); if (resourceServiceProvider != null) { IJavaSearchParticipation javaSearchParticipation = resourceServiceProvider .get(IJavaSearchParticipation.class); if (javaSearchParticipation == null || javaSearchParticipation.canContainJvmReferences(resourceURI)) searchIn(uri, resourceDescription); } if (subMonitor.isCanceled()) { return; } subMonitor.worked(1); } for (ResourceSet resourceSet : projectToResourceSet.values()) { resourceSet.getResources().clear(); resourceSet.eAdapters().clear(); } } finally { subMonitor.done(); } }
From source file:brooklyn.location.docker.strategy.affinity.DockerAffinityRuleStrategy.java
@Override public List<DockerHostLocation> filterLocations(List<DockerHostLocation> locations, Entity entity) { List<DockerHostLocation> available = Lists.newArrayList(); // Select hosts that satisfy the affinity rules for (DockerHostLocation machine : locations) { Optional<List<String>> entityRules = Optional .fromNullable(entity.config().get(DockerHost.DOCKER_HOST_AFFINITY_RULES)); Optional<List<String>> hostRules = Optional .fromNullable(machine.getOwner().config().get(DockerHost.DOCKER_HOST_AFFINITY_RULES)); Optional<List<String>> infrastructureRules = Optional.fromNullable( machine.getOwner().getInfrastructure().config().get(DockerHost.DOCKER_HOST_AFFINITY_RULES)); Iterable<String> combined = Iterables.concat( Optional.presentInstances(ImmutableList.of(entityRules, hostRules, infrastructureRules))); AffinityRules rules = AffinityRules.rulesFor(entity).parse(combined); Iterable<Entity> entities = getBrooklynManagementContext().getEntityManager() .findEntities(EntityPredicates.locationsIncludes(machine)); if (Iterables.isEmpty(entities)) { if (rules.allowEmptyLocations()) { available.add(machine);/*from w w w . j a v a2s . com*/ } } else { Iterable<Entity> filtered = Iterables.filter(entities, rules); if (Iterables.size(filtered) == Iterables.size(entities)) { available.add(machine); } } } if (LOG.isDebugEnabled()) { LOG.debug("Available Docker hosts: {}", Iterables.toString(available)); } return available; }
From source file:com.netxforge.netxstudio.common.model.ComputationContextProvider.java
/** * Get the {@link RFSService Resource Facing Service } setting from the * computation context.//from w w w . j av a 2 s . co m * * @return the period or <code>null</code> if none specified. */ public RFSService rfsServiceInContext() { final Iterable<IComputationContext> filter = Iterables.filter(context, new Predicate<IComputationContext>() { public boolean apply(IComputationContext o) { return o.getContext() instanceof RFSService; } }); if (Iterables.size(filter) == 1) { return (RFSService) ((IComputationContext) filter.iterator().next()).getContext(); } return null; }
From source file:app.ToDoItemsByCategoryViewModel.java
private static int countIn(final Iterable<ToDoItem> items, final ToDoItem.Subcategory subcategory) { return Iterables.size(Iterables.filter(items, ToDoItem.Predicates.thoseSubcategorised(subcategory))); }
From source file:com.facebook.buck.graph.AbstractBottomUpTraversal.java
public final void traverse() { Iterables.addAll(nodesToExplore, graph.getNodesWithNoOutgoingEdges()); while (!nodesToExplore.isEmpty()) { T node = nodesToExplore.remove(); if (visitedNodes.contains(node)) { Preconditions.checkState(false, "The queue of nodes to explore should not contain a node that has already been" + " visited."); }// www . j a v a2 s.c o m visit(node); visitedNodes.add(node); // Only add a node to the set of nodes to be explored if all the nodes it depends on have // been visited already. We achieve the same by keeping track of the out degrees of explorable // nodes. After visiting a node, decrement the out degree of each of its parent node. When the // out degree reaches zero, it is safe to add that node to the list of nodes to explore next. for (T exploreCandidate : graph.getIncomingNodesFor(node)) { if (!effectiveOutDegreesOfExplorableNodes.containsKey(exploreCandidate)) { effectiveOutDegreesOfExplorableNodes.put(exploreCandidate, new AtomicInteger(Iterables.size(graph.getOutgoingNodesFor(exploreCandidate)))); } if (effectiveOutDegreesOfExplorableNodes.get(exploreCandidate).decrementAndGet() == 0) { nodesToExplore.add(exploreCandidate); } } } }