List of usage examples for com.google.common.collect Iterators all
public static <T> boolean all(Iterator<T> iterator, Predicate<? super T> predicate)
From source file:org.polarsys.reqcycle.traceability.table.handlers.DeleteLinkHandler.java
@Override public boolean isEnabled() { ISelection selection = getSelection(); if (selection instanceof IStructuredSelection) { Iterator<?> iterator = ((IStructuredSelection) selection).iterator(); return Iterators.all(iterator, Predicates.instanceOf(TransverseLink.class)); }//from w w w . j a va2 s . c o m return false; }
From source file:org.cryptomator.frontend.webdav.servlet.WebDavServlet.java
@Override protected boolean isPreconditionValid(WebdavRequest request, DavResource resource) { IfHeader ifHeader = new IfHeader(request); if (ifHeader.hasValue() && Iterators.all(ifHeader.getAllTokens(), Predicates.equalTo(NO_LOCK))) { // https://tools.ietf.org/html/rfc4918#section-10.4.8: // "DAV:no-lock" is known to never represent a current lock token. return false; } else if (ifHeader.hasValue() && Iterators.any(ifHeader.getAllNotTokens(), Predicates.equalTo(NO_LOCK))) { // by applying "Not" to a state token that is known not to be current, the Condition always evaluates to true. return true; } else {//from w ww . j a va 2 s .c o m return request.matchesIfHeader(resource); } }
From source file:org.onosproject.cordconfig.access.AccessAgentConfig.java
private boolean areOltsValid() { JsonNode olts = node.get(OLTS);//w w w . j av a 2s .c om if (!olts.isObject()) { return false; } return Iterators.all(olts.fields(), item -> ConnectPoint.deviceConnectPoint(item.getKey()) != null && isMacAddress((ObjectNode) olts, item.getKey(), MANDATORY)); }
From source file:de.cau.cs.kieler.ecoreviz.OpenDiagramHandler.java
/** * {@inheritDoc}//from w w w. ja v a 2 s . c o m */ @SuppressWarnings("unchecked") public Object execute(final ExecutionEvent event) throws ExecutionException { final ISelection selection = HandlerUtil.getCurrentSelection(event); if (selection instanceof IStructuredSelection) { final IStructuredSelection sSelection = (IStructuredSelection) selection; final List<EModelElement> listSelection = new LinkedList<EModelElement>(); if (selection instanceof KlighdTreeSelection) { // do not react on selections in KLighD diagrams return null; } // if all elements are either ecore packages or classes if (Iterators.all(sSelection.iterator(), EPACKAGE_ECLASS_PREDICATE)) { Iterator<EModelElement> emIt = Iterators.filter(sSelection.iterator(), EMODEL_ELEMENT_PREDICATE); while (emIt.hasNext()) { listSelection.add(emIt.next()); } } else { // otherwise check the elements piece by piece for files for (Object o : sSelection.toArray()) { if (o instanceof IFile) { try { IFile f = (IFile) o; ResourceSet rs = new ResourceSetImpl(); Resource r = rs.getResource( URI.createPlatformResourceURI(f.getFullPath().toString(), true), true); if (r.getContents().size() > 0) { if (r.getContents().get(0) instanceof EPackage) { listSelection.add((EModelElement) r.getContents().get(0)); } } } catch (Exception e) { StatusManager.getManager().handle( new Status(IStatus.ERROR, PLUGIN_ID, "Could not load selected file.", e), StatusManager.SHOW); } } else { handleUnknownSelection(selection); return null; } } } EModelElementCollection model = EModelElementCollection.of(listSelection.iterator()); DiagramViewManager.createView("de.cau.cs.kieler.ecoreviz.EModelElementCollectionDiagram", "Ecore Diagram", model, KlighdSynthesisProperties.create()); return null; } handleUnknownSelection(selection); return null; }
From source file:org.eclipse.sirius.business.internal.modelingproject.manager.InitializeModelingProjectJob.java
/** * Constructor.//from ww w . java 2s . com * * @param projects * The projects concerned by this job */ public InitializeModelingProjectJob(List<IProject> projects) { this(Iterators.all(projects.iterator(), new Predicate<IProject>() { @Override public boolean apply(IProject input) { try { return input.members().length == 1; } catch (CoreException e) { return false; } } }) ? JOB_LABEL_FOR_EMPTY_PROJECTS : JOB_LABEL); this.projects = projects; }
From source file:com.github.jonross.seq4j.Seq.java
/** * Wraps {@link Iterators#all(Iterator, Predicate); returns true if every element in the * sequence satisfies the given predicate. */// w w w. ja va 2 s. co m boolean all(Predicate<? super T> p) { return Iterators.all(this, p); }
From source file:org.eclipse.sirius.ui.tools.internal.views.common.modelingproject.OpenRepresentationsFileJob.java
/** * Constructor to open several representations files. * * @param elements//from w ww . ja v a 2 s .c o m * A list of URIs of the representations files to open or a list * of the modeling projects to initialize and open. */ public OpenRepresentationsFileJob(List<? extends Object> elements) { super(OpenRepresentationsFileJob.JOB_LABEL); if (!(Iterators.all(elements.iterator(), Predicates.instanceOf(URI.class)) || Iterators.all(elements.iterator(), Predicates.instanceOf(ModelingProject.class)))) { throw new IllegalArgumentException(Messages.OpenRepresentationsFileJob_errorInvalidInputList); } Iterators.addAll(this.representationsFilesURIs, Iterators.filter(elements.iterator(), URI.class)); Iterators.addAll(this.modelingProjects, Iterators.filter(elements.iterator(), ModelingProject.class)); }
From source file:org.eclipse.sirius.ui.tools.internal.views.common.modelingproject.OpenRepresentationsFileJob.java
/** * Launch this job when all other openRepresentationFile's job are finished. * * @param elements//from w ww . ja v a2 s.c om * A list of URIs of the representations files to open or a list * of the modeling projects to initialize and open. * @param user * <code>true</code> if this job is a user-initiated job, and * <code>false</code> otherwise. */ public static void scheduleNewWhenPossible(List<? extends Object> elements, boolean user) { if (!(Iterators.all(elements.iterator(), Predicates.instanceOf(URI.class)) || Iterators.all(elements.iterator(), Predicates.instanceOf(ModelingProject.class)))) { throw new IllegalArgumentException(Messages.OpenRepresentationsFileJob_errorInvalidInputList); } // Just wait other job if some are already in progress OpenRepresentationsFileJob.waitOtherJobs(); // Schedule a new job for this representations file. Job job = new OpenRepresentationsFileJob(elements); job.setUser(user); job.setPriority(Job.SHORT); job.schedule(); }
From source file:org.apache.cassandra.noTTL.NoTTLReader.java
/** * Calculate approximate key count.//from www. j ava2s . co m * If cardinality estimator is available on all given sstables, then this method use them to estimate * key count. * If not, then this uses index summaries. * * @param sstables SSTables to calculate key count * @return estimated key count */ public static long getApproximateKeyCount(Collection<NoTTLReader> sstables) { long count = -1; // check if cardinality estimator is available for all SSTables boolean cardinalityAvailable = !sstables.isEmpty() && Iterators.all(sstables.iterator(), new Predicate<NoTTLReader>() { public boolean apply(NoTTLReader sstable) { return sstable.descriptor.version.hasNewStatsFile(); } }); // if it is, load them to estimate key count if (cardinalityAvailable) { boolean failed = false; ICardinality cardinality = null; for (NoTTLReader sstable : sstables) { if (sstable.openReason == OpenReason.EARLY) continue; try { CompactionMetadata metadata = (CompactionMetadata) sstable.descriptor.getMetadataSerializer() .deserialize(sstable.descriptor, MetadataType.COMPACTION); // If we can't load the CompactionMetadata, we are forced to estimate the keys using the index // summary. (CASSANDRA-10676) if (metadata == null) { logger.warn("Reading cardinality from Statistics.db failed for {}", sstable.getFilename()); failed = true; break; } if (cardinality == null) cardinality = metadata.cardinalityEstimator; else cardinality = cardinality.merge(metadata.cardinalityEstimator); } catch (IOException e) { logger.warn("Reading cardinality from Statistics.db failed.", e); failed = true; break; } catch (CardinalityMergeException e) { logger.warn("Cardinality merge failed.", e); failed = true; break; } } if (cardinality != null && !failed) count = cardinality.cardinality(); } // if something went wrong above or cardinality is not available, calculate using index summary if (count < 0) { for (NoTTLReader sstable : sstables) count += sstable.estimatedKeys(); } return count; }
From source file:org.apache.kudu.client.KuduTable.java
/** * Retrieves a formatted representation of this table's range partitions. The * range partitions will be returned in sorted order by value, and will * contain no duplicates.//from ww w.j a va2 s . c om * * @param deadline the deadline of the operation * @return a list of the formatted range partitions */ @InterfaceAudience.LimitedPrivate("Impala") @InterfaceStability.Unstable public List<String> getFormattedRangePartitions(long deadline) throws Exception { List<String> rangePartitions = new ArrayList<>(); for (LocatedTablet tablet : getTabletsLocations(deadline)) { Partition partition = tablet.getPartition(); // Filter duplicate range partitions by taking only the tablets whose hash // partitions are all 0s. if (!Iterators.all(partition.getHashBuckets().iterator(), Predicates.equalTo(0))) { continue; } rangePartitions.add(partition.formatRangePartition(this)); } return rangePartitions; }