List of usage examples for com.google.common.collect Iterables isEmpty
public static boolean isEmpty(Iterable<?> iterable)
From source file:co.cask.cdap.data2.datafabric.dataset.service.DatasetService.java
@Override protected void startUp() throws Exception { LOG.info("Starting DatasetService..."); mdsDatasets.startAndWait();/*from w w w . j a v a2 s .com*/ typeManager.startAndWait(); opExecutorClient.startAndWait(); httpService.startAndWait(); // setting watch for ops executor service that we need to be running to operate correctly ServiceDiscovered discover = discoveryServiceClient.discover(Constants.Service.DATASET_EXECUTOR); opExecutorDiscovered = SettableFuture.create(); opExecutorServiceWatch = discover.watchChanges(new ServiceDiscovered.ChangeListener() { @Override public void onChange(ServiceDiscovered serviceDiscovered) { if (!Iterables.isEmpty(serviceDiscovered)) { LOG.info("Discovered {} service", Constants.Service.DATASET_EXECUTOR); opExecutorDiscovered.set(serviceDiscovered); } } }, MoreExecutors.sameThreadExecutor()); for (DatasetMetricsReporter metricsReporter : metricReporters) { metricsReporter.start(); } }
From source file:com.google.cloud.dataflow.sdk.testing.CoderProperties.java
/** * Verifies that for the given {@code Coder<Iterable<T>>}, * and value of type {@code Iterable<T>}, encoding followed by decoding yields an * equal value of type {@code Collection<T>}, in the given {@code Coder.Context}. *//*w w w.j a v a2 s. c om*/ @SuppressWarnings("unchecked") public static <T, IterableT extends Iterable<T>> void coderDecodeEncodeContentsInSameOrderInContext( Coder<IterableT> coder, Coder.Context context, IterableT value) throws Exception { Iterable<T> result = decodeEncode(coder, context, value); // Matchers.contains() requires at least one element if (Iterables.isEmpty(value)) { assertThat(result, emptyIterable()); } else { // This is the only Matchers.contains() overload that takes literal values assertThat(result, contains((T[]) Iterables.toArray(value, Object.class))); } }
From source file:org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.validator.AbstractInteractionFrameValidator.java
/** * Performs all the computations required to validate the resizing, and * stores any important information which will be useful to actually execute * the resize if it is valid, like for example avoid contact with siblings. */// w w w . j a v a 2s . c o m protected void validate() { valid = checkAndComputeRanges(); if (valid) { Collection<ISequenceEvent> finalParents = getFinalParentsWithAutoExpand(); Collection<ISequenceEvent> movableParents = Lists .newArrayList(Iterables.filter(finalParents, Predicates.not(unMove))); Collection<ISequenceEvent> fixedParents = Lists.newArrayList(Iterables.filter(finalParents, unMove)); if (movableParents.isEmpty() || !movedElements.containsAll(movableParents)) { valid = valid && Iterables.isEmpty(Iterables.filter(finalParents, invalidParents)); valid = valid && (!Iterables.any(finalParents, Predicates.instanceOf(Operand.class)) || finalParents.size() == 1); valid = valid && checkFinalRangeStrictlyIncludedInParents(movableParents); valid = valid && checkLocalSiblings(movableParents); } valid = valid && checkFinalRangeStrictlyIncludedInParents(fixedParents); valid = valid && checkLocalSiblings(fixedParents); } if (getRequestQuery().isResize()) { valid = valid && checkGlobalPositions(); } }
From source file:org.apache.cassandra.db.lifecycle.View.java
static Function<View, View> updateLiveSet(final Set<SSTableReader> remove, final Iterable<SSTableReader> add) { if (remove.isEmpty() && Iterables.isEmpty(add)) return Functions.identity(); return new Function<View, View>() { public View apply(View view) { Map<SSTableReader, SSTableReader> sstableMap = replace(view.sstablesMap, remove, add); return new View(view.liveMemtables, view.flushingMemtables, sstableMap, view.compacting, SSTableIntervalTree.build(sstableMap.keySet())); }/*from ww w.ja va 2 s . c o m*/ }; }
From source file:com.spectralogic.ds3cli.command.PutBulk.java
@Override public PutBulkResult call() throws Exception { /* Ensure the bucket exists and if not create it */ final Ds3ClientHelpers helpers = getClientHelpers(); helpers.ensureBucketExists(this.bucketName); Iterable<Path> filesToPut = this.getFilesToPut(); if (this.sync) { filesToPut = new FilteringIterable<>(filesToPut, new SyncFilter(this.prefix != null ? this.prefix : "", this.inputDirectory, this.getClientHelpers(), this.bucketName)); if (Iterables.isEmpty(filesToPut)) { return new PutBulkResult("SUCCESS: All files are up to date"); }//from w ww. j a va 2 s. com } final FileUtils.ObjectsToPut objectsToPut = FileUtils.getObjectsToPut(filesToPut, this.inputDirectory, this.prefix, this.ignoreErrors); final Iterable<Ds3Object> ds3Objects = objectsToPut.getDs3Objects(); return this.transfer(helpers, ds3Objects, objectsToPut.getDs3IgnoredObjects()); }
From source file:com.isotrol.impe3.core.modules.ModuleDefinitionLoader.java
private void checkMethods() throws ModuleException { final List<Method> methods = getMethods(); // The interface must not be empty if (methods.isEmpty()) { throw new EmptyModuleException(getType()); }/*from w ww . j a va2 s.c om*/ // And all methods must be either dependencies, provisions or a configuration. if (!Iterables.isEmpty(filter(methods, IS_INVALID))) { throw new InvalidMethodsException(getType()); } }
From source file:org.cinchapi.common.util.NonBlockingHashMultimap.java
@Override public boolean putAll(K key, Iterable<? extends V> values) { if (!Iterables.isEmpty(values)) { Set<V> set = get(key); if (set == emptySet) { set = new NonBlockingHashSet<V>(); map.put(key, set);//from ww w . j a v a2 s . c o m } int currentSize = set.size(); Iterators.addAll(set, values.iterator()); if (set.size() - currentSize > 0) { totalSize += (set.size() - currentSize); return true; } else { return false; } } else { return false; } }
From source file:org.eclipse.sirius.diagram.editor.properties.sections.style.nodestyledescription.NodeStyleDescriptionSizeComputationExpressionPropertySection.java
private boolean needsCustomTooltip() { boolean customEObjectTooltip = eObject instanceof WorkspaceImageDescription; boolean customEObjectListTooltip = eObjectList != null && !eObjectList.isEmpty() && !Iterables.isEmpty(Iterables.filter(eObjectList, WorkspaceImageDescription.class)); return customEObjectTooltip || customEObjectListTooltip; }
From source file:org.apache.druid.server.ClientInfoResource.java
@GET @Path("/{dataSourceName}") @Produces(MediaType.APPLICATION_JSON)//from w w w . ja va2 s .c o m @ResourceFilters(DatasourceResourceFilter.class) public Map<String, Object> getDatasource(@PathParam("dataSourceName") String dataSourceName, @QueryParam("interval") String interval, @QueryParam("full") String full) { if (full == null) { return ImmutableMap.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 = Intervals.of(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; }
From source file:org.asoem.greyfish.core.actions.ContractNetInitiatorAction.java
private static MessageTemplate createAcceptReplyTemplate( final Iterable<? extends ACLMessage<?>> acceptMessages) { if (Iterables.isEmpty(acceptMessages)) { return MessageTemplates.alwaysFalse(); } else {// w ww. ja v a 2 s . c o m return MessageTemplates.or( // is a reply Iterables.toArray( Iterables.transform(acceptMessages, new Function<ACLMessage, MessageTemplate>() { @Override public MessageTemplate apply(final ACLMessage aclMessage) { return MessageTemplates.isReplyTo(aclMessage); } }), MessageTemplate.class)); } }