List of usage examples for com.google.common.collect Iterables isEmpty
public static boolean isEmpty(Iterable<?> iterable)
From source file:com.webbfontaine.valuewebb.irms.impl.risk.data.RiskResultCollector.java
private static <T> boolean notEmpty(Iterable<T> selectedResults) { return !Iterables.isEmpty(selectedResults); }
From source file:org.jboss.hal.ballroom.autocomplete.ReadChildrenAutoComplete.java
private void verifyTemplates(Iterable<AddressTemplate> templates) { if (Iterables.isEmpty(templates)) { throw new IllegalArgumentException("Templates must not be empty in ReadChildrenAutoComplete"); }//from ww w. j a v a 2 s.c om }
From source file:com.google.javascript.jscomp.DependencyOptions.java
/** * Returns a {@link DependencyOptions} using the {@link DependencyMode#PRUNE} mode with the given * entry points./*from w ww .ja v a 2s . c o m*/ */ public static DependencyOptions pruneForEntryPoints(Iterable<ModuleIdentifier> entryPoints) { checkState(!Iterables.isEmpty(entryPoints), "DependencyMode.PRUNE requires at least one entry point"); return new AutoValue_DependencyOptions(DependencyMode.PRUNE, ImmutableList.copyOf(entryPoints)); }
From source file:eu.trentorise.opendata.semantics.services.Schemas.java
/** * * Checks if provided path is valid//ww w . ja va 2 s.c o m * * @param prependedErrorMessage * the exception message to use if the check fails; will be * converted to a string using String.valueOf(Object) and * prepended to more specific error messages. * * @throws IllegalArgumentException * if provided path fails validation * * @return a valid immutable path */ public static List<String> checkSourcePath(@Nullable Iterable<String> path, @Nullable Object prependedErrorMessage) { checkNotNull(path); if (Iterables.isEmpty(path)) { return ImmutableList.of(); } String kind = path.iterator().next(); checkArgument(ALLOWED_SOURCES.contains(kind), "path kind must be one of %s, found instead: '%s'", ALLOWED_SOURCES, kind); if (!SCHEMA_SOURCE.equals(kind)) { checkNotEmpty(path, "Invalid id path!"); } if (DCAT_SOURCE.equals(kind)) { throw new UnsupportedOperationException("Todo implement me!"); //Tracel.checkPathFromClass(DcatMetadata.class, PropertyPath.parse(path)); } for (String property : path) { checkNotEmpty(property, "Invalid property in path %s", path); } return ImmutableList.copyOf(path); }
From source file:org.eclipse.elk.alg.layered.intermediate.compaction.LGraphToCGraphTransformer.java
/** * Collects the positions and dimensions of {@link LNode}s and vertical segments in the layered * graph and writes them to the {@link CNode}s. *//*from w w w . ja v a 2s. co m*/ private void readNodes() { List<VerticalSegment> verticalSegments = Lists.newArrayList(); // resetting to avoid problems if this is called repeatedly cGraph.cNodes.clear(); // 1. collecting positions of graph elements Map<LNode, CNode> nodeMap = Maps.newHashMap(); for (Layer layer : layeredGraph) { for (LNode node : layer) { // comment boxes are part of a node's margins // hence we can neglect them here without the risk // of other nodes overlapping them after compaction if (node.getProperty(LayeredOptions.COMMENT_BOX)) { if (!Iterables.isEmpty(node.getConnectedEdges())) { LEdge e = Iterables.get(node.getConnectedEdges(), 0); LNode other = e.getSource().getNode(); if (other == node) { other = e.getTarget().getNode(); } Pair<LNode, KVector> p = Pair.of(other, node.getPosition().clone().sub(other.getPosition())); commentOffsets.put(node, p); continue; } } // add all nodes CLNode cNode = new CLNode(node, layeredGraph); cGraph.cNodes.add(cNode); nodeMap.put(node, cNode); } } for (Layer layer : layeredGraph) { for (LNode node : layer) { final CNode cNode = nodeMap.get(node); // add vertical edge segments for (LEdge edge : node.getOutgoingEdges()) { Iterator<KVector> bends = edge.getBendPoints().iterator(); boolean first = true; VerticalSegment lastSegment = null; // infer vertical segments from positions of bendpoints if (bends.hasNext()) { KVector bend1 = bends.next(); KVector bend2 = null; // get segment of source n/s port if (edge.getSource().getSide() == PortSide.NORTH) { VerticalSegment vs = new VerticalSegment(bend1, new KVector(bend1.x, cNode.hitbox.y), cNode, edge); vs.blockBottomSpacing = true; verticalSegments.add(vs); } if (edge.getSource().getSide() == PortSide.SOUTH) { VerticalSegment vs = new VerticalSegment(bend1, new KVector(bend1.x, cNode.hitbox.y + cNode.hitbox.height), cNode, edge); vs.blockTopSpacing = true; verticalSegments.add(vs); } // get regular segments while (bends.hasNext()) { bend2 = bends.next(); if (!CompareFuzzy.eq(bend1.y, bend2.y)) { lastSegment = new VerticalSegment(bend1, bend2, null, edge); verticalSegments.add(lastSegment); // the first vertical segment of an outgoing edge if (first) { first = false; if (bend2.y < cNode.hitbox.y) { lastSegment.blockBottomSpacing = true; } else if (bend2.y > cNode.hitbox.y + cNode.hitbox.height) { lastSegment.blockTopSpacing = true; } else { // completely surrounded lastSegment.blockTopSpacing = true; lastSegment.blockBottomSpacing = true; } } } if (bends.hasNext()) { bend1 = bend2; } } // handle last vertical segment if (lastSegment != null) { CNode cTargetNode = nodeMap.get(edge.getTarget().getNode()); if (bend1.y < cTargetNode.hitbox.y) { lastSegment.blockBottomSpacing = true; } else if (bend1.y > cTargetNode.hitbox.y + cTargetNode.hitbox.height) { lastSegment.blockTopSpacing = true; } else { // completely surrounded lastSegment.blockTopSpacing = true; lastSegment.blockBottomSpacing = true; } } } } // same for incoming edges to get NSSegments on target side for (LEdge edge : node.getIncomingEdges()) { if (!edge.getBendPoints().isEmpty()) { // get segment of target n/s port KVector bend1 = edge.getBendPoints().getLast(); if (edge.getTarget().getSide() == PortSide.NORTH) { VerticalSegment vs = new VerticalSegment(bend1, new KVector(bend1.x, cNode.hitbox.y), cNode, edge); vs.blockBottomSpacing = true; verticalSegments.add(vs); } if (edge.getTarget().getSide() == PortSide.SOUTH) { VerticalSegment vs = new VerticalSegment(bend1, new KVector(bend1.x, cNode.hitbox.y + cNode.hitbox.height), cNode, edge); vs.blockTopSpacing = true; verticalSegments.add(vs); } } } } } // 2. combining intersecting segments in CLEdges to process them as one if (!verticalSegments.isEmpty()) { // sorting the segments by position in ascending order Collections.sort(verticalSegments); // merging intersecting segments in the same CLEdge VerticalSegment last = verticalSegments.get(0); CLEdge c = new CLEdge(last, layeredGraph); for (int i = 1; i < verticalSegments.size(); i++) { VerticalSegment verticalSegment = verticalSegments.get(i); if (c.intersects(verticalSegment)) { c.addSegment(verticalSegment); } else { cGraph.cNodes.add(c); c = new CLEdge(verticalSegment, layeredGraph); } last = verticalSegment; } cGraph.cNodes.add(c); } verticalSegments.clear(); // 3. grouping nodes with their connected north/south segments groupCNodes(); }
From source file:org.janusgraph.util.system.ConfigurationPrinter.java
private void printNamespace(ConfigNamespace n, String prefix) { String newPrefix = prefix + n.getName() + "."; if (n.isUmbrella()) newPrefix += "[X]."; if (n.isRoot()) newPrefix = ""; //Override for root namespace //Only print namespace if it contains (visible) options if (!Iterables.isEmpty(getSortedChildOptions(n))) { stream.println(getNamespaceSectionHeader(n, prefix)); stream.println(getTableHeader()); for (ConfigOption<?> o : getSortedChildOptions(n)) { stream.println(getTableLineForOption(o, newPrefix)); }/*from ww w . j av a2 s .c o m*/ stream.println(TABLE_FOOTER_LINES); } for (ConfigNamespace cn : getSortedChildNamespaces(n)) { printNamespace(cn, newPrefix); } }
From source file:org.lttng.scope.lttng.ust.core.analysis.debuginfo.internal.FileOffsetMapper.java
/** * Get the function/symbol name corresponding to binary file and offset. * * @param file//from ww w. j a v a2s .c o m * The binary file to look at * @param buildId * The expected buildId of the binary file (is not verified at * the moment) * @param offset * The memory offset in the file * @return The corresponding function/symbol name */ public static @Nullable String getFunctionNameFromOffset(File file, @Nullable String buildId, long offset) { /* * TODO We are currently also using 'addr2line' to resolve function * names, which requires the binary's DWARF information to be available. * A better approach would be to use the binary's symbol table (if it is * not stripped), since this is usually more readily available than * DWARF. */ Iterable<Addr2lineInfo> output = getAddr2lineInfo(file, buildId, offset); if (output == null || Iterables.isEmpty(output)) { return null; } Addr2lineInfo info = Iterables.getLast(output); return info.fFunctionName; }
From source file:co.cask.cdap.internal.app.services.DefaultServiceConfigurer.java
private void verifyHandlers(List<? extends HttpServiceHandler> handlers) { Preconditions.checkArgument(!Iterables.isEmpty(handlers), "Service %s should have at least one handler", name);// ww w . java 2 s .c o m try { List<HttpHandler> httpHandlers = Lists.newArrayList(); for (HttpServiceHandler handler : handlers) { httpHandlers.add(createHttpHandler(handler)); } // Constructs a NettyHttpService, to verify that the handlers passed in by the user are valid. NettyHttpService.builder().addHttpHandlers(httpHandlers).build(); } catch (Throwable t) { String errMessage = String.format("Invalid handlers in service: %s.", name); LOG.error(errMessage, t); throw new IllegalArgumentException(errMessage, t); } }
From source file:org.apache.flex.compiler.internal.driver.JSTarget.java
@Override public ISWF build(Collection<ICompilerProblem> problems) { buildStarted();/* ww w.j a va 2s. c om*/ try { Iterable<ICompilerProblem> fatalProblems = getFatalProblems(); if (!Iterables.isEmpty(fatalProblems)) { Iterables.addAll(problems, fatalProblems); return null; } Set<ICompilationUnit> compilationUnitSet = new HashSet<ICompilationUnit>(); Target.RootedCompilationUnits rootedCompilationUnits = getRootedCompilationUnits(); Iterables.addAll(problems, rootedCompilationUnits.getProblems()); compilationUnitSet.addAll(rootedCompilationUnits.getUnits()); buildAndCollectProblems(compilationUnitSet, problems); List<ICompilationUnit> reachableCompilationUnits = project .getReachableCompilationUnitsInSWFOrder(rootedCompilationUnits.getUnits()); ISWF swf = initializeSWF(reachableCompilationUnits); // make main frame for DoABC tags final SWFFrame mainFrame = new SWFFrame(); swf.addFrame(mainFrame); // Add definitions. for (final ICompilationUnit cu : compilationUnitSet) { // ignore externals if (isLinkageExternal(cu, targetSettings)) continue; // ignore any resource bundles if (cu instanceof ResourceBundleCompilationUnit) continue; // Create a DoABC tag per compilation unit. // Please add this API to SWFTarget. Thx. // protected Boolean addToFrame(ICompilationUnit cu, SWFFrame mainFrame) throws InterruptedException // final boolean tagsAdded = cu.getSWFTagsRequest().get().addToFrame(mainFrame); final boolean tagsAdded = addToFrame(cu, mainFrame); if (!tagsAdded) { ICompilerProblem problem = new UnableToBuildSWFTagProblem(cu.getAbsoluteFilename()); problems.add(problem); } } createLinkReport(problems); return swf; } catch (BuildCanceledException bce) { return null; } catch (InterruptedException ie) { return null; } finally { buildFinished(); } }
From source file:org.gradle.model.internal.core.ModelTypeInitializationException.java
private static void maybeAppendConstructables(StringBuilder s, Iterable<ModelType<?>> constructableTypes, int pad) { if (!Iterables.isEmpty(constructableTypes)) { String padding = pad(pad); s.append(String.format("%n%s- or a type which Gradle is capable of constructing:", padding)); for (ModelType<?> modelType : constructableTypes) { s.append(String.format("%n %s- %s", padding, modelType.getName())); }/*from w w w. ja va 2s .c om*/ } }