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:org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema.java
BaseSchema(final List<YangModuleInfo> modules) { try {/*w ww.ja v a 2 s . com*/ final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create(); moduleInfoBackedContext.addModuleInfos(modules); schemaContext = moduleInfoBackedContext.tryToCreateSchemaContext().get(); mappedRpcs = Maps.uniqueIndex(schemaContext.getOperations(), RpcDefinition::getQName); } catch (final RuntimeException e) { throw new ExceptionInInitializerError(e); } }
From source file:org.jboss.seam.social.examples.webclient.SocialClient.java
public Map<String, OAuthSession> getSessionsMap() { return Maps.uniqueIndex(getSessions(), new Function<OAuthSession, String>() { @Override/* ww w .j a v a2 s . c o m*/ public String apply(OAuthSession arg0) { return arg0.toString(); } }); }
From source file:org.jclouds.azure.storage.blob.blobstore.functions.ListBlobsResponseToResourceList.java
public PageSet<? extends StorageMetadata> apply(ListBlobsResponse from) { Set<StorageMetadata> contents = Sets.<StorageMetadata>newHashSet(Iterables.transform(from, object2blobMd)); Map<String, StorageMetadata> nameToMd = Maps.uniqueIndex(contents, indexer); for (String prefix : from.getBlobPrefixes()) { prefix = prefix.endsWith("/") ? prefix.substring(0, prefix.lastIndexOf('/')) : prefix; if (!nameToMd.containsKey(prefix) || nameToMd.get(prefix).getType() != StorageType.RELATIVE_PATH) contents.add(prefix2ResourceMd.apply(prefix)); }// w w w .ja va 2s. c om return new PageSetImpl<StorageMetadata>(contents, from.getNextMarker()); }
From source file:org.jclouds.openstack.keystone.v1_1.suppliers.RegionIdToURIFromAuthForServiceSupplier.java
@Override public Map<String, Supplier<URI>> get() { Auth authResponse = auth.get();/*from ww w . ja v a2 s . c o m*/ Collection<Endpoint> endpointsForService = authResponse.getServiceCatalog().get(apiType); Map<String, Endpoint> regionIdToEndpoint = Maps.uniqueIndex(endpointsForService, endpointToRegion); return Maps.transformValues(regionIdToEndpoint, endpointToSupplierURI); }
From source file:com.isotrol.impe3.pms.core.support.PortalPages.java
/** * Constructor//w w w . j a v a 2s . co m * @param pages Page definitions. */ private PortalPages(Iterable<PageDfn> pages) { map = Maps.uniqueIndex(pages, DFN2ID); byKey = Maps.newHashMap(); for (PageDfn p : pages) { final PageMapKey pageKey = PageMapKeySupport.of(p); if (pageKey != null) { final PageDfn p2 = byKey.get(pageKey); if (p2 != null) { Loggers.core().warn("Duplicate page key [{}]. Keeping last page.", new Object[] { pageKey }); } byKey.put(pageKey, p); } } }
From source file:org.jclouds.cloudstack.predicates.OSCategoryIn.java
@Override public Predicate<Template> apply(final Set<String> acceptableCategories) { final Map<String, String> categories = categoriesSupplier.get(); final Set<String> acceptableOSTypeIds = Maps.filterValues( Maps.transformValues(Maps.uniqueIndex(osTypesSupplier.get(), new Function<OSType, String>() { @Override/*from w w w . j ava2s .co m*/ public String apply(OSType input) { return input.getId(); } }), new Function<OSType, String>() { @Override public String apply(OSType input) { return categories.get(input.getOSCategoryId()); } }), Predicates.in(acceptableCategories)).keySet(); return new Predicate<Template>() { @Override public boolean apply(Template input) { return Predicates.in(acceptableOSTypeIds).apply(input.getOSTypeId()); } @Override public String toString() { return "OSCategoryIn(" + acceptableCategories + ")"; } }; }
From source file:org.cloudifysource.restDoclet.docElements.DocAnnotation.java
public DocAnnotation(AnnotationDesc annotationDesc) { name_ = annotationDesc.annotationType() == null ? annotationDesc.toString() : annotationDesc.annotationType().typeName(); attributeMap_ = Maps.uniqueIndex(Arrays.asList(annotationDesc.elementValues()), annotationDescKeyFn_); }
From source file:ec.tss.tsproviders.spreadsheet.engine.SpreadSheetSource.java
@Deprecated public SpreadSheetSource(List<SpreadSheetCollection> list, String factoryName) { this.collections = Maps.uniqueIndex(list, o -> o != null ? o.sheetName : null); this.factoryName = factoryName; }
From source file:com.facebook.buck.android.resources.ResTablePackage.java
public static ResTablePackage slice(ResTablePackage resPackage, Map<Integer, Integer> countsToSlice) { resPackage.assertValidIds(countsToSlice.keySet()); int packageId = resPackage.packageId; byte[] nameData = Arrays.copyOf(resPackage.nameData, NAME_DATA_LENGTH); List<ResTableTypeSpec> newSpecs = resPackage.getTypeSpecs().stream() .map(spec -> ResTableTypeSpec.slice(spec, countsToSlice.getOrDefault(spec.getResourceType(), 0))) .collect(ImmutableList.toImmutableList()); StringPool keys = resPackage.keys;// w w w.j ava2s. c om // Figure out what keys are used by the retained references. ImmutableSortedSet.Builder<Integer> keyRefs = ImmutableSortedSet .orderedBy(Comparator.comparing(keys::getString)); newSpecs.forEach(spec -> spec.visitKeyReferences(keyRefs::add)); ImmutableList<Integer> keysToExtract = keyRefs.build().asList(); Map<Integer, Integer> keyMapping = Maps.uniqueIndex(IntStream.range(0, keysToExtract.size())::iterator, keysToExtract::get); // Extract a StringPool that contains just the keys used by the new specs. StringPool newKeys = StringPool.create(keysToExtract.stream().map(keys::getString)::iterator); // Adjust the key references. for (ResTableTypeSpec spec : newSpecs) { spec.transformKeyReferences(keyMapping::get); } StringPool types = resPackage.types.copy(); int chunkSize = HEADER_SIZE + types.getChunkSize() + newKeys.getChunkSize(); for (ResTableTypeSpec spec : newSpecs) { chunkSize += spec.getTotalSize(); } return new ResTablePackage(chunkSize, packageId, nameData, types, newKeys, newSpecs); }
From source file:fr.xebia.workshop.continuousdelivery.InfrastructureTopologyScanner.java
public Collection<TeamInfrastructure> scan() { Filter filter = new Filter("tag:Workshop", newArrayList("continuous-delivery-workshop")); List<Reservation> reservations = ec2.describeInstances(new DescribeInstancesRequest().withFilters(filter)) .getReservations();/*from w w w .ja v a 2s . c om*/ Iterable<Instance> instances = AmazonAwsUtils.toEc2Instances(reservations); Iterable<Instance> runningInstances = Iterables.filter(instances, AmazonAwsUtils.PREDICATE_RUNNING_OR_PENDING_INSTANCE); runningInstances = AmazonAwsUtils.awaitForEc2Instances(runningInstances, ec2); Map<String, Instance> runningInstancesByInstanceId = Maps.uniqueIndex(runningInstances, AmazonAwsFunctions.EC2_INSTANCE_TO_INSTANCE_ID); List<String> runningInstanceIds = newArrayList( Iterables.transform(runningInstances, AmazonAwsFunctions.EC2_INSTANCE_TO_INSTANCE_ID)); List<TagDescription> tags = ec2 .describeTags(new DescribeTagsRequest().withFilters(new Filter("resource-id", runningInstanceIds))) .getTags(); Map<String, Map<String, String>> tagsByInstanceId = new MapMaker() .makeComputingMap(new Function<String, Map<String, String>>() { @Override public Map<String, String> apply(String instanceId) { return Maps.newHashMap(); } }); for (TagDescription tag : tags) { tagsByInstanceId.get(tag.getResourceId()).put(tag.getKey(), tag.getValue()); } Map<String, TeamInfrastructure> teamInfrastructureByTeamIdentifier = new MapMaker() .makeComputingMap(new Function<String, TeamInfrastructure>() { @Override public TeamInfrastructure apply(String teamIdentifier) { return new TeamInfrastructure(workshopInfrastructure, teamIdentifier); } }); Instance nexusServer = null; for (Map.Entry<String, Map<String, String>> entry : tagsByInstanceId.entrySet()) { Map<String, String> instanceTags = entry.getValue(); String instanceId = entry.getKey(); Instance instance = runningInstancesByInstanceId.get(instanceId); String teamIdentifier = instanceTags.get("TeamIdentifier"); if (teamIdentifier == null) { if (TeamInfrastructure.ROLE_NEXUS.equals(instanceTags.get("Role"))) { nexusServer = instance; } else { // not a per team server (e.g. Nexus server) } } else { TeamInfrastructure teamInfrastructure = teamInfrastructureByTeamIdentifier.get(teamIdentifier); teamInfrastructure.addInstance(instance, instanceTags); } } Collection<TeamInfrastructure> teamInfrastructures = teamInfrastructureByTeamIdentifier.values(); for (TeamInfrastructure teamInfrastructure : teamInfrastructures) { teamInfrastructure.setNexus(nexusServer); } return teamInfrastructures; }