Java 类org.apache.commons.collections15.multimap.MultiHashMap 实例源码

项目:VarJ    文件:TestMultiHashMap.java   
private void loadMap(MultiHashMap map) {
    // Set up so that we load the keys "randomly"
    // (i.e. we don't want to load int row-order, so that all like keys
    // load together. We want to mix it up...)

    int numRows = sMapPairs.length;
    int maxCols = 0;
    for (int ii = 0; ii < sMapPairs.length; ii++) {
        if (sMapPairs[ii].length > maxCols) {
            maxCols = sMapPairs[ii].length;
        }
    }
    for (int ii = 0; ii < maxCols; ii++) {
        for (int jj = 0; jj < numRows; jj++) {
            if (ii < sMapPairs[jj].length) {
                map.put(sMapPairs[jj][ii].mKey, sMapPairs[jj][ii].mValue);
                //---------------------------------------------------------
            }
        }
    }
    assertTrue(map.size() == sMapPairs.length);
}
项目:VarJ    文件:TestMultiHashMap.java   
public void testTotalSize() {
    MultiHashMap map = new MultiHashMap();
    assertEquals(0, map.totalSize());
    map.put("A", "AA");
    assertEquals(1, map.totalSize());
    map.put("B", "BA");
    assertEquals(2, map.totalSize());
    map.put("B", "BB");
    assertEquals(3, map.totalSize());
    map.put("B", "BC");
    assertEquals(4, map.totalSize());
    map.remove("A");
    assertEquals(3, map.totalSize());
    map.remove("B", "BC");
    assertEquals(2, map.totalSize());
}
项目:VarJ    文件:TestMultiHashMap.java   
public void testSize_Key() {
    MultiHashMap map = new MultiHashMap();
    assertEquals(0, map.size("A"));
    assertEquals(0, map.size("B"));
    map.put("A", "AA");
    assertEquals(1, map.size("A"));
    assertEquals(0, map.size("B"));
    map.put("B", "BA");
    assertEquals(1, map.size("A"));
    assertEquals(1, map.size("B"));
    map.put("B", "BB");
    assertEquals(1, map.size("A"));
    assertEquals(2, map.size("B"));
    map.put("B", "BC");
    assertEquals(1, map.size("A"));
    assertEquals(3, map.size("B"));
    map.remove("A");
    assertEquals(0, map.size("A"));
    assertEquals(3, map.size("B"));
    map.remove("B", "BC");
    assertEquals(0, map.size("A"));
    assertEquals(2, map.size("B"));
}
项目:VarJ    文件:TestMultiHashMap.java   
public void testClone() {
    MultiHashMap map = new MultiHashMap();
    map.put("A", "1");
    map.put("A", "2");
    Collection coll = (Collection) map.get("A");
    assertEquals(1, map.size());
    assertEquals(2, coll.size());

    MultiHashMap cloned = (MultiHashMap) map.clone();
    Collection clonedColl = (Collection) cloned.get("A");
    assertNotSame(map, cloned);
    assertNotSame(coll, clonedColl);
    assertEquals(1, map.size());
    assertEquals(2, coll.size());
    assertEquals(1, cloned.size());
    assertEquals(2, clonedColl.size());
    map.put("A", "3");
    assertEquals(1, map.size());
    assertEquals(3, coll.size());
    assertEquals(1, cloned.size());
    assertEquals(2, clonedColl.size());
}
项目:VarJ    文件:TestMultiHashMap.java   
public void testConstructorCopy1() {
    MultiHashMap map = new MultiHashMap();
    map.put("A", "1");
    map.put("A", "2");
    Collection coll = (Collection) map.get("A");
    assertEquals(1, map.size());
    assertEquals(2, coll.size());

    MultiHashMap newMap = new MultiHashMap(map);
    Collection newColl = (Collection) newMap.get("A");
    assertNotSame(map, newMap);
    assertNotSame(coll, newColl);
    assertEquals(1, map.size());
    assertEquals(2, coll.size());
    assertEquals(1, newMap.size());
    assertEquals(2, newColl.size());

    map.put("A", "3");
    assertEquals(1, map.size());
    assertEquals(3, coll.size());
    assertEquals(1, newMap.size());
    assertEquals(2, newColl.size());
}
项目:VarJ    文件:TestMultiHashMap.java   
public void testConstructorCopy2() {
    Map map = new HashMap();
    map.put("A", "1");
    map.put("B", "2");
    assertEquals(2, map.size());

    MultiHashMap newMap = new MultiHashMap(map);
    Collection newColl = (Collection) newMap.get("A");
    assertNotSame(map, newMap);
    assertEquals(2, map.size());
    assertEquals(2, newMap.size());
    assertEquals(1, newColl.size());

    map.put("A", "3");
    assertEquals(2, map.size());
    assertEquals(2, newMap.size());
    assertEquals(1, newColl.size());

    map.put("C", "4");
    assertEquals(3, map.size());
    assertEquals(2, newMap.size());
    assertEquals(1, newColl.size());
}
项目:Zeppa-AppEngine    文件:TextualSimilarity.java   
public TextualSimilarity()
{
    if(allWordNetEntries == null)
    {
        allWordNetEntries = new MultiHashMap<String,String>();

        for(String tag : Arrays.asList("n","v","r","a"))
            allWordNetEntries.putAll(tag, WordNetUtils.getInstance().getAllWords(GeneralUtils.getTagfromTag(tag))); 

    }

    if(el == null)
    {
        try
        {
            el = new EnglishLemmatizer();   
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

}
项目:ADW    文件:TextualSimilarity.java   
public TextualSimilarity()
{
    if(allWordNetEntries == null)
    {
        allWordNetEntries = new MultiHashMap<String,String>();

        for(String tag : Arrays.asList("n","v","r","a"))
            allWordNetEntries.putAll(tag, WordNetUtils.getInstance().getAllWords(GeneralUtils.getTagfromTag(tag))); 

    }

    if(el == null)
    {
        try
        {
            el = new EnglishLemmatizer();   
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

}
项目:VarJ    文件:TestMultiHashMap.java   
public void testPutNGet() {
    MultiHashMap map = new MultiHashMap();
    loadMap(map);
    checkMap(map);

    assertTrue(map.get(new Integer(99)) == null);

    map.clear();
    assertTrue(map.size() == 0);
}
项目:VarJ    文件:TestMultiHashMap.java   
public void testContainsValue() {
    MultiHashMap map = new MultiHashMap();
    loadMap(map);

    assertTrue(map.containsValue("uno"));
    assertTrue(map.containsValue("quatro"));
    assertTrue(map.containsValue("two"));

    assertTrue(!map.containsValue("uggaBugga"));

    map.clear();
}
项目:VarJ    文件:TestMultiHashMap.java   
public void testValues() {
    MultiHashMap map = new MultiHashMap();
    loadMap(map);

    Collection vals = map.values();
    assertTrue(vals.size() == getFullSize());

    map.clear();
}
项目:VarJ    文件:TestMultiHashMap.java   
private void checkKeyList(MultiHashMap map, int index) {
    assertTrue(index < sMapPairs.length);
    Integer key = sMapPairs[index][0].mKey;

    Object obj = map.get(key);
    //--------------------------

    assertTrue(obj != null);
    assertTrue(obj instanceof Collection);
    Collection keyList = (Collection) obj;

    assertTrue(keyList.size() == sMapPairs[index].length);
    Iterator iter = keyList.iterator();
    while (iter.hasNext()) {
        Object oval = iter.next();
        assertTrue(oval != null);
        assertTrue(oval instanceof String);
        String val = (String) oval;
        boolean foundIt = false;
        for (int ii = 0; ii < sMapPairs[index].length; ii++) {
            if (val.equals(sMapPairs[index][ii].mValue)) {
                foundIt = true;
            }
        }
        assertTrue(foundIt);
    }
}
项目:VarJ    文件:TestMultiHashMap.java   
public void testMapEquals() {
    MultiHashMap one = new MultiHashMap();
    Integer value = new Integer(1);
    one.put("One", value);
    one.remove("One", value);

    MultiHashMap two = new MultiHashMap();
    assertEquals(two, one);
}
项目:VarJ    文件:TestMultiHashMap.java   
public void testIterator_Key() {
    MultiHashMap map = new MultiHashMap();
    assertEquals(false, map.iterator("A").hasNext());
    map.put("A", "AA");
    Iterator it = map.iterator("A");
    assertEquals(true, it.hasNext());
    it.next();
    assertEquals(false, it.hasNext());
}
项目:VarJ    文件:TestMultiHashMap.java   
public void testContainsValue_Key() {
    MultiHashMap map = new MultiHashMap();
    assertEquals(false, map.containsValue("A", "AA"));
    assertEquals(false, map.containsValue("B", "BB"));
    map.put("A", "AA");
    assertEquals(true, map.containsValue("A", "AA"));
    assertEquals(false, map.containsValue("A", "AB"));
}
项目:VarJ    文件:TestMultiHashMap.java   
public void testPutAll_KeyCollection() {
    MultiHashMap map = new MultiHashMap();
    Collection coll = Arrays.asList(new Object[]{"X", "Y", "Z"});

    assertEquals(true, map.putAll("A", coll));
    assertEquals(3, map.size("A"));
    assertEquals(true, map.containsValue("A", "X"));
    assertEquals(true, map.containsValue("A", "Y"));
    assertEquals(true, map.containsValue("A", "Z"));

    assertEquals(false, map.putAll("A", null));
    assertEquals(3, map.size("A"));
    assertEquals(true, map.containsValue("A", "X"));
    assertEquals(true, map.containsValue("A", "Y"));
    assertEquals(true, map.containsValue("A", "Z"));

    assertEquals(false, map.putAll("A", new ArrayList()));
    assertEquals(3, map.size("A"));
    assertEquals(true, map.containsValue("A", "X"));
    assertEquals(true, map.containsValue("A", "Y"));
    assertEquals(true, map.containsValue("A", "Z"));

    coll = Arrays.asList(new Object[]{"M"});
    assertEquals(true, map.putAll("A", coll));
    assertEquals(4, map.size("A"));
    assertEquals(true, map.containsValue("A", "X"));
    assertEquals(true, map.containsValue("A", "Y"));
    assertEquals(true, map.containsValue("A", "Z"));
    assertEquals(true, map.containsValue("A", "M"));
}
项目:Automacron    文件:MotifSelectionAlgorithmImpl.java   
private MultiHashMap<Integer, String> partitionMotifsByLength(Map<String, Motif> motifs) {
    MultiHashMap<Integer, String> partitionedMotifMap = new MultiHashMap<Integer, String>();

    for (String key : motifs.keySet()) {
        partitionedMotifMap.put(MotifProcessingUtils.getNumberOfGroupsInMotifString(key), key);
    }

    return partitionedMotifMap;
}
项目:Automacron    文件:BenchMarks.java   
private MultiHashMap<Integer, String> partitionMotifsByLength(Map<String, Motif> motifs) {
    MultiHashMap<Integer, String> partitionedMotifMap = new MultiHashMap<Integer, String>();

    for (String key : motifs.keySet()) {
        partitionedMotifMap.put(MotifProcessingUtils.getNumberOfGroupsInMotifString(key), key);
    }

    return partitionedMotifMap;
}
项目:VarJ    文件:TestMultiHashMap.java   
public MultiMap makeEmptyMap() {
    return new MultiHashMap();
}
项目:VarJ    文件:TestMultiHashMap.java   
private void checkMap(MultiHashMap map) {
    for (int ii = 0; ii < sMapPairs.length; ii++) {
        checkKeyList(map, ii);
    }
}
项目:VarJ    文件:TestMultiHashMap.java   
public void testGetCollection() {
    MultiHashMap map = new MultiHashMap();
    map.put("A", "AA");
    assertSame(map.get("A"), map.getCollection("A"));
}
项目:Automacron    文件:MotifSelectionAlgorithmImpl.java   
private Map<String, Motif> filterOutRedundantMotifs(Map<String, Motif> toFilter, MotifStatCalculator motifStatCalculator) {
        // find sub motifs and remove those which have a lower MSP and/or whose sub occurrences cause the numbers
        // for the motif to be lower than the threshold.
        MultiHashMap<Integer, String> partitionedMotifMap = partitionMotifsByLength(toFilter);

        Map<String, Set<Long>> motifNodes = new HashMap<String, Set<Long>>();
        // remove sub-parts of motifs. motifs which are intermediary motifs before the final version was built.

        for (int key : partitionedMotifMap.keySet()) {
            // we do this for each partition.
            for (String motif : partitionedMotifMap.get(key)) {

                if (toFilter.containsKey(motif)) {

                    if (!motifNodes.containsKey(motif)) {
                        motifNodes.put(motif, MotifProcessingUtils.flattenNodeIds(toFilter.get(motif).getNodesInMotif()));
                    }

                    for (String candidate : partitionedMotifMap.get(key)) {
                        if (!motif.equals(candidate)) {
                            if (!motifNodes.containsKey(candidate)) {
                                motifNodes.put(candidate, MotifProcessingUtils.flattenNodeIds(toFilter.get(candidate).getNodesInMotif()));
                            }

                            if (motifNodes.get(motif).containsAll(motifNodes.get(candidate))) {
                                toFilter.remove(candidate);
                            }
                        }
                    }
                }
            }
        }

//        Set<String> removed = new HashSet<String>();
//        for (int key : partitionedMotifMap.keySet()) {
//            for (String motif : partitionedMotifMap.get(key)) {
//                String tmpMotif = motif.replaceAll("}", "");
//                for (int nextKey = key + 1; partitionedMotifMap.containsKey(nextKey) && !removed.contains(motif); nextKey++) {
//                    for (String parentMotif : partitionedMotifMap.get(nextKey)) {
//                        if (parentMotif.contains(tmpMotif)) {
//                            int parentMotifUsage = toFilter.get(parentMotif).getCumulativeUsage();
//                            Motif motifToReduce = toFilter.get(motif);
//                            motifToReduce.setCumulativeUsage(motifToReduce.getCumulativeUsage() - parentMotifUsage);
//                            if (!motifStatCalculator.isMotifOverrepresented(motifToReduce)) {
//                                toFilter.remove(motif);
//                                removed.add(motif);
//                                break;
//                            } else {
//                                motifToReduce.setCumulativeUsage(motifToReduce.getCumulativeUsage() + parentMotifUsage);
//                            }
//                        }
//                    }
//                }
//            }
//        }

        return toFilter;
    }
项目:VarJ    文件:AbstractTestMultiMap.java   
/**
 * Override to return a map other than HashMap as the confirmed map.
 *
 * @return a map that is known to be valid
 */
public MultiMap makeConfirmedMap() {
    return new MultiHashMap();
}