fiftyone.mobile.detection
Class Match

java.lang.Object
  extended by fiftyone.mobile.detection.Match

public class Match
extends Object

Generate when a device detection is requested to include the signature matched, the confidence of the match and the method used to obtain the match.


Nested Class Summary
(package private)  class Match.MatchState
          Used to persist the match results to the cache.
private  class Match.PossibleSignature
          Used to represent a signature index and the number of times it occurs in the matched nodes.
private  class Match.PossibleSignatures
          A custom linked list used to identify the most frequently occurring signature indexes.
static interface Match.RankedSignatureIterator
          Used to iterate over the closest signatures.
 
Field Summary
(package private)  int closestSignaturesCount
           
private  Dataset dataSet
          The data set used for the detection.
private  Integer lowestScore
          The current lowest score for the target user agent.
 MatchMethods method
           
 int nextCharacterPositionIndex
          The next character position to be checked.
private static Comparator<Node> nodeComparator
          Comparator used to order the nodes by length with the shortest first.
private  List<Node> nodes
          List of nodes found for the match.
(package private)  int nodesEvaluated
           
(package private)  Profile[] profiles
           
private  Map<String,String[]> results
           
(package private)  int rootNodesEvaluated
           
private  Signature signature
           
private  List<Signature> signatures
           
(package private)  int signaturesCompared
           
(package private)  int signaturesRead
           
(package private)  int stringsRead
           
private  String targetUserAgent
           
private  byte[] targetUserAgentArray
           
 
Constructor Summary
Match(Dataset dataSet)
          Constructs a new detection match ready to be used.
Match(Dataset dataSet, String targetUserAgent)
          Constructs a new detection match ready to be used to identify the profiles associated with the target user agent.
 
Method Summary
private  Match.PossibleSignatures buildInitialList(int[] list)
           
 void cleanTargetUserAgentArray()
          Replaces any characters in the target user agent which are outside the range the dataset used when it was built with question marks.
(package private)  Match.RankedSignatureIterator getClosestSignatures()
          Returns a distinct list of signatures which most closely match the target user agent string.
 int getClosestSignaturesCount()
          The number of closest signatures returned for evaluation.
private  int getClosestSignaturesForNode(int[] signatureIndexList, Match.PossibleSignatures linkedList, int maxCount, int iteration)
           
(package private)  Dataset getDataSet()
           
 String getDeviceId()
          The unique id of the Device.
 int getDifference()
           
(package private)  int getExactSignatureIndex()
           
(package private)  int getIndexOf(Node node)
          Returns the start character position of the node within the target user agent, or -1 if the node does not exist.
 Integer getLowestScore()
           
 MatchMethods getMethod()
          The method used to obtain the match.
 List<Node> getNodes()
           
 int getNodesEvaluated()
          The number of nodes checked.
 Profile[] getProfiles()
          Array of profiles associated with the device that was found.
 Map<String,String[]> getResults()
           
 int getRootNodesEvaluated()
          The number of root nodes checked against the target user agent.
 Signature getSignature()
          The signature with the closest match to the user agent provided.
 int getSignaturesCompared()
          The number of signatures that were compared against the target user agent if the Closest match method was used.
 int getSignaturesRead()
          The number of signatures read during the detection.
 int getStringsRead()
          The number of strings that were read from the data structure for the match.
 String getTargetUserAgent()
          The target user agent string used for the detection.
 byte[] getTargetUserAgentArray()
          The user agent string as an ASCII byte array.
 String getUserAgent()
          The user agent of the matching device with irrelevant characters removed.
 Values getValues(Property property)
          Gets the values associated with the property name using the profiles found by the match.
 Values getValues(String propertyName)
          Gets the values associated with the property name using the profiles found by the match.
 void incrNodesEvaluated()
           
 void incrStringsRead()
           
private  void init(String targetUserAgent)
          Initialises the match object ready for detection.
 int insertNode(Node node)
          Inserts the node into the list checking to find it's correct position in the list first.
(package private)  void reset(String targetUserAgent)
          Resets the match for the user agent returning all the fields to the values they would have when the match was first constructed.
(package private)  void resetNextCharacterPositionIndex()
          Reset the next character position index based on the length of the target user agent and the root nodes.
 void setLowestScore(Integer lowestScore)
           
(package private)  void setSignature(Signature signature)
           
(package private)  void setState(Match.MatchState state)
          Sets the match properties based on the state information provided.
 String toString()
          A string representation of the nodes found from the target user agent.
 void updateProfile(int profileId)
          Override the profiles found by the match with the profileId provided.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nodeComparator

private static final Comparator<Node> nodeComparator
Comparator used to order the nodes by length with the shortest first.


signatures

private final List<Signature> signatures

nodes

private final List<Node> nodes
List of nodes found for the match.


dataSet

private final Dataset dataSet
The data set used for the detection.


nextCharacterPositionIndex

public int nextCharacterPositionIndex
The next character position to be checked.


targetUserAgentArray

private byte[] targetUserAgentArray

targetUserAgent

private String targetUserAgent

signature

private Signature signature

method

public MatchMethods method

signaturesRead

int signaturesRead

signaturesCompared

int signaturesCompared

rootNodesEvaluated

int rootNodesEvaluated

nodesEvaluated

int nodesEvaluated

stringsRead

int stringsRead

closestSignaturesCount

int closestSignaturesCount

profiles

Profile[] profiles

lowestScore

