fiftyone.mobile.detection.entities
Class Node

java.lang.Object
  extended by fiftyone.mobile.detection.entities.BaseEntity
      extended by fiftyone.mobile.detection.entities.Node
All Implemented Interfaces:
Comparable<Node>

public class Node
extends BaseEntity
implements Comparable<Node>

A node in the trie data structures held at each character position.


Nested Class Summary
(package private)  class Node.NodeNumericIndexIterator
           
 
Field Summary
private  byte[] characters
           
private  int characterStringOffset
          The offset in the strings data structure to the string that contains all the characters of the node.
private  NodeIndex[] children
          A list of all the child node indexes.
static int MIN_LENGTH
          The minimum length of a node assuming no node indexes or signatures.
 short nextCharacterPosition
          The next character position to the left of this node or a negative number if this is not a complete node.
static int NODE_INDEX_LENGTH
          The length of a node index.
static int NODE_NUMERIC_INDEX_LENGTH
          The length of a numeric node index.
private  NodeNumericIndex[] numericChildren
          An array of all the numeric children.
private  Node parent
           
(package private)  int parentIndex
          The parent index for this node.
 short position
          The position of the first character the node represents in the signature or target user agent.
private static Range[] ranges
           
private  Node root
           
private  int[] signatureIndexes
          A list of all the signature indexes that relate to this node.
 
Constructor Summary
Node(Dataset dataSet, int offset, BinaryReader reader)
          Constructs a new instance of Node
 
Method Summary
 void addCharacters(byte[] values)
          Adds the characters for this node to the values array.
 int compareTo(Node other)
          Compares one node to another for the purposes of determining the signature the node relates to.
 byte[] getCharacters()
          Gets an array containing all the characters of the node.
 int getChildrenLength()
           
 Node getCompleteNode(Match match)
          Returns a complete node for the match object provided.
 Node getCompleteNumericNode(Match match)
           
private  Integer getCurrentPositionAsNumeric(Match match)
          Returns the node position as a number.
 boolean getIsOverlap(Match match)
          Returns true if any of the nodes in the match have overlapping characters with this one.
private  boolean getIsOverlap(Node node)
          Returns true if the node overlaps with this one.
 int getLength()
          Returns the number of characters in the node tree.
(package private)  Node getNextNode(Match match)
          Returns the next node for the characters provided from the start index for the number of characters specified.
private  Integer getNumber(byte[] array, int start, int length)
          Returns an integer representation of the characters between start and end.
 int getNumericChildrenLength()
           
private  Node.NodeNumericIndexIterator getNumericNodeIterator(int target)
          Provides an iterator which provides the closest numeric children to the target is ascending order of difference
(package private)  Node getParent()
          Returns the parent node for this node.
private  Range getRange(int target)
          Determines the range the target value falls between
 int[] getRankedSignatureIndexes()
           
 Node getRoot()
          Returns the root node for this node.
 void init()
          Called after the entire data set has been loaded to ensure any further initialisation steps that require other items in the data set can be completed.
(package private)  boolean isComplete()
          Returns true if this node represents a completed sub string and the next character position is set.
private static NodeIndex[] readNodeIndexes(Dataset dataSet, BinaryReader reader, int offset, short count)
          Used by the constructor to read the variable length list of child node indexes associated with the node.
private static NodeNumericIndex[] readNodeNumericIndexes(Dataset dataSet, BinaryReader reader, short count)
          Used by the constructor to read the variable length list of child node numeric indexes associated with the node.
 String toString()
          Returns a string of spaces with the characters relating to this node populated.
 
Methods inherited from class fiftyone.mobile.detection.entities.BaseEntity
binarySearch, getDataSet, getIndex, readIntegerArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NODE_INDEX_LENGTH

public static final int NODE_INDEX_LENGTH
The length of a node index.

See Also:
Constant Field Values

NODE_NUMERIC_INDEX_LENGTH

public static final int NODE_NUMERIC_INDEX_LENGTH
The length of a numeric node index.

See Also:
Constant Field Values

MIN_LENGTH

public static final int MIN_LENGTH
The minimum length of a node assuming no node indexes or signatures.

See Also:
Constant Field Values

ranges

private static final Range[] ranges

signatureIndexes

private final int[] signatureIndexes
A list of all the signature indexes that relate to this node.


children

private final NodeIndex[] children
A list of all the child node indexes.


numericChildren

private final NodeNumericIndex[] numericChildren
An array of all the numeric children.


parentIndex

final int parentIndex
The parent index for this node.


characterStringOffset

private final int characterStringOffset
The offset in the strings data structure to the string that contains all the characters of the node. Or -1 if the node is not complete and no characters are available.


nextCharacterPosition

public final short nextCharacterPosition
The next character position to the left of this node or a negative number if this is not a complete node.


