View Javadoc

1   /*
2    * Copyright (C) 2007 University of Cambridge
3    *
4    * This file is part of Fosstrak (www.fosstrak.org).
5    *
6    * Fosstrak is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License version 2.1, as published by the Free Software Foundation.
9    *
10   * Fosstrak is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13   * Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public
16   * License along with Fosstrak; if not, write to the Free
17   * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18   * Boston, MA  02110-1301  USA
19   */
20  
21  package org.fosstrak.tdt;
22  
23  import java.util.*;
24  
25  /**
26   * NoisyMap is a front-end for a String to String Map that 
27   * prints a message to System.out every time an entry is updated.
28   * It is intended for testing purposes only.
29   */
30  
31  
32  public class NoisyMap implements Map<String,String> {
33  	private Map<String,String> map;
34  	public NoisyMap(Map<String,String> map){
35  	    this.map = map;
36  	}
37  	public void clear() { map.clear(); }
38  	     //Removes all mappings from this map (optional operation).
39  	public  boolean 	containsKey(Object key) 
40  	{
41  	    return map.containsKey(key);
42  	}
43  	     //          Returns true if this map contains a mapping for the specified key.
44  	public  boolean 	containsValue(Object value)
45  	{
46  	    return map.containsValue(value);
47  	}
48  	     //          Returns true if this map maps one or more keys to the specified value.
49  	public Set<Map.Entry<String,String>> 	entrySet()
50  	{
51  	    return map.entrySet();
52  	}
53  	     //          Returns a set view of the mappings contained in this map.
54  	public boolean 	equals(Object o) {
55  	    return map.equals(o);
56  	}
57  	     //          Compares the specified object with this map for equality.
58  	public String 	get(Object key) {
59  	    return map.get(key);
60  	}
61  	     //          Returns the value to which this map maps the specified key.
62  	public int 	hashCode()
63  	{
64  	    return map.hashCode();
65  	}
66  	     //          Returns the hash code value for this map.
67  	public boolean 	isEmpty()
68      {
69  	return map.isEmpty();
70      }
71      //          Returns true if this map contains no key-value mappings.
72      public Set<String> 	keySet()
73      {
74  	return map.keySet();
75      }
76      //          Returns a set view of the keys contained in this map.
77      public String 	put(String key, String value)
78      {
79  	System.out.println("   " + key + " := " + value + " (" + value.length() + " chars)");
80  	return map.put(key, value);
81      }
82      //          Associates the specified value with the specified key in this map (optional operation).
83      public void 	putAll(Map<? extends String,? extends String> t)
84      {
85  	map.putAll(t);
86      }
87      //          Copies all of the mappings from the specified map to this map (optional operation).
88      public String 	remove(Object key)
89      {
90  	return map.remove(key);
91      }
92      //          Removes the mapping for this key from this map if it is present (optional operation).
93      public int 	size()
94      {
95  	return map.size();
96      }
97      //          Returns the number of key-value mappings in this map.
98      public Collection<String> 	values()
99      {
100 	return map.values();
101     }
102     //          Returns a collection view of the values contained in this map.
103  
104 }