diff --git a/README.md b/README.md
index 332cff6..d352d09 100644
--- a/README.md
+++ b/README.md
@@ -31,6 +31,8 @@ import ua_parser.Client;
System.out.println(c.os.minor); // => "1"
System.out.println(c.device.family); // => "iPhone"
+ System.out.println(c.device.brand); // => "Apple"
+ System.out.println(c.device.model); // => "iPhone"
```
## Publish to Sonatype OSSRH and Maven Central Repository
diff --git a/pom.xml b/pom.xml
index 9c083f5..ea02d8a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,6 @@
jar
1.4.1-SNAPSHOT
User Agent Parser for Java
-
Java implementation of the UA Parser library. Derives operating system, browser and device
metadata from a user-agent string. This library consumes the regular expression
@@ -93,9 +92,31 @@
1.7
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 3.0.0-M3
+
+ true
+
+
+
+ maven-assembly-plugin
+
+
+
+ com.allen.capturewebdata.Main
+
+
+
+ jar-with-dependencies
+
+
+
-
+
+
ossrh
@@ -118,7 +139,7 @@
org.apache.maven.plugins
maven-javadoc-plugin
- 3.0.0
+ 3.0.1
attach-javadocs
diff --git a/src/main/java/ua_parser/Device.java b/src/main/java/ua_parser/Device.java
index 81c37cb..648d9fe 100644
--- a/src/main/java/ua_parser/Device.java
+++ b/src/main/java/ua_parser/Device.java
@@ -25,32 +25,42 @@
*/
public class Device {
public final String family;
+ public final String brand;
+ public final String model;
- public Device(String family) {
- this.family = family;
- }
+ public Device(String family, String brand, String model) {
+ this.family = family;
+ this.brand = brand;
+ this.model = model;
+ }
public static Device fromMap(Map m) {
- return new Device((String) m.get("family"));
+ return new Device(m.get("family"), m.get("brand"), m.get("model"));
}
@Override
public boolean equals(Object other) {
- if (other == this) return true;
if (!(other instanceof Device)) return false;
Device o = (Device) other;
- return (this.family != null && this.family.equals(o.family)) || this.family == o.family;
+ return (((this.family != null && this.family.equals(o.family)) || this.family == o.family) &&
+ ((this.brand != null && this.brand.equals(o.brand)) || this.brand == o.brand ) &&
+ ((this.model != null && this.model.equals(o.model)) || this.model == o.model ));
}
@Override
public int hashCode() {
- return family == null ? 0 : family.hashCode();
+ int h = family == null ? 0 : family.hashCode();
+ h += brand == null ? 0 : brand.hashCode();
+ h += model == null ? 0 : model.hashCode();
+ return h;
}
@Override
public String toString() {
- return String.format("{\"family\": %s}",
- family == null ? Constants.EMPTY_STRING : '"' + family + '"');
+ return String.format("{\"family\": %s, \"brand\": %s, \"model\": %s}",
+ family == null ? Constants.EMPTY_STRING : '"' + family + '"',
+ brand == null ? Constants.EMPTY_STRING : '"' + brand + '"',
+ model == null ? Constants.EMPTY_STRING : '"' + model + '"');
}
}
\ No newline at end of file
diff --git a/src/main/java/ua_parser/DeviceParser.java b/src/main/java/ua_parser/DeviceParser.java
index 300647e..dc6aca7 100644
--- a/src/main/java/ua_parser/DeviceParser.java
+++ b/src/main/java/ua_parser/DeviceParser.java
@@ -39,15 +39,17 @@ public Device parse(String agentString) {
return null;
}
- String device = null;
+ Device device = null;
for (DevicePattern p : patterns) {
if ((device = p.match(agentString)) != null) {
break;
}
}
- if (device == null) device = "Other";
+ if (device != null) {
+ return device;
+ }
- return new Device(device);
+ return new Device("Other", null, null);
}
public static DeviceParser fromList(List