/** * Read the map in using a custom routine. */ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); int count = in.readInt(); if (count > 3) { delegateMap = createDelegateMap(); } for (int i = count; i > 0; i--) { put(in.readObject(), in.readObject()); } }
/** * Read the map in using a custom routine. */ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); int count = in.readInt(); if (count > 3) { delegateMap = createDelegateMap(); } for (int i = count; i > 0; i--) { put(in.readObject(), in.readObject()); } }
/** * Puts all the values from the specified map into this map. * * @param map the map to add * @throws NullPointerException if the map is null */ public void putAll(Map map) { int size = map.size(); if (size == 0) { return; } if (delegateMap != null) { delegateMap.putAll(map); return; } if (size < 4) { for (Iterator it = map.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); put(entry.getKey(), entry.getValue()); } } else { convertToMap(); delegateMap.putAll(map); } }
/** * Puts all the values from the specified map into this map. * * @param map the map to add * @throws NullPointerException if the map is null */ public void putAll(Map map) { int size = map.size(); if (size == 0) { return; } if (delegateMap != null) { delegateMap.putAll(map); return; } if (size < 4) { for (Iterator it = map.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); put(entry.getKey(), entry.getValue()); } } else { convertToMap(); delegateMap.putAll(map); } }
public void testCollections261() { final Flat3Map m = new Flat3Map(); m.put( new Integer(1), new Integer(1) ); m.put( new Integer(0), new Integer(0) ); assertEquals( new Integer(1), m.remove( new Integer(1) ) ); assertEquals( new Integer(0), m.remove( new Integer(0) ) ); 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 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 testEntryIteratorSetValue3() throws Exception { final Flat3Map map = new Flat3Map(); map.put(ONE, TEN); map.put(TWO, TWENTY); map.put(THREE, THIRTY); final Iterator it = map.entrySet().iterator(); it.next(); it.next(); final Map.Entry entry = (Map.Entry) it.next(); entry.setValue("NewValue"); assertEquals(3, map.size()); assertEquals(true, map.containsKey(ONE)); assertEquals(true, map.containsKey(TWO)); assertEquals(true, map.containsKey(THREE)); assertEquals(TEN, map.get(ONE)); assertEquals(TWENTY, map.get(TWO)); assertEquals("NewValue", map.get(THREE)); }
public void testEntryIteratorSetValue2() throws Exception { final Flat3Map map = new Flat3Map(); map.put(ONE, TEN); map.put(TWO, TWENTY); map.put(THREE, THIRTY); final Iterator it = map.entrySet().iterator(); it.next(); final Map.Entry entry = (Map.Entry) it.next(); entry.setValue("NewValue"); assertEquals(3, map.size()); assertEquals(true, map.containsKey(ONE)); assertEquals(true, map.containsKey(TWO)); assertEquals(true, map.containsKey(THREE)); assertEquals(TEN, map.get(ONE)); assertEquals("NewValue", map.get(TWO)); assertEquals(THIRTY, map.get(THREE)); }
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 testEntryIteratorSetValue1() throws Exception { final Flat3Map map = new Flat3Map(); map.put(ONE, TEN); map.put(TWO, TWENTY); map.put(THREE, THIRTY); final Iterator it = map.entrySet().iterator(); final Map.Entry entry = (Map.Entry) it.next(); entry.setValue("NewValue"); assertEquals(3, map.size()); assertEquals(true, map.containsKey(ONE)); assertEquals(true, map.containsKey(TWO)); assertEquals(true, map.containsKey(THREE)); assertEquals("NewValue", map.get(ONE)); assertEquals(TWENTY, map.get(TWO)); assertEquals(THIRTY, map.get(THREE)); }
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 testClone4() {
/** * Read the map in using a custom routine. */ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); int count = in.readInt(); if (count > 3) { delegateMap = createDelegateMap(); } for (int i = count; i > 0; i--) { put(in.readObject(), in.readObject()); } }
/** * Read the map in using a custom routine. */ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); int count = in.readInt(); if (count > 3) { delegateMap = createDelegateMap(); } for (int i = count; i > 0; i--) { put(in.readObject(), in.readObject()); } }
/** * Read the map in using a custom routine. */ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); int count = in.readInt(); if (count > 3) { delegateMap = createDelegateMap(); } for (int i = count; i > 0; i--) { put(in.readObject(), in.readObject()); } }
/** * Read the map in using a custom routine. */ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); int count = in.readInt(); if (count > 3) { delegateMap = createDelegateMap(); } for (int i = count; i > 0; i--) { put(in.readObject(), in.readObject()); } }
/** * Read the map in using a custom routine. */ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); int count = in.readInt(); if (count > 3) { delegateMap = createDelegateMap(); } for (int i = count; i > 0; i--) { put(in.readObject(), in.readObject()); } }
/** * Puts all the values from the specified map into this map. * * @param map the map to add * @throws NullPointerException if the map is null */ public void putAll(Map map) { int size = map.size(); if (size == 0) { return; } if (delegateMap != null) { delegateMap.putAll(map); return; } if (size < 4) { for (Iterator it = map.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); put(entry.getKey(), entry.getValue()); } } else { convertToMap(); delegateMap.putAll(map); } }