List of usage examples for com.google.common.collect FluentIterable toList
@CheckReturnValue public final ImmutableList<E> toList()
From source file:at.ac.tuwien.infosys.jcloudscale.vm.openstack.OpenStackWrapper.java
/** * Finds the first instance with the specified IP address. * @param ip/*ww w . j a va 2 s . co m*/ * @return */ public String findOpenStackIdByIP(String ip) { FluentIterable<? extends Resource> servers = openstack.list().concat(); for (Resource server : servers.toList()) { Server theServer = openstack.get(server.getId()); if (hostHasAddressAssociated(theServer.getId(), ip)) return theServer.getId(); } log.severe("No Openstack host for IP " + ip + " found"); return null; }
From source file:springfox.documentation.swagger2.mappers.ModelMapper.java
private Model mapProperties(springfox.documentation.schema.Model source) { ModelImpl model = new ModelImpl().description(source.getDescription()) .discriminator(source.getDiscriminator()).example(source.getExample()).name(source.getName()); SortedMap<String, ModelProperty> sortedProperties = sort(source.getProperties()); Map<String, Property> modelProperties = mapProperties(sortedProperties); model.setProperties(modelProperties); FluentIterable<String> requiredFields = FluentIterable.from(source.getProperties().values()) .filter(requiredProperty()).transform(propertyName()); model.setRequired(requiredFields.toList()); model.setSimple(false);//from w ww.j av a 2 s.c o m model.setType(ModelImpl.OBJECT); if (isMapType(source.getType())) { Optional<Class> clazz = typeOfValue(source); if (clazz.isPresent()) { model.additionalProperties(property(clazz.get().getSimpleName())); } else { model.additionalProperties(new ObjectProperty()); } } return model; }
From source file:com.google.gerrit.server.project.RefFilter.java
public List<T> filter(List<T> refs) throws BadRequestException { FluentIterable<T> results = FluentIterable.from(refs); if (!Strings.isNullOrEmpty(matchSubstring)) { results = results.filter(new SubstringPredicate(matchSubstring)); } else if (!Strings.isNullOrEmpty(matchRegex)) { results = results.filter(new RegexPredicate(matchRegex)); }//from www. j a va 2 s .co m if (start > 0) { results = results.skip(start); } if (limit > 0) { results = results.limit(limit); } return results.toList(); }
From source file:org.opendaylight.controller.md.sal.common.impl.service.AbstractDataBroker.java
protected ImmutableList<DataCommitHandler<P, D>> affectedCommitHandlers(final Set<P> paths) { final Supplier<ImmutableList<DataCommitHandler<P, D>>> _function = new Supplier<ImmutableList<DataCommitHandler<P, D>>>() { @Override//from w ww . jav a 2 s . co m public ImmutableList<DataCommitHandler<P, D>> get() { Map<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>> _asMap = commitHandlers.asMap(); Set<Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>>> _entrySet = _asMap.entrySet(); FluentIterable<Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>>> _from = FluentIterable .<Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>>>from(_entrySet); final Predicate<Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>>> _function = new Predicate<Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>>>() { @Override public boolean apply(final Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>> it) { P _key = it.getKey(); boolean _isAffectedBy = isAffectedBy(_key, paths); return _isAffectedBy; } }; FluentIterable<Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>>> _filter = _from .filter(_function); final Function<Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>>, Collection<DataCommitHandlerRegistrationImpl<P, D>>> _function_1 = new Function<Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>>, Collection<DataCommitHandlerRegistrationImpl<P, D>>>() { @Override public Collection<DataCommitHandlerRegistrationImpl<P, D>> apply( final Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>> it) { Collection<DataCommitHandlerRegistrationImpl<P, D>> _value = it.getValue(); return _value; } }; FluentIterable<DataCommitHandlerRegistrationImpl<P, D>> _transformAndConcat = _filter .<DataCommitHandlerRegistrationImpl<P, D>>transformAndConcat(_function_1); final Function<DataCommitHandlerRegistrationImpl<P, D>, DataCommitHandler<P, D>> _function_2 = new Function<DataCommitHandlerRegistrationImpl<P, D>, DataCommitHandler<P, D>>() { @Override public DataCommitHandler<P, D> apply(final DataCommitHandlerRegistrationImpl<P, D> it) { DataCommitHandler<P, D> _instance = it.getInstance(); return _instance; } }; FluentIterable<DataCommitHandler<P, D>> _transform = _transformAndConcat .<DataCommitHandler<P, D>>transform(_function_2); return _transform.toList(); } }; return AbstractDataBroker.<ImmutableList<DataCommitHandler<P, D>>>withLock(this.registrationLock, _function); }
From source file:org.opendaylight.controller.md.sal.common.impl.service.AbstractDataBroker.java
protected ImmutableList<DataCommitHandler<P, D>> probablyAffectedCommitHandlers(final HashSet<P> paths) { final Supplier<ImmutableList<DataCommitHandler<P, D>>> _function = new Supplier<ImmutableList<DataCommitHandler<P, D>>>() { @Override/*w w w .j a v a2 s . c o m*/ public ImmutableList<DataCommitHandler<P, D>> get() { Map<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>> _asMap = commitHandlers.asMap(); Set<Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>>> _entrySet = _asMap.entrySet(); FluentIterable<Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>>> _from = FluentIterable .<Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>>>from(_entrySet); final Predicate<Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>>> _function = new Predicate<Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>>>() { @Override public boolean apply(final Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>> it) { P _key = it.getKey(); boolean _isProbablyAffectedBy = isProbablyAffectedBy(_key, paths); return _isProbablyAffectedBy; } }; FluentIterable<Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>>> _filter = _from .filter(_function); final Function<Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>>, Collection<DataCommitHandlerRegistrationImpl<P, D>>> _function_1 = new Function<Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>>, Collection<DataCommitHandlerRegistrationImpl<P, D>>>() { @Override public Collection<DataCommitHandlerRegistrationImpl<P, D>> apply( final Entry<P, Collection<DataCommitHandlerRegistrationImpl<P, D>>> it) { Collection<DataCommitHandlerRegistrationImpl<P, D>> _value = it.getValue(); return _value; } }; FluentIterable<DataCommitHandlerRegistrationImpl<P, D>> _transformAndConcat = _filter .<DataCommitHandlerRegistrationImpl<P, D>>transformAndConcat(_function_1); final Function<DataCommitHandlerRegistrationImpl<P, D>, DataCommitHandler<P, D>> _function_2 = new Function<DataCommitHandlerRegistrationImpl<P, D>, DataCommitHandler<P, D>>() { @Override public DataCommitHandler<P, D> apply(final DataCommitHandlerRegistrationImpl<P, D> it) { DataCommitHandler<P, D> _instance = it.getInstance(); return _instance; } }; FluentIterable<DataCommitHandler<P, D>> _transform = _transformAndConcat .<DataCommitHandler<P, D>>transform(_function_2); return _transform.toList(); } }; return AbstractDataBroker.<ImmutableList<DataCommitHandler<P, D>>>withLock(this.registrationLock, _function); }
From source file:org.apache.brooklyn.rest.resources.ServerResource.java
@Override public VersionSummary getVersion() { if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SERVER_STATUS, null)) throw WebResourceUtils.unauthorized("User '%s' is not authorized for this operation", Entitlements.getEntitlementContext().user()); // TODO/*from ww w.j ava 2 s . c om*/ // * "build-metadata.properties" is probably the wrong name // * we should include brooklyn.version and a build timestamp in this file // * the authority for brooklyn should probably be core rather than brooklyn-rest-server InputStream input = ResourceUtils.create().getResourceFromUrl("classpath://build-metadata.properties"); Properties properties = new Properties(); String gitSha1 = null, gitBranch = null; try { properties.load(input); gitSha1 = properties.getProperty(BUILD_SHA_1_PROPERTY); gitBranch = properties.getProperty(BUILD_BRANCH_PROPERTY); } catch (IOException e) { log.error("Failed to load build-metadata.properties", e); } gitSha1 = BrooklynVersion.INSTANCE.getSha1FromOsgiManifest(); FluentIterable<BrooklynFeatureSummary> features = FluentIterable.from(BrooklynVersion.getFeatures(mgmt())) .transform(BrooklynFeatureTransformer.FROM_FEATURE); return new VersionSummary(BrooklynVersion.get(), gitSha1, gitBranch, features.toList()); }
From source file:com.gwtplatform.mvp.processors.proxy.AbstractProxyDetails.java
@Override public Collection<String> getImports() { FluentIterable<String> imports = from(getProxyEventMethods()) .transformAndConcat(HasImports.EXTRACT_IMPORTS_FUNCTION).append(getProxyType().getImports()) .append(getPresenterType().getImports()); if (getBundleDetails() != null) { imports = imports.append(getBundleDetails().getImports()); }/*from ww w . j a va 2 s. com*/ if (getCustomProvider() != null) { imports = imports.append(getCustomProvider().getImports()); } return imports.toList(); }
From source file:org.sosy_lab.cpachecker.util.cwriter.PathToCWithLoopsTranslator.java
/** * Recreates a function from the currentStartNode up to the given untilNode. * @param functionEntryNode the entry node into this function * @param currentStartNode the node from where the recreation should start * @param untilNode the node where the recreation should end * @param block the current basic block// w w w . jav a 2s .co m * @return the c-code of the recreated function part */ private String recreateFunction(FunctionEntryNode functionEntryNode, CFANode currentStartNode, CFANode untilNode, BasicBlock block) { StringBuilder wholeFunction = new StringBuilder(); Deque<CFAEdge> nextEdge = new ArrayDeque<>(); // the function entry node always has exactly one following edge // which is labeled "function start dummy edge" // therefore it is safe to only use this edge without further checks nextEdge.offer(currentStartNode.getLeavingEdge(0)); while (!nextEdge.isEmpty()) { CFAEdge currentEdge = nextEdge.poll(); wholeFunction.append(processSimpleWithLoop(currentEdge, block, "")); if (currentEdge.getSuccessor() == untilNode) { return wholeFunction.toString(); } // there is no successor after this node // so just look if we have more edges to do if (currentEdge instanceof AReturnStatementEdge) { continue; } CFANode successor = currentEdge.getSuccessor(); // check if we already encountered the current edge before if (handledEdges.contains(currentEdge)) { continue; } FluentIterable<Loop> currentLoops = from(getLoopsOfNode(loopStructure, successor)); // we found a loop which has to be handled if (!currentLoops.isEmpty()) { Pair<String, CFAEdge> tmp = recreateLoop(currentEdge, block, currentLoops.toList()); // there should be only one successor on a leaving edge from a loop assert tmp.getSecond().getSuccessor().getNumLeavingEdges() == 1; nextEdge.offer(tmp.getSecond().getSuccessor().getLeavingEdge(0)); wholeFunction.append(tmp.getFirst()); // we found an if-statement } else if (successor.getNumLeavingEdges() > 1) { Pair<String, CFAEdge> tmp = recreateIf(currentEdge, block, functionEntryNode); nextEdge.offer(tmp.getSecond()); wholeFunction.append(tmp.getFirst()); // a normal edge } else { CFAEdge leavingEdge = successor.getLeavingEdge(0); // use the summary edge so that we write only the code of one function if (leavingEdge instanceof CFunctionCallEdge) { leavingEdge = successor.getLeavingSummaryEdge(); } nextEdge.offer(leavingEdge); } } return wholeFunction.toString(); }
From source file:ezbake.deployer.AccumuloEzDeployerStore.java
private FluentIterable<Value> searchWithinStore(Text fieldName, String fieldValue, final Text resultColumnQualifier) throws TException { Scanner scanner = createScanner(); scanner.setRange(Range.exact(new Text(fieldValue), new Text(ARTIFACT_INDEX_CF + ":" + fieldName))); FluentIterable<Range> matches = FluentIterable.from(scanner) .transform(new Function<Map.Entry<Key, Value>, Range>() { @Override// w w w . j av a 2 s . co m public Range apply(Map.Entry<Key, Value> input) { return Range.exact(asText(input.getValue()), ARTIFACT_CF, resultColumnQualifier); } }); if (matches.isEmpty()) { return FluentIterable.from(Collections.<Value>emptyList()); } final BatchScanner batchScanner = createBatchScanner(); try { batchScanner.setRanges(matches.toList()); return FluentIterable .from(FluentIterable.from(batchScanner).transform(new Function<Map.Entry<Key, Value>, Value>() { @Override public Value apply(Map.Entry<Key, Value> keyValueEntry) { return keyValueEntry.getValue(); } }).toList()); } finally { closeWriter(batchScanner); } }
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 w ww. j a va 2s . c o m*/ } 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); } } }