List of usage examples for com.google.common.collect Iterables isEmpty
public static boolean isEmpty(Iterable<?> iterable)
From source file:org.icgc.dcc.portal.util.ElasticsearchResponseUtils.java
public static Long getLong(Object value) { if (null == value) { return null; }/*ww w. j a va2 s. co m*/ if (value instanceof Long) { return (Long) value; } if (value instanceof Float) { return ((Float) value).longValue(); } if (value instanceof Integer) { return Long.valueOf((Integer) value); } if (value instanceof Iterable<?>) { val iterable = (Iterable<?>) value; return Iterables.isEmpty(iterable) ? null : Longs.tryParse(Iterables.get(iterable, 0).toString()); } return Longs.tryParse(value.toString()); }
From source file:org.eclipse.sirius.diagram.ui.business.api.helper.graphicalfilters.CompositeFilterApplicationBuilder.java
private void handleHideCompositeFilters(final DDiagramElement element, final List<CompositeFilterDescription> appliedFilters) { DDiagramElementQuery elementQuery = new DDiagramElementQuery(element); Iterable<CompositeFilterDescription> appliedHideFilters = Iterables.filter(appliedFilters, new IsHideFilter()); Option<AppliedCompositeFilters> appliedCompositeFilters = elementQuery.getAppliedCompositeFilters(); if (appliedCompositeFilters.some()) { updateFilterApplication(element, appliedCompositeFilters.get(), Lists.newArrayList(appliedHideFilters)); } else if (!Iterables.isEmpty(appliedHideFilters)) { createFilterApplication(element, Lists.newArrayList(appliedHideFilters)); }//w w w. j a v a2 s . c o m }
From source file:org.janusgraph.graphdb.types.TypeUtil.java
public static boolean hasAnyIndex(PropertyKey key) { InternalRelationType type = (InternalRelationType) key; return !Iterables.isEmpty(type.getKeyIndexes()) || Iterables.size(type.getRelationIndexes()) > 1; //The type itself is also returned as an index }
From source file:org.eclipse.elk.layered.p5edges.splines.Rectangle.java
/** * Creates a rectangle around all given coordinates. * /*from ww w . j a v a2 s . c om*/ * @param vectors The coordinates to span the rectangle around. */ public Rectangle(final Iterable<KVector> vectors) { if (Iterables.isEmpty(vectors)) { throw new IllegalArgumentException("The list of vectors may not be empty."); } for (final KVector vector : vectors) { top = Math.min(top, vector.y); right = Math.max(right, vector.x); bottom = Math.max(bottom, vector.y); left = Math.min(left, vector.x); } }
From source file:com.jeffjirsa.cassandra.db.compaction.TimeWindowCompactionStrategy.java
/** * * @param gcBefore//from w ww. ja v a2 s .co m * @return */ private List<SSTableReader> getNextBackgroundSSTables(final int gcBefore) { if (Iterables.isEmpty(cfs.getSSTables(SSTableSet.LIVE))) return Collections.emptyList(); Set<SSTableReader> uncompacting = ImmutableSet .copyOf(filter(cfs.getUncompactingSSTables(), sstables::contains)); // Find fully expired SSTables. Those will be included no matter what. Set<SSTableReader> expired = Collections.emptySet(); if (System.currentTimeMillis() - lastExpiredCheck > options.expiredSSTableCheckFrequency) { logger.debug("TWCS expired check sufficiently far in the past, checking for fully expired SSTables"); expired = CompactionController.getFullyExpiredSSTables(cfs, uncompacting, cfs.getOverlappingSSTables(SSTableSet.CANONICAL, uncompacting), gcBefore); lastExpiredCheck = System.currentTimeMillis(); } else { logger.debug("TWCS skipping check for fully expired SSTables"); } Set<SSTableReader> candidates = Sets.newHashSet(filterSuspectSSTables(uncompacting)); List<SSTableReader> compactionCandidates = new ArrayList<>( getNextNonExpiredSSTables(Sets.difference(candidates, expired), gcBefore)); if (!expired.isEmpty()) { logger.debug("Including expired sstables: {}", expired); compactionCandidates.addAll(expired); } return compactionCandidates; }
From source file:org.jboss.hal.core.mbui.table.ModelNodeTable.java
/** Shortcut for {@code super.update(data, NamedNode::getName)} */ public void update(Iterable<T> data) { if (!identifierChecked) { checkIdentifier(Iterables.isEmpty(data) ? null : data.iterator().next()); }// www. ja va2 s. co m update(data, RESET, identifier); }
From source file:com.google.devtools.build.lib.skyframe.SkyframeLabelVisitor.java
@Override public boolean sync(EventHandler eventHandler, Set<Target> targetsToVisit, Set<Label> labelsToVisit, boolean keepGoing, int parallelThreads, int maxDepth) throws InterruptedException { rootCauses.clear();// w w w . j a v a2 s . c o m lastBuildKeepGoing = false; EvaluationResult<TransitiveTargetValue> result = transitivePackageLoader.loadTransitiveTargets(eventHandler, targetsToVisit, labelsToVisit, keepGoing, parallelThreads); updateVisitedValues(result.values()); lastBuildKeepGoing = keepGoing; if (!hasErrors(result)) { return true; } Set<Entry<SkyKey, ErrorInfo>> errors = result.errorMap().entrySet(); if (!keepGoing) { // We may have multiple errors, but in non keep_going builds, we're obligated to print only // one of them. Preconditions.checkState(!errors.isEmpty(), result); Entry<SkyKey, ErrorInfo> error = errors.iterator().next(); ErrorInfo errorInfo = error.getValue(); SkyKey topLevel = error.getKey(); Label topLevelLabel = (Label) topLevel.argument(); if (!Iterables.isEmpty(errorInfo.getCycleInfo())) { skyframeCyclesReporter.get().reportCycles(errorInfo.getCycleInfo(), topLevel, eventHandler); errorAboutLoadingFailure(topLevelLabel, null, eventHandler); } else if (isDirectErrorFromTopLevelLabel(topLevelLabel, labelsToVisit, errorInfo)) { // An error caused by a non-top-level label has already been reported during error // bubbling but an error caused by the top-level non-target label itself hasn't been // reported yet. Note that errors from top-level targets have already been reported // during target parsing. errorAboutLoadingFailure(topLevelLabel, errorInfo.getException(), eventHandler); } return false; } for (Entry<SkyKey, ErrorInfo> errorEntry : errors) { SkyKey key = errorEntry.getKey(); ErrorInfo errorInfo = errorEntry.getValue(); Preconditions.checkState(key.functionName().equals(SkyFunctions.TRANSITIVE_TARGET), errorEntry); Label topLevelLabel = (Label) key.argument(); if (!Iterables.isEmpty(errorInfo.getCycleInfo())) { skyframeCyclesReporter.get().reportCycles(errorInfo.getCycleInfo(), key, eventHandler); rootCauses.putAll(topLevelLabel, getRootCausesOfCycles(topLevelLabel, errorInfo.getCycleInfo())); } if (isDirectErrorFromTopLevelLabel(topLevelLabel, labelsToVisit, errorInfo)) { // Unlike top-level targets, which have already gone through target parsing, // errors directly coming from top-level labels have not been reported yet. // // See the note in the --nokeep_going case above. eventHandler.handle(Event.error(errorInfo.getException().getMessage())); } warnAboutLoadingFailure(topLevelLabel, eventHandler); for (SkyKey badKey : errorInfo.getRootCauses()) { if (badKey.functionName().equals(SkyFunctions.PACKAGE)) { // Transitive target function may ask for a Package, but don't include this in the root // causes. We'll get more precise information from dependencies on transitive and direct // target dependencies. continue; } Preconditions.checkState(badKey.argument() instanceof Label, "%s %s %s", key, errorInfo, badKey); rootCauses.put(topLevelLabel, (Label) badKey.argument()); } } for (Label topLevelLabel : result.<Label>keyNames()) { SkyKey topLevelTransitiveTargetKey = TransitiveTargetValue.key(topLevelLabel); TransitiveTargetValue topLevelTransitiveTargetValue = result.get(topLevelTransitiveTargetKey); if (topLevelTransitiveTargetValue.getTransitiveRootCauses() != null) { rootCauses.putAll(topLevelLabel, topLevelTransitiveTargetValue.getTransitiveRootCauses()); warnAboutLoadingFailure(topLevelLabel, eventHandler); } } return false; }
From source file:org.polymap.rhei.fulltext.FullQueryProposalDecorator.java
@Override public Iterable<String> propose(String query, int maxResults, String field) throws Exception { // fields (other than the _analyzed_ field) are stored as single term if (field != null) { return next.propose(query, maxResults, field); } else {// ww w .j av a2s . c o m String prefix = substringBeforeLast(query, SEPARATOR); String term = substringAfterLast(query, SEPARATOR); // no separator found -> just pass through if (StringUtils.isEmpty(term)) { return next.propose(query, maxResults, field); } // search just for the last term in the search else { // request more than maxResults proposals if prefix present, as we later // filter proposals that are not correct for the given prefix Iterable<String> results = next.propose(term, maxResults * proposalIncreaseFactor.get(), field); // join prefix and proposal final String finalPrefix = prefix; results = transform(results, new Function<String, String>() { public String apply(String input) { return Joiner.on(SEPARATOR).skipNulls().join(finalPrefix, input); } }); // check if joined proposal actually finds something return limit(filter(results, new Predicate<String>() { public boolean apply(String input) { try { return !Iterables.isEmpty(next.search(input, 1)); } catch (Exception e) { throw new RuntimeException(e); } } }), maxResults); } } }
From source file:com.google.javascript.rhino.jstype.PropertyMap.java
/** * Returns the secondary parents of this property map, for interfaces that * need multiple inheritance./*from w w w. j a v a 2s.co m*/ */ Iterable<PropertyMap> getSecondaryParents() { if (parentSource == null) { return ImmutableList.of(); } Iterable<ObjectType> extendedInterfaces = parentSource.getCtorExtendedInterfaces(); // Most of the time, this will be empty. if (Iterables.isEmpty(extendedInterfaces)) { return ImmutableList.of(); } return Iterables.transform(extendedInterfaces, PROP_MAP_FROM_TYPE); }
From source file:com.spectralogic.ds3cli.command.Recover.java
@Override public DefaultResult call() throws Exception { try {//from w ww. ja va 2s . com if (listOnly) { return new DefaultResult( RecoveryFileManager.printSearchFiles(this.id, this.bucketName, this.jobType)); } if (deleteFiles) { return new DefaultResult(RecoveryFileManager.deleteFiles(this.id, this.bucketName, this.jobType)); } // get exactly file to recover final Iterable<Path> files = RecoveryFileManager.searchFiles(this.id, this.bucketName, this.jobType); if (Iterables.isEmpty(files)) { return new DefaultResult("No matching recovery files found."); } if (Iterables.size(files) > 1) { return new DefaultResult("Multiple matching recovery files found:\n" + RecoveryFileManager.printSearchFiles(this.id, this.bucketName, this.jobType) + "Please restrict search criteria."); } final Path file = files.iterator().next(); final RecoveryJob job = RecoveryFileManager.getRecoveryJobByFile(file.toFile()); return new DefaultResult(recover(job)); } catch (final IOException e) { throw new CommandException("Recovery Job failed", e); } }