public class TrieProvider extends Object implements Disposable
| Modifier and Type | Class and Description |
|---|---|
static class |
TrieProvider.OffsetType
The type of integers used to represent the offset to the children.
|
| Modifier and Type | Field and Description |
|---|---|
private ByteBuffer |
_devices
Byte array of the devices list.
|
private short[] |
_lookupList
Byte array of the look up list loaded into memory.
|
private long |
_nodesOffset
The position in the source data file of the nodes.
|
private TriePool |
_pool
A pool of readers that can be used in multi threaded operation.
|
private ByteBuffer |
_properties
Byte array of the available properties.
|
private int |
_propertyCount
The number of properties available in total.
|
private Map<String,Integer> |
_propertyIndex
Dictionary of property names to indexes.
|
private List<String> |
_propertyNames
List of the available property names.
|
private ByteBuffer |
_Strings
Byte array of the Strings available.
|
String |
Copyright
The copy right notice associated with the data file.
|
private static int |
SIZE_OF_BYTE |
private static int |
SIZE_OF_INT |
private static int |
SIZE_OF_LONG |
private static int |
SIZE_OF_SHORT |
private static int |
SIZE_OF_UBYTE |
private static int |
SIZE_OF_UINT |
private static int |
SIZE_OF_USHORT |
| Constructor and Description |
|---|
TrieProvider(String copyright,
byte[] strings,
byte[] properties,
byte[] devices,
short[] lookupList,
long nodesLength,
long nodesOffset,
String fileName)
Constructs a new instance of a tree provider.
|
| Modifier and Type | Method and Description |
|---|---|
void |
dispose()
Disposes of the pool assigned to the provider.
|
private short |
getChild(int lookupOffset,
byte value)
Returns the offset in the node for the current character.
|
String |
getDeviceId(int deviceIndex)
Returns the device id matching the device index.
|
int |
getDeviceIndex(String userAgent)
Returns the index of the device associated with the given user agent.
|
private int |
getDeviceIndex(TrieReader reader,
byte[] userAgent,
int index,
int parentDeviceIndex)
Returns the offset in the device byte array to the device matching the
useragent provided.
|
private int |
getDeviceIndex(TrieReader reader,
byte[] userAgent,
int index,
int parentDeviceIndex,
StringBuilder matchedUserAgent)
Returns the offset in the device byte array to the device matching the
useragent provided.
|
int |
getPropertyIndex(String property)
Returns the integer index of the property in the list of values
associated with the device.
|
String |
getPropertyValue(int deviceIndex,
int propertyIndex)
Returns the value of the property index provided for the device index
provided.
|
String |
getPropertyValue(int deviceIndex,
String property)
Returns the property value based on the useragent provided.
|
private String |
getStringValue(int offset)
Returns the String at the offset provided.
|
String |
getUserAgent(String userAgent)
Returns the user agent matched against the one provided.
|
private static byte[] |
getUserAgentByteArray(String userAgent)
Converts a user agent in to a null terminated byte array.
|
private void |
initPropertyNames()
Initialises the full list of property names available from the provider.
|
List<String> |
PropertyNames()
List of all property names for the provider.
|
private void |
setNextNodePosition(TrieReader reader,
short childIndex,
short numberOfChildren,
TrieProvider.OffsetType offsetType)
Returns the position in the nodes stream of the next node.
|
static int |
sizeOfOffsets(TrieProvider.OffsetType offsetType)
The number of bytes each offset takes.
|
private static final int SIZE_OF_LONG
private static final int SIZE_OF_UINT
private static final int SIZE_OF_INT
private static final int SIZE_OF_USHORT
private static final int SIZE_OF_SHORT
private static final int SIZE_OF_UBYTE
private static final int SIZE_OF_BYTE
public String Copyright
private ByteBuffer _Strings
private ByteBuffer _properties
private ByteBuffer _devices
private short[] _lookupList
private TriePool _pool
private long _nodesOffset
private final Map<String,Integer> _propertyIndex
private int _propertyCount
public TrieProvider(String copyright, byte[] strings, byte[] properties, byte[] devices, short[] lookupList, long nodesLength, long nodesOffset, String fileName) throws FileNotFoundException
copyright - The copyright notice for the data file.strings - Array containing all Strings in the output.properties - Array of properties.devices - Array of devices.lookupList - Lookups data array.nodesLength - The length of the node data.nodesOffset - The position of the start of the nodes in the file
provided.fileName - Name of the source data file used to create the provider.FileNotFoundExceptionpublic String getUserAgent(String userAgent) throws Exception
userAgent - Exceptionpublic int getDeviceIndex(String userAgent) throws Exception
userAgent - Exceptionpublic String getDeviceId(int deviceIndex)
deviceIndex">Index - of the device whose Id should be returnedpublic String getPropertyValue(int deviceIndex, String property)
deviceIndex - The index of the device whose property should be
returned.property">The - name of the property required.public String getPropertyValue(int deviceIndex, int propertyIndex)
deviceIndex - Index for the device.propertyIndex - Index of the property required.public int getPropertyIndex(String property)
property - public void dispose()
dispose in interface Disposableprivate void initPropertyNames()
private String getStringValue(int offset)
offset - private static byte[] getUserAgentByteArray(String userAgent)
userAgent - The useragent to be tested.private short getChild(int lookupOffset,
byte value)
throws ArrayIndexOutOfBoundsException
lookupOffset - The offset in the byte arrayvalue - The value to be checked.ArrayIndexOutOfBoundsExceptionpublic static int sizeOfOffsets(TrieProvider.OffsetType offsetType)
offsetType - private void setNextNodePosition(TrieReader reader, short childIndex, short numberOfChildren, TrieProvider.OffsetType offsetType) throws IOException
reader - Reader with exclusive access to the underlying filechildIndex - numberOfChildren - offsetType - IOExceptionprivate int getDeviceIndex(TrieReader reader, byte[] userAgent, int index, int parentDeviceIndex) throws Exception
reader - Reader with exclusive access to the underlying file.userAgent - A null terminated byte array of the user agent to be
tested.index - The index in the array of the current character.parentDeviceIndex - The device index of the parent node.Exceptionprivate int getDeviceIndex(TrieReader reader, byte[] userAgent, int index, int parentDeviceIndex, StringBuilder matchedUserAgent) throws Exception
reader - Reader with exclusive access to the underlying file.userAgent - A null terminated byte array of the user agent to be
tested.index - The index in the array of the current character.parentDeviceIndex - The parent device index to be used if this node
doesn't have a different one.matchedUserAgent">The - characters of the user agent matched.Exception