List of usage examples for com.google.common.collect Iterables isEmpty
public static boolean isEmpty(Iterable<?> iterable)
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 w ww . ja 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(); } }; 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.workhorse.graph.builder.BaseBuilder.java
protected final void runValidation() { Iterable<String> errors = validate(); if (!Iterables.isEmpty(errors)) { throw new RuntimeException( String.format("Builder has the following validation errors: %S", Joiner.on(',').join(errors))); }//w w w . j a va2 s . c o m }
From source file:com.facebook.buck.rules.keys.StringifyAlterRuleKey.java
@Override public void amendKey(RuleKeyObjectSink sink, BuildRule rule) { Object val = valueExtractor.getValue(rule); String stringVal = (val == null) ? null : String.valueOf(val); sink.setReflectively(valueExtractor.getName(), stringVal); if (val != null) { Iterable<Path> absolutePaths = findAbsolutePaths(val); if (!Iterables.isEmpty(absolutePaths)) { LOG.warn("Value %s contains absolute paths %s and it is included in a rule key.", valueExtractor.getFullyQualifiedName(), ImmutableSet.copyOf(absolutePaths)); }//from www. j a v a 2s . c om } }
From source file:com.anathema_roguelike.main.ui.uielements.interactiveuielements.SelectionScreen.java
private void init(Iterable<T> choices, Message instructionsMessage, boolean cancellable, float contentBackground) { int x = getX() + (int) (getWidth() * .05); int y = getY() + (int) (getHeight() * .2); menu = new SelectionMenu<T>(x, y, (int) (getWidth() * .3), getHeight() / 2, false, 1, choices, cancellable, contentBackground);/*from w ww . jav a 2 s.c o m*/ description = new MenuDescription<T>(menu, Iterables.isEmpty(choices) ? null : Utils.getSuperclass(Iterables.get(choices, 0))); if (instructionsMessage != null) { instructions = new TextBox(x, y - 2, menu.getWidth() + description.getWidth(), 1, instructionsMessage, contentBackground); addUIElement(instructions); } addUIElement(description); setFocusedUIElement(menu); }
From source file:org.eclipse.sirius.diagram.sequence.business.internal.VerticalPositionFunction.java
/** * Returns the vertical position of the specified end as it appears on the * diagram associated to this function, or <code>INVALID_POSITION</code> if * the end is invalid or is not part of the diagram. * /*from ww w.java 2 s .c o m*/ * @param end * the end for which to compute the position. * @return the vertical position of the end, or * <code>INVALID_POSITION</code>. */ public Integer apply(EventEnd end) { Integer result; SingleEventEnd see = null; EObject semanticEvent = null; if (end instanceof SingleEventEnd) { see = (SingleEventEnd) end; } else if (end instanceof CompoundEventEnd) { see = ((CompoundEventEnd) end).getEventEnds().iterator().next(); } if (see != null) { semanticEvent = see.getSemanticEvent(); } Iterable<View> eventViews = ISequenceElementAccessor.getViewsForSemanticElement(diagram, semanticEvent); if (Iterables.isEmpty(eventViews) && end instanceof CompoundEventEnd) { for (SingleEventEnd see2 : ((CompoundEventEnd) end).getEventEnds()) { if (see != null) { semanticEvent = see2.getSemanticEvent(); } eventViews = ISequenceElementAccessor.getViewsForSemanticElement(diagram, semanticEvent); if (!Iterables.isEmpty(eventViews)) { break; } } } if (Iterables.isEmpty(eventViews)) { result = INVALID_POSITION; } else { result = INVALID_POSITION; Range range = Range.emptyRange(); for (View potentialView : eventViews) { range = VerticalRangeFunction.INSTANCE.apply(potentialView); if (!range.isEmpty()) { break; } } if (EventEndHelper.PUNCTUAL_COMPOUND_EVENT_END.apply(end)) { result = (int) range.middleValue(); } else if (EventEndHelper.PUNCTUAL_COMPOUND_EVENT_END.apply(end)) { result = (int) range.middleValue(); } else { result = (int) (see.isStart() ? range.getLowerBound() : range.getUpperBound()); } } return result; }
From source file:org.eclipse.elk.alg.layered.intermediate.compaction.LGraphToCGraphTransformer.java
/** * {@inheritDoc}//from w w w. java 2 s . c o m */ @Override public CGraph transform(final LGraph inputGraph) { layeredGraph = inputGraph; commentOffsets.clear(); // checking if the graph has edges and possibly prohibiting vertical compaction hasEdges = false; outer: for (Layer l : layeredGraph) { for (LNode n : l) { if (!Iterables.isEmpty(n.getConnectedEdges())) { hasEdges = true; break outer; } } } EnumSet<Direction> supportedDirections = EnumSet.of(Direction.UNDEFINED, Direction.LEFT, Direction.RIGHT); if (!hasEdges) { supportedDirections.add(Direction.UP); supportedDirections.add(Direction.DOWN); } // initializing fields cGraph = new CGraph(supportedDirections); // importing LGraphElements into CNodes readNodes(); return cGraph; }
From source file:com.google.copybara.util.Glob.java
/** * Creates a function {@link Glob} that when a {@link Path} is passed it returns a * {@link PathMatcher} relative to the path. * * @param include list of strings representing the globs to include/match * @param exclude list of strings representing the globs to exclude from the include set * * @throws IllegalArgumentException if any glob is not valid */// ww w. ja va 2s . co m public Glob(Iterable<String> include, Iterable<String> exclude) { this(ImmutableList.copyOf(include), Iterables.isEmpty(exclude) ? null : new Glob(exclude)); }
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); }//w w w .java 2 s. c o m tuples.forEach(t -> error.addRawMessage(messageGetStrategy.get(t))); ErrorUtils.handleError(collector, error); }
From source file:org.apache.abdera2.writer.AbstractWriter.java
protected void finishCompressedOutputStream(OutputStream out, WriterOptions options) throws IOException { if (!Iterables.isEmpty(options.getCompressionCodecs())) ((DeflaterOutputStream) out).finish(); }
From source file:com.google.devtools.build.skyframe.SimpleCycleDetector.java
@Override public void checkForCycles(Iterable<SkyKey> badRoots, EvaluationResult.Builder<?> result, ParallelEvaluatorContext evaluatorContext) throws InterruptedException { try (AutoProfiler p = AutoProfiler.logged("Checking for Skyframe cycles", logger, 10)) { for (SkyKey root : badRoots) { ErrorInfo errorInfo = checkForCycles(root, evaluatorContext); if (errorInfo == null) { // This node just wasn't finished when evaluation aborted -- there were no cycles below // it. Preconditions.checkState(!evaluatorContext.keepGoing(), "", root, badRoots); continue; }// w w w .ja va 2s. c om Preconditions.checkState(!Iterables.isEmpty(errorInfo.getCycleInfo()), "%s was not evaluated, but was not part of a cycle", root); result.addError(root, errorInfo); if (!evaluatorContext.keepGoing()) { return; } } } }