fiftyone.device.example.illustration
Class MatchForDeviceId

java.lang.Object
  extended by fiftyone.device.example.illustration.MatchForDeviceId

public class MatchForDeviceId
extends Object

Example shows how to use an existing 51Degrees deviceId to obtain a Match object with relevant properties and values.

Example illustrates:

At the end a short console message will be printed containing a hash code of the object, deviceId and the value for the IsMobile property. Notice that all three objects are different as demonstrated by hash value but have the same deviceId and value for the IsMobile property.

Storing deviceId as opposed to the individual properties is a much more efficient way of retaining device information for future use. Byte array is the most efficient of the three options demonstrated as it only requires enough space to store the number of integers corresponding to the number of profiles (one profile per component).

main assumes it is being run with a working directory at root of project or of this module.


Field Summary
protected  String mobileUserAgent
           
protected  Provider provider
           
 
Constructor Summary
MatchForDeviceId()
          Creates new provider object with the Stream dataset.
 
Method Summary
 void close()
          Closes the Dataset by releasing data file readers and freeing the data file from locks.
static void main(String[] args)
          Performs a match of the pre-defined User-Agent to retrieve Id, then shows how to use the Id to get a Match object.
 Match matchForDeviceIdArray(byte[] deviceId)
          Returns a Match object corresponding to the provided byte array Id.
 Match matchForDeviceIdList(ArrayList<Integer> deviceIds)
          Returns a Match object corresponding to the provided list of profile IDs.
 Match matchForDeviceIdString(String deviceId)
          Returns a Match object corresponding to the provided string deviceId.
 Match matchForUserAgent(String userAgent)
          Performs match for a User-Agent string and returns Match object with detection results.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

provider

protected final Provider provider

mobileUserAgent

protected final String mobileUserAgent
See Also:
Constant Field Values
Constructor Detail

MatchForDeviceId

public MatchForDeviceId()
                 throws IOException
Creates new provider object with the Stream dataset.

Throws:
IOException - if there was a problem accessing the data file.
Method Detail

main

public static void main(String[] args)
                 throws IOException
Performs a match of the pre-defined User-Agent to retrieve Id, then shows how to use the Id to get a Match object. The Id can be stored as a byte array, string or a list of integers corresponding to profiles.

Three match objects with different references but same deviceId and IsMobile values are generated to demonstrate that all three methods of storing deviceId produce the same result.

Parameters:
args - command line arguments.
Throws:
IOException - if there was a problem accessing data file.

matchForUserAgent

public Match matchForUserAgent(String userAgent)
                        throws IOException
Performs match for a User-Agent string and returns Match object with detection results.

Parameters:
userAgent - String representing typical HTTP User-Agent header.
Returns:
Match object with detection results.
Throws:
IOException - if there was a problem accessing the data file.

matchForDeviceIdString

public Match matchForDeviceIdString(String deviceId)
                             throws IOException
Returns a Match object corresponding to the provided string deviceId. String deviceId derived by: match.getDeviceId();

Parameters:
deviceId - String representation of the deviceId.
Returns:
Match object with detection results.
Throws:
IOException - if there was a problem accessing the data file.

matchForDeviceIdArray

public Match matchForDeviceIdArray(byte[] deviceId)
                            throws IOException
Returns a Match object corresponding to the provided byte array Id. Byte array id is retrieved by: match.getDeviceIdAsByteArray();

Parameters:
deviceId - byte array representation of deviceId.
Returns:
Match object with detection results.
Throws:
IOException - if there was a problem accessing the data file.

matchForDeviceIdList

public Match matchForDeviceIdList(ArrayList<Integer> deviceIds)
                           throws IOException
Returns a Match object corresponding to the provided list of profile IDs. A list of profile IDs is derived from: for (Profile profile : match.getProfiles()) {

Parameters:
deviceIds - a list of integers where each integer is a profile Id.
Returns:
Match object with detection results.
Throws:
IOException - if there was a problem accessing the data file.

close

public void close()
           throws IOException
Closes the Dataset by releasing data file readers and freeing the data file from locks. This method should only be used when the Dataset is no longer required, i.e. when device detection functionality is no longer required, or the data file needs to be freed.

Throws:
IOException - if there is a problem accessing the data file.


Copyright © 2017 51Degrees. All rights reserved.