com.mhhe.clrs2e
Class Huffman.PrefixCodeItem

java.lang.Object
  |
  +--com.mhhe.clrs2e.Huffman.Node
        |
        +--com.mhhe.clrs2e.Huffman.PrefixCodeItem
All Implemented Interfaces:
java.lang.Comparable, DynamicSetElement
Enclosing class:
Huffman

public static class Huffman.PrefixCodeItem
extends Huffman.Node
implements DynamicSetElement

Inner class for an item in a prefix code. Objects of this class serve as leaves in a Huffman tree, once it has been constructed.


Nested Class Summary
 
Nested classes inherited from class com.mhhe.clrs2e.DynamicSetElement
DynamicSetElement.Helper
 
Field Summary
private  char character
          The character that this entry represents.
private  java.lang.String codeWord
          This character's codeword, once the Huffman tree has been constructed.
 
Constructor Summary
Huffman.PrefixCodeItem(char c, double freq)
          Creates a new item in a prefix code.
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares this node to another, based on their frequencies.
 char getChar()
          Returns the character.
 java.lang.String getCodeWord()
          Returns the codeword.
 java.lang.Comparable getKey()
          Returns the frequency as the key.
 void setKey(java.lang.Comparable key)
          Cannot set the key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.mhhe.clrs2e.DynamicSetElement
compareTo, getKey, setKey
 

Field Detail

character

private final char character
The character that this entry represents.


codeWord

private java.lang.String codeWord
This character's codeword, once the Huffman tree has been constructed.

Constructor Detail

Huffman.PrefixCodeItem

public Huffman.PrefixCodeItem(char c,
                              double freq)
Creates a new item in a prefix code.

Parameters:
c - This entry's character.
freq - This entry's frequency.
Method Detail

getChar

public char getChar()
Returns the character.


getCodeWord

public java.lang.String getCodeWord()
Returns the codeword.


setKey

public void setKey(java.lang.Comparable key)
Cannot set the key.

Specified by:
setKey in interface DynamicSetElement
Parameters:
key - The key, but it cannot be set.
Throws:
java.lang.UnsupportedOperationException - always.

getKey

public java.lang.Comparable getKey()
Returns the frequency as the key.

Specified by:
getKey in interface DynamicSetElement

compareTo

public int compareTo(java.lang.Object o)
Compares this node to another, based on their frequencies.

Specified by:
compareTo in interface DynamicSetElement
Parameters:
o - The other node.
Returns:
A negative integer if this node's frequency is less, 0 if the nodes have equal frequencies, or a positive integer if this node's frequency is greater.
Throws:
java.lang.ClassCastException - if o does not reference a Node object.