001/**
002 * Portions Copyright 2001 Sun Microsystems, Inc.
003 * Portions Copyright 1999-2001 Language Technologies Institute, 
004 * Carnegie Mellon University.
005 * All Rights Reserved.  Use is subject to license terms.
006 * 
007 * See the file "license.terms" for information on usage and
008 * redistribution of this file, and for a DISCLAIMER OF ALL 
009 * WARRANTIES.
010 */
011package com.sun.speech.freetts;
012import java.io.PrintWriter;
013
014/**
015 * Contains the information that is shared between multiple items.
016 */
017public class ItemContents {
018    private FeatureSetImpl features;
019    private FeatureSetImpl relations;
020
021    /**
022     * Class Constructor.
023     */
024    public ItemContents() {
025        features = new FeatureSetImpl();
026        relations = new FeatureSetImpl();
027    }
028    
029    /**
030     * Adds the given item to the set of relations. Whenever an item
031     * is added to a relation, it should add the name and the Item reference
032     * to this set of name/item mappings. This allows an item to find
033     * out the set of all relations that it is contained in.
034     *
035     * @param relationName the name of the relation
036     * @param item the item reference in the relation
037     */
038    public void addItemRelation(String relationName, Item item) {
039        // System.out.println("AddItemRelation: " + relationName
040        //                    + " item: " + item);
041        relations.setObject(relationName, item);
042    }
043
044    /**
045     * Removes the relation/item mapping from this ItemContents.
046     *
047     * @param relationName the name of the relation/item to remove
048     */
049    public void removeItemRelation(String relationName) {
050        relations.remove(relationName);
051    }
052
053    // for debugging
054    public void showRelations() {
055        PrintWriter pw = new PrintWriter(System.out);
056        relations.dump(pw, 0, "Contents relations", true);
057        pw.flush();
058    }
059
060    /**
061     * Given the name of a relation, returns the item the shares the
062     * same ItemContents.
063     *
064     * @param relationName the name of the relation of interest
065     *
066     * @return the item associated with this ItemContents in the named
067     * relation, or null if it does not exist
068     */
069    public Item getItemRelation(String relationName) {
070        return (Item) relations.getObject(relationName);
071    }
072
073    /**
074     * Returns the feature set for this item contents.
075     *
076     * @return the FeatureSet for this contents
077     */
078    public FeatureSet getFeatures() {
079        return features; 
080    }
081}