org.crosswire.jsword.passage
Class TreeKey

java.lang.Object
  extended by org.crosswire.jsword.passage.AbstractKeyList
      extended by org.crosswire.jsword.passage.TreeKey
All Implemented Interfaces:
Serializable, Cloneable, Comparable<Key>, Iterable<Key>, Key

public class TreeKey
extends AbstractKeyList

A Key that knows where the data is in the real file.

Author:
DM Smith
See Also:
The GNU Lesser General Public License for details., Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.crosswire.jsword.passage.AbstractKeyList
AbstractKeyList.NameVisitor, AbstractKeyList.OsisIDVisitor, AbstractKeyList.OsisRefVisitor
 
Field Summary
private  List<Key> children
          The immediate children of this tree node.
private static org.slf4j.Logger log
          The log stream
private  Key parent
          The parent of this key.
private static long serialVersionUID
          Serialization ID
 
Constructor Summary
TreeKey(String text)
          Setup with the key name.
TreeKey(String name, Key parent)
          Setup with the key name and positions of data in the file
 
Method Summary
 void addAll(Key key)
          Adds the specified element to this set if it is not already present.
 void blur(int by, RestrictionType restrict)
          Widen the range of the verses/keys in this list.
 boolean canHaveChildren()
          Returns false if the receiver is a leaf node and can not have children.
 void clear()
          Removes all of the elements from this set (optional operation).
 TreeKey clone()
          This needs to be declared here so that it is visible as a method on a derived Key.
 boolean contains(Key key)
          Returns true if this set contains the specified element.
 boolean equals(Object obj)
          equality is tricky if comparing TreeKeys (as used by GenBooks) because some child keys can have the same name but different parents
 Key get(int index)
          Gets a key from a specific point in this list of children.
 int getCardinality()
          Returns the number of elements in this set (its cardinality).
 int getChildCount()
          Returns the number of children that this node has.
 String getOsisID()
          The OSIS defined id specification for this Key.
 String getOsisRef()
          The OSIS defined reference specification for this Key.
 Key getParent()
          All keys have parents unless they are the root of a Key.
 String getRootName()
          A Human readable version of the Key's top level name.
 int indexOf(Key that)
          Reverse a Key into the position the key holds in the list of children
 boolean isEmpty()
          Does this Key have 0 members
 Iterator<Key> iterator()
           
private  String osisify(String str)
           
 void removeAll(Key key)
          Removes the specified elements from this set if it is present.
 
Methods inherited from class org.crosswire.jsword.passage.AbstractKeyList
compareTo, getName, getName, hashCode, retain, retainAll, setName, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

parent

private Key parent
The parent of this key.


children

private List<Key> children
The immediate children of this tree node.


log

private static final org.slf4j.Logger log
The log stream


serialVersionUID

private static final long serialVersionUID
Serialization ID

See Also:
Constant Field Values
Constructor Detail

TreeKey

public TreeKey(String name,
               Key parent)
Setup with the key name and positions of data in the file

Parameters:
name -
parent -

TreeKey

public TreeKey(String text)
Setup with the key name. Use solely for searching.

Parameters:
text -
Method Detail

canHaveChildren

public boolean canHaveChildren()
Description copied from interface: Key
Returns false if the receiver is a leaf node and can not have children. Any attempt to add()/remove() will throw

Returns:
true if the key can have children

getChildCount

public int getChildCount()
Description copied from interface: Key
Returns the number of children that this node has. Leaf nodes return 0.

Returns:
the number of children for the node

getCardinality

public int getCardinality()
Description copied from interface: Key
Returns the number of elements in this set (its cardinality). If this set contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

This method is potentially expensive, as it often requires cycling through all the keys in the set.

Returns:
the number of elements in this set (its cardinality).

isEmpty

public boolean isEmpty()
Description copied from interface: Key
Does this Key have 0 members

Specified by:
isEmpty in interface Key
Overrides:
isEmpty in class AbstractKeyList
Returns:
true if this set contains no elements.

contains

public boolean contains(Key key)
Description copied from interface: Key
Returns true if this set contains the specified element.

Specified by:
contains in interface Key
Overrides:
contains in class AbstractKeyList
Parameters:
key - element whose presence in this set is to be tested.
Returns:
true if this set contains the specified element.

iterator

public Iterator<Key> iterator()

addAll

public void addAll(Key key)
Description copied from interface: Key
Adds the specified element to this set if it is not already present.

Parameters:
key - element to be added to this set.

removeAll

public void removeAll(Key key)
Description copied from interface: Key
Removes the specified elements from this set if it is present.

Parameters:
key - object to be removed from this set, if present.

clear

public void clear()
Description copied from interface: Key
Removes all of the elements from this set (optional operation). This set will be empty after this call returns (unless it throws an exception).


get

public Key get(int index)
Description copied from interface: Key
Gets a key from a specific point in this list of children.

Parameters:
index - The index of the Key to retrieve
Returns:
The specified key

indexOf

public int indexOf(Key that)
Description copied from interface: Key
Reverse a Key into the position the key holds in the list of children

Parameters:
that - The Key to find
Returns:
The index of the key or < 0 if the key is not in the list

getParent

public Key getParent()
Description copied from interface: Key
All keys have parents unless they are the root of a Key.

Returns:
The parent of this tree, or null if this Key is the root.

equals

public boolean equals(Object obj)
equality is tricky if comparing TreeKeys (as used by GenBooks) because some child keys can have the same name but different parents

Specified by:
equals in interface Key
Overrides:
equals in class AbstractKeyList
Returns:
true if equal

blur

public void blur(int by,
                 RestrictionType restrict)
Description copied from interface: Key
Widen the range of the verses/keys in this list. This is primarily for "find x within n verses of y" type applications.

Parameters:
by - The number of verses/keys to widen by
restrict - How should we restrict the blurring?
See Also:
Passage

clone

public TreeKey clone()
Description copied from interface: Key
This needs to be declared here so that it is visible as a method on a derived Key.

Specified by:
clone in interface Key
Overrides:
clone in class AbstractKeyList
Returns:
A complete copy of ourselves

getRootName

public String getRootName()
Description copied from interface: Key
A Human readable version of the Key's top level name. For Biblical passages this uses short books names. For a dictionary it might return A-Z.

Specified by:
getRootName in interface Key
Overrides:
getRootName in class AbstractKeyList
Returns:
a String containing a description of the Key

getOsisRef

public String getOsisRef()
Description copied from interface: Key
The OSIS defined reference specification for this Key. When the key is a single element, it is an OSIS book name with '.' separating the parts. When the key is multiple elements, it uses a range notation. Note, this will create a comma separated list of ranges, which is improper OSIS.

Specified by:
getOsisRef in interface Key
Overrides:
getOsisRef in class AbstractKeyList
Returns:
a String containing the OSIS description of the verses

getOsisID

public String getOsisID()
Description copied from interface: Key
The OSIS defined id specification for this Key. When the key is a single element, it is an OSIS book name with '.' separating the parts. When the key is multiple elements, it uses a space to separate each.

Specified by:
getOsisID in interface Key
Overrides:
getOsisID in class AbstractKeyList
Returns:
a String containing the OSIS description of the verses

osisify

private String osisify(String str)

Copyright ยจ 2003-2015