Class Item

  • All Implemented Interfaces:
    Dumpable

    public class Item
    extends java.lang.Object
    implements Dumpable
    Represents a node in a Relation. Items can have shared contents but each item has its own set of Daughters. The shared contents of an item (represented by ItemContents) includes the feature set for the item and the set of all relations that this item is contained in. An item can be contained in a number of relations and as daughters to other items. This class is used to keep track of all of these relationships. There may be many instances of item that reference the same shared ItemContents.
    • Constructor Summary

      Constructors 
      Constructor Description
      Item​(Relation relation, ItemContents sharedContents)
      Creates an item.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Item addDaughter​(Item item)
      Adds the given item as a daughter to this item.
      Item appendItem​(Item originalItem)
      Appends an item in this list after this item.
      Item createDaughter()
      Creates a new Item, adds it as a daughter to this item and returns the new item.
      void dump​(java.io.PrintWriter out, int pad, java.lang.String title)
      Dumps out this item to the given output stream.
      boolean equalsShared​(Item otherItem)
      Determines if the shared contents of the two items are the same.
      java.lang.Object findFeature​(java.lang.String pathAndFeature)
      Finds the feature by following the given path.
      Item findItem​(java.lang.String path)
      Finds the item specified by the given path.
      Item getDaughter()
      Retrieves the first daughter of this item.
      FeatureSet getFeatures()
      Returns the feature set of this item.
      Item getItemAs​(java.lang.String relationName)
      Finds the item in the given relation that has the same shared contents.
      Item getLastDaughter()
      Retrieves the last daughter of this item.
      Item getNext()
      Gets the next item in this list.
      Item getNthDaughter​(int which)
      Retrieves the Nth daughter of this item.
      Relation getOwnerRelation()
      Retrieves the owning Relation.
      Item getParent()
      Returns the parent of this item.
      Item getPrevious()
      Gets the previous item in this list.
      ItemContents getSharedContents()
      Retrieves the shared contents for this item.
      Utterance getUtterance()
      Returns the utterance associated with this item.
      boolean hasDaughters()
      Determines if this item has daughters.
      Item prependItem​(Item originalItem)
      Prepends an item in this list before this item.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Item

        public Item​(Relation relation,
                    ItemContents sharedContents)
        Creates an item. The item is coupled to a particular Relation. If shared contents is null a new sharedContents is created.
        Parameters:
        relation - the relation that owns this item
        sharedContents - the contents that is shared with others. If null, a new sharedContents is created.
    • Method Detail

      • getItemAs

        public Item getItemAs​(java.lang.String relationName)
        Finds the item in the given relation that has the same shared contents.
        Parameters:
        relationName - the relation of interest
        Returns:
        the item as found in the given relation or null if not found
      • getOwnerRelation

        public Relation getOwnerRelation()
        Retrieves the owning Relation.
        Returns:
        the relation that owns this item
      • getSharedContents

        public ItemContents getSharedContents()
        Retrieves the shared contents for this item.
        Returns:
        the shared item contents
      • hasDaughters

        public boolean hasDaughters()
        Determines if this item has daughters.
        Returns:
        true if this item has daughters
      • getDaughter

        public Item getDaughter()
        Retrieves the first daughter of this item.
        Returns:
        the first daughter or null if none
      • getNthDaughter

        public Item getNthDaughter​(int which)
        Retrieves the Nth daughter of this item.
        Parameters:
        which - the index of the daughter to return
        Returns:
        the Nth daughter or null if none at the given index
      • getLastDaughter

        public Item getLastDaughter()
        Retrieves the last daughter of this item.
        Returns:
        the last daughter or null if none at the given index
      • addDaughter

        public Item addDaughter​(Item item)
        Adds the given item as a daughter to this item.
        Parameters:
        item - the new daughter
      • createDaughter

        public Item createDaughter()
        Creates a new Item, adds it as a daughter to this item and returns the new item.
        Returns:
        the newly created item that was added as a daughter
      • getParent

        public Item getParent()
        Returns the parent of this item.
        Returns:
        the parent of this item
      • getUtterance

        public Utterance getUtterance()
        Returns the utterance associated with this item.
        Returns:
        the utterance that contains this item
      • getFeatures

        public FeatureSet getFeatures()
        Returns the feature set of this item.
        Returns:
        the feature set of this item
      • dump

        public void dump​(java.io.PrintWriter out,
                         int pad,
                         java.lang.String title)
        Dumps out this item to the given output stream.
        Specified by:
        dump in interface Dumpable
        Parameters:
        out - where to send the output
        pad - the leading whitspace
        title - the title for the dump
      • findFeature

        public java.lang.Object findFeature​(java.lang.String pathAndFeature)
        Finds the feature by following the given path. Path is a string of ":" or "." separated strings with the following interpretations:
        • n - next item
        • p - previous item
        • parent - the parent
        • daughter - the daughter
        • daughter1 - same as daughter
        • daughtern - the last daughter
        • R:relname - the item as found in the given relation 'relname'
        The last element of the path will be interpreted as a voice/language specific feature function (if present) or an item feature name. If the feature function exists it will be called with the item specified by the path, otherwise, a feature will be retrieved with the given name. If neither exist than a String "0" is returned.
        Parameters:
        pathAndFeature - the path to follow
      • findItem

        public Item findItem​(java.lang.String path)
        Finds the item specified by the given path. Path is a string of ":" or "." separated strings with the following interpretations:
        • n - next item
        • p - previous item
        • parent - the parent
        • daughter - the daughter
        • daughter1 - same as daughter
        • daughtern - the last daughter
        • R:relname - the item as found in the given relation 'relname'
        If the given path takes us outside of the bounds of the item graph, then list access exceptions will be thrown.
        Parameters:
        path - the path to follow
        Returns:
        the item at the given path
      • getNext

        public Item getNext()
        Gets the next item in this list.
        Returns:
        the next item or null
      • getPrevious

        public Item getPrevious()
        Gets the previous item in this list.
        Returns:
        the previous item or null
      • appendItem

        public Item appendItem​(Item originalItem)
        Appends an item in this list after this item.
        Parameters:
        originalItem - new item has shared contents with this item (or * null)
        Returns:
        the newly appended item
      • prependItem

        public Item prependItem​(Item originalItem)
        Prepends an item in this list before this item.
        Parameters:
        originalItem - new item has shared contents with this item (or * null)
        Returns:
        the newly appended item
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equalsShared

        public boolean equalsShared​(Item otherItem)
        Determines if the shared contents of the two items are the same.
        Parameters:
        otherItem - the item to compare
        Returns:
        true if the shared contents are the same