values;
/**
* The version of the data set.
*/
public Version version;
/**
* The version of the data set as an Enumeration.
*/
public DetectionConstants.FORMAT_VERSIONS versionEnum;
/**
* The number of bytes to allocate to a buffer returning XML format data for
* a match.
*/
public int xmlBufferLength;
/**
* Constructs a new data set ready to have lists of data assigned to it.
*
* @param lastModified The date and time the source of the data was
* last modified.
* @param mode The mode of operation the data set will be using.
* @throws java.io.IOException signals an I/O exception occurred
*/
public Dataset(Date lastModified, Modes mode) throws IOException {
this.httpHeaders = null;
this.maximumRank = 0;
this.disposed = false;
this.lastModified = Calendar.getInstance();
this.lastModified.setTime(lastModified);
this.mode = mode;
}
/**
* Returns time that has elapsed since the data in the data set was current.
*
* @return time in seconds between now and when data file was published.
*/
public long getAge() {
Date now = new Date();
Date was = new Date((long)age);
long difference = now.getTime() - was.getTime();
long diffInSeconds = TimeUnit.MILLISECONDS.toSeconds(difference);
return diffInSeconds;
}
/**
* The largest rank value that can be returned. Maximum rank value can be
* useful when working with signature ranks to calculate the rank percentage
* and quickly sort.
*
* @return The largest rank value that can be returned.
*/
public int getMaximumRank() {
int maxRank = maximumRank;
if (maxRank == 0 && rankedSignatureIndexes != null) {
synchronized(this) {
maxRank = maximumRank;
if (maxRank == 0 && rankedSignatureIndexes != null) {
maximumRank = maxRank = rankedSignatureIndexes.size();
}
}
}
return maxRank;
}
/**
* Indicates if the data set has been disposed.
*
* @return True if dataset has been disposed, False otherwise.
*/
public boolean getDisposed() {
return disposed;
}
private boolean disposed;
/**
* Returns the hardware {@link Component} that contains a set of
* {@link Property properties} and {@link Profile profiles} related to
* hardware (such as: IsCrawler property).
*
* Note that for the 'Lite' data file this component returns only three
* properties: IsMobile, ScreenPixelsWidth and ScreenPixelsHeight.
*
* Premium and Enterprise data files contain considerably more data, meaning
* more accurate detections and access to properties like DeviceType,
* IsTablet, DeviceRAM, HardwareName, PriceBand, ScreenInchesWidth and more.
*
* Compare data options.
*
* For more information see:
*
* 51Degrees Pattern Data Model
*
* @return hardware component for the hardware platform
* @throws IOException signals an I/O exception occurred
*/
@SuppressWarnings("DoubleCheckedLocking")
public Component getHardware() throws IOException {
Component localHardware = hardware;
if (localHardware == null) {
synchronized (this) {
localHardware = hardware;
if (localHardware == null) {
hardware = localHardware = getComponent("HardwarePlatform");
}
}
}
return localHardware;
}
private volatile Component hardware;
/**
* Returns the software {@link Component} that contains a set of
* {@link Property properties} and {@link Profile profiles} related to
* software. Software component includes properties like: PlatformName and
* PlatformVersion.
*
* Premium and Enterprise data files contain considerably more data, meaning
* more accurate detections and access to properties like PlatformVendor,
* CLDC and CcppAccept.
*
* Compare data options.
*
* For more information see:
*
* 51Degrees Pattern Data Model
*
* @return software component for the software platform
* @throws IOException if there was a problem accessing data file.
*/
@SuppressWarnings("DoubleCheckedLocking")
public Component getSoftware() throws IOException {
Component localSoftware = software;
if (localSoftware == null) {
synchronized (this) {
localSoftware = software;
if (localSoftware == null) {
software = localSoftware = getComponent("SoftwarePlatform");
}
}
}
return localSoftware;
}
private volatile Component software;
/**
* Returns the browser {@link Component} that contains a set of
* {@link Property properties} and {@link Profile profiles} related to
* browsers.
*
* Premium and Enterprise data files contain considerably more data, meaning
* more accurate detections and access to properties like AjaxRequestType,
* IsWebApp, HtmlVersion and Javascript.
*
* Compare data options.
*
* For more information see:
*
* 51Degrees Pattern Data Model
*
* @return browser {@code Component}.
* @throws IOException if there was a problem accessing data file.
*/
@SuppressWarnings("DoubleCheckedLocking")
public Component getBrowsers() throws IOException {
Component localBrowsers = browsers;
if (localBrowsers == null) {
synchronized (this) {
localBrowsers = browsers;
if (localBrowsers == null) {
browsers = localBrowsers = getComponent("BrowserUA");
}
}
}
return localBrowsers;
}
private volatile Component browsers;
/**
* Returns the crawler {@link Component} that contains a set of
* {@link Property properties} and {@link Profile profiles} related to
* crawlers (such as: IsCrawler property).
*
* Note that for the 'Lite' data file this component will not return any
* properties. Some profiles will be returned but no properties associated
* with this component will be available.
*
* Premium and Enterprise data files contain considerably more data, meaning
* more accurate detections and access to the IsCrawler property.
*
* Compare data options.
*
* For more information see:
*
* 51Degrees Pattern Data Model
*
* @return crawler component
* @throws IOException signals an I/O exception has occurred
*/
@SuppressWarnings("DoubleCheckedLocking")
public Component getCrawlers() throws IOException {
Component localCrawlers = crawlers;
if (localCrawlers == null) {
synchronized (this) {
localCrawlers = crawlers;
if (localCrawlers == null) {
crawlers = localCrawlers = getComponent("Crawler");
}
}
}
return localCrawlers;
}
private volatile Component crawlers;
/**
* The copyright notice associated with the data file.
*
* @return copyright notice for the current data file as a string of text.
* @throws IOException if there was a problem accessing data file.
*/
@SuppressWarnings("DoubleCheckedLocking")
public String getCopyright() throws IOException {
String localCopyright = copyright;
if (localCopyright == null) {
synchronized (this) {
localCopyright = copyright;
if (localCopyright == null) {
copyright = localCopyright =
strings.get(copyrightOffset).toString();
}
}
}
return localCopyright;
}
/**
* The common name of the data set such as 'Lite', 'Premium' and
* 'Enterprise'.
*
* @return name of the data set as a string.
* @throws IOException if there was a problem accessing data file.
*/
@SuppressWarnings("DoubleCheckedLocking")
public String getName() throws IOException {
String localName = name;
if (localName == null) {
synchronized (this) {
localName = name;
if (localName == null) {
name = localName = strings.get(nameOffset).toString();
}
}
}
return localName;
}
private volatile String name;
/**
* Major version of the data file backing the this data set.
*
* @return major version of the data file.
* @throws IOException if there was a problem accessing data file.
*/
@SuppressWarnings("DoubleCheckedLocking")
public String getFormat() throws IOException {
String localFormat = format;
if (localFormat == null) {
synchronized (this) {
localFormat = format;
if (localFormat == null) {
format = localFormat = strings.get(formatOffset).toString();
}
}
}
return localFormat;
}
/**
* Used to search for a signature from a list of nodes.
*
* @return search instance connected to the list of signatures
*/
@SuppressWarnings("DoubleCheckedLocking")
SearchSignatureByNodes getSignatureSearch() {
SearchSignatureByNodes result = sigantureSearch;
if (result == null) {
synchronized (this) {
result = sigantureSearch;
if (result == null) {
sigantureSearch = result = new SearchSignatureByNodes(
signatures);
}
}
}
return result;
}
private volatile SearchSignatureByNodes sigantureSearch;
/**
* @return an instance of the profile offset search.
*/
@SuppressWarnings("DoubleCheckedLocking")
private SearchProfileOffsetByProfileId getProfileOffsetSearch() {
SearchProfileOffsetByProfileId result = profileOffsetSearch;
if (result == null) {
synchronized (this) {
result = profileOffsetSearch;
if (result == null) {
profileOffsetSearch = result =
new SearchProfileOffsetByProfileId(profileOffsets);
}
}
}
return result;
}
private volatile SearchProfileOffsetByProfileId profileOffsetSearch;
/**
* Get the profiles associated with the {@link Property} name and
* value which intersects with filterProfiles if provided.
* @param propertyName the name of the {@link Property} to find as a string.
* @param valueName the {@link Property Property's} {@link Value} to find
* as a string.
* @param filterProfiles the list of {@link Profile Profiles} to search in.
* Or null to find all matching
* {@link Profile Profiles}.
* @return A read-only list of {@link Profile} objects in ascending index
* order.
* @throws IOException
* @throws IllegalArgumentException if the property does not exist.
*/
public List findProfiles(String propertyName, String valueName, List filterProfiles) throws IOException {
Property property = this.properties.get(propertyName);
if (property == null) {
throw new IllegalArgumentException(String.format(
"Property '%s' does not exist in the '%s' data set. " +
"Upgrade to a different data set which includes the property.",
propertyName,
this.name));
}
return findProfiles(property, valueName, filterProfiles);
}
/**
* Get the profiles associated with the {@link Property} name and
* value which intersects with filterProfiles if provided.
* @param property the {@link Property} object to seach with.
* @param valueName the {@link Property Property's} {@link Value} to find
* as a string.
* @param filterProfiles the list of {@link Profile Profiles} to search in.
* Or null to find all matching
* {@link Profile Profiles}.
* @return A read-only list of {@link Profile} objects in ascending index
* order.
* @throws IOException
*/
public List findProfiles(Property property, String valueName, List filterProfiles) throws IOException {
return property.findProfiles(valueName, filterProfiles);
}
/**
* Returns an iterable of all {@link Component Components} in the current
* data file.
*
* For more information see:
*
* 51Degrees Pattern Data Model
*
* @return iterable of {@code Component} entities in the current data file.
*/
public IReadonlyList getComponents() {
return components;
}
/**
* Returns an iterable list of maps contained within the data file.
* May contain multiple maps with the same name.
*
* @return a read-only list of all maps contained in the data set.
*/
public IReadonlyList