List of usage examples for com.google.common.collect Iterables any
public static <T> boolean any(Iterable<T> iterable, Predicate<? super T> predicate)
From source file:org.apache.kylin.common.KylinVersion.java
public boolean isSignatureCompatibleWith(final KylinVersion v) { if (!isCompatibleWith(v)) { return false; }// w w w. jav a 2 s . c o m if (v.isSnapshot || isSnapshot) { return false;//for snapshot versions things are undetermined } boolean signatureIncompatible = Iterables.any(Iterables.filter( SIGNATURE_INCOMPATIBLE_REVISIONS, new Predicate<KylinVersion>() { @Override public boolean apply(@Nullable KylinVersion input) { return v.major == input.major && v.minor == input.minor; } }), new Predicate<KylinVersion>() { @Override public boolean apply(@Nullable KylinVersion input) { return input.revision > v.revision; } }); return !signatureIncompatible; }
From source file:org.apache.aurora.scheduler.configuration.ConfigurationManager.java
public static boolean isDedicated(Iterable<IConstraint> taskConstraints) { return Iterables.any(taskConstraints, getConstraintByName(DEDICATED_ATTRIBUTE)); }
From source file:org.jclouds.openstack.nova.v2_0.functions.PresentWhenExtensionAnnotationNamespaceEqualsAnyNamespaceInExtensionsSet.java
@Override public Optional<Object> apply(ClassMethodArgsAndReturnVal input) { Optional<org.jclouds.openstack.v2_0.services.Extension> ext = Optional .fromNullable(input.getClazz().getAnnotation(org.jclouds.openstack.v2_0.services.Extension.class)); if (ext.isPresent()) { checkState(input.getArgs() != null && input.getArgs().length == 1, "expecting an arg %s", input); URI namespace = URI.create(ext.get().namespace()); if (Iterables.any( extensions.getUnchecked(checkNotNull(input.getArgs()[0], "arg[0] in %s", input).toString()), ExtensionPredicates.namespaceOrAliasEquals(namespace, aliases.get(namespace)))) return Optional.of(input.getReturnVal()); }// w w w. j ava2s. com return Optional.absent(); }
From source file:com.github.blacklocus.rdsecho.utl.RdsFind.java
public Predicate<DBInstance> instanceHasTag(final String region, final String accountNumber, final String tagKey, final String tagValue) { return new Predicate<DBInstance>() { @Override/*from w ww .ja v a 2s . c o m*/ public boolean apply(DBInstance instance) { String rdsInstanceArn = instanceArn(region, accountNumber, instance.getDBInstanceIdentifier()); ListTagsForResourceResult result = rds .listTagsForResource(new ListTagsForResourceRequest().withResourceName(rdsInstanceArn)); return Iterables.any(result.getTagList(), new Predicate<Tag>() { @Override public boolean apply(Tag tag) { return tagKey.equals(tag.getKey()) && tagValue.equals(tag.getValue()); } }); } }; }
From source file:edu.harvard.med.screensaver.ui.attachedFiles.AttachedFileSearchResults.java
@Override protected List<? extends TableColumn<Tuple<Integer>, ?>> buildColumns() { List<TableColumn<Tuple<Integer>, ?>> columns = Lists.newArrayList(); if (_attachedFileTypesFilter == null || Iterables.any(_attachedFileTypesFilter, Predicates.instanceOf(UserAttachedFileType.class))) { columns.add(//w ww .ja v a 2s . c o m new IntegerTupleColumn<AttachedFile, Integer>( RelationshipPath.from(AttachedFile.class).to(AttachedFile.screeningRoomUser) .toProperty("id"), "Screener ID", "The identifier of the screener to which the file is attached", TableColumn.UNGROUPED) { @Override public Object cellAction(Tuple<Integer> t) { return _userViewer.viewEntity(getAttachedFile(t).getScreeningRoomUser()); } @Override public boolean isCommandLink() { return true; } }); columns.add(new TextTupleColumn<AttachedFile, Integer>( RelationshipPath.from(AttachedFile.class).to(AttachedFile.screeningRoomUser) .toProperty("lastName"), "User Last Name", "The last name of the user to which the file is attached", TableColumn.UNGROUPED)); columns.add(new TextTupleColumn<AttachedFile, Integer>( RelationshipPath.from(AttachedFile.class).to(AttachedFile.screeningRoomUser) .toProperty("firstName"), "User First Name", "The first name of the user to which the file is attached", TableColumn.UNGROUPED)); final PropertyPath<AttachedFile> labHeadLabAffiliationPropertyPath = RelationshipPath .from(AttachedFile.class).to(AttachedFile.screeningRoomUser).to(ScreeningRoomUser.LabHead) .to(LabHead.labAffiliation).toProperty("affiliationName"); columns.add(new TextTupleColumn<AttachedFile, Integer>( RelationshipPath.from(AttachedFile.class).to(AttachedFile.screeningRoomUser) .to(LabHead.labAffiliation).toProperty("affiliationName"), "User Lab Affiliation", "The lab affiliation of the user to which the file is attached", TableColumn.UNGROUPED) { @Override public String getCellValue(Tuple<Integer> tuple) { String cellValue = super.getCellValue(tuple); if (cellValue == null) { cellValue = (String) tuple .getProperty(TupleDataFetcher.makePropertyKey(labHeadLabAffiliationPropertyPath)); } return cellValue; } }); ((TextTupleColumn) Iterables.getLast(columns)).addRelationshipPath(labHeadLabAffiliationPropertyPath); } if (_attachedFileTypesFilter == null || Iterables.any(_attachedFileTypesFilter, Predicates.instanceOf(ScreenAttachedFileType.class))) { columns.add(new TextTupleColumn<AttachedFile, Integer>(AttachedFile.screen.toProperty("facilityId"), "Screen", "The screen to which the file is attached", TableColumn.UNGROUPED) { @Override public Object cellAction(Tuple<Integer> t) { return _screenViewer.viewEntity(getAttachedFile(t).getScreen()); } @Override public boolean isCommandLink() { return true; } }); } if (_attachedFileTypesFilter == null || _attachedFileTypesFilter.size() > 1) { columns.add(new VocabularyTupleColumn<AttachedFile, Integer, AttachedFileType>( RelationshipPath.from(AttachedFile.class).toProperty("fileType"), "Type", "The type of the attached file", TableColumn.UNGROUPED, new VocabularyConverter<AttachedFileType>(_allAttachedFileTypes), _allAttachedFileTypes)); } columns.add(new TextTupleColumn<AttachedFile, Integer>( RelationshipPath.from(AttachedFile.class).toProperty("filename"), "File Name", "The name of the attached file", TableColumn.UNGROUPED) { @Override public Object cellAction(Tuple<Integer> t) { try { return AttachedFiles.doDownloadAttachedFile(getAttachedFile(t), getFacesContext(), _dao); } catch (Exception e) { throw new RuntimeException(e); } } @Override public boolean isCommandLink() { return true; } }); columns.add(new DateTupleColumn<AttachedFile, Integer>( RelationshipPath.from(AttachedFile.class).toProperty("fileDate"), "File Date", "The date of the attached file", TableColumn.UNGROUPED)); return columns; }
From source file:org.eclipse.emf.compare.ide.ui.internal.logical.Graph.java
/** * Checks if the given element is a parent of the given potential child, directly or not. * //from w ww. j a v a2s . c om * @param parent * Element that could be a parent of <code>potentialChild</code>. * @param potentialChild * The potential child of <code>parent</code>. */ public boolean hasChild(E parent, E potentialChild) { synchronized (nodes) { final Node<E> node = nodes.get(potentialChild); if (node != null) { return Iterables.any(node.getAllParents(), is(parent)); } return false; } }
From source file:org.apache.jackrabbit.oak.plugins.index.lucene.Aggregate.java
private static boolean hasNodeIncludes(List<? extends Include> includes) { return Iterables.any(includes, new Predicate<Include>() { @Override//from w ww . ja va2 s . co m public boolean apply(Include input) { return input instanceof NodeInclude; } }); }
From source file:eu.numberfour.n4js.external.ExternalProjectsCollector.java
/** * Sugar for collecting {@link IWorkspace Eclipse workspace} projects that have any direct dependency to any * external projects. Same as {@link #collectProjectsWithDirectExternalDependencies()} but does not considers all * the available projects but only those that are given as the argument. * * @param externalProjects//from ww w . j a v a 2 s. com * the external projects that has to be considered as a possible dependency of an Eclipse workspace based * project. * @return an iterable of Eclipse workspace projects that has direct dependency to an external project given as the * argument. */ public Iterable<IProject> collectProjectsWithDirectExternalDependencies( final Iterable<? extends IProject> externalProjects) { if (!Platform.isRunning()) { return emptyList(); } final Collection<String> externalIds = from(externalProjects).transform(p -> p.getName()).toSet(); final Predicate<String> externalIdsFilter = Predicates.in(externalIds); return from(asList(getWorkspace().getRoot().getProjects())) .filter(p -> Iterables.any(getDirectExternalDependencyIds(p), externalIdsFilter)); }
From source file:org.apache.cassandra.db.compaction.CompactionTask.java
/** * For internal use and testing only. The rest of the system should go through the submit* methods, * which are properly serialized.//w w w . j a v a 2 s . c o m * Caller is in charge of marking/unmarking the sstables as compacting. */ protected void runMayThrow() throws Exception { // The collection of sstables passed may be empty (but not null); even if // it is not empty, it may compact down to nothing if all rows are deleted. assert transaction != null; if (transaction.originals().isEmpty()) return; // Note that the current compaction strategy, is not necessarily the one this task was created under. // This should be harmless; see comments to CFS.maybeReloadCompactionStrategy. AbstractCompactionStrategy strategy = cfs.getCompactionStrategy(); if (DatabaseDescriptor.isSnapshotBeforeCompaction()) cfs.snapshotWithoutFlush(System.currentTimeMillis() + "-compact-" + cfs.name); // note that we need to do a rough estimate early if we can fit the compaction on disk - this is pessimistic, but // since we might remove sstables from the compaction in checkAvailableDiskSpace it needs to be done here long expectedWriteSize = cfs.getExpectedCompactedFileSize(transaction.originals(), compactionType); long earlySSTableEstimate = Math.max(1, expectedWriteSize / strategy.getMaxSSTableBytes()); checkAvailableDiskSpace(earlySSTableEstimate, expectedWriteSize); // sanity check: all sstables must belong to the same cfs assert !Iterables.any(transaction.originals(), new Predicate<SSTableReader>() { @Override public boolean apply(SSTableReader sstable) { return !sstable.descriptor.cfname.equals(cfs.name); } }); UUID taskId = SystemKeyspace.startCompaction(cfs, transaction.originals()); // new sstables from flush can be added during a compaction, but only the compaction can remove them, // so in our single-threaded compaction world this is a valid way of determining if we're compacting // all the sstables (that existed when we started) StringBuilder ssTableLoggerMsg = new StringBuilder("["); for (SSTableReader sstr : transaction.originals()) { ssTableLoggerMsg.append(String.format("%s:level=%d, ", sstr.getFilename(), sstr.getSSTableLevel())); } ssTableLoggerMsg.append("]"); String taskIdLoggerMsg = taskId == null ? UUIDGen.getTimeUUID().toString() : taskId.toString(); logger.debug("Compacting ({}) {}", taskIdLoggerMsg, ssTableLoggerMsg); long start = System.nanoTime(); long totalKeysWritten = 0; long estimatedKeys = 0; try (CompactionController controller = getCompactionController(transaction.originals())) { Set<SSTableReader> actuallyCompact = Sets.difference(transaction.originals(), controller.getFullyExpiredSSTables()); SSTableFormat.Type sstableFormat = getFormatType(transaction.originals()); List<SSTableReader> newSStables; AbstractCompactionIterable ci; // SSTableScanners need to be closed before markCompactedSSTablesReplaced call as scanners contain references // to both ifile and dfile and SSTR will throw deletion errors on Windows if it tries to delete before scanner is closed. // See CASSANDRA-8019 and CASSANDRA-8399 try (Refs<SSTableReader> refs = Refs.ref(actuallyCompact); AbstractCompactionStrategy.ScannerList scanners = strategy.getScanners(actuallyCompact)) { ci = new CompactionIterable(compactionType, scanners.scanners, controller, sstableFormat, taskId); try (CloseableIterator<AbstractCompactedRow> iter = ci.iterator()) { if (collector != null) collector.beginCompaction(ci); long lastCheckObsoletion = start; if (!controller.cfs.getCompactionStrategy().isActive) throw new CompactionInterruptedException(ci.getCompactionInfo()); try (CompactionAwareWriter writer = getCompactionAwareWriter(cfs, transaction, actuallyCompact)) { estimatedKeys = writer.estimatedKeys(); while (iter.hasNext()) { if (ci.isStopRequested()) throw new CompactionInterruptedException(ci.getCompactionInfo()); try (AbstractCompactedRow row = iter.next()) { if (writer.append(row)) totalKeysWritten++; if (System.nanoTime() - lastCheckObsoletion > TimeUnit.MINUTES.toNanos(1L)) { controller.maybeRefreshOverlaps(); lastCheckObsoletion = System.nanoTime(); } } } // don't replace old sstables yet, as we need to mark the compaction finished in the system table newSStables = writer.finish(); } finally { // point of no return -- the new sstables are live on disk; next we'll start deleting the old ones // (in replaceCompactedSSTables) if (taskId != null) SystemKeyspace.finishCompaction(taskId); if (collector != null) collector.finishCompaction(ci); } } } // log a bunch of statistics about the result and save to system table compaction_history long dTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start); long startsize = SSTableReader.getTotalBytes(transaction.originals()); long endsize = SSTableReader.getTotalBytes(newSStables); double ratio = (double) endsize / (double) startsize; StringBuilder newSSTableNames = new StringBuilder(); for (SSTableReader reader : newSStables) newSSTableNames.append(reader.descriptor.baseFilename()).append(","); double mbps = dTime > 0 ? (double) endsize / (1024 * 1024) / ((double) dTime / 1000) : 0; long totalSourceRows = 0; String mergeSummary = updateCompactionHistory(cfs.keyspace.getName(), cfs.getColumnFamilyName(), ci, startsize, endsize); logger.debug(String.format( "Compacted (%s) %d sstables to [%s] to level=%d. %,d bytes to %,d (~%d%% of original) in %,dms = %fMB/s. %,d total partitions merged to %,d. Partition merge counts were {%s}", taskIdLoggerMsg, transaction.originals().size(), newSSTableNames.toString(), getLevel(), startsize, endsize, (int) (ratio * 100), dTime, mbps, totalSourceRows, totalKeysWritten, mergeSummary)); logger.trace(String.format("CF Total Bytes Compacted: %,d", CompactionTask.addToTotalBytesCompacted(endsize))); logger.trace("Actual #keys: {}, Estimated #keys:{}, Err%: {}", totalKeysWritten, estimatedKeys, ((double) (totalKeysWritten - estimatedKeys) / totalKeysWritten)); if (offline) Refs.release(Refs.selfRefs(newSStables)); } }
From source file:org.eclipse.sirius.diagram.business.api.query.DDiagramElementQuery.java
/** * Check if the label of this {@link DDiagramElement} is directly hidden. * /*w ww.j a v a 2 s .c o m*/ * @return true if the label of the given element is hidden. */ public boolean isLabelHidden() { return Iterables.any(element.getGraphicalFilters(), Predicates.instanceOf(HideLabelFilter.class)); }