List of usage examples for com.google.common.collect ImmutableBiMap copyOf
public static <K, V> ImmutableBiMap<K, V> copyOf(Iterable<? extends Entry<? extends K, ? extends V>> entries)
From source file:org.terasology.persistence.serializers.EventSerializer.java
/** * Sets the mapping between event classes and the ids that are used for serialization * * @param table/*ww w . ja v a 2 s . c o m*/ */ public void setIdMapping(Map<Class<? extends Event>, Integer> table) { idTable = ImmutableBiMap.copyOf(table); }
From source file:com.google.enterprise.connector.util.filter.CopyPropertyFilter.java
/** * Sets the property name map. This {@code Map<String, String>} * maps source property name (the {@code key}) to the destination * property name (the {@code value}).//from www. j a v a2 s.c om * * @param propertyNameMap sourceName-to-destinationName {@link Map} * @throws NullPointerException if {@code propertyNameMap} is {@code null} */ public void setPropertyNameMap(Map<String, String> propertyNameMap) { Preconditions.checkNotNull(propertyNameMap); this.nameMap = ImmutableBiMap.copyOf(propertyNameMap).inverse(); }
From source file:com.facebook.presto.sql.planner.optimizations.TableLayoutRewriter.java
public PlanNode planTableScan(TableScanNode node, Expression predicate) { DomainTranslator.ExtractionResult decomposedPredicate = DomainTranslator.fromPredicate(metadata, session, predicate, symbolAllocator.getTypes()); TupleDomain<ColumnHandle> simplifiedConstraint = decomposedPredicate.getTupleDomain() .transform(node.getAssignments()::get).intersect(node.getCurrentConstraint()); List<TableLayoutResult> layouts = metadata.getLayouts(session, node.getTable(), new Constraint<>(simplifiedConstraint, bindings -> true), Optional.of(ImmutableSet.copyOf(node.getAssignments().values()))); if (layouts.isEmpty()) { return new ValuesNode(idAllocator.getNextId(), node.getOutputSymbols(), ImmutableList.of()); }/*from ww w . jav a 2 s . c o m*/ TableLayoutResult layout = layouts.get(0); TableScanNode result = new TableScanNode(node.getId(), node.getTable(), node.getOutputSymbols(), node.getAssignments(), Optional.of(layout.getLayout().getHandle()), simplifiedConstraint.intersect(layout.getLayout().getPredicate()), Optional.ofNullable(node.getOriginalConstraint()).orElse(predicate)); Map<ColumnHandle, Symbol> assignments = ImmutableBiMap.copyOf(node.getAssignments()).inverse(); Expression resultingPredicate = combineConjuncts(decomposedPredicate.getRemainingExpression(), DomainTranslator.toPredicate(layout.getUnenforcedConstraint().transform(assignments::get))); if (!BooleanLiteral.TRUE_LITERAL.equals(resultingPredicate)) { return new FilterNode(idAllocator.getNextId(), result, resultingPredicate); } return result; }
From source file:com.haulmont.cuba.gui.components.OptionsField.java
@Deprecated default void setOptionsMap(Map<String, I> map) { BiMap<String, I> biMap = ImmutableBiMap.copyOf(map); setOptionsSource(new MapOptions<>(map)); setOptionCaptionProvider(v -> biMap.inverse().get(v)); }
From source file:org.terasology.persistence.serializers.NetworkEntitySerializer.java
public void setIdMapping(Map<Class<? extends Component>, Integer> componentIdMapping) { this.idTable = ImmutableBiMap.copyOf(componentIdMapping); }
From source file:net.sourcedestination.sai.comparison.matching.MatchingGenerator.java
public static GraphMatching includeEdgeMatching(final GraphMatching nodeMatching, BiMap<Integer, Integer> edgeMatch) { final BiMap<Integer, Integer> copyEdgeMatch = ImmutableBiMap.copyOf(edgeMatch); // transform Map.Entry to Pair instances final ImmutableSet<Pair<Integer>> matchedEdges = ImmutableSet.copyOf(edgeMatch.entrySet().stream() .map((arg) -> Pair.makePair(arg.getKey(), arg.getValue())).collect(toSet())); return new GraphMatching() { @Override/* w ww . jav a2s. c om*/ public Graph getGraph1() { return nodeMatching.getGraph1(); } @Override public Graph getGraph2() { return nodeMatching.getGraph2(); } @Override public int getMatchedNodeInGraph2(int g1NodeID) { return nodeMatching.getMatchedNodeInGraph2(g1NodeID); } @Override public int getMatchedNodeInGraph1(int g2NodeID) { return nodeMatching.getMatchedNodeInGraph1(g2NodeID); } @Override public Set<Pair<Integer>> getAllNodeMatches() { return nodeMatching.getAllNodeMatches(); } @Override public int getMatchedEdgeInGraph2(int g1NodeID) { if (copyEdgeMatch.containsKey(g1NodeID)) return copyEdgeMatch.get(g1NodeID); return -1; } @Override public int getMatchedEdgeInGraph1(int g2NodeID) { if (copyEdgeMatch.inverse().containsKey(g2NodeID)) return copyEdgeMatch.inverse().get(g2NodeID); return -1; } @Override public Set<Pair<Integer>> getAllEdgeMatches() { return matchedEdges; } }; }
From source file:org.terasology.persistence.serializers.ComponentSerializer.java
/** * Sets the mapping between component classes and the ids that are used for serialization * * @param table// w w w.j a v a 2 s . c o m */ public void setIdMapping(Map<Class<? extends Component>, Integer> table) { idTable = ImmutableBiMap.copyOf(table); }
From source file:dagger.internal.codegen.SubcomponentNames.java
private static ImmutableBiMap<ComponentDescriptor, String> disambiguateConflictingSimpleNames( Collection<ComponentDescriptor> components, ImmutableMap<ComponentDescriptor, Namer> componentNamers) { Map<String, ComponentDescriptor> generatedSimpleNames = new LinkedHashMap<>(); // Let's see if we can get away with using simpleName() everywhere. for (ComponentDescriptor component : components) { Namer namer = componentNamers.get(component); if (generatedSimpleNames.containsKey(namer.simpleName())) { break; }/*from ww w .ja v a 2 s.c o m*/ generatedSimpleNames.put(namer.simpleName(), component); } if (generatedSimpleNames.size() != components.size()) { // Simple approach didn't work out, let's use more complicated names. // We keep them small to fix https://github.com/google/dagger/issues/421. generatedSimpleNames.clear(); UniqueNameSet nameSet = new UniqueNameSet(); for (ComponentDescriptor component : components) { Namer namer = componentNamers.get(component); String simpleName = namer.simpleName(); String basePrefix = namer.uniquingPrefix(); generatedSimpleNames.put(format("%s_%s", nameSet.getUniqueName(basePrefix), simpleName), component); } } return ImmutableBiMap.copyOf(generatedSimpleNames).inverse(); }
From source file:org.ambraproject.wombat.config.site.SiteSet.java
/** * Build a map representing the one-to-one relationship between journal keys and journal names. * <p/>/*from w ww .j a v a 2s.c o m*/ * As a side effect, validates that the relationship actually is one-to-one -- that is, that multiple sites have the * same journal key if and only if they have the same journal name. It is easier to obey this constraint if the {@code * journalKey} and {@code journalName} config values are always set in the {@code journal.yaml} or {@code * journal.json} file of the same theme, which should be a parent of all themes belonging to that journal. * * @param sites the set of all sites being served * @return a map between journal keys and journal names * @throws IllegalArgumentException if two sites with the same journal key have unequal journal names or if two sites * with the same journal name have unequal journal keys */ private static ImmutableBiMap<String, String> buildJournalKeysToNames(Set<Site> sites) { Multimap<String, Site> keysToSites = groupByJournalKey(sites); BiMap<String, String> keysToNames = HashBiMap.create(keysToSites.keySet().size()); for (Map.Entry<String, Collection<Site>> entry : keysToSites.asMap().entrySet()) { String journalKey = entry.getKey(); Iterator<Site> siteIterator = entry.getValue().iterator(); String journalName = siteIterator.next().getJournalName(); while (siteIterator.hasNext()) { String nextJournalName = siteIterator.next().getJournalName(); if (!journalName.equals(nextJournalName)) { String message = String.format("Inconsistent journal names with key=%s: %s; %s", journalKey, journalName, nextJournalName); throw new IllegalArgumentException(message); } } if (keysToNames.containsValue(journalName)) { String message = String.format("Overloaded journal name (%s) for keys: %s; %s", journalName, journalKey, keysToNames.inverse().get(journalName)); throw new IllegalArgumentException(message); } keysToNames.put(journalKey, journalName); } return ImmutableBiMap.copyOf(keysToNames); }
From source file:com.torodb.torod.db.postgresql.meta.StructuresCache.java
public BiMap<Integer, DocStructure> getAllStructures() { return ImmutableBiMap.copyOf(structures); }