--- /dev/null
+/**\r
+ * PropertyMap class\r
+ * Maps identifiers to property lists\r
+ * Used for stylesheets, character maps, etc\r
+ *\r
+ * @author Daniel Jackson\r
+ * @version 0, 07/03/01\r
+ */\r
+\r
+package tagger;\r
+import java.io.*;\r
+import java.util.*;\r
+\r
+public class PropertyMap {\r
+ private HashMap map; // String -> LinkedList [Property]\r
+\r
+ /**\r
+ * ensures: constructs an empty property map\r
+ */\r
+ public PropertyMap () {\r
+ map = new HashMap ();\r
+ }\r
+\r
+ /**\r
+ * ensures: constructs a property map using the parser <code>p</code>.\r
+ */\r
+ public PropertyMap (PropertyParser p) {\r
+ map = new HashMap ();\r
+ try {\r
+ while (p.has_more_properties ()) {\r
+ LinkedList props = p.get_property_list ();\r
+ Property prop = (Property) props.removeFirst ();\r
+ map.put (prop.value, props);\r
+ }\r
+ } catch (IOException e) {Assert.unreachable ();}\r
+ }\r
+\r
+ /**\r
+ * ensures: incorporates properties using the parser <code>p</code>.\r
+ */\r
+ public void incorporate (PropertyParser p) {\r
+ try {\r
+ while (p.has_more_properties ()) {\r
+ LinkedList props = p.get_property_list ();\r
+ Property prop = (Property) props.removeFirst ();\r
+ map.put (prop.value, props);\r
+ }\r
+ } catch (IOException e) {Assert.unreachable ();}\r
+ }\r
+\r
+ /**\r
+ * @return the property list for item <code>item</code>. Returns null if no such item.\r
+ */\r
+ public List get_property_list (String item) {\r
+ return (List) map.get (item);\r
+ }\r
+\r
+ /**\r
+ * @return the value of property <code>prop</code> for item <code>item</code>\r
+ * or null if it does not exist\r
+ */\r
+ public String get_property (String item, String prop) {\r
+ List props = (List) map.get (item);\r
+ if (props == null) return null;\r
+ ListIterator iter = props.listIterator ();\r
+ while (iter.hasNext ()) {\r
+ Property p = (Property) iter.next ();\r
+ if (p.property.equals (prop))\r
+ return p.value;\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /**\r
+ * @return the set of items with property lists in the map\r
+ */\r
+ public Set get_items () {\r
+ return map.keySet ();\r
+ }\r
+\r
+ public String toString () {\r
+ return map.toString ();\r
+ }\r
+}\r