upstream version 1.2.2
[debian/freetts] / com / sun / speech / freetts / ItemContents.java
1 /**
2  * Portions Copyright 2001 Sun Microsystems, Inc.
3  * Portions Copyright 1999-2001 Language Technologies Institute, 
4  * Carnegie Mellon University.
5  * All Rights Reserved.  Use is subject to license terms.
6  * 
7  * See the file "license.terms" for information on usage and
8  * redistribution of this file, and for a DISCLAIMER OF ALL 
9  * WARRANTIES.
10  */
11 package com.sun.speech.freetts;
12 import java.io.PrintWriter;
13
14 /**
15  * Contains the information that is shared between multiple items.
16  */
17 public class ItemContents {
18     private FeatureSetImpl features;
19     private FeatureSetImpl relations;
20
21     /**
22      * Class Constructor.
23      */
24     public ItemContents() {
25         features = new FeatureSetImpl();
26         relations = new FeatureSetImpl();
27     }
28     
29     /**
30      * Adds the given item to the set of relations. Whenever an item
31      * is added to a relation, it should add the name and the Item reference
32      * to this set of name/item mappings. This allows an item to find
33      * out the set of all relations that it is contained in.
34      *
35      * @param relationName the name of the relation
36      * @param item the item reference in the relation
37      */
38     public void addItemRelation(String relationName, Item item) {
39         // System.out.println("AddItemRelation: " + relationName
40         //                    + " item: " + item);
41         relations.setObject(relationName, item);
42     }
43
44     /**
45      * Removes the relation/item mapping from this ItemContents.
46      *
47      * @param relationName the name of the relation/item to remove
48      */
49     public void removeItemRelation(String relationName) {
50         relations.remove(relationName);
51     }
52
53     // for debugging
54     public void showRelations() {
55         PrintWriter pw = new PrintWriter(System.out);
56         relations.dump(pw, 0, "Contents relations", true);
57         pw.flush();
58     }
59
60     /**
61      * Given the name of a relation, returns the item the shares the
62      * same ItemContents.
63      *
64      * @param relationName the name of the relation of interest
65      *
66      * @return the item associated with this ItemContents in the named
67      * relation, or null if it does not exist
68      */
69     public Item getItemRelation(String relationName) {
70         return (Item) relations.getObject(relationName);
71     }
72
73     /**
74      * Returns the feature set for this item contents.
75      *
76      * @return the FeatureSet for this contents
77      */
78     public FeatureSet getFeatures() {
79         return features; 
80     }
81 }