List of usage examples for com.google.common.collect FluentIterable firstMatch
@CheckReturnValue public final Optional<E> firstMatch(Predicate<? super E> predicate)
From source file:org.eclipse.tracecompass.tmf.remote.core.proxy.RemoteSystemProxy.java
/** * Return a remote connection using OSGI service. * * @param remoteServicesId//w ww.j a v a 2 s . c o m * ID of remote service * @param name * name of connection * @return the corresponding remote connection or null */ public static @Nullable IRemoteConnection getRemoteConnection(final String remoteServicesId, final String name) { IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class); if (manager == null) { return null; } FluentIterable<IRemoteConnection> connections = FluentIterable.from(manager.getAllRemoteConnections()); Optional<IRemoteConnection> ret = connections.firstMatch(new Predicate<IRemoteConnection>() { @Override public boolean apply(@Nullable IRemoteConnection input) { return ((input != null) && input.getConnectionType().getId().equals(remoteServicesId.toString()) && input.getName().equals(name.toString())); } }); return ret.orNull(); }
From source file:darwin.resourcehandling.handle.FileHandleCache.java
public ResourceHandle get(final URI file) { URI tmp = null;/* www . j a v a 2 s .c om*/ if (file.isAbsolute()) { FluentIterable<URI> folders = ClasspathHelper.getClasspathFolders(); Optional<URI> match = folders.firstMatch(new Predicate<URI>() { @Override public boolean apply(URI input) { return !input.relativize(file).equals(file); } }); if (match.isPresent()) { tmp = match.get().relativize(file); } } if (tmp == null) { tmp = file; } ResourceHandle h = handles.get(tmp); if (h == null) { h = new ClasspathFileHandler(notifier, tmp); handles.put(tmp, h); } return h; }
From source file:com.b2international.snowowl.datastore.oplock.impl.DatastoreOperationLockException.java
@Override public String getMessage() { final FluentIterable<DatastoreLockContext> contexts = FluentIterable.from(targetMap.values()); final Optional<DatastoreLockContext> rootContext = contexts .firstMatch(new Predicate<DatastoreLockContext>() { @Override//from w w w . j av a 2s . c o m public boolean apply(DatastoreLockContext input) { return DatastoreLockContextDescriptions.ROOT.equals(input.getParentDescription()); } }); DatastoreLockContext context = null; if (rootContext.isPresent()) { context = rootContext.get(); } else { if (contexts.first().isPresent()) { context = contexts.first().get(); } else { return super.getMessage(); } } return String.format("%s %s is %s.", super.getMessage(), context.getUserId(), context.getDescription()); }
From source file:com.adobe.acs.commons.wcm.comparisons.PageVersionCompareModel.java
/** Private methods **/ private Optional<Evolution> version(FluentIterable<Evolution> evolutions, final String name) { return evolutions.firstMatch(new Predicate<Evolution>() { @Override//from ww w . j a v a 2 s.com public boolean apply(Evolution evolution) { return evolution.getVersionName().equalsIgnoreCase(name); } }); }
From source file:org.jclouds.dimensiondata.cloudcontrol.compute.strategy.GetOrCreateNetworkDomainThenCreateNodes.java
private Optional<String> getExistingVlan(final String networkDomainId, final String vlanName) { FluentIterable<Vlan> vlans = api.getNetworkApi().listVlans(networkDomainId).concat(); final Optional<Vlan> vlan = vlans.firstMatch(new Predicate<Vlan>() { @Override/* ww w .j a v a2 s . co m*/ public boolean apply(final Vlan input) { return input.name().equals(vlanName); } }); if (vlan.isPresent()) { return Optional.of(vlan.get().id()); } else { return Optional.absent(); } }
From source file:springfox.documentation.spring.data.rest.EntityServicesProvider.java
private Collection<RequestHandler> maybeCombine(List<RequestHandler> metadataHandlers, Predicate<RequestHandler> selector) { List<RequestHandler> combined = newArrayList(); Iterable<RequestHandler> selected = FluentIterable.from(metadataHandlers) .filter(and(selector, getHandler())); FluentIterable<RequestHandler> selectedCompliment = FluentIterable.from(metadataHandlers) .filter(and(not(selector), getHandler())); for (RequestHandler each : selected) { Optional<RequestHandler> found = selectedCompliment .firstMatch(samePathMapping(each.getPatternsCondition())); combined.add(combine(each, found)); }/*from w w w. ja v a2 s . c om*/ combined.addAll(FluentIterable.from(metadataHandlers).filter(EntitySearchRequestHandler.class) .filter(collectionHandlers()).toList()); return combined; }