Example usage for com.google.common.collect HashBiMap create

List of usage examples for com.google.common.collect HashBiMap create

Introduction

In this page you can find the example usage for com.google.common.collect HashBiMap create.

Prototype

public static <K, V> HashBiMap<K, V> create() 

Source Link

Document

Returns a new, empty HashBiMap with the default initial capacity (16).

Usage

From source file:org.apache.niolex.common.guava.GuavaCollections.java

/**
 * @param args//ww  w  . j a va2 s  . co  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());
    }/*from w w w  .  j a  v  a2  s .c o  m*/

    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: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);//from w ww . j av  a2  s  .c  o  m
        encoding++;
    }

    return mapping;
}

From source file:de.paleocrafter.powergrid.energy.network.EnergyNetwork.java

public EnergyNetwork(World world, WorldVector3D startingComponent) {
    components = HashBiMap.create();
    if (world.getBlockTileEntity(startingComponent.getX(), startingComponent.getY(),
            startingComponent.getZ()) instanceof INetworkComponent) {
        components.put(startingComponent, (INetworkComponent) world.getBlockTileEntity(startingComponent.getX(),
                startingComponent.getY(), startingComponent.getZ()));
    } else {/* w w w  .  j a v  a 2s . c o  m*/
        throw new IllegalArgumentException();
    }
}

From source file:org.carrot2.util.attribute.constraint.ValueHintMappingUtils.java

/**
 * Returns a bidirectional mapping between valid attribute values (keys) and
 * user-friendly names (values).// w  w  w.ja v  a2s .co m
 */
public static BiMap<String, String> getValueToFriendlyName(Class<? extends Enum<?>> clazz) {
    final BiMap<String, String> valueToName = HashBiMap.create();

    for (Enum<?> e : clazz.getEnumConstants()) {
        String value = e.name();
        String name = e.toString();

        if (e instanceof IValueHintMapping) {
            value = ((IValueHintMapping) e).getAttributeValue();
            name = ((IValueHintMapping) e).getUserFriendlyName();
        }

        valueToName.put(value, name);
    }

    return valueToName;
}

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);/*from   w ww.j a va  2  s.c o  m*/
        encoding++;
    }
    return mapping;
}

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//from w ww .  j  av  a 2s  .  co m
 * @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();
}

From source file:cuchaz.m3l.util.IdNumberMappings.java

public IdNumberMappings() {
    m_numberToId = HashBiMap.create();
}

From source file:edu.upc.dama.wikiparser.model.ArticlesIdsRelations.java

public ArticlesIdsRelations() {
    this.titleIdMap = HashBiMap.create();
    this.normalizedIdMap = HashBiMap.create();
}

From source file:de.xaniox.heavyspleef.addon.java.SharedClassContext.java

public SharedClassContext() {
    this.classes = HashBiMap.create();
}