fiftyone.device.example.illustration
Class DynamicFilters

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

public class DynamicFilters
extends Object

Example of filtering signatures to obtain a subset based on one or more property : value condition. The example starts with a full set of signatures available in the data file and narrows them down to only leave signatures that correspond to mobile devices running Android OS that use the Chrome browser. The example then prints out a list of device IDs for the remaining signatures and the rank for each signature.

Example covers:

Every invocation of the filterBy() function will narrow down the subset of signatures available based on the provided property name and value. Eventually only a small subset will be left.

Dynamic filtering can be useful in a number of cases. For example: when creating an interdependent menu where one choice narrows down the options in a subsequent choice.

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


Field Summary
protected  Dataset dataset
           
protected  ArrayList<Signature> signatures
           
 
Constructor Summary
DynamicFilters()
          Creates a new Dataset using memory factory which loads a memory-resident representation of data.
 
Method Summary
 void close()
          Closes the Dataset by releasing data file readers and freeing the data file from locks.
 ArrayList<Signature> filterBy(String propertyName, String propertyValue, ArrayList<Signature> listToFilter)
          Filters the provided set of signatures to only return those, where the specified property is equal to the specified value.
static
<E> ArrayList<E>
iterableToArrayList(Iterable<E> iter)
          Converts Iterable list of 51Degrees signatures to an ArrayList of signatures.
static void main(String[] args)
          Instantiates this class and launches the demo.
 void run()
          Repeatedly calls the filter function and prints results.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dataset

protected Dataset dataset

signatures

protected ArrayList<Signature> signatures
Constructor Detail

DynamicFilters

public DynamicFilters()
               throws IOException
Creates a new Dataset using memory factory which loads a memory-resident representation of data. Also loads a copy of signatures into an ArrayList.

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

main

public static void main(String[] args)
                 throws IOException
Instantiates this class and launches the demo.

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

run

public void run()
         throws IOException
Repeatedly calls the filter function and prints results. The filtered subset of signatures represents mobile devices that run on Android OS and use Chrome Web browser.

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

filterBy

public ArrayList<Signature> filterBy(String propertyName,
                                     String propertyValue,
                                     ArrayList<Signature> listToFilter)
                              throws IOException
Filters the provided set of signatures to only return those, where the specified property is equal to the specified value. For example: calling this function with "IsMobile","True",null will return a subset of signatures where the IsMobile property evaluates to "True".

After checking for valid input method, iterates through the provided list of signatures to check if the required property of the current signature has the required value. If so, a signature is added to the temporary list that gets returned at the end.

If the signature list was not provided, a complete list of signatures available in the data file will be used.

Parameters:
propertyName - String containing name of the property to check for, not null.
propertyValue - String with value that the required property must evaluate to, not null.
listToFilter - an ArrayList of signatures to perform filtering on. If null the entire set of signatures will be used.
Returns:
Subset of signatures where property equals value.
Throws:
IOException - if there was a problem accessing data file.

iterableToArrayList

public static <E> ArrayList<E> iterableToArrayList(Iterable<E> iter)
Converts Iterable list of 51Degrees signatures to an ArrayList of signatures.

Type Parameters:
E - generic.
Parameters:
iter - Iterable to convert to ArrayList.
Returns:
ArrayList of 51Degrees signatures.

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.