You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devicemap.apache.org by wk...@apache.org on 2014/09/05 03:03:52 UTC

svn commit: r1622591 - in /incubator/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device: BotDeviceBuilder.java DesktopOSDeviceBuilder.java IOSDeviceBuilder.java

Author: wkeil
Date: Fri Sep  5 01:03:51 2014
New Revision: 1622591

URL: http://svn.apache.org/r1622591
Log:
DMAP-35: Refactor Simple DDR 
Added extra builders matching Device Data
Task-Url: https://issues.apache.org/jira/browse/DMAP-35

Added:
    incubator/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/BotDeviceBuilder.java
    incubator/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/DesktopOSDeviceBuilder.java
Modified:
    incubator/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/IOSDeviceBuilder.java

Added: incubator/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/BotDeviceBuilder.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/BotDeviceBuilder.java?rev=1622591&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/BotDeviceBuilder.java (added)
+++ incubator/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/BotDeviceBuilder.java Fri Sep  5 01:03:51 2014
@@ -0,0 +1,85 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.devicemap.simpleddr.builder.device;
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import org.apache.devicemap.simpleddr.model.device.Device;
+import org.apache.devicemap.simpleddr.model.BuiltObject;
+import org.apache.devicemap.simpleddr.model.UserAgent;
+
+public class BotDeviceBuilder implements DeviceBuilder {
+
+	private final Map<String, String> simpleTokenMap;
+	private Map<String, Device> devices;
+
+	public BotDeviceBuilder() {
+		simpleTokenMap = new LinkedHashMap<String, String>();
+	}
+
+	public void putDevice(String deviceId, List<String> initProperties) {
+
+		for (String token : initProperties) {
+			simpleTokenMap.put(token, deviceId);
+		}
+	}
+
+	public void completeInit(Map<String, Device> devices) {
+		this.devices = devices;
+
+		for (String deviceID : simpleTokenMap.values()) {
+			if (!devices.containsKey(deviceID)) {
+				throw new IllegalStateException(
+						"unable to find device with id: " + deviceID
+								+ "in devices");
+			}
+		}
+	}
+
+	public boolean canBuild(UserAgent userAgent) {
+		for (String token : simpleTokenMap.keySet()) {
+			if (userAgent.getCompleteUserAgent().matches(
+					"(?i).*" + Pattern.quote(token) + ".*")) {
+				return true;
+			}
+		}
+		return false;
+	}
+
+	public BuiltObject build(UserAgent userAgent, int confidenceTreshold) {
+		Iterator<String> it = simpleTokenMap.keySet().iterator();
+		while (it.hasNext()) {
+			String token = (String) it.next();
+			if (userAgent.getCompleteUserAgent().matches(
+					"(?i).*" + Pattern.quote(token) + ".*")) {
+				String desktopDeviceId = simpleTokenMap.get(token);
+				if (desktopDeviceId != null) {
+					Device device = devices.get(desktopDeviceId);
+					return device;
+				}
+			}
+		}
+		return null;
+	}
+
+}

Added: incubator/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/DesktopOSDeviceBuilder.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/DesktopOSDeviceBuilder.java?rev=1622591&view=auto
==============================================================================
--- incubator/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/DesktopOSDeviceBuilder.java (added)
+++ incubator/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/DesktopOSDeviceBuilder.java Fri Sep  5 01:03:51 2014
@@ -0,0 +1,85 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.devicemap.simpleddr.builder.device;
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import org.apache.devicemap.simpleddr.model.device.Device;
+import org.apache.devicemap.simpleddr.model.BuiltObject;
+import org.apache.devicemap.simpleddr.model.UserAgent;
+
+public class DesktopOSDeviceBuilder implements DeviceBuilder {
+
+	private final Map<String, String> simpleTokenMap;
+	private Map<String, Device> devices;
+
+	public DesktopOSDeviceBuilder() {
+		simpleTokenMap = new LinkedHashMap<String, String>();
+	}
+
+	public void putDevice(String deviceId, List<String> initProperties) {
+
+		for (String token : initProperties) {
+			simpleTokenMap.put(token, deviceId);
+		}
+	}
+
+	public void completeInit(Map<String, Device> devices) {
+		this.devices = devices;
+
+		for (String deviceID : simpleTokenMap.values()) {
+			if (!devices.containsKey(deviceID)) {
+				throw new IllegalStateException(
+						"unable to find device with id: " + deviceID
+								+ "in devices");
+			}
+		}
+	}
+
+	public boolean canBuild(UserAgent userAgent) {
+		for (String token : simpleTokenMap.keySet()) {
+			if (userAgent.getCompleteUserAgent().matches(
+					"(?i).*" + Pattern.quote(token) + ".*")) {
+				return true;
+			}
+		}
+		return false;
+	}
+
+	public BuiltObject build(UserAgent userAgent, int confidenceTreshold) {
+		Iterator<String> it = simpleTokenMap.keySet().iterator();
+		while (it.hasNext()) {
+			String token = (String) it.next();
+			if (userAgent.getCompleteUserAgent().matches(
+					"(?i).*" + Pattern.quote(token) + ".*")) {
+				String desktopDeviceId = simpleTokenMap.get(token);
+				if (desktopDeviceId != null) {
+					Device device = devices.get(desktopDeviceId);
+					return device;
+				}
+			}
+		}
+		return null;
+	}
+
+}

Modified: incubator/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/IOSDeviceBuilder.java
URL: http://svn.apache.org/viewvc/incubator/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/IOSDeviceBuilder.java?rev=1622591&r1=1622590&r2=1622591&view=diff
==============================================================================
--- incubator/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/IOSDeviceBuilder.java (original)
+++ incubator/devicemap/trunk/devicemap/java/simpleddr/src/main/java/org/apache/devicemap/simpleddr/builder/device/IOSDeviceBuilder.java Fri Sep  5 01:03:51 2014
@@ -27,7 +27,7 @@ import org.apache.devicemap.simpleddr.mo
 
 public class IOSDeviceBuilder implements DeviceBuilder {
 
-    private LinkedHashMap<String, String> iOSDevices;
+    private final Map<String, String> iOSDevices;
     private Map<String, Device> devices;
 
     public IOSDeviceBuilder() {
@@ -44,7 +44,7 @@ public class IOSDeviceBuilder implements
     }
 
     public Device build(UserAgent userAgent, int confidenceTreshold) {
-        Iterator it = iOSDevices.keySet().iterator();
+        Iterator<String> it = iOSDevices.keySet().iterator();
         while (it.hasNext()) {
             String token = (String) it.next();
             if (userAgent.getCompleteUserAgent().matches(".*" + token + ".*")) {