List of usage examples for com.google.common.collect ImmutableBiMap builder
public static <K, V> Builder<K, V> builder()
From source file:org.ambraproject.wombat.config.site.SiteSet.java
@VisibleForTesting // otherwise use SiteSet.create public SiteSet(Iterable<Site> sites) { ImmutableBiMap.Builder<String, Site> map = ImmutableBiMap.builder(); for (Site site : sites) { map.put(site.getKey(), site);//from w ww . j a v a 2 s. co m } this.sites = map.build(); this.journalKeysToNames = buildJournalKeysToNames(this.sites.values()); }
From source file:org.apache.atlas.repository.memory.HierarchicalTypeStore.java
HierarchicalTypeStore(MemRepository repository, HierarchicalType hierarchicalType) throws RepositoryException { this.hierarchicalType = (IConstructableType) hierarchicalType; this.repository = repository; ImmutableMap.Builder<AttributeInfo, IAttributeStore> b = new ImmutableBiMap.Builder<>(); typeNameList = Lists.newArrayList((String) null); ImmutableList<AttributeInfo> l = hierarchicalType.immediateAttrs; for (AttributeInfo i : l) { b.put(i, AttributeStores.createStore(i)); }/* w w w . java 2s . c o m*/ attrStores = b.build(); ImmutableList.Builder<HierarchicalTypeStore> b1 = new ImmutableList.Builder<>(); Set<String> allSuperTypeNames = hierarchicalType.getAllSuperTypeNames(); for (String s : allSuperTypeNames) { b1.add(repository.getStore(s)); } superTypeStores = b1.build(); nextPos = 0; idPosMap = new HashMap<>(); freePositions = new ArrayList<>(); lock = new ReentrantReadWriteLock(); }
From source file:org.theelements.enigma.Rotor.java
private static ImmutableBiMap<Character, Character> buildMap(String mapping) { Preconditions.checkArgument(mapping.length() == 26); ImmutableBiMap.Builder<Character, Character> builder = ImmutableBiMap.builder(); for (int i = 0; i < mapping.length(); i++) { builder.put(LETTERS[i], mapping.charAt(i)); }//from w w w . j a va2 s . co m return builder.build(); }
From source file:org.opendaylight.controller.md.sal.dom.broker.impl.ShardedDOMDataTreeProducer.java
ShardedDOMDataTreeProducer(final ShardedDOMDataTree dataTree, final Map<DOMDataTreeIdentifier, DOMDataTreeShard> shardMap, final Set<DOMDataTreeShard> shards) { this.dataTree = Preconditions.checkNotNull(dataTree); // Create shard -> chain map final Builder<DOMDataTreeShard, DOMStoreTransactionChain> cb = ImmutableBiMap.builder(); final Queue<Exception> es = new LinkedList<>(); for (final DOMDataTreeShard s : shards) { if (s instanceof DOMStore) { try { final DOMStoreTransactionChain c = ((DOMStore) s).createTransactionChain(); LOG.trace("Using DOMStore chain {} to access shard {}", c, s); cb.put(s, c);//from w ww. ja v a 2 s . c o m } catch (final Exception e) { LOG.error("Failed to instantiate chain for shard {}", s, e); es.add(e); } } else { LOG.error("Unhandled shard instance type {}", s.getClass()); } } this.shardToChain = cb.build(); // An error was encountered, close chains and report the error if (shardToChain.size() != shards.size()) { for (final DOMStoreTransactionChain c : shardToChain.values()) { try { c.close(); } catch (final Exception e) { LOG.warn("Exception raised while closing chain {}", c, e); } } final IllegalStateException e = new IllegalStateException("Failed to completely allocate contexts", es.poll()); while (!es.isEmpty()) { e.addSuppressed(es.poll()); } throw e; } idToShard = ImmutableMap.copyOf(shardMap); }
From source file:com.lyndir.omicron.api.ThriftObject.java
ImmutableResourceCost cast(final ResourceCost resourceCost) { ImmutableMap.Builder<ResourceType, Integer> builder = ImmutableBiMap.builder(); resourceCost.getQuantitiesByResourceType().forEach((resourceType, quantity) -> { builder.put(cast(resourceType), (int) quantity); });//from w ww . j a va 2 s .com return new ImmutableResourceCost(builder.build()); }
From source file:com.github.nmorel.gwtjackson.guava.client.deser.ImmutableBiMapJsonDeserializer.java
@Override protected ImmutableBiMap<K, V> doDeserialize(JsonReader reader, JsonDeserializationContext ctx, JsonDeserializerParameters params) { ImmutableBiMap.Builder<K, V> builder = ImmutableBiMap.builder(); buildMap(reader, ctx, params, builder); return builder.build(); }
From source file:com.facebook.buck.rules.SymlinkTree.java
/** * Because of cross-cell, multiple {@link SourcePath}s can resolve to the same relative path, * despite having distinct absolute paths. This presents a challenge for rules that require * gathering all of the inputs in one directory. * * @param sourcePaths set of SourcePaths to process * @param resolver resolver//from w ww.j a va 2 s . co m * @return a map that assigns a unique relative path to each of the SourcePaths. */ public static ImmutableBiMap<SourcePath, Path> resolveDuplicateRelativePaths( ImmutableSortedSet<SourcePath> sourcePaths, SourcePathResolver resolver) { // This serves a dual purpose - it keeps track of whether a particular relative path had been // assigned to a SourcePath and how many times a particular relative path had been seen. Multiset<Path> assignedPaths = HashMultiset.create(); ImmutableBiMap.Builder<SourcePath, Path> builder = ImmutableBiMap.builder(); List<SourcePath> conflicts = new ArrayList<>(); for (SourcePath sourcePath : sourcePaths) { Path relativePath = resolver.getRelativePath(sourcePath); if (!assignedPaths.contains(relativePath)) { builder.put(sourcePath, relativePath); assignedPaths.add(relativePath); } else { conflicts.add(sourcePath); } } for (SourcePath conflict : conflicts) { Path relativePath = resolver.getRelativePath(conflict); Path parent = MorePaths.getParentOrEmpty(relativePath); String extension = MorePaths.getFileExtension(relativePath); String name = MorePaths.getNameWithoutExtension(relativePath); while (true) { StringBuilder candidateName = new StringBuilder(name); candidateName.append('-'); int suffix = assignedPaths.count(relativePath); candidateName.append(suffix); if (!extension.isEmpty()) { candidateName.append('.'); candidateName.append(extension); } Path candidate = parent.resolve(candidateName.toString()); if (!assignedPaths.contains(candidate)) { assignedPaths.add(candidate); builder.put(conflict, candidate); break; } else { assignedPaths.add(relativePath); } } } return builder.build(); }
From source file:alluxio.StorageTierAssoc.java
/** * Constructs a new instance using the given list of storage tier aliases in order of their * position in the hierarchy./* ww w . jav a 2 s. c om*/ * * @param storageTierAliases the list of aliases */ protected StorageTierAssoc(List<String> storageTierAliases) { ImmutableBiMap.Builder<String, Integer> builder = new ImmutableBiMap.Builder<>(); for (int ordinal = 0; ordinal < storageTierAliases.size(); ordinal++) { builder.put(storageTierAliases.get(ordinal), ordinal); } mAliasToOrdinal = builder.build(); }
From source file:com.google.caliper.util.Util.java
public static <T> ImmutableBiMap<T, String> assignNames(Set<T> items) { ImmutableList<T> itemList = ImmutableList.copyOf(items); ImmutableBiMap.Builder<T, String> itemNamesBuilder = ImmutableBiMap.builder(); for (int i = 0; i < itemList.size(); i++) { itemNamesBuilder.put(itemList.get(i), generateUniqueName(i)); }/*from ww w. j a va2s . co m*/ return itemNamesBuilder.build(); }
From source file:org.neatrchlab.StatefulP4Interpreter.java
@Override public ImmutableBiMap<Criterion.Type, String> criterionTypeMap() { ImmutableBiMap.Builder<Criterion.Type, String> builder = ImmutableBiMap.builder(); builder.put(Criterion.Type.IN_PORT, "standard_metadata.ingress_port"); builder.put(Criterion.Type.ETH_DST, "ethernet.dstAddr"); builder.put(Criterion.Type.ETH_SRC, "ethernet.srcAddr"); builder.put(Criterion.Type.ETH_TYPE, "ethernet.etherType"); return builder.build(); }