Ejemplo n.º 1
0
 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"));
 }
Ejemplo n.º 2
0
  public void testValues() {
    MultiHashMap map = new MultiHashMap();
    loadMap(map);

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

    map.clear();
  }
Ejemplo n.º 3
0
  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);
  }
Ejemplo n.º 4
0
 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());
 }
Ejemplo n.º 5
0
  // ----------------------------
  //          Tests
  // ----------------------------
  public void testPutNGet() {
    MultiHashMap map = new MultiHashMap();
    loadMap(map);
    checkMap(map);

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

    map.clear();
    assertTrue(map.size() == 0);
  }
Ejemplo n.º 6
0
  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);
    }
  }
Ejemplo n.º 7
0
  public void testPutAll_Map1() {
    MultiMap original = new MultiHashMap();
    original.put("key", "object1");
    original.put("key", "object2");

    MultiHashMap test = new MultiHashMap();
    test.put("keyA", "objectA");
    test.put("key", "object0");
    test.putAll(original);

    assertEquals(2, test.size());
    assertEquals(4, test.totalSize());
    assertEquals(1, test.getCollection("keyA").size());
    assertEquals(3, test.getCollection("key").size());
    assertEquals(true, test.containsValue("objectA"));
    assertEquals(true, test.containsValue("object0"));
    assertEquals(true, test.containsValue("object1"));
    assertEquals(true, test.containsValue("object2"));
  }
Ejemplo n.º 8
0
  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);
  }
Ejemplo n.º 9
0
  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());
  }
Ejemplo n.º 10
0
  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();
  }
Ejemplo n.º 11
0
 public void testRemove_KeyItem() {
   MultiHashMap map = new MultiHashMap();
   map.put("A", "AA");
   map.put("A", "AB");
   map.put("A", "AC");
   assertEquals(null, map.remove("C", "CA"));
   assertEquals(null, map.remove("A", "AD"));
   assertEquals("AC", map.remove("A", "AC"));
   assertEquals("AB", map.remove("A", "AB"));
   assertEquals("AA", map.remove("A", "AA"));
   assertEquals(new MultiHashMap(), map);
 }
Ejemplo n.º 12
0
  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());
  }
Ejemplo n.º 13
0
  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"));
  }
Ejemplo n.º 14
0
 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"));
 }
Ejemplo n.º 15
0
 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());
 }
Ejemplo n.º 16
0
 // -----------------------------------------------------------------------
 public void testGetCollection() {
   MultiHashMap map = new MultiHashMap();
   map.put("A", "AA");
   assertSame(map.get("A"), map.getCollection("A"));
 }