List of usage examples for com.google.common.collect FluentIterable first
@CheckReturnValue public final Optional<E> first()
From source file:org.codeseed.common.config.PropertySources.java
/** * Returns a source which returns the first non-{@code null} value from a * series of sources.//from ww w. ja va2 s . c om * * @param sources * the ordered sources to combine * @return property source that considers multiple sources */ public static PropertySource compose(Iterable<PropertySource> sources) { FluentIterable<PropertySource> s = FluentIterable.from(sources) .filter(Predicates.not(Predicates.equalTo(empty()))); if (s.isEmpty()) { return empty(); } else if (s.size() == 1) { return s.first().get(); } else { return new CompositionSource(s.toList()); } }
From source file:org.jclouds.examples.rackspace.autoscale.CreateWebhook.java
private void createWebhook() { System.out.format("Create Webhook%n"); FluentIterable<Webhook> result = webhookApi.create(NAME, ImmutableMap.<String, Object>of()); System.out.format(" %s%n", result.first().get()); }
From source file:org.testfx.service.query.impl.NodeQueryImpl.java
@Override @SuppressWarnings("unchecked") public <T extends Node> T query() { FluentIterable<Node> query = FluentIterable.from(parentNodes); return (T) query.first().orNull(); }
From source file:org.testfx.service.query.impl.NodeQueryImpl.java
@Override @SuppressWarnings("unchecked") public <T extends Node> Optional<T> tryQuery() { FluentIterable<Node> query = FluentIterable.from(parentNodes); return (Optional<T>) query.first(); }
From source file:org.jclouds.abiquo.domain.cloud.VirtualDatacenter.java
public VirtualMachineTemplate getAvailableTemplate(final Integer id) { PaginatedCollection<VirtualMachineTemplateDto, VirtualMachineTemplatesDto> templates = context.getApi() .getCloudApi()// w w w. j ava 2s . com .listAvailableTemplates(target, VirtualMachineTemplateOptions.builder().idTemplate(id).build()); FluentIterable<VirtualMachineTemplateDto> all = templates.toPagedIterable().concat(); return wrap(context, VirtualMachineTemplate.class, all.first().orNull()); }
From source file:org.jclouds.abiquo.domain.cloud.VirtualDatacenter.java
public VirtualMachineTemplate getAvailablePersistentTemplate(final Integer id) { PaginatedCollection<VirtualMachineTemplateDto, VirtualMachineTemplatesDto> templates = context.getApi() .getCloudApi().listAvailableTemplates(target, VirtualMachineTemplateOptions.builder().idTemplate(id) .persistent(StatefulInclusion.ALL).build()); FluentIterable<VirtualMachineTemplateDto> all = templates.toPagedIterable().concat(); return wrap(context, VirtualMachineTemplate.class, all.first().orNull()); }
From source file:ezbake.deployer.AccumuloEzDeployerStore.java
private Optional<Value> getValueFromStore(String fqApplicationId, Text columnQualifier) throws TException { FluentIterable<Value> rows = getValueFromStoreIterator(new Text(fqApplicationId), columnQualifier); return rows.first(); }
From source file:io.selendroid.server.model.DeviceStore.java
/** * Finds a device for the requested capabilities. <b>important note:</b> if the device is not any * longer used, call the {@link #release(AndroidDevice, AndroidApp)} method. * * @param caps The desired test session capabilities. * @return Matching device for a test session. * @throws DeviceStoreException/*from ww w .j a v a 2s . c o m*/ * @see {@link #release(AndroidDevice, AndroidApp)} */ public synchronized AndroidDevice findAndroidDevice(SelendroidCapabilities caps) throws DeviceStoreException { Preconditions.checkArgument(caps != null, "Error: capabilities are null"); if (androidDevices.isEmpty()) { throw new DeviceStoreException("Fatal Error: Device Store does not contain any Android Device."); } String platformVersion = caps.getPlatformVersion(); Iterable<AndroidDevice> candidateDevices = Strings.isNullOrEmpty(platformVersion) ? Iterables.concat(androidDevices.values()) : androidDevices.get(DeviceTargetPlatform.fromPlatformVersion(platformVersion)); candidateDevices = Objects.firstNonNull(candidateDevices, Collections.EMPTY_LIST); FluentIterable<AndroidDevice> allMatchingDevices = FluentIterable.from(candidateDevices) .filter(deviceNotInUse()).filter(deviceSatisfiesCapabilities(caps)); if (!allMatchingDevices.isEmpty()) { AndroidDevice matchingDevice = allMatchingDevices.filter(deviceRunning()).first() .or(allMatchingDevices.first()).get(); if (!deviceRunning().apply(matchingDevice)) { log.info("Using potential match: " + matchingDevice); } devicesInUse.add(matchingDevice); return matchingDevice; } else { throw new DeviceStoreException( "No devices are found. " + "This can happen if the devices are in use or no device screen " + "matches the required capabilities."); } }
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 ww .j av a2s . c om 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.siemens.sw360.portal.portlets.moderation.ModerationPortlet.java
private void renderNextModeration(RenderRequest request, RenderResponse response, final User user, String sessionMessage, ModerationService.Iface client, ModerationRequest moderationRequest) throws IOException, PortletException, TException { if (ACTION_CANCEL.equals(request.getParameter(ACTION))) { SessionMessages.add(request, "request_processed", sessionMessage); renderStandardView(request, response); return;//from ww w . ja va 2 s .c om } List<ModerationRequest> requestsByModerator = client.getRequestsByModerator(user); ImmutableList<ModerationRequest> openModerationRequests = FluentIterable.from(requestsByModerator) .filter(new Predicate<ModerationRequest>() { @Override public boolean apply(ModerationRequest input) { return ModerationState.PENDING.equals(input.getModerationState()); } }).toList(); Collections.sort(openModerationRequests, compareByTimeStamp()); int nextIndex = openModerationRequests.indexOf(moderationRequest) + 1; if (nextIndex < openModerationRequests.size()) { sessionMessage += " You have assigned yourself to this moderation request."; SessionMessages.add(request, "request_processed", sessionMessage); renderEditViewForId(request, response, openModerationRequests.get(nextIndex).getId()); } else { FluentIterable<ModerationRequest> requestsInProgressAndAssignedToMe = FluentIterable .from(requestsByModerator).filter(new Predicate<ModerationRequest>() { @Override public boolean apply(ModerationRequest input) { return ModerationState.INPROGRESS.equals(input.getModerationState()) && user.getEmail().equals(input.getReviewer()); } }); if (requestsInProgressAndAssignedToMe.first().isPresent()) { sessionMessage += " You have returned to your first open request."; SessionMessages.add(request, "request_processed", sessionMessage); renderEditViewForId(request, response, Collections.min(requestsInProgressAndAssignedToMe.toList(), compareByTimeStamp()).getId()); } else { sessionMessage += " You have no open Requests."; SessionMessages.add(request, "request_processed", sessionMessage); renderStandardView(request, response); } } }