Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package examples;
 
 import org.mapdb.Bind;
 import org.mapdb.Fun;
 
Simple way to create bidirectional map (can find key for given value) using Binding.
public class Bidi_Map {
    public static void main(String[] args) {
        //primary map
        HTreeMap<Long,Stringmap = DBMaker.newTempHashMap();
        // inverse mapping for primary map
        NavigableSet<Fun.Tuple2<StringLong>> inverseMapping = new TreeSet<Fun.Tuple2<StringLong>>();
        //NOTE: you may also use Set provided by MapDB to make it persistent
        // bind inverse mapping to primary map, so it is auto-updated
        Bind.mapInverse(mapinverseMapping);
        map.put(10L,"value2");
        map.put(1111L,"value");
        map.put(1112L,"value");
        map.put(11L,"val");
        //now find all keys for given value
        for(Long key: Fun.filter(inverseMapping"value")){
            ..println("Key for 'value' is: "+key);
        }
    }
New to GrepCode? Check out our FAQ X