fiftyone.device.example.illustration
Class StronglyTypedValues

java.lang.Object
  extended by fiftyone.device.example.illustration.StronglyTypedValues
All Implemented Interfaces:
Closeable

public class StronglyTypedValues
extends Object
implements Closeable

Getting started example of using 51Degrees device detection. The example shows how to:

  1. Instantiate 51Degrees detection provider
      
          provider = new Provider(StreamFactory.create(
          Shared.getLitePatternV32(), false));
      
      
  2. Pass in a single HTTP User-Agent header
      
          Match match = provider.match(userAgent);
      
      
  3. Extract the value of the IsMobile property as boolean
      
          match.getValues("IsMobile").toBool();
      
      
main assumes it is being run with a working directory at root of project or of this module.


Field Summary
protected  String desktopUserAgent
           
protected  String mediaHubUserAgent
           
protected  String mobileUserAgent
           
protected  Provider provider
           
 
Constructor Summary
StronglyTypedValues()
          Initialises the device detection Provider with the included Lite data file.
 
Method Summary
 void close()
          Closes the Dataset by releasing data file readers and freeing the data file from locks.
 boolean isMobile(String userAgent)
          Matches provided User-Agent string and returns the IsMobile property value as boolean.
static void main(String[] args)
          Main entry point for this example.
 
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

desktopUserAgent

protected final String desktopUserAgent
See Also:
Constant Field Values

mediaHubUserAgent

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

StronglyTypedValues

public StronglyTypedValues()
                    throws IOException
Initialises the device detection Provider with the included Lite data file. For more data see: compare data options

Throws:
IOException - can be thrown if there is a problem reading from the provided data file.
Method Detail

isMobile

public boolean isMobile(String userAgent)
                 throws IOException
Matches provided User-Agent string and returns the IsMobile property value as boolean. Detection initiated by invoking Provider.match(java.lang.String). Detection results are then stored in the Match object and can be accessed using the Match.getValues("PropertyName") method.

Parameters:
userAgent - HTTP User-Agent string.
Returns:
True if the User-Agent is mobile, False otherwise.
Throws:
IOException - if there is a problem accessing the data file.

main

public static void main(String[] args)
                 throws IOException
Main entry point for this example. For each of the User-Agents defined in this class:
  1. invokes isMobile(java.lang.String) method; and
  2. prints output depending on the boolean value returned by the isMobile method.

Parameters:
args - command line arguments, not used.
Throws:
IOException - if there is 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.

Specified by:
close in interface Closeable
Throws:
IOException - if there is a problem accessing the data file.


Copyright © 2017 51Degrees. All rights reserved.