Example usage for com.google.common.collect BiMap get

List of usage examples for com.google.common.collect BiMap get

Introduction

In this page you can find the example usage for com.google.common.collect BiMap get.

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

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

/**
 * @param args//from  w  ww  . ja  v  a 2s  .com
 */
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:edu.rit.flick.genetics.ByteConverterBiMapFactory.java

public static void main(final String[] args) {
    final BiMap<String, Byte> byteConverter = new ByteConverterBiMapFactory().getByteConverter(4);

    System.out.println(byteConverter.size());

    System.out.println("A    : " + byteConverter.get("A"));
    System.out.println("AT   : " + byteConverter.get("AT"));
    System.out.println("TNAG : " + byteConverter.get("TNAG"));
}

From source file:edu.cmu.cs.lti.ark.fn.identification.training.ConvertAlphabetFile.java

public static void main(String[] args) throws Exception {
    final String alphabetFile = args[0];
    final String modelFile = args[1];
    final String outFile = args[2];
    final String featureType = args[3];
    final double threshold = args.length >= 5 ? Double.parseDouble(args[4].trim()) : DEFAULT_THRESHOLD;

    // read in map from feature id -> feature name
    final BiMap<Integer, String> featureNameById = readAlphabetFile(new File(alphabetFile)).inverse();
    // read in parameter values
    final double[] parameters = TrainBatch.loadModel(modelFile);
    // write out list of (feature name, feature value) pairs
    final BufferedWriter output = Files.newWriter(new File(outFile), Charsets.UTF_8);
    try {/* w  w  w  .  jav a2 s  .  c  om*/
        output.write(String.format("%s\n", featureType));
        for (int i : xrange(parameters.length)) {
            final double val = parameters[i];
            if (Math.abs(val) <= threshold)
                continue;
            output.write(String.format("%s\t%s\n", featureNameById.get(i), val));
        }
    } finally {
        closeQuietly(output);
    }
}

From source file:org.eclipse.wb.internal.core.model.layout.GeneralLayoutData.java

/**
 * @param map/* ww  w. j av  a2s. c  o m*/
 *          the {@link BiMap} generic -> real.
 * 
 * @return the real value that corresponds given generic one, may be <code>null</code>.
 */
public static <K, T> T getRealValue(BiMap<K, T> map, K generic) {
    return generic == null ? null : map.get(generic);
}

From source file:org.opennaas.extensions.genericnetwork.model.helpers.Circuit2RequestHelper.java

/**
 * Generates internal Port Id given external Port Id and networkDevicePortIdsMap
 * //from w  ww .  j  a  v  a2  s .  c om
 * @param networkDevicePortIdsMap
 * @param externalPortId
 * @return
 */
public static String generateInternalPortId(String externalPortId,
        BiMap<String, DevicePortId> networkDevicePortIdsMap) {
    return networkDevicePortIdsMap.get(externalPortId).getDevicePortId();
}

From source file:org.rm3l.ddwrt.utils.Utils.java

public static int getThemeBackgroundColor(@NotNull final Context context, @NotNull final String routerUuid) {
    final long theme = context.getSharedPreferences(routerUuid, Context.MODE_PRIVATE).getLong(THEMING_PREF,
            DEFAULT_THEME);/*from w  ww.j  a  v  a2  s  . c o m*/
    final BiMap<Integer, Integer> colorToThemeInverse = colorToTheme.inverse();
    Integer color = colorToThemeInverse.get(Long.valueOf(theme).intValue());
    if (color == null) {
        color = colorToThemeInverse.get(Long.valueOf(DEFAULT_THEME).intValue());
    }
    return context.getResources().getColor(color);
}

From source file:org.onosproject.provider.of.device.impl.OpenFlowDeviceValueMapper.java

/**
 * Looks up the specified input value to the corresponding value with the specified map.
 *
 * @param map bidirectional mapping/*  ww  w. ja  v  a 2s . c  o m*/
 * @param input input value
 * @param cls class of output value
 * @param <I> type of input value
 * @param <O> type of output value
 * @return the corresponding value stored in the specified map
 */
private static <I, O> O lookup(BiMap<I, O> map, I input, Class<O> cls) {
    if (!map.containsKey(input)) {
        throw new RuntimeException(
                String.format("No mapping found for %s when converting to %s", input, cls.getName()));
    }

    return map.get(input);
}

From source file:net.cazzar.corelib.lib.SoundSystemHelper.java

@Nullable
public static String getIdentifierForRecord(ItemRecord record, int x, int y, int z) {
    ResourceLocation resource = record.getRecordResource("records." + record.recordName);
    //        if (resource == null) return null;

    SoundEventAccessorComposite sound = getSoundHandler().getSound(resource);
    float f1 = 16F;

    if (sound == null) {
        return null;
    }/* w  w w  .  j a v a  2 s .co m*/

    SoundPoolEntry soundpoolentry = sound.cloneEntry();

    SoundCategory soundcategory = sound.getSoundCategory();
    float volume = (float) MathHelper.clamp_double(
            (double) f1 * soundpoolentry.getVolume() * (double) mc().gameSettings.getSoundLevel(soundcategory),
            0.0D, MAX_VOLUME);
    float pitch = (float) MathHelper.clamp_double(
            (double) f1 * soundpoolentry.getVolume() * (double) mc().gameSettings.getSoundLevel(soundcategory),
            0.0D, 1.0D);
    //        ResourceLocation resourcelocation = soundpoolentry.getSoundPoolEntryLocation();

    // I know the type.
    //noinspection unchecked
    HashBiMap<String, ISound> playingSounds = (HashBiMap<String, ISound>) getSoundManager().playingSounds;
    BiMap<ISound, String> inverse = playingSounds.inverse();

    return inverse.get(new CustomSound(volume, resource, false, 0, pitch, x, y, z));
}

From source file:org.onosproject.provider.of.message.impl.OpenFlowControlMessageMapper.java

/**
 * Looks up the specified input value to the corresponding value with the specified map.
 *
 * @param map   bidirectional mapping//from  w ww. j av a  2s  .com
 * @param input input type
 * @param cls   class of output value
 * @param <I>   type of input value
 * @param <O>   type of output value
 * @return the corresponding value stored in the specified map
 */
private static <I, O> O lookup(BiMap<I, O> map, I input, Class<O> cls) {
    if (!map.containsKey(input)) {
        throw new RuntimeException(
                String.format("No mapping found for %s when converting to %s", input, cls.getName()));
    }
    return map.get(input);
}

From source file:eu.netide.core.globalfib.flow.OpenFlowValueMapper.java

/**
 * Looks up the specified input value to the corresponding value with the specified map.
 *
 * @param map bidirectional mapping/*from   w w  w .java2  s.  c  o  m*/
 * @param input input value
 * @param cls class of output value
 * @param <I> type of input value
 * @param <O> type of output value
 * @return the corresponding value stored in the specified map
 * @throws NoMappingFoundException if no corresponding value is found
 */
private static <I, O> O lookup(BiMap<I, O> map, I input, Class<O> cls) {
    if (!map.containsKey(input)) {
        throw new NoMappingFoundException(input, cls);
    }

    return map.get(input);
}