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

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

Introduction

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

Prototype

BiMap<V, K> inverse();

Source Link

Document

Returns the inverse view of this bimap, which maps each of this bimap's values to its associated key.

Usage

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

/**
 * @param args/* w ww  .  j  a v  a2 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:org.eclipse.wb.internal.core.model.layout.GeneralLayoutData.java

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

From source file:com.facebook.buck.distributed.DistributedBuildTargetGraphCodec.java

private static <T> int getIndex(T value, BiMap<Integer, T> index) {
    Integer i = index.inverse().get(value);
    if (i == null) {
        i = index.size();//from ww  w  .  j  a v a  2 s .c o m
        index.put(i, value);
    }
    return i;
}

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//ww  w.  j a  v a2 s.c  o  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:org.opencb.opencga.storage.core.metadata.StudyConfiguration.java

public static <T, R> BiMap<R, T> inverseMap(BiMap<T, R> map) {
    return map.inverse();
}

From source file:org.usergrid.security.shiro.utils.SubjectUtils.java

public static Set<String> getOrganizationNames() {
    Subject currentUser = getSubject();
    if (currentUser == null) {
        return null;
    }/*from  w w w .  j a v a2s.co m*/
    if (!currentUser.hasRole(ROLE_ORGANIZATION_ADMIN)) {
        return null;
    }
    BiMap<UUID, String> organizations = getOrganizations();
    if (organizations == null) {
        return null;
    }
    return organizations.inverse().keySet();
}

From source file:org.usergrid.security.shiro.utils.SubjectUtils.java

public static OrganizationInfo getOrganization(Identifier identifier) {
    if (identifier == null) {
        return null;
    }//  w w w.  j  av a 2s  . com
    UUID organizationId = null;
    String organizationName = null;
    BiMap<UUID, String> organizations = getOrganizations();
    if (organizations == null) {
        return null;
    }
    if (identifier.isName()) {
        organizationName = identifier.getName().toLowerCase();
        organizationId = organizations.inverse().get(organizationName);
    } else if (identifier.isUUID()) {
        organizationId = identifier.getUUID();
        organizationName = organizations.get(organizationId);
    }
    if ((organizationId != null) && (organizationName != null)) {
        return new OrganizationInfo(organizationId, organizationName);
    }
    return null;
}

From source file:org.usergrid.security.shiro.utils.SubjectUtils.java

public static ApplicationInfo getApplication(Identifier identifier) {
    if (identifier == null) {
        return null;
    }/*from  w  w w.  j  a v  a2 s .c om*/
    if (!isApplicationAdmin() && !isApplicationUser()) {
        return null;
    }
    String applicationName = null;
    UUID applicationId = null;
    BiMap<UUID, String> applications = getApplications();
    if (applications == null) {
        return null;
    }
    if (identifier.isName()) {
        applicationName = identifier.getName().toLowerCase();
        applicationId = applications.inverse().get(applicationName);
        if (applicationId == null) {
            applicationId = applications.inverse().get(identifier.getName());
        }
    } else if (identifier.isUUID()) {
        applicationId = identifier.getUUID();
        applicationName = applications.get(identifier.getUUID());
    }
    if ((applicationId != null) && (applicationName != null)) {
        return new ApplicationInfo(applicationId, applicationName);
    }
    return null;
}

From source file:gr.forth.ics.swkm.model2.diff.DiffUtils.java

static RdfNode mapNodeToAnotherModel(Resource node, Model m, BiMap<String, String> namespaceMap) {
    RdfNode mappedNode = null;/*w w w.j a  va 2s. c o  m*/
    if (namespaceMap.containsKey(node.getUri().getNamespace())) {
        Uri u = new Uri(namespaceMap.get(node.getUri().getNamespace()), node.getUri().getLocalName());
        if (m.mapResource(u).hasTriples()) {
            mappedNode = m.mapResource(u);
        }
    } else if (namespaceMap.containsValue(node.getUri().getNamespace())) {
        Uri u = new Uri(namespaceMap.inverse().get(node.getUri().getNamespace()), node.getUri().getLocalName());
        if (m.mapResource(u).hasTriples()) {
            mappedNode = m.mapResource(u);
        }
    } else {
        if (m.mapResource(node.getIdentifier()).hasTriples()) {
            mappedNode = m.mapResource(node.getIdentifier());
        }
    }
    return mappedNode;
}

From source file:blue.lapis.pore.converter.type.material.DurabilityConverter.java

@SuppressWarnings({ "rawtypes", "unchecked" }) // I can't parameterize this either; it scares the compiler
private static <T extends VariantData<U, T, ?>, U extends CatalogType> T getItemData(ItemStack item,
        Class<T> type, BiMap<U, Integer> map) {
    int damage = item.getDurability();
    if (!map.containsValue(damage)) {
        throw new UnsupportedOperationException();
    }//from  w  w  w. jav a  2s  . c o  m
    // no idea why a typecast is necessary here but excluding it makes javac angry
    @SuppressWarnings("RedundantCast")
    T data = (T) Pore.getGame().getRegistry().createItemBuilder()
            .itemType(MaterialConverter.asItem(item.getType())).quantity(1).build().getOrCreate(type).get();
    data.type().set(map.inverse().get(damage));
    return data;
}