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)); }
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))); }
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; }
/** * 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(); } }
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()); }
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; }
public void remove() { if (canRemove == false) { throw new IllegalStateException(AbstractHashedMap.REMOVE_INVALID); } parent.remove(getKey()); nextIndex--; canRemove = false; }
public Iterator iterator() { if (parent.delegateMap != null) { return parent.delegateMap.values().iterator(); } if (parent.size() == 0) { return EmptyIterator.INSTANCE; } return new ValuesIterator(parent); }
public Iterator iterator() { if (parent.delegateMap != null) { return parent.delegateMap.keySet().iterator(); } if (parent.size() == 0) { return EmptyIterator.INSTANCE; } return new KeySetIterator(parent); }
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)); }
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 boolean contains(Object value) { return parent.containsValue(value); }
public void clear() { parent.clear(); }
public int size() { return parent.size(); }
public boolean remove(Object key) { boolean result = parent.containsKey(key); parent.remove(key); return result; }
public boolean contains(Object key) { return parent.containsKey(key); }