/**
 * Item.java -- OList data element type, used in Lab06, Lab09, Lab10,
 * Lab13, Lab14
 */
package lab14;

/** This class represents the type of each data element stored
 * in an ordered list or a binary search tree in these labs.
 * Each Item object contains a String value, together with
 * an occurrence count for that value.
 */
public class Item {
    private String value;
    private int occurrences;
  
    /** Creates a new Item instance containing the specified
     * String value, and initializes its occurrence count to 1.
     */
    public Item (String value) {
        this.value = value;
        occurrences = 1;
    }
  
    /** Sets the String value of the object to the specified
     *  parameter value, and automatically resets the associated
     *  occurrence count to 1.
     * @param value The new value to be stored in this Item object.
     */
    public void setValue (String value) {
        this.value = value;
        this.occurrences = 1;
    }
  
    /** Returns the String value currently stored by this Item object.
     * @return The value currently stored in this object.
     */
    public String getValue () {
        return value;
    }
  
    /** Increments the occurrence counter for this <B>Item</B> object.
     */
    public void incOccurrences () {
        occurrences++;
    }
  	 
    /** Decrements the occurrence counter for this <B>Item</B> object.
     */
    public void decOccurrences () {
       occurrences--;
    }
  	 
    /** Returns the occurrence count for this <B>Item</B> object.
     * This values represents the number of times the <B>String</B>
     * value stored in this object has been inserted into an
     * ordered list or a binary search tree.
     */
    public int getOccurrences () {
        return occurrences;
    }
  	  
    public String toString () {
        return value + " (" + occurrences + ")";
    }
}
