FileDocCategorySizeDatePackage
PropertiesMap.javaAPI DocExample2819Thu May 29 13:36:28 BST 2003com.darwinsys.util

PropertiesMap

public class PropertiesMap extends Object implements Map
PropertiesMap -- a Map that loads from a Properties file, but unlike Properties, preserves the ordering of the original file.

Written mainly as a demonstration of building a simple Map implementation from scratch, but useful when order matters and yet you want the convenience of Map acccess.

author
Ian F. Darwin
version
$Id: PropertiesMap.java,v 1.4 2003/05/29 17:36:28 ian Exp $

Fields Summary
private List
names
private List
values
Constructors Summary
Methods Summary
public voidclear()
Discard all object references held in the collection, i.e., reset to its initial state.

		names.clear();
		values.clear();
	
public booleancontainsKey(java.lang.Object obj)
Return true if the given object is contained as a Key

		return names.contains(obj);
	
public booleancontainsValue(java.lang.Object obj)
Return true if the given object is contained as a Value

		return values.contains(obj);
	
public java.util.SetentrySet()
EntrySet (not implemented, returns null)

		return null;
	
public java.lang.Objectget(java.lang.Object obj)
Get a given object

		return values.get(names.indexOf(obj));
	
public booleanisEmpty()
Return true if the Map is empty

		return names.isEmpty();
	
public java.util.SetkeySet()
Return the set of keys

		return new HashSet(names);
	
public voidload(java.lang.String fileName)


	      
		if (fileName == null) {
			throw new IOException("filename is null!");
		}
		InputStream is = new FileInputStream(fileName);
		BufferedReader rdr = new BufferedReader(
			new InputStreamReader(is));
		String line;
		while ((line = rdr.readLine()) != null) {
			int ix = line.indexOf('=");
			String name = line.substring(0, ix);
			String value = line.substring(ix+1);
			names.add(name);
			values.add(value);
		}
		rdr.close();
	
public java.lang.Objectput(java.lang.Object n, java.lang.Object v)
Add a given object into this Map.

		names.add(n);
		values.add(v);
		return n;
	
public voidputAll(java.util.Map map)
Merge all the values from another map into this map.

		Iterator k = map.keySet().iterator();
		while (k.hasNext()) {
			Object key = k.next();
			Object val = map.get(key);
			put(key, val);
		}
	
public java.lang.Objectremove(java.lang.Object obj)
Remove a given object

		int i = values.indexOf(obj);
		if (i < 0) 
			throw new IllegalArgumentException("remove(" + obj + ") not found");
		names.remove(i);
		values.remove(i);
		return obj;
	
public intsize()
Return the number of entries in the Map

		return names.size();
	
public java.util.Collectionvalues()
Return a Collection containing the values

		return values;