Esempio n. 1
0
 public void testEquals2() {
   Flat3Map map1 = new Flat3Map();
   map1.put("a", "testA");
   map1.put("b", "testB");
   Flat3Map map2 = new Flat3Map();
   map2.put("a", "testB");
   map2.put("c", "testA");
   assertEquals(false, map1.equals(map2));
 }
Esempio n. 2
0
  public void testCollections261_2() {
    Flat3Map m = new Flat3Map();

    m.put(new Integer(2), new Integer(2));
    m.put(new Integer(1), new Integer(1));
    m.put(new Integer(0), new Integer(0));
    assertEquals(new Integer(2), m.remove(new Integer(2)));
    assertEquals(new Integer(1), m.remove(new Integer(1)));
    assertEquals(new Integer(0), m.remove(new Integer(0)));
  }
Esempio n. 3
0
 public boolean remove(Object obj) {
   if (obj instanceof Map.Entry == false) {
     return false;
   }
   Map.Entry entry = (Map.Entry) obj;
   Object key = entry.getKey();
   boolean result = parent.containsKey(key);
   parent.remove(key);
   return result;
 }
Esempio n. 4
0
 /**
  * Clones the map without cloning the keys or values.
  *
  * @return a shallow clone
  * @since Commons Collections 3.1
  */
 public Object clone() {
   try {
     Flat3Map cloned = (Flat3Map) super.clone();
     if (cloned.delegateMap != null) {
       cloned.delegateMap = (HashedMap) cloned.delegateMap.clone();
     }
     return cloned;
   } catch (CloneNotSupportedException ex) {
     throw new InternalError();
   }
 }
Esempio n. 5
0
 public void testSerialisation0() throws Exception {
   Flat3Map map = new Flat3Map();
   ByteArrayOutputStream bout = new ByteArrayOutputStream();
   ObjectOutputStream out = new ObjectOutputStream(bout);
   out.writeObject(map);
   byte[] bytes = bout.toByteArray();
   out.close();
   ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
   ObjectInputStream in = new ObjectInputStream(bin);
   Flat3Map ser = (Flat3Map) in.readObject();
   in.close();
   assertEquals(0, map.size());
   assertEquals(0, ser.size());
 }
Esempio n. 6
0
 public Object setValue(Object value) {
   if (canRemove == false) {
     throw new IllegalStateException(AbstractHashedMap.SETVALUE_INVALID);
   }
   Object old = getValue();
   switch (nextIndex) {
     case 3:
       parent.value3 = value;
     case 2:
       parent.value2 = value;
     case 1:
       parent.value1 = value;
   }
   return old;
 }
Esempio n. 7
0
 public void remove() {
   if (canRemove == false) {
     throw new IllegalStateException(AbstractHashedMap.REMOVE_INVALID);
   }
   parent.remove(getKey());
   nextIndex--;
   canRemove = false;
 }
Esempio n. 8
0
 public Iterator iterator() {
   if (parent.delegateMap != null) {
     return parent.delegateMap.values().iterator();
   }
   if (parent.size() == 0) {
     return EmptyIterator.INSTANCE;
   }
   return new ValuesIterator(parent);
 }
Esempio n. 9
0
 public Iterator iterator() {
   if (parent.delegateMap != null) {
     return parent.delegateMap.keySet().iterator();
   }
   if (parent.size() == 0) {
     return EmptyIterator.INSTANCE;
   }
   return new KeySetIterator(parent);
 }
Esempio n. 10
0
  public void testSerialisation2() throws Exception {
    Flat3Map map = new Flat3Map();
    map.put(ONE, TEN);
    map.put(TWO, TWENTY);

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bout);
    out.writeObject(map);
    byte[] bytes = bout.toByteArray();
    out.close();
    ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
    ObjectInputStream in = new ObjectInputStream(bin);
    Flat3Map ser = (Flat3Map) in.readObject();
    in.close();
    assertEquals(2, map.size());
    assertEquals(2, ser.size());
    assertEquals(true, ser.containsKey(ONE));
    assertEquals(true, ser.containsKey(TWO));
    assertEquals(TEN, ser.get(ONE));
    assertEquals(TWENTY, ser.get(TWO));
  }
Esempio n. 11
0
  public void testClone2() {
    Flat3Map map = new Flat3Map();
    assertEquals(0, map.size());
    map.put(ONE, TEN);
    map.put(TWO, TWENTY);
    assertEquals(2, map.size());
    assertEquals(true, map.containsKey(ONE));
    assertEquals(true, map.containsKey(TWO));
    assertSame(TEN, map.get(ONE));
    assertSame(TWENTY, map.get(TWO));

    // clone works (size = 2)
    Flat3Map cloned = (Flat3Map) map.clone();
    assertEquals(2, cloned.size());
    assertEquals(true, cloned.containsKey(ONE));
    assertEquals(true, cloned.containsKey(TWO));
    assertSame(TEN, cloned.get(ONE));
    assertSame(TWENTY, cloned.get(TWO));

    // change original doesn't change clone
    map.put(TEN, ONE);
    map.put(TWENTY, TWO);
    assertEquals(4, map.size());
    assertEquals(2, cloned.size());
    assertEquals(true, cloned.containsKey(ONE));
    assertEquals(true, cloned.containsKey(TWO));
    assertSame(TEN, cloned.get(ONE));
    assertSame(TWENTY, cloned.get(TWO));
  }
Esempio n. 12
0
 public boolean contains(Object value) {
   return parent.containsValue(value);
 }
Esempio n. 13
0
 public void clear() {
   parent.clear();
 }
Esempio n. 14
0
 public int size() {
   return parent.size();
 }
Esempio n. 15
0
 public boolean remove(Object key) {
   boolean result = parent.containsKey(key);
   parent.remove(key);
   return result;
 }
Esempio n. 16
0
 public boolean contains(Object key) {
   return parent.containsKey(key);
 }