Author: wkeil Date: Sun Aug 21 17:35:32 2016 New Revision: 1757070 URL: http://svn.apache.org/viewvc?rev=1757070&view=rev Log: DMAP-196: Deploy Snapshots to Apache Snapshot repo
Task-Url: https://issues.apache.org/jira/browse/DMAP-196 Modified: devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceFixer.java devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceHints.java devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapClient.java devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapFactory.java devicemap/trunk/clients/1.0/java/console/src/main/java/org/apache/devicemap/console/DeviceMapConsole.java Modified: devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceFixer.java URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceFixer.java?rev=1757070&r1=1757069&r2=1757070&view=diff ============================================================================== --- devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceFixer.java (original) +++ devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceFixer.java Sun Aug 21 17:35:32 2016 @@ -24,15 +24,12 @@ import static org.apache.devicemap.data. import java.util.HashMap; import java.util.Map; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import org.apache.devicemap.data.DeviceType; import org.apache.devicemap.data.UserAgent; /** * @author Werner Keil - * @version 0.2 + * @version 1.0 */ abstract class DeviceFixer { private static final Logger LOG = Logger.getLogger(DeviceFixer.class @@ -48,7 +45,7 @@ abstract class DeviceFixer { private static final String CHROME_VERSION_REGEXP = "Chrome.([0-9a-z\\.b]+).*"; private static final String SAFARI_REGEXP = ".*Safari/([0-9\\.]+).*?"; - + private static final String BROWSER = "mobile_browser"; private static final String BROWSER_VERSION = "mobile_browser_version"; @@ -63,7 +60,7 @@ abstract class DeviceFixer { } else { attributes = device.getAttributes(); } - + // OS String pattern = userAgent.getPatternElementsInside(); if (pattern != null && pattern.contains(";")) { @@ -151,22 +148,21 @@ abstract class DeviceFixer { String parts = pattern.substring(pattern.indexOf(CHROME)); String version = parts.substring(CHROME.length() + 1, parts.indexOf(" ")); -// System.out.println(version); + // System.out.println(version); // Matcher chromeVersionMatcher = // chromeVersionPattern.matcher(pattern); // System.out.println(chromeVersionMatcher); - final String versionExisting = attributes - .get(BROWSER_VERSION); + final String versionExisting = attributes.get(BROWSER_VERSION); if (!version.equals(versionExisting)) { - LOG.fine("Fixing '" + versionExisting + "' to '" - + version + "'"); + LOG.fine("Fixing '" + versionExisting + "' to '" + version + + "'"); attributes.put(BROWSER_VERSION, version); } } // Pattern safariPattern = Pattern.compile(SAFARI_REGEXP); } - + device.setAttributes(attributes); // logger.info("Device: " + device.getId() + " - " + Modified: devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceHints.java URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceHints.java?rev=1757070&r1=1757069&r2=1757070&view=diff ============================================================================== --- devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceHints.java (original) +++ devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceHints.java Sun Aug 21 17:35:32 2016 @@ -20,47 +20,51 @@ package org.apache.devicemap; /** * @author Werner Keil - * @version 0.2 + * @version 0.3 */ abstract class DeviceHints { - static enum WindowsVersion { - WIN_81("Windows NT 6.3" ,"Windows 8.1", "8.1"), - WIN_8("Windows NT 6.2", "Windows 8", "8.0"), - WIN_7("Windows NT 6.1", "Windows 7", "7.0"), - VISTA("Windows NT 6.0", "Windows Vista", "6.0"), - WIN_2003("Windows NT 5.2", "Windows Server 2003; Windows XP x64 Edition", "2003"), - WIN_XP("Windows NT 5.1", "Windows XP", "5.1"), - WIN_2000_SP1("Windows NT 5.01", "Windows 2000, Service Pack 1 (SP1)", "5.01"), - WIN_2000("Windows NT 5.0", "Windows 2000", "2000"), - WIN_NT_4("Windows NT 4.0", "Microsoft Windows NT 4.0", "4.0"), - WIN_ME("Windows 98; Win 9x 4.90", "Windows Millennium Edition (Windows Me)", "4.90"), - WIN_98("Windows 98", "Windows 98", "98"), - WIN_95("Windows 95", "Windows 95", "95"), - WIN_CE("Windows CE", "Windows CE", "CE"); // TODO version nr? - - private final String token; - private final String description; - private final String version; - - private WindowsVersion(String t, String d, String v) { - token = t; - description = d; - version = v; - } - - String getDescription() { - return description; - } - - String getVersion() { - return version; - } - - static final WindowsVersion ofToken(String token) { - for (WindowsVersion version : values()) { - if (version.token.equalsIgnoreCase(token)) return version; - } - return null; - } + static enum WindowsVersion { + WIN_81("Windows NT 6.3", "Windows 8.1", "8.1"), // + WIN_8("Windows NT 6.2", "Windows 8", "8.0"), // + WIN_7("Windows NT 6.1", "Windows 7", "7.0"), // + VISTA("Windows NT 6.0", "Windows Vista", "6.0"), // + WIN_2003("Windows NT 5.2", + "Windows Server 2003; Windows XP x64 Edition", "2003"), // + WIN_XP("Windows NT 5.1", "Windows XP", "5.1"), // + WIN_2000_SP1("Windows NT 5.01", "Windows 2000, Service Pack 1 (SP1)", + "5.01"), // + WIN_2000("Windows NT 5.0", "Windows 2000", "2000"), // + WIN_NT_4("Windows NT 4.0", "Microsoft Windows NT 4.0", "4.0"), // + WIN_ME("Windows 98; Win 9x 4.90", + "Windows Millennium Edition (Windows Me)", "4.90"), // + WIN_98("Windows 98", "Windows 98", "98"), // + WIN_95("Windows 95", "Windows 95", "95"), // + WIN_CE("Windows CE", "Windows CE", "CE"); // TODO version nr? + + private final String token; + private final String description; + private final String version; + + private WindowsVersion(String t, String d, String v) { + token = t; + description = d; + version = v; + } + + String getDescription() { + return description; + } + + String getVersion() { + return version; + } + + static final WindowsVersion ofToken(String token) { + for (WindowsVersion version : values()) { + if (version.token.equalsIgnoreCase(token)) + return version; + } + return null; } + } } Modified: devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapClient.java URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapClient.java?rev=1757070&r1=1757069&r2=1757070&view=diff ============================================================================== --- devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapClient.java (original) +++ devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapClient.java Sun Aug 21 17:35:32 2016 @@ -34,10 +34,11 @@ import org.apache.devicemap.loader.Loade /** * @author Werner Keil - * @version 1.1 + * @version 1.2 */ public class DeviceMapClient { - private static final Logger LOG = Logger.getLogger(DeviceMapClient.class.getName()); + private static final Logger LOG = Logger.getLogger(DeviceMapClient.class + .getName()); private static final java.util.regex.Pattern TEXT_SPLIT_PATTERN = java.util.regex.Pattern .compile(" |-|_|/|\\\\|\\[|\\]|\\(|\\)|;"); @@ -57,12 +58,13 @@ public class DeviceMapClient { uAttributes = Collections.unmodifiableMap(uAttributes); unknown = new Device(Device.UNKNOWN_ID, uAttributes); } - + public void initDeviceData(LoaderOption option) throws IOException { initDeviceData(option, null); } - public synchronized void initDeviceData(LoaderOption option, String path) throws IOException { + public synchronized void initDeviceData(LoaderOption option, String path) + throws IOException { devices = LoaderFactory.getLoader(option, path).getData(); initCount++; @@ -215,4 +217,4 @@ public class DeviceMapClient { Map<String, DeviceType> getDevices() { return devices; } -} +} \ No newline at end of file Modified: devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapFactory.java URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapFactory.java?rev=1757070&r1=1757069&r2=1757070&view=diff ============================================================================== --- devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapFactory.java (original) +++ devicemap/trunk/clients/1.0/java/client/src/main/java/org/apache/devicemap/DeviceMapFactory.java Sun Aug 21 17:35:32 2016 @@ -23,43 +23,43 @@ import org.apache.devicemap.loader.Loade /** * @author Werner Keil - * @version 1.1.1 + * @version 1.2 */ public final class DeviceMapFactory { private static DeviceMapClient client = null; private static volatile boolean initialized = false; - + private static final LoaderOption DEFAULT = LoaderOption.JAR; private DeviceMapFactory() { } public static DeviceMapClient getClient() { - return getClient(DEFAULT, null); + return getClient(DEFAULT, null); } public static DeviceMapClient getClient(LoaderOption option) { - return getClient(option, null); + return getClient(option, null); } public static DeviceMapClient getClient(LoaderOption option, String path) { - if (!initialized) { - synchronized (DeviceMapFactory.class) { - if (!initialized) { - client = new DeviceMapClient(); - try { - client.initDeviceData(option, path); - } catch (IOException ex) { - throw new RuntimeException(ex); - } - initialized = true; - } - } - } - return client; + if (!initialized) { + synchronized (DeviceMapFactory.class) { + if (!initialized) { + client = new DeviceMapClient(); + try { + client.initDeviceData(option, path); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + initialized = true; + } + } + } + return client; } public static void resetClient() { - initialized = false; + initialized = false; } } Modified: devicemap/trunk/clients/1.0/java/console/src/main/java/org/apache/devicemap/console/DeviceMapConsole.java URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/1.0/java/console/src/main/java/org/apache/devicemap/console/DeviceMapConsole.java?rev=1757070&r1=1757069&r2=1757070&view=diff ============================================================================== --- devicemap/trunk/clients/1.0/java/console/src/main/java/org/apache/devicemap/console/DeviceMapConsole.java (original) +++ devicemap/trunk/clients/1.0/java/console/src/main/java/org/apache/devicemap/console/DeviceMapConsole.java Sun Aug 21 17:35:32 2016 @@ -48,212 +48,221 @@ import org.apache.devicemap.loader.impl. * @version 1.2 */ public class DeviceMapConsole { - private static final String APP_NAME = "DeviceMap Java Console"; - private static final String CLASS_NAME = DeviceMapConsole.class.getName(); - private static final Logger LOG = Logger.getLogger(CLASS_NAME); - private static final String CONFIG_FILE = "app.properties"; - private static final String CONFIG_PROP_CONNECT = "connectionString"; - - public static void main(String[] args) throws Exception { - System.out.println(APP_NAME - + " " + DeviceMapConsole.class.getPackage() - .getImplementationVersion()); - - final Configurations configs = new Configurations(); - // Read data from this file - final File propertiesFile = new File(CONFIG_FILE); - final PropertiesConfiguration config = configs.properties(propertiesFile); - - @SuppressWarnings("unused") - boolean debug = false; - String loaderPath = null; - LoaderOption option = LoaderOption.UNINITIALIZED; - String parameter = null; - Level debugLevel = Level.OFF; - - CommandLine lvCmd = null; - final HelpFormatter lvFormater = new HelpFormatter(); - final CommandLineParser lvParser = new DefaultParser(); - final Options lvOptions = new Options(); - - final Option lvHelp = new Option("h", "help", false, "Show Help."); - final Option lverbose = new Option("v", "verbose", false, - "Verbose mode."); - - lvOptions.addOption(lvHelp); - lvOptions.addOption(lverbose); - lvOptions.addOption(new Option("o", "json", false, "Output as JSON.")); - - lvOptions.addOption(Option.builder("d").longOpt("device").argName("UA") - .desc("User Agent of device to test").hasArg() - .optionalArg(true).build()); - - lvOptions.addOption(Option.builder("u").longOpt("url").argName("url") - .desc("Load DeviceMap resouces from URL or \"default\"") - .hasArg().optionalArg(true).build()); - - lvOptions.addOption(Option.builder("f").longOpt("folder") - .argName("path") - .desc("Load DeviceMap resouces from folder or \"default\"") - .hasArg().optionalArg(true).build()); - - lvOptions.addOption(Option.builder("j") - .longOpt("jar") - .argName("jar") - .desc("Load DeviceMap resouces from JAR file in classpath or \"default\"") - .hasArg().optionalArg(true).build()); - - try { - lvCmd = lvParser.parse(lvOptions, args); - - if (lvCmd.hasOption('h')) { - lvFormater.printHelp(CLASS_NAME, lvOptions); - return; - } - - if (lvCmd.hasOption('v')) { - debug = true; - debugLevel = Level.ALL; - LOG.setLevel(debugLevel); - Logger.getLogger(DeviceMapClient.class.getName()).setLevel( - debugLevel); - Logger.getLogger(DDRLoader.class.getName()) - .setLevel(debugLevel); - for (Handler h : Logger - .getLogger(DeviceMapClient.class.getName()).getParent() - .getHandlers()) { - if (h instanceof ConsoleHandler) { - h.setLevel(debugLevel); - } - } - } - - if (lvCmd.hasOption('f')) { - option = LoaderOption.FOLDER; - loaderPath = lvCmd.getOptionValue('f'); - } - - if (lvCmd.hasOption('j')) { - LOG.fine("JAR: " + lvCmd.getOptionObject('j')); - option = LoaderOption.JAR; - } - - if (lvCmd.hasOption('u')) { - option = LoaderOption.URL; - loaderPath = lvCmd.getOptionValue('u'); - LOG.fine("URL: " + lvCmd.getOptionObject('u')); - } + private static final String APP_NAME = "DeviceMap Java Console"; + private static final String CLASS_NAME = DeviceMapConsole.class.getName(); + private static final Logger LOG = Logger.getLogger(CLASS_NAME); + private static final String CONFIG_FILE = "app.properties"; + private static final String CONFIG_PROP_CONNECT = "connectionString"; + + public static void main(String[] args) throws Exception { + System.out.println(APP_NAME + + " " + + DeviceMapConsole.class.getPackage() + .getImplementationVersion()); + + final Configurations configs = new Configurations(); + // Read data from this file + final File propertiesFile = new File(CONFIG_FILE); + final PropertiesConfiguration config = configs + .properties(propertiesFile); + + @SuppressWarnings("unused") + boolean debug = false; + String loaderPath = null; + LoaderOption option = LoaderOption.UNINITIALIZED; + String parameter = null; + Level debugLevel = Level.OFF; + + CommandLine lvCmd = null; + final HelpFormatter lvFormater = new HelpFormatter(); + final CommandLineParser lvParser = new DefaultParser(); + final Options lvOptions = new Options(); + + final Option lvHelp = new Option("h", "help", false, "Show Help."); + final Option lverbose = new Option("v", "verbose", false, + "Verbose mode."); + + lvOptions.addOption(lvHelp); + lvOptions.addOption(lverbose); + lvOptions.addOption(new Option("o", "json", false, "Output as JSON.")); + + lvOptions.addOption(Option.builder("d").longOpt("device").argName("UA") + .desc("User Agent of device to test").hasArg() + .optionalArg(true).build()); + + lvOptions.addOption(Option.builder("u").longOpt("url").argName("url") + .desc("Load DeviceMap resouces from URL or \"default\"") + .hasArg().optionalArg(true).build()); + + lvOptions.addOption(Option.builder("f").longOpt("folder") + .argName("path") + .desc("Load DeviceMap resouces from folder or \"default\"") + .hasArg().optionalArg(true).build()); + + lvOptions + .addOption(Option + .builder("j") + .longOpt("jar") + .argName("jar") + .desc("Load DeviceMap resouces from JAR file in classpath or \"default\"") + .hasArg().optionalArg(true).build()); + + try { + lvCmd = lvParser.parse(lvOptions, args); + + if (lvCmd.hasOption('h')) { + lvFormater.printHelp(CLASS_NAME, lvOptions); + return; + } + + if (lvCmd.hasOption('v')) { + debug = true; + debugLevel = Level.ALL; + LOG.setLevel(debugLevel); + Logger.getLogger(DeviceMapClient.class.getName()).setLevel( + debugLevel); + Logger.getLogger(DDRLoader.class.getName()) + .setLevel(debugLevel); + for (Handler h : Logger + .getLogger(DeviceMapClient.class.getName()).getParent() + .getHandlers()) { + if (h instanceof ConsoleHandler) { + h.setLevel(debugLevel); + } + } + } - if (lvCmd.hasOption('d')) { - parameter = lvCmd.getOptionValue('d'); - LOG.fine("UA: " + lvCmd.getOptionObject('d')); - } + if (lvCmd.hasOption('f')) { + option = LoaderOption.FOLDER; + loaderPath = lvCmd.getOptionValue('f'); + } + + if (lvCmd.hasOption('j')) { + LOG.fine("JAR: " + lvCmd.getOptionObject('j')); + option = LoaderOption.JAR; + } + + if (lvCmd.hasOption('u')) { + option = LoaderOption.URL; + loaderPath = lvCmd.getOptionValue('u'); + LOG.fine("URL: " + lvCmd.getOptionObject('u')); + } + + if (lvCmd.hasOption('d')) { + parameter = lvCmd.getOptionValue('d'); + LOG.fine("UA: " + lvCmd.getOptionObject('d')); + } + + if ("default".equals(loaderPath)) { + loaderPath = config.getString(CONFIG_PROP_CONNECT); + } + + if (LoaderOption.UNINITIALIZED.equals(option)) { + option = LoaderOption.URL; + } + final DeviceMapClient client = new DeviceMapClient(); + final long start = System.currentTimeMillis(); + client.initDeviceData(option, loaderPath); + long diff = System.currentTimeMillis() - start; + + System.out.println("Loaded " + client.getDeviceCount() + + " devices with " + client.getPatternCount() + + " patterns and " + client.getNodeCount() + " nodes in " + + diff + " ms"); + + System.out.println("Cold run"); + long startn = System.nanoTime(); + final long startm = System.currentTimeMillis(); + map(client, + "Mozilla/5.0 (Linux; U; Android 2.2; en; HTC Aria A6380 Build/ERE27) AppleWebKit/540.13+ (KHTML, like Gecko) Version/3.1 Mobile Safari/524.15.0"); + map(client, + "Mozilla/5.0 (iPad; U; CPU OS 4_3_5 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile/8L1"); + map(client, + "Mozilla/5.0 (BlackBerry; U; BlackBerry 9810; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0.261 Mobile Safari/534.11+"); + map(client, + "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X; en-us) AppleWebKit/536.26 (KHTML, like Gecko) CriOS/23.0.1271.91 Mobile/10A403 Safari/8536.25"); + // long diffn = (System.nanoTime() - startn) / 1000; + final long diffm = System.currentTimeMillis() - startm; + System.out.println("End cold run : " + diffm + " ms"); + + long diffn; + if (parameter == null) { + } else if ((new File(parameter)).exists()) { + System.out.println("Text file: " + parameter); + int count = 0; + int total = 0; + + BufferedReader in = new BufferedReader( + new FileReader(parameter)); + String line; + Device device; + while ((line = in.readLine()) != null) { + System.out.println("Text: '" + line + "'"); + startn = System.nanoTime(); + device = client.classifyDevice(line); + diffn = System.nanoTime() - startn; + total += diffn; + count++; + + System.out.println("Text lookup " + count + ": '" + + device.getId() + "' time: " + (diffn / 1000) + + "usec"); + } - if ("default".equals(loaderPath)) { - loaderPath = config.getString(CONFIG_PROP_CONNECT); - } + in.close(); - if (LoaderOption.UNINITIALIZED.equals(option)) { - option = LoaderOption.URL; - } - final DeviceMapClient client = new DeviceMapClient(); - final long start = System.currentTimeMillis(); - client.initDeviceData(option, loaderPath); - long diff = System.currentTimeMillis() - start; - - System.out.println("Loaded " + client.getDeviceCount() - + " devices with " + client.getPatternCount() - + " patterns and " + client.getNodeCount() + " nodes in " - + diff + " ms"); - - System.out.println("Cold run"); - long startn = System.nanoTime(); - final long startm = System.currentTimeMillis(); - map(client, "Mozilla/5.0 (Linux; U; Android 2.2; en; HTC Aria A6380 Build/ERE27) AppleWebKit/540.13+ (KHTML, like Gecko) Version/3.1 Mobile Safari/524.15.0"); - map(client, "Mozilla/5.0 (iPad; U; CPU OS 4_3_5 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile/8L1"); - map(client, "Mozilla/5.0 (BlackBerry; U; BlackBerry 9810; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0.261 Mobile Safari/534.11+"); - map(client, "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X; en-us) AppleWebKit/536.26 (KHTML, like Gecko) CriOS/23.0.1271.91 Mobile/10A403 Safari/8536.25"); - //long diffn = (System.nanoTime() - startn) / 1000; - final long diffm = System.currentTimeMillis() - startm; - System.out.println("End cold run : " + diffm + " ms"); - - long diffn; - if (parameter == null) { - } else if ((new File(parameter)).exists()) { - System.out.println("Text file: " + parameter); - int count = 0; - int total = 0; - - BufferedReader in = new BufferedReader( - new FileReader(parameter)); - String line; - Device device; - while ((line = in.readLine()) != null) { - System.out.println("Text: '" + line + "'"); - startn = System.nanoTime(); - device = client.classifyDevice(line); - diffn = System.nanoTime() - startn; - total += diffn; - count++; - - System.out.println("Text lookup " + count + ": '" - + device.getId() + "' time: " + (diffn / 1000) - + "usec"); - } - - in.close(); - - if (count == 0) { - count = 1; - } - total /= count; - - System.out.println("TOTAL lookups: " + count - + ", average time: " + (total / 1000) + "usec"); - } else { - System.out.println("UA: '" + parameter + "'"); - startn = System.nanoTime(); - final Device device = client.classifyDevice(parameter); - diffn = System.nanoTime() - startn; - System.out.println("UA lookup: '" + device.getId() + "' time: " - + (diffn / 1000) + "usec"); - if (lvCmd.hasOption('o')) { - System.out.println("DeviceMap JSON => " + device.toString()); - } else { - Map<String, String> m = device.getAttributes(); - // iterate thru the attributes - if (m != null - && (m.keySet() != null && m.keySet().size() > 0)) { - System.out.println("=== ATTRIBUTES ==="); - for (String attr : m.keySet()) { - System.out.println(attr + ": " + m.get(attr)); - } - } else { - System.out.println("No attributes found for '" - + parameter + "'."); - } - } - } + if (count == 0) { + count = 1; + } + total /= count; - return; - } catch (ParseException pvException) { - lvFormater.printHelp(CLASS_NAME, lvOptions); - System.out.println("Parse Error:" + pvException.getMessage()); - return; + System.out.println("TOTAL lookups: " + count + + ", average time: " + (total / 1000) + "usec"); + } else { + System.out.println("UA: '" + parameter + "'"); + startn = System.nanoTime(); + final Device device = client.classifyDevice(parameter); + diffn = System.nanoTime() - startn; + System.out.println("UA lookup: '" + device.getId() + "' time: " + + (diffn / 1000) + "usec"); + if (lvCmd.hasOption('o')) { + System.out + .println("DeviceMap JSON => " + device.toString()); + } else { + Map<String, String> m = device.getAttributes(); + // iterate thru the attributes + if (m != null + && (m.keySet() != null && m.keySet().size() > 0)) { + System.out.println("=== ATTRIBUTES ==="); + for (String attr : m.keySet()) { + System.out.println(attr + ": " + m.get(attr)); + } + } else { + System.out.println("No attributes found for '" + + parameter + "'."); + } } + } + + return; + } catch (ParseException pvException) { + lvFormater.printHelp(CLASS_NAME, lvOptions); + System.out.println("Parse Error:" + pvException.getMessage()); + return; } + } - private static void map(DeviceMapClient client, String text) { - StopWatch stopWatch = new StopWatch(); - stopWatch.start(); - - Device device = client.classifyDevice(text); - stopWatch.stop(); - String deviceId = "unknown"; - if (device != null) { - deviceId = device.getId(); - } - System.out.println("Result: " + deviceId + " took " - + stopWatch.getTime() + " ms"); + private static void map(DeviceMapClient client, String text) { + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + + Device device = client.classifyDevice(text); + stopWatch.stop(); + String deviceId = "unknown"; + if (device != null) { + deviceId = device.getId(); } + System.out.println("Result: " + deviceId + " took " + + stopWatch.getTime() + " ms"); + } }
