List of usage examples for com.google.common.collect Maps uniqueIndex
public static <K, V> ImmutableMap<K, V> uniqueIndex(Iterator<V> values, Function<? super V, K> keyFunction)
From source file:com.microsoft.azure.management.appservice.implementation.FunctionDeploymentSlotImpl.java
@Override public Observable<Map<String, HostNameBinding>> getHostNameBindingsAsync() { return this.manager().inner().webApps() .listHostNameBindingsSlotAsync(resourceGroupName(), parent().name(), name()) .flatMap(new Func1<Page<HostNameBindingInner>, Observable<HostNameBindingInner>>() { @Override//from w w w . j a v a 2 s . com public Observable<HostNameBindingInner> call( Page<HostNameBindingInner> hostNameBindingInnerPage) { return Observable.from(hostNameBindingInnerPage.items()); } }).map(new Func1<HostNameBindingInner, HostNameBinding>() { @Override public HostNameBinding call(HostNameBindingInner hostNameBindingInner) { return new HostNameBindingImpl<>(hostNameBindingInner, FunctionDeploymentSlotImpl.this); } }).toList().map(new Func1<List<HostNameBinding>, Map<String, HostNameBinding>>() { @Override public Map<String, HostNameBinding> call(List<HostNameBinding> hostNameBindings) { return Collections.unmodifiableMap( Maps.uniqueIndex(hostNameBindings, new Function<HostNameBinding, String>() { @Override public String apply(HostNameBinding input) { return input.name().replace(name() + "/", ""); } })); } }); }
From source file:org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestClient.java
public <R extends RestResponse<E>, E extends Named> Map<String, E> retrieveItems(IOperationMonitor monitor, String path, TypeToken typeToken) throws BugzillaRestException { R response = new BugzillaRestAuthenticatedGetRequest<R>(client, path, typeToken).run(monitor); E[] members = response.getArray();/* ww w . j a v a 2s . c o m*/ return Maps.uniqueIndex(Lists.newArrayList(members), new Function<E, String>() { public String apply(E input) { return input.getName(); }; }); }
From source file:org.opentestsystem.authoring.testauth.service.impl.AffinityGroupHelper.java
private static final void populateDefaultItemSelectionParameters(final AffinityGroup affinityGroup, final String segmentId, final ItemSelectionAlgorithm itemSelectionAlgorithm) { if (itemSelectionAlgorithm != null && itemSelectionAlgorithm.getBlueprintParameters() != null) { affinityGroup.getAffinityGroupValueMap().get(segmentId) .setItemSelectionParameters(Maps.newHashMap(Maps.transformValues( Maps.uniqueIndex(itemSelectionAlgorithm.getBlueprintParameters(), ItemSelectionAlgorithmHelper.ISA_PARAMETER_NAME_TRANSFORMER), ItemSelectionAlgorithmHelper.ISA_PARAMETER_DEFAULT_VALUE_TRANSFORMER))); } else {/*w w w .ja va 2 s. com*/ affinityGroup.getAffinityGroupValueMap().get(segmentId).setItemSelectionParameters(null); } }
From source file:org.awesomeagile.webapp.controller.HackpadController.java
/** * Create a Hackpad on behalf of an authenticated caller * @param principal The entity requesting the Hackpad creation * @param documentTypeValue The type of document the entity wishes to be created * @return A CreatedDocument instance, from which the document URL can be * retrieved.//from ww w . j a va2s . com * @throws MalformedURLException */ @RequestMapping(method = RequestMethod.POST, path = "/api/hackpad/{doctype}") @ResponseBody @Transactional public CreatedDocument createNewHackpad(@AuthenticationPrincipal AwesomeAgileSocialUser principal, @PathVariable("doctype") String documentTypeValue) throws MalformedURLException { HackpadDocumentTemplate template = templates.get(documentTypeValue); if (template == null) { throw new ResourceNotFoundException("Bad document type"); } Map<DocumentType, Document> documentsByType = Maps .uniqueIndex(documentRepository.findAllByUserId(principal.getUser().getId()), Document.GET_TYPE); DocumentType type = DocumentType.valueOf(documentTypeValue); Document existingDocument = documentsByType.get(type); if (existingDocument != null) { return new CreatedDocument(existingDocument.getUrl()); } PadIdentity identity = client.createHackpad(template.getTitle()); if (identity == null) { throw new RuntimeException("Unknown error creating hackpad template " + template.getTitle()); } client.updateHackpad(identity, client.getHackpad(template.getPadIdentity())); String documentUrl = client.fullUrl(identity.getPadId()); Document doc = new Document().setUser(principal.getUser()).setUrl(documentUrl).setDocumentType(type); documentRepository.save(doc); return new CreatedDocument(documentUrl); }
From source file:com.codemacro.jcm.model.Cluster.java
public void setNodesStatus(Map<String, NodeStatus> statusSet) { Map<String, Node> mNodes = null; synchronized (nodes) { mNodes = Maps.uniqueIndex(nodes, new Function<Node, String>() { public String apply(Node node) { return node.getSpec(); }/* ww w . ja v a2s .c o m*/ }); } for (Map.Entry<String, NodeStatus> entry : statusSet.entrySet()) { Node n = mNodes.get(entry.getKey()); if (n != null) { n.setStatus((NodeStatus) entry.getValue()); n.updateLastCheck(); } } }
From source file:org.opendaylight.yangtools.yang.model.util.FilteringSchemaContextProxy.java
/** * Filters SchemaContext for yang modules * * @param delegate original SchemaContext * @param rootModules modules (yang schemas) to be available and all their dependencies (modules importing rootModule and whole chain of their imports) * @param additionalModuleIds (additional) modules (yang schemas) to be available and whole chain of their imports * *//*from w w w . j a v a 2 s . co m*/ public FilteringSchemaContextProxy(final SchemaContext delegate, final Collection<ModuleId> rootModules, final Set<ModuleId> additionalModuleIds) { Preconditions.checkArgument(rootModules != null, "Base modules cannot be null."); Preconditions.checkArgument(additionalModuleIds != null, "Additional modules cannot be null."); final Builder<Module> filteredModulesBuilder = new Builder<>(); final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(new TreeMap<>(), MODULE_SET_SUPPLIER); final SetMultimap<String, Module> nameMap = Multimaps.newSetMultimap(new TreeMap<>(), MODULE_SET_SUPPLIER); ImmutableMap.Builder<ModuleIdentifier, String> identifiersToSourcesBuilder = ImmutableMap.builder(); //preparing map to get all modules with one name but difference in revision final TreeMultimap<String, Module> nameToModulesAll = getStringModuleTreeMultimap(); nameToModulesAll.putAll(getStringModuleMap(delegate)); //in case there is a particular dependancy to view filteredModules/yang models //dependancy is checked for module name and imports processForRootModules(delegate, rootModules, filteredModulesBuilder); //adding additional modules processForAdditionalModules(delegate, additionalModuleIds, filteredModulesBuilder); filteredModulesBuilder.addAll( getImportedModules(Maps.uniqueIndex(delegate.getModules(), ModuleId.MODULE_TO_MODULE_ID::apply), filteredModulesBuilder.build(), nameToModulesAll)); /** * Instead of doing this on each invocation of getModules(), pre-compute * it once and keep it around -- better than the set we got in. */ this.filteredModules = filteredModulesBuilder.build(); for (final Module module : filteredModules) { nameMap.put(module.getName(), module); nsMap.put(module.getNamespace(), module); identifiersToSourcesBuilder.put(module, module.getSource()); } namespaceToModules = ImmutableSetMultimap.copyOf(nsMap); nameToModules = ImmutableSetMultimap.copyOf(nameMap); identifiersToSources = identifiersToSourcesBuilder.build(); }
From source file:ezbake.deployer.cli.EzDeployerCli.java
public EzDeployerCli(String[] args) throws TTransportException { //Using Supplier because the pool hasn't been initialized yet Supplier<ThriftClientPool> clientPoolSupplier = Suppliers.memoize(new Supplier<ThriftClientPool>() { @Override// ww w . j a v a 2 s . c o m public ThriftClientPool get() { return pool.get(); } }); allCommands = Lists.newArrayList((Command) new DeployCommand(), new DeployTarCommand(), new UnDeployCommand(), new PurgeCommand(), new GetAllApplicationVersionsCommand(), new LatestVersionCommand(), new ListDeployedCommand(), new PublishLatestArtifactCommand(), new PublishArtifactCommand(), new PingCommand(), new SSLCertsCommand(clientPoolSupplier), new ReregisterCommand()); operations = Maps.uniqueIndex(allCommands, new Function<Command, String>() { @Override public String apply(Command input) { return input.getName(); } }); globalParameters = new GlobalParameters(args, allCommands); }
From source file:de.brands4friends.daleq.core.RowBuilder.java
private Map<FieldType, FieldHolder> createTypeToHolderIndex(final TableType tableType) { return Maps.uniqueIndex(fields.values(), new Function<FieldHolder, FieldType>() { @Override//from w w w . jav a 2 s . c om public FieldType apply(@Nullable final FieldHolder fieldHolder) { if (fieldHolder == null) { throw new IllegalArgumentException("fieldHolder"); } final FieldTypeReference fieldTypeReference = fieldHolder.getFieldTypeRef(); final FieldType fieldType = fieldTypeReference.resolve(tableType); if (fieldType == null) { return throwNoSuchDaleqFieldException(fieldHolder, tableType); } return fieldType; } }); }
From source file:org.eclipse.emf.mwe2.language.factory.SettingProviderImpl.java
public Map<QualifiedName, ISetting> getSettings(final Object obj, JvmType type) { Map<QualifiedName, JvmFeature> features = injectableFeatureLookup.getInjectableFeatures(type); Iterable<ISetting> settings = Iterables.transform(features.entrySet(), new Function<Map.Entry<QualifiedName, JvmFeature>, ISetting>() { public ISetting apply(final Map.Entry<QualifiedName, JvmFeature> from) { if (from.getValue() instanceof JvmOperation) { return new ISetting() { public void setValue(Object value) { Method method = reflectAccess.getMethod((JvmOperation) from.getValue()); try { method.invoke(obj, value); } catch (Exception e) { throw new WrappedException(e); }/* w w w .ja v a2 s . c o m*/ } public QualifiedName getName() { return from.getKey(); } }; } else if (from.getValue() instanceof JvmField) { return new ISetting() { public void setValue(Object value) { Field field = reflectAccess.getField((JvmField) from.getValue()); try { field.set(obj, value); } catch (Exception e) { throw new WrappedException(e); } } public QualifiedName getName() { return from.getKey(); } }; } throw new IllegalArgumentException( from.getValue().getIdentifier() + " can not be handled."); } }); return Maps.uniqueIndex(settings, new Function<ISetting, QualifiedName>() { public QualifiedName apply(ISetting from) { return from.getName(); } }); }
From source file:org.ambraproject.rhino.model.ArticleItem.java
@Transient private ImmutableMap<String, ArticleFile> getFileMap() { return (fileMap != null) ? fileMap : (fileMap = Maps.uniqueIndex(getFiles(), ArticleFile::getFileType)); }