/** * <p>Answer a string representation of this map. This can be quite a long string for * large maps.<p> */ @Override public String toString() { StringBuffer buf = new StringBuffer( "OneToManyMap{" ); String sep = ""; for ( From key : keySet() ) { buf.append( sep ); buf.append( key ); buf.append( "={" ); String sep1 = ""; for ( Iterator<To> j = getAll( key ); j.hasNext(); ) { buf.append( sep1 ); buf.append( j.next() ); sep1 = ","; } buf.append( "}" ); sep = ","; } buf.append("}"); return buf.toString(); }
/** * <p>Answer a string representation of this map. This can be quite a long string for * large maps.<p> */ @Override public String toString() { StringBuffer buf = new StringBuffer( "OneToManyMap{" ); String sep = ""; for ( From key : keySet() ) { buf.append( sep ); buf.append( key ); buf.append( "={" ); String sep1 = ""; for ( Iterator<To> j = getAll( key ); j.hasNext(); ) { buf.append( sep1 ); buf.append( j.next() ); sep1 = ","; } buf.append( "}" ); sep = ","; } buf.append("}"); return buf.toString(); }
/** * <p>Construct a new one-to-many map whose contents are * initialised from the existing map.</p> * * @param map An existing one-to-many map */ public OneToManyMap( OneToManyMap<From, To> map ) { // copy the contents of the existing map // note we can't just use the copying constructor for hashmap // as we don't want to share the arraylists that are the key values for ( From key : map.keySet() ) { for ( Iterator<To> j = map.getAll( key ); j.hasNext(); ) { put( key, j.next() ); } } }
/** * <p>Construct a new one-to-many map whose contents are * initialised from the existing map.</p> * * @param map An existing one-to-many map */ public OneToManyMap( OneToManyMap<From, To> map ) { // copy the contents of the existing map // note we can't just use the copying constructor for hashmap // as we don't want to share the arraylists that are the key values for ( From key : map.keySet() ) { for ( Iterator<To> j = map.getAll( key ); j.hasNext(); ) { put( key, j.next() ); } } }
public void testKeySet() { OneToManyMap<String, String> map0 = new OneToManyMap<>(); Set<String> keys = new HashSet<>(); assertEquals( keys, map0.keySet() ); map0.put( s0, s1 ); keys.add( s0 ); assertEquals( keys, map0.keySet() ); map0.put( s2, s1 ); keys.add( s2 ); assertEquals( keys, map0.keySet() ); }
public void testKeySet() { OneToManyMap<String, String> map0 = new OneToManyMap<>(); Set<String> keys = new HashSet<>(); assertEquals( keys, map0.keySet() ); map0.put( s0, s1 ); keys.add( s0 ); assertEquals( keys, map0.keySet() ); map0.put( s2, s1 ); keys.add( s2 ); assertEquals( keys, map0.keySet() ); }