List of usage examples for com.google.common.collect BiMap put
@Override @Nullable V put(@Nullable K key, @Nullable V value);
From source file:org.apache.niolex.common.guava.GuavaCollections.java
/** * @param args/*from ww w.java 2 s.c o m*/ */ public static void main(String[] args) { Multiset<String> wordsMultiset = HashMultiset.create(); wordsMultiset.add("abc"); wordsMultiset.add("abc"); wordsMultiset.add("abcd"); System.out.println("count => " + wordsMultiset.count("abc")); System.out.println("count => " + wordsMultiset.count("abcd")); BiMap<String, String> biMap = HashBiMap.create(); biMap.put("good", "morning"); biMap.put("bad", "afternoon"); System.out.println("good => " + biMap.get("good")); System.out.println("afternoon => " + biMap.inverse().get("afternoon")); RangeMap<Integer, String> rangeMap = TreeRangeMap.create(); rangeMap.put(Range.closed(1, 11), "Nice"); rangeMap.put(Range.openClosed(11, 15), "Girl"); System.out.println("11 => " + rangeMap.get(11)); System.out.println("12 => " + rangeMap.get(12)); System.out.println("15 => " + rangeMap.get(15)); System.out.println("16 => " + rangeMap.get(16)); List<Integer> countUp = Ints.asList(1, 2, 3, 4, 5); List<Integer> countDown = Lists.reverse(countUp); // {5, 4, 3, 2, 1} System.out.println("countUp => " + countUp); System.out.println("countDown => " + countDown); }
From source file:com.google.cloud.genomics.dataflow.pipelines.VariantSimilarity.java
public static void main(String[] args) throws IOException, GeneralSecurityException { // Register the options so that they show up via --help PipelineOptionsFactory.register(Options.class); Options options = PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class); // Option validation is not yet automatic, we make an explicit call here. Options.Methods.validateOptions(options); OfflineAuth auth = GenomicsOptions.Methods.getGenomicsAuth(options); List<String> callSetNames = GenomicsUtils.getCallSetsNames(options.getVariantSetId(), auth); Collections.sort(callSetNames); // Ensure a stable sort order for reproducible results. BiMap<String, Integer> dataIndices = HashBiMap.create(); for (String callSetName : callSetNames) { dataIndices.put(callSetName, dataIndices.size()); }/*ww w. j a v a2 s . c om*/ Pipeline p = Pipeline.create(options); p.begin(); PCollection<StreamVariantsRequest> requests; if (null != options.getSitesFilepath()) { // Compute PCA on a list of sites. requests = p.apply(TextIO.Read.named("ReadSites").from(options.getSitesFilepath())) .apply(new SitesToShards.SitesToStreamVariantsShardsTransform(options.getVariantSetId())); } else { List<StreamVariantsRequest> shardRequests = options.isAllReferences() ? ShardUtils.getVariantRequests(options.getVariantSetId(), ShardUtils.SexChromosomeFilter.EXCLUDE_XY, options.getBasesPerShard(), auth) : ShardUtils.getVariantRequests(options.getVariantSetId(), options.getReferences(), options.getBasesPerShard()); requests = p.apply(Create.of(shardRequests)); } requests.apply(new VariantStreamer(auth, ShardBoundary.Requirement.STRICT, VARIANT_FIELDS)) .apply(ParDo.of(new ExtractSimilarCallsets())) .apply(new OutputPCoAFile(dataIndices, options.getOutput())); p.run(); }
From source file:org.eclipse.b3.enums.TriStateEnumHelper.java
private static BiMap<TriState, String> createEnumMap() { BiMap<TriState, String> map = new EnumHashBiMap<TriState, String>(TriState.class); map.put(TriState.DEFAULT, DEFAULT_STR); map.put(TriState.TRUE, TRUE_STR);/*from ww w . ja v a 2 s .co m*/ map.put(TriState.FALSE, FALSE_STR); return Maps.unmodifiableBiMap(map); }
From source file:edu.uci.ics.jung.algorithms.util.Indexer.java
/** * Returns a <code>BiMap</code> mapping each element of the collection to its * index as encountered while iterating over the collection. The purpose * of the index operation is to supply an O(1) replacement operation for the * O(n) <code>indexOf(element)</code> method of a <code>List</code> * @param <T> the type of the collection elements * @param collection the collection whose indices are to be generated * @param start start index/* www .j a v a 2 s. com*/ * @return a bidirectional map from collection elements to start-based indices */ public static <T> BiMap<T, Integer> create(Collection<T> collection, int start) { BiMap<T, Integer> map = HashBiMap.<T, Integer>create(); int i = start; for (T t : collection) { map.put(t, i++); } return map; }
From source file:com.anhth12.lambda.app.schema.CategoricalValueEncodings.java
private static <T> BiMap<T, Integer> mapDistinctValues(Collection<T> distinct) { BiMap<T, Integer> mapping = HashBiMap.create(); int encoding = 0; for (T t : distinct) { mapping.put(t, encoding); encoding++;/*from www . ja v a2 s . c o m*/ } return mapping; }
From source file:org.opendaylight.yangtools.yang.model.export.YinExportUtils.java
private static Map<String, URI> prefixToNamespace(final SchemaContext ctx, final Module module) { final BiMap<String, URI> prefixMap = HashBiMap.create(module.getImports().size() + 1); prefixMap.put(module.getPrefix(), module.getNamespace()); for (final ModuleImport imp : module.getImports()) { final String prefix = imp.getPrefix(); final URI namespace = getModuleNamespace(ctx, imp.getModuleName()); prefixMap.put(prefix, namespace); }//from w ww . ja v a 2s . co m return prefixMap; }
From source file:org.eclipse.b3.enums.MergeConflictStrategyEnumHelper.java
private static BiMap<MergeConflictStrategy, String> createEnumMap() { BiMap<MergeConflictStrategy, String> map = new EnumHashBiMap<MergeConflictStrategy, String>( MergeConflictStrategy.class); map.put(MergeConflictStrategy.DEFAULT, BRANCH_POINT_DEFAULT_STR); map.put(MergeConflictStrategy.FAIL, FAIL_STR); map.put(MergeConflictStrategy.USE_WORKSPACE, USE_WORKSPACE_STR); map.put(MergeConflictStrategy.USE_SCM, USE_SCM_STR); return Maps.unmodifiableBiMap(map); }
From source file:com.cloudera.oryx.app.schema.CategoricalValueEncodings.java
private static <T> BiMap<T, Integer> mapDistinctValues(Collection<T> distinct) { BiMap<T, Integer> mapping = HashBiMap.create(); int encoding = 0; for (T t : distinct) { mapping.put(t, encoding); encoding++;/* www .j a v a 2 s . c o m*/ } return mapping; }
From source file:com.paolodragone.wsn.util.Senses.java
public static Map<String, Integer> buildSenseUIdMap(Collection<Sense> senses) { BiMap<String, Integer> senseUIdMap = HashBiMap.create(); for (Sense sense : senses) { int id = sense.getId(); senseUIdMap.put(getUId(sense), id); }/*w w w . jav a2s . c o m*/ return senseUIdMap; }
From source file:com.google.cloud.genomics.utils.CallSetUtils.java
/** * Create a bi-directional map of names to ids for a collection of callsets. * * As a side effect, this will throw an IllegalArgumentException when the collection of callsets * is malformed due to multiple is mapping to the same name. * * @param callSets/* w w w . j ava 2 s.c om*/ * @return the bi-directional map */ public static final BiMap<String, String> getCallSetNameMapping(Iterable<CallSet> callSets) { BiMap<String, String> idToName = HashBiMap.create(); for (CallSet callSet : callSets) { // Dev Note: Be sure to keep this map loading as id -> name since it ensures that // the values are unique. idToName.put(callSet.getId(), callSet.getName()); } return idToName.inverse(); }