List of usage examples for com.google.common.collect Iterables isEmpty
public static boolean isEmpty(Iterable<?> iterable)
From source file:org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.java
/** * Returns a {@link SideInputReader} based on {@link SideInputInfo} descriptors and {@link * PCollectionView PCollectionViews}.// w w w . j av a 2s . com * * <p>If side input source metadata is provided by the service in {@link SideInputInfo * sideInputInfos}, we request a {@link SideInputReader} from the {@code executionContext} using * that info. If no side input source metadata is provided but the DoFn expects side inputs, as a * fallback, we request a {@link SideInputReader} based only on the expected views. * * <p>These cases are not disjoint: Whenever a {@link GroupAlsoByWindowFn} takes side inputs, * {@code doFnInfo.getSideInputViews()} should be non-empty. * * <p>A note on the behavior of the Dataflow service: Today, the first case corresponds to batch * mode, while the fallback corresponds to streaming mode. */ public SideInputReader getSideInputReader(@Nullable Iterable<? extends SideInputInfo> sideInputInfos, @Nullable Iterable<? extends PCollectionView<?>> views, DataflowOperationContext operationContext) throws Exception { if (sideInputInfos != null && !Iterables.isEmpty(sideInputInfos)) { return getSideInputReader(sideInputInfos, operationContext); } else if (views != null && !Iterables.isEmpty(views)) { return getSideInputReaderForViews(views); } else { return NullSideInputReader.empty(); } }
From source file:org.jclouds.vcloud.director.v1_5.domain.params.ControlAccessParams.java
public ControlAccessParams(Boolean sharedToEveryone, String everyoneAccessLevel, Iterable<AccessSetting> accessSettings) { this.sharedToEveryone = sharedToEveryone; if (sharedToEveryone) { this.everyoneAccessLevel = checkNotNull(everyoneAccessLevel, "everyoneAccessLevel"); this.accessSettings = null; } else {//from w w w . j a v a 2 s .c o m this.everyoneAccessLevel = null; this.accessSettings = Iterables.isEmpty(checkNotNull(accessSettings, "accessSettings")) ? null : ImmutableList.copyOf(accessSettings); } }
From source file:org.eclipse.xtend.maven.AbstractXtendCompilerMojo.java
protected void compile(String classPath, List<String> sourcePaths, String outputPath) throws MojoExecutionException { XtendBatchCompiler compiler = getBatchCompiler(); Log log = getLog();//from w w w. j av a 2 s . c om compiler.setResourceSetProvider(new MavenProjectResourceSetProvider(project)); Iterable<String> filtered = filter(sourcePaths, FILE_EXISTS); if (Iterables.isEmpty(filtered)) { String dir = Iterables.toString(sourcePaths); log.info("skip compiling sources because the configured directory '" + dir + "' does not exist."); return; } String baseDir = project.getBasedir().getAbsolutePath(); log.debug("Set Java Compliance Level: " + javaSourceVersion); compiler.setJavaSourceVersion(javaSourceVersion); log.debug("Set generateSyntheticSuppressWarnings: " + generateSyntheticSuppressWarnings); compiler.setGenerateSyntheticSuppressWarnings(generateSyntheticSuppressWarnings); log.debug("Set generateGeneratedAnnotation: " + generateGeneratedAnnotation); compiler.setGenerateGeneratedAnnotation(generateGeneratedAnnotation); log.debug("Set includeDateInGeneratedAnnotation: " + includeDateInGeneratedAnnotation); compiler.setIncludeDateInGeneratedAnnotation(includeDateInGeneratedAnnotation); log.debug("Set generatedAnnotationComment: " + generatedAnnotationComment); compiler.setGeneratedAnnotationComment(generatedAnnotationComment); log.debug("Set baseDir: " + baseDir); compiler.setBasePath(baseDir); log.debug("Set temp directory: " + getTempDirectory()); compiler.setTempDirectory(getTempDirectory()); log.debug("Set DeleteTempDirectory: " + false); compiler.setDeleteTempDirectory(false); log.debug("Set classpath: " + classPath); compiler.setClassPath(classPath); String bootClassPath = getBootClassPath(); log.debug("Set bootClasspath: " + bootClassPath); compiler.setBootClassPath(bootClassPath); log.debug("Set source path: " + concat(File.pathSeparator, newArrayList(filtered))); compiler.setSourcePath(concat(File.pathSeparator, newArrayList(filtered))); log.debug("Set output path: " + outputPath); compiler.setOutputPath(outputPath); log.debug("Set encoding: " + encoding); compiler.setFileEncoding(encoding); log.debug("Set writeTraceFiles: " + writeTraceFiles); compiler.setWriteTraceFiles(writeTraceFiles); if (!compiler.compile()) { String dir = concat(File.pathSeparator, newArrayList(filtered)); throw new MojoExecutionException("Error compiling xtend sources in '" + dir + "'."); } }
From source file:eu.esdihumboldt.hale.ui.views.data.internal.explore.InstanceContentProvider.java
/** * @see ITreeContentProvider#hasChildren(Object) *//*www. j av a 2s .com*/ @Override public boolean hasChildren(Object element) { if (element instanceof Pair<?, ?>) { Pair<?, ?> pair = (Pair<?, ?>) element; if (pair.getFirst() == Metadata.METADATA && pair.getSecond() instanceof Instance) { return true; } element = pair.getSecond(); } if (element instanceof Group) { Group group = (Group) element; return !Iterables.isEmpty(group.getPropertyNames()); } return false; }
From source file:org.locationtech.geogig.storage.memory.HeapGraphDatabase.java
@Override public boolean put(ObjectId commitId, ImmutableList<ObjectId> parentIds) { Node n = graph.getOrAdd(commitId); if (parentIds.isEmpty()) { // the root node, only update on first addition if (!n.isRoot()) { n.setRoot(true);//ww w . j a va 2 s .c o m return true; } } // has the node been attached to graph? if (Iterables.isEmpty(n.to())) { // nope, attach it for (ObjectId parent : parentIds) { Node p = graph.getOrAdd(parent); graph.newEdge(n, p); } // only mark as updated if it is actually attached boolean added = !Iterables.isEmpty(n.to()); return added; } return false; }
From source file:org.apache.aurora.common.zookeeper.CandidateImpl.java
@Nullable private String getLeader(Iterable<String> memberIds) { return Iterables.isEmpty(memberIds) ? null : MOST_RECENT_JUDGE.apply(memberIds); }
From source file:com.facebook.presto.sql.ExpressionUtils.java
public static Expression combineConjunctsWithDefault(Iterable<Expression> expressions, Expression emptyDefault) { requireNonNull(expressions, "expressions is null"); // Flatten all the expressions into their component conjuncts expressions = Iterables.concat(Iterables.transform(expressions, ExpressionUtils::extractConjuncts)); // Strip out all true literal conjuncts expressions = Iterables.filter(expressions, not(Predicates.<Expression>equalTo(TRUE_LITERAL))); expressions = removeDuplicates(expressions); return Iterables.isEmpty(expressions) ? emptyDefault : and(expressions); }
From source file:msi.gama.lang.gaml.ui.templates.GamlTemplateFactory.java
private static void dump(final String title, final Iterable<? extends INamed> descs, final StringBuilder sb) { if (!Iterables.isEmpty(descs)) { final List<INamed> named = Lists.newArrayList(descs); Collections.sort(named, INamed.COMPARATOR); sb.append(title);// w w w . j a va2 s .c o m for (final INamed sd : named) { sb.append(commentLine).append(sd.serialize(true)); } sb.append(Strings.LN); } }
From source file:com.google.cloud.dataflow.sdk.util.StateFetcher.java
public Map<CodedTupleTag<?>, List<?>> fetchList(String computation, ByteString key, long workToken, String prefix, Iterable<? extends CodedTupleTag<?>> tags) throws IOException { if (Iterables.isEmpty(tags)) { return Collections.emptyMap(); }/*from w ww.jav a 2 s .c om*/ Windmill.KeyedGetDataRequest.Builder requestBuilder = Windmill.KeyedGetDataRequest.newBuilder().setKey(key) .setWorkToken(workToken); Map<ByteString, CodedTupleTag<?>> tagMap = new HashMap<>(); for (CodedTupleTag<?> tag : tags) { ByteString tagString = ByteString.copyFromUtf8(prefix + tag.getId()); if (tagMap.put(tagString, tag) == null) { requestBuilder.addListsToFetch( Windmill.TagList.newBuilder().setTag(tagString).setEndTimestamp(Long.MAX_VALUE).build()); } } Map<CodedTupleTag<?>, List<?>> resultMap = new HashMap<>(); Windmill.KeyedGetDataResponse keyResponse = getResponse(computation, key, requestBuilder); for (Windmill.TagList tagList : keyResponse.getListsList()) { CodedTupleTag<?> tag = tagMap.get(tagList.getTag()); resultMap.put(tag, decodeTagList(tag, tagList)); } return resultMap; }
From source file:io.druid.server.ClientInfoResource.java
@GET @Path("/{dataSourceName}") @Produces(MediaType.APPLICATION_JSON)//from www. j a v a 2 s. c o m public Map<String, Object> getDatasource(@PathParam("dataSourceName") String dataSourceName, @QueryParam("interval") String interval, @QueryParam("full") String full) { if (full == null) { return ImmutableMap.<String, Object>of(KEY_DIMENSIONS, getDatasourceDimensions(dataSourceName, interval), KEY_METRICS, getDatasourceMetrics(dataSourceName, interval)); } Interval theInterval; if (interval == null || interval.isEmpty()) { DateTime now = getCurrentTime(); theInterval = new Interval(segmentMetadataQueryConfig.getDefaultHistory(), now); } else { theInterval = new Interval(interval); } TimelineLookup<String, ServerSelector> timeline = timelineServerView .getTimeline(new TableDataSource(dataSourceName)); Iterable<TimelineObjectHolder<String, ServerSelector>> serversLookup = timeline != null ? timeline.lookup(theInterval) : null; if (serversLookup == null || Iterables.isEmpty(serversLookup)) { return Collections.EMPTY_MAP; } Map<Interval, Object> servedIntervals = new TreeMap<>(new Comparator<Interval>() { @Override public int compare(Interval o1, Interval o2) { if (o1.equals(o2) || o1.overlaps(o2)) { return 0; } else { return o1.isBefore(o2) ? -1 : 1; } } }); for (TimelineObjectHolder<String, ServerSelector> holder : serversLookup) { final Set<Object> dimensions = Sets.newHashSet(); final Set<Object> metrics = Sets.newHashSet(); final PartitionHolder<ServerSelector> partitionHolder = holder.getObject(); if (partitionHolder.isComplete()) { for (ServerSelector server : partitionHolder.payloads()) { final DataSegment segment = server.getSegment(); dimensions.addAll(segment.getDimensions()); metrics.addAll(segment.getMetrics()); } } servedIntervals.put(holder.getInterval(), ImmutableMap.of(KEY_DIMENSIONS, dimensions, KEY_METRICS, metrics)); } //collapse intervals if they abut and have same set of columns Map<String, Object> result = Maps.newLinkedHashMap(); Interval curr = null; Map<String, Set<String>> cols = null; for (Map.Entry<Interval, Object> e : servedIntervals.entrySet()) { Interval ival = e.getKey(); if (curr != null && curr.abuts(ival) && cols.equals(e.getValue())) { curr = curr.withEnd(ival.getEnd()); } else { if (curr != null) { result.put(curr.toString(), cols); } curr = ival; cols = (Map<String, Set<String>>) e.getValue(); } } //add the last one in if (curr != null) { result.put(curr.toString(), cols); } return result; }