List of usage examples for com.google.common.collect Iterables size
public static int size(Iterable<?> iterable)
From source file:jflowmap.data.StaxGraphMLReader.java
public Iterable<Graph> readFromLocation(String location) throws IOException { logger.info("Loading file \"" + location + "\""); InputStream is = IOLib.streamFromString(location); if (is == null) { throw new IOException("Couldn't read from location: \"" + location + "\""); }//w w w . j a va 2 s . co m Iterable<Graph> graphs = readFromStream(is); logger.info("Finished loading file. Number of graphs loaded: " + Iterables.size(graphs)); return graphs; }
From source file:org.eclipse.elk.tree.intermediate.NeighborsProcessor.java
/** * Set the neighbors of each node in the current level and for their children. A neighbor is the * current node's nearest node, at the same level. A siblings is a neighbor with the same * parent.//from w w w . j a v a2 s . 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(); } }; TNode lN = null; /** * the left neighbor is the previous processed node the right neighbor of the left * neighbor is the current node */ for (TNode cN : currentLevel) { /** append the children of the current node to the next level */ nextLevel = Iterables.concat(nextLevel, cN.getChildren()); if (lN != null) { lN.setProperty(Properties.RIGHTNEIGHBOR, cN); cN.setProperty(Properties.LEFTNEIGHBOR, lN); if (cN.getParent() == lN.getParent()) { lN.setProperty(Properties.RIGHTSIBLING, cN); cN.setProperty(Properties.LEFTSIBLING, lN); } } lN = cN; } /** 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:cz.afri.smg.objects.sll.SMGSingleLinkedListFinder.java
private void buildInboundPointers() { for (SMGEdgePointsTo pt : smg.getPTEdges()) { int pointer = pt.getValue(); Iterable<SMGEdgeHasValue> hvEdges = smg .getHVEdges(new SMGEdgeHasValueFilter().filterHavingValue(pointer)); inboundPointers.put(pointer, Iterables.size(hvEdges)); }// w ww. j a va 2 s . com }
From source file:org.knight.examples.guava.strings.StringsExamples.java
private void split() { //result is ["foo ", " bar ", "", ""] String s3 = "foo , bar ,,"; Iterable<String> it1 = Splitter.on(',').split(s3); StringBuilder sb1 = new StringBuilder(); sb1.append("s3 split size=" + Iterables.size(it1)); sb1.append("||"); for (String s : it1) { sb1.append(s);//from w w w. j av a 2 s . c o m sb1.append("||"); } log(sb1.toString()); //result is ["hello", "java,guava", "world"] String s4 = "hello; java,guava ; world;"; //if no omitEmptyStrings(), the result is ["hello", "java,guava", "world", ""] List<String> list = Splitter.on(';').trimResults().omitEmptyStrings().splitToList(s4); log("split list size=" + list.size() + ": " + list.toString()); String s5 = "guava,learning,best;foo"; //split by fixed length Iterable<String> it2 = Splitter.fixedLength(5).split(s5); StringBuilder sb2 = new StringBuilder(); sb2.append("s5 split size=" + Iterables.size(it2)); sb2.append("||"); for (String s : it2) { sb2.append(s); sb2.append("||"); } log(it2.toString()); Iterable<String> it3 = Splitter.on(',').limit(2).omitEmptyStrings().split(s5); StringBuilder sb3 = new StringBuilder(); sb3.append("s5 limit split size=" + Iterables.size(it3)); sb3.append("||"); for (String s : it3) { sb3.append(s); sb3.append("||"); } log("s5 limit size=" + Iterables.size(it3) + ": " + it3.toString()); }
From source file:org.eclipse.elk.alg.mrtree.intermediate.NeighborsProcessor.java
/** * Set the neighbors of each node in the current level and for their children. A neighbor is the * current node's nearest node, at the same level. A siblings is a neighbor with the same * parent.//from ww w. j a v a 2 s. 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(); } }; TNode lN = null; /** * the left neighbor is the previous processed node the right neighbor of the left * neighbor is the current node */ for (TNode cN : currentLevel) { /** append the children of the current node to the next level */ nextLevel = Iterables.concat(nextLevel, cN.getChildren()); if (lN != null) { lN.setProperty(InternalProperties.RIGHTNEIGHBOR, cN); cN.setProperty(InternalProperties.LEFTNEIGHBOR, lN); if (cN.getParent() == lN.getParent()) { lN.setProperty(InternalProperties.RIGHTSIBLING, cN); cN.setProperty(InternalProperties.LEFTSIBLING, lN); } } lN = cN; } /** 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.eclipse.elk.alg.layered.intermediate.compaction.CLNode.java
/** * Constructor, infers hitbox from position, size and margins of the {@link LNode}. Also sets * the {@link org.eclipse.elk.alg.layered.compaction.oned.Quadruplet CompactionLock} according * to the ratio of incoming to outgoing {@link de.cau.cs.kieler.klay.layered.graph.LEdge LEdge} * s. {@link NodeType#EXTERNAL_PORT external port dummy nodes} are never locked to keep the * graph size minimal. They are later reset to the border position by the * {@link de.cau.cs.kieler.klay.layered.graph.transform.KGraphLayoutTransferrer * KGraphLayoutTransferrer}/*from w w w .j a v a 2s . co m*/ * * @param lNode * the node * @param layeredGraph * the containing layered graph */ public CLNode(final LNode lNode, final LGraph layeredGraph) { // getting the spacing properties horizontalSpacing = (double) layeredGraph.getProperty(LayeredOptions.SPACING_NODE); verticalSpacing = horizontalSpacing * layeredGraph.getProperty(LayeredOptions.SPACING_IN_LAYER_SPACING_FACTOR); // calculating the necessary hitbox dimensions this.lNode = lNode; hitbox = new Rectangle(lNode.getPosition().x - lNode.getMargin().left, lNode.getPosition().y - lNode.getMargin().top, lNode.getSize().x + lNode.getMargin().left + lNode.getMargin().right, lNode.getSize().y + lNode.getMargin().top + lNode.getMargin().bottom); cGroupOffset.reset(); // locking the node for directions that fewer edges are connected in int difference = Iterables.size(lNode.getIncomingEdges()) - Iterables.size(lNode.getOutgoingEdges()); if (difference < 0) { lock.set(true, Direction.LEFT); } else if (difference > 0) { lock.set(true, Direction.RIGHT); } // excluding external port dummies if (lNode.getType() == NodeType.EXTERNAL_PORT) { lock.set(false, false, false, false); } }
From source file:org.jclouds.rimuhosting.miro.location.RimuHostingLocationSupplier.java
@Override public Set<? extends Location> get() { Builder<Location> locations = ImmutableSet.builder(); Iterable<DataCenter> list = Iterables .filter(Iterables.transform(sync.getPricingPlanList(), new Function<PricingPlan, DataCenter>() { @Override//from w w w .j a va2 s.co m public DataCenter apply(PricingPlan arg0) { return arg0.getDataCenter(); } }), Predicates.<DataCenter>notNull()); Location provider = Iterables.getOnlyElement(super.get()); if (Iterables.size(list) == 0) locations.add(provider); else { Map<String, Supplier<Set<String>>> isoCodesById = isoCodesByIdSupplier.get(); for (DataCenter from : list) { LocationBuilder builder = new LocationBuilder().scope(LocationScope.ZONE).id(from.getId()) .description(from.getName()).parent(provider); if (isoCodesById.containsKey(from.getId())) builder.iso3166Codes(isoCodesById.get(from.getId()).get()); locations.add(builder.build()); } } return locations.build(); }
From source file:com.ydy.cf.solver.impl.AlternatingLeastSquaresSolver.java
private Vector solve(Iterable<Vector> featureVectors, Vector ratingVector, double lambda, int numFeatures) { Preconditions.checkNotNull(featureVectors, "Feature vectors cannot be null"); Preconditions.checkArgument(!Iterables.isEmpty(featureVectors)); Preconditions.checkNotNull(ratingVector, "rating vector cannot be null"); Preconditions.checkArgument(ratingVector.getNumNondefaultElements() > 0, "Rating vector cannot be empty"); Preconditions.checkArgument(Iterables.size(featureVectors) == ratingVector.getNumNondefaultElements()); int nui = ratingVector.getNumNondefaultElements(); Matrix MiIi = createMiIi(featureVectors, numFeatures); Matrix RiIiMaybeTransposed = createRiIiMaybeTransposed(ratingVector); /* compute Ai = MiIi * t(MiIi) + lambda * nui * E */ Matrix Ai = addLambdaTimesNuiTimesE(MiIi.times(MiIi.transpose()), lambda, nui); /* compute Vi = MiIi * t(R(i,Ii)) */ Matrix Vi = MiIi.times(RiIiMaybeTransposed); /* compute Ai * ui = Vi */ return solve(Ai, Vi); }
From source file:org.eclipse.sirius.diagram.ui.tools.internal.figure.ContainerWithTitleBlockFigure.java
/** * This method is overridden to draw a line over the border node. * //from w w w . ja va 2 s.c o m * {@inheritDoc} */ @Override protected void paintBorder(Graphics graphics) { super.paintBorder(graphics); graphics.setLineStyle(Graphics.LINE_SOLID); graphics.setLineWidth(1); graphics.setForegroundColor(geBorderColor()); Iterable<ViewNodeContainerFigureDesc> filter = Iterables.filter(getChildren(), ViewNodeContainerFigureDesc.class); if (Iterables.size(filter) == 1) { ViewNodeContainerFigureDesc child = filter.iterator().next(); SiriusWrapLabel containerLabelFigure = child.getLabelFigure(); // Only LabelBorderStyleWithBeveledCorner is supported. if (containerLabelFigure != null && containerLabelFigure.isVisible() && LabelBorderStyleIds.LABEL_BORDER_STYLE_WITH_BEVELED_CORNERS_ID .equals(labelBorderStyleDescription.getId())) { Rectangle containerLabelFigureBounds = containerLabelFigure.getBounds(); paintTitleBlockOnLabel(graphics, containerLabelFigureBounds); } } }
From source file:org.apache.metron.writer.BulkWriterComponent.java
public void error(String sensorType, Throwable e, Iterable<Tuple> tuples, MessageGetStrategy messageGetStrategy) { tuples.forEach(t -> collector.ack(t)); MetronError error = new MetronError().withSensorType(sensorType) .withErrorType(Constants.ErrorType.INDEXING_ERROR).withThrowable(e); if (!Iterables.isEmpty(tuples)) { LOG.error("Failing " + Iterables.size(tuples) + " tuples", e); }/*from w w w. ja v a 2 s .c o m*/ tuples.forEach(t -> error.addRawMessage(messageGetStrategy.get(t))); ErrorUtils.handleError(collector, error); }