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));
  }
  public void testSerialisation4() throws Exception {
    Flat3Map map = new Flat3Map();
    map.put(ONE, TEN);
    map.put(TWO, TWENTY);
    map.put(TEN, ONE);
    map.put(TWENTY, TWO);

    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(4, map.size());
    assertEquals(4, ser.size());
    assertEquals(true, ser.containsKey(ONE));
    assertEquals(true, ser.containsKey(TWO));
    assertEquals(true, ser.containsKey(TEN));
    assertEquals(true, ser.containsKey(TWENTY));
    assertEquals(TEN, ser.get(ONE));
    assertEquals(TWENTY, ser.get(TWO));
    assertEquals(ONE, ser.get(TEN));
    assertEquals(TWO, ser.get(TWENTY));
  }
 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());
 }
Exemple #4
0
 public Iterator iterator() {
   if (parent.delegateMap != null) {
     return parent.delegateMap.values().iterator();
   }
   if (parent.size() == 0) {
     return EmptyIterator.INSTANCE;
   }
   return new ValuesIterator(parent);
 }
Exemple #5
0
 public Iterator iterator() {
   if (parent.delegateMap != null) {
     return parent.delegateMap.keySet().iterator();
   }
   if (parent.size() == 0) {
     return EmptyIterator.INSTANCE;
   }
   return new KeySetIterator(parent);
 }
Exemple #6
0
 public int size() {
   return parent.size();
 }