position

public final short position
The position of the first character the node represents in the signature or target user agent.


root

private Node root

parent

private Node parent

characters

private byte[] characters
Constructor Detail

Node

public Node(Dataset dataSet,
            int offset,
            BinaryReader reader)
Constructs a new instance of Node

Parameters:
dataSet - The data set the node is contained within
offset - The offset in the data structure to the node
Method Detail

getRoot

public Node getRoot()
             throws IOException
Returns the root node for this node.

Throws:
IOException

getParent

Node getParent()
         throws IOException
Returns the parent node for this node.

Throws:
IOException

isComplete

boolean isComplete()
Returns true if this node represents a completed sub string and the next character position is set.


getLength

public int getLength()
              throws IOException
Returns the number of characters in the node tree.

Throws:
IOException

getCharacters

public byte[] getCharacters()
                     throws IOException
Gets an array containing all the characters of the node.

Throws:
IOException

getRankedSignatureIndexes

public int[] getRankedSignatureIndexes()

getChildrenLength

public int getChildrenLength()

getNumericChildrenLength

public int getNumericChildrenLength()

readNodeNumericIndexes

private static NodeNumericIndex[] readNodeNumericIndexes(Dataset dataSet,
                                                         BinaryReader reader,
                                                         short count)
Used by the constructor to read the variable length list of child node numeric indexes associated with the node.

Parameters:
dataSet - The data set the node is contained within
reader - Reader connected to the source data structure and positioned to start reading
count - The number of elements to read into the array
Returns:
An array of child numeric node indexes for the node

readNodeIndexes

private static NodeIndex[] readNodeIndexes(Dataset dataSet,
                                           BinaryReader reader,
                                           int offset,
                                           short count)
Used by the constructor to read the variable length list of child node indexes associated with the node.

Parameters:
dataSet - The data set the node is contained within
reader - Reader connected to the source data structure and positioned to start reading
offset - The offset in the data structure to the node
count - The number of elements to read into the array
Returns:
An array of child node indexes for the node

init

public void init()
          throws IOException
Called after the entire data set has been loaded to ensure any further initialisation steps that require other items in the data set can be completed.

Throws:
IOException

getCompleteNumericNode

public Node getCompleteNumericNode(Match match)
                            throws IOException
Throws:
IOException

getNumericNodeIterator

private Node.NodeNumericIndexIterator getNumericNodeIterator(int target)
Provides an iterator which provides the closest numeric children to the target is ascending order of difference

Parameters:
target - value of the sub string in the user agent
Returns:
an iterator configured to provide numeric children in ascending order of difference

getRange

private Range getRange(int target)
Determines the range the target value falls between

Parameters:
target - value whose range is required
Returns:
the range the target falls between

getCurrentPositionAsNumeric

private Integer getCurrentPositionAsNumeric(Match match)
Returns the node position as a number.

Parameters:
match - results including the target user agent
Returns:
Null if there is no numeric characters, otherwise the characters as an integer

getNumber

private Integer getNumber(byte[] array,
                          int start,
                          int length)
Returns an integer representation of the characters between start and end. Assumes that all the characters are numeric characters.

Parameters:
array - Array of characters with numeric characters present between start and end
start - The first character to use to convert to a number
length - The number of characters to use in the conversion
Returns:

getCompleteNode

public Node getCompleteNode(Match match)
                     throws IOException
Returns a complete node for the match object provided.

Parameters:
match - results including the target user agent
Returns:
The next child node, or null if there isn't one
Throws:
IOException

getNextNode

Node getNextNode(Match match)
           throws IOException
Returns the next node for the characters provided from the start index for the number of characters specified.

Parameters:
match - Match results including the target user agent
Returns:
The next child node, or null if there isn't one
Throws:
IOException

getIsOverlap

private boolean getIsOverlap(Node node)
                      throws IOException
Returns true if the node overlaps with this one.

Parameters:
node -
Returns:
Throws:
IOException

getIsOverlap

public boolean getIsOverlap(Match match)
                     throws IOException
Returns true if any of the nodes in the match have overlapping characters with this one.

Parameters:
match -
Returns:
Throws:
IOException

addCharacters

public void addCharacters(byte[] values)
                   throws IOException
Adds the characters for this node to the values array.

Parameters:
values -
Throws:
IOException

toString

public String toString()
Returns a string of spaces with the characters relating to this node populated.

Overrides:
toString in class Object
Returns:
a string representation of the node

compareTo

public int compareTo(Node other)
Compares one node to another for the purposes of determining the signature the node relates to.

Specified by:
compareTo in interface Comparable<Node>
Parameters:
other - node to be compared
Returns:
-1 if this node is lower than the other, 1 if higher or 0 if equal.