private Integer lowestScore
The current lowest score for the target user agent. Initialised to the largest possible result.


results

private Map<String,String[]> results
Constructor Detail

Match

public Match(Dataset dataSet)
Constructs a new detection match ready to be used.

Parameters:
dataSet -

Match

public Match(Dataset dataSet,
             String targetUserAgent)
      throws UnsupportedEncodingException
Constructs a new detection match ready to be used to identify the profiles associated with the target user agent.

Parameters:
dataSet -
targetUserAgent -
Throws:
UnsupportedEncodingException
Method Detail

getTargetUserAgentArray

public byte[] getTargetUserAgentArray()
The user agent string as an ASCII byte array.


getTargetUserAgent

public String getTargetUserAgent()
The target user agent string used for the detection.


getSignature

public Signature getSignature()
The signature with the closest match to the user agent provided.


setSignature

void setSignature(Signature signature)

reset

void reset(String targetUserAgent)
     throws UnsupportedEncodingException
Resets the match for the user agent returning all the fields to the values they would have when the match was first constructed. Used to avoid having to reallocate memory for data structures when a lot of detections are being performed.

Parameters:
targetUserAgent -
Throws:
UnsupportedEncodingException

setState

void setState(Match.MatchState state)
Sets the match properties based on the state information provided.

Parameters:
state - of a previous match from the cache.

init

private void init(String targetUserAgent)
           throws UnsupportedEncodingException
Initialises the match object ready for detection.

Parameters:
targetUserAgent -
Throws:
UnsupportedEncodingException

getDifference

public int getDifference()

getMethod

public MatchMethods getMethod()
The method used to obtain the match.


getSignaturesRead

public int getSignaturesRead()
The number of signatures read during the detection.


getSignaturesCompared

public int getSignaturesCompared()
The number of signatures that were compared against the target user agent if the Closest match method was used.


getRootNodesEvaluated

public int getRootNodesEvaluated()
The number of root nodes checked against the target user agent.


getNodesEvaluated

public int getNodesEvaluated()
The number of nodes checked.


getStringsRead

public int getStringsRead()
The number of strings that were read from the data structure for the match.


getClosestSignaturesCount

public int getClosestSignaturesCount()
The number of closest signatures returned for evaluation.


getDeviceId

public String getDeviceId()
                   throws IOException
The unique id of the Device.

Throws:
IOException

getProfiles

public Profile[] getProfiles()
                      throws IOException
Array of profiles associated with the device that was found.

Throws:
IOException

getUserAgent

public String getUserAgent()
The user agent of the matching device with irrelevant characters removed.


resetNextCharacterPositionIndex

void resetNextCharacterPositionIndex()
Reset the next character position index based on the length of the target user agent and the root nodes.


getExactSignatureIndex

int getExactSignatureIndex()
                     throws IOException
Returns:
if the nodes of the match correspond exactly to a signature then return the index of the signature. Otherwise -1.
Throws:
IOException

getClosestSignatures

Match.RankedSignatureIterator getClosestSignatures()
                                             throws IOException
Returns a distinct list of signatures which most closely match the target user agent string. Where a single signature is not present across all the nodes the signatures which match the most nodes from the target user agent string are returned.

Returns:
An enumeration of closest signatures.
Throws:
IOException

getClosestSignaturesForNode

private int getClosestSignaturesForNode(int[] signatureIndexList,
                                        Match.PossibleSignatures linkedList,
                                        int maxCount,
                                        int iteration)

buildInitialList

private Match.PossibleSignatures buildInitialList(int[] list)

getNodes

public List<Node> getNodes()

getLowestScore

public Integer getLowestScore()

setLowestScore

public void setLowestScore(Integer lowestScore)

incrStringsRead

public void incrStringsRead()

incrNodesEvaluated

public void incrNodesEvaluated()

getDataSet

Dataset getDataSet()

getValues

public Values getValues(Property property)
                 throws IOException
Gets the values associated with the property name using the profiles found by the match. If matched profiles don't contain a value then the default profiles for each of the components are also checked.

Parameters:
property - The property whose values are required
Returns:
Array of the values associated with the property, or null if the property does not exist
Throws:
IOException

getValues

public Values getValues(String propertyName)
                 throws IOException
Gets the values associated with the property name using the profiles found by the match. If matched profiles don't contain a value then the default profiles for each of the components are also checked.

Parameters:
propertyName - The property name whose values are required
Returns:
Array of the values associated with the property, or null if the property does not exist
Throws:
IOException

getResults

public Map<String,String[]> getResults()
                                throws IOException
Throws:
IOException

cleanTargetUserAgentArray

public void cleanTargetUserAgentArray()
Replaces any characters in the target user agent which are outside the range the dataset used when it was built with question marks.


getIndexOf

int getIndexOf(Node node)
         throws IOException
Returns the start character position of the node within the target user agent, or -1 if the node does not exist.

Parameters:
node -
Returns:
Throws:
IOException

updateProfile

public void updateProfile(int profileId)
                   throws IOException
Override the profiles found by the match with the profileId provided.

Parameters:
profileId - The ID of the profile to replace the existing component
Throws:
IOException

toString

public String toString()
A string representation of the nodes found from the target user agent.

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

insertNode

public int insertNode(Node node)
Inserts the node into the list checking to find it's correct position in the list first.

Parameters:
node - The node to be added to the match list
Returns:
The index of the node inserted into the list