public class DynamicFilters extends Object
Example covers:
Dataset dataset = MemoryFactory.create(
Shared.getLitePatternV32(), true);
iterableToArrayList(dataset.getSignatures())
filterBy method, that:
for (Signature sig : listToFilter) {
Values vals = sig.getValues(property);
if (vals.get(propertyValue) != null)
, and if so, adds the signature to the temporary list:
filterResults.add(sig);
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.
| Modifier and Type | Field and Description |
|---|---|
protected Dataset |
dataset |
protected ArrayList<Signature> |
signatures |
| Constructor and Description |
|---|
DynamicFilters()
Creates a new Dataset using memory factory which loads a
memory-resident representation of data.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
public DynamicFilters()
throws IOException
IOException - if there was a problem reading from the data file.public static void main(String[] args) throws IOException
args - command line argumentsIOException - if there was a problem accessing data file.public void run()
throws IOException
IOException - if there was a problem accessing data file.public ArrayList<Signature> filterBy(String propertyName, String propertyValue, ArrayList<Signature> listToFilter) throws IOException
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.
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.IOException - if there was a problem accessing data file.public static <E> ArrayList<E> iterableToArrayList(Iterable<E> iter)
E - generic.iter - Iterable to convert to ArrayList.public void close()
throws IOException
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.IOException - if there is a problem accessing the data file.Copyright © 2015 51Degrees. All rights reserved.