1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.any23.extractor.microdata;
19
20 import java.util.Locale;
21
22
23
24
25
26
27 public class ItemProp extends Item {
28
29
30
31
32 private final String name;
33
34
35
36
37 private final ItemPropValue value;
38
39
40
41
42
43
44
45
46
47
48
49 public ItemProp(String xpath, String name, ItemPropValue value) {
50 this(xpath, name, value, false);
51 }
52
53 final boolean reverse;
54
55 ItemProp(String xpath, String name, ItemPropValue value, boolean reverse) {
56 super(xpath);
57
58 if (name == null) {
59 throw new NullPointerException("name cannot be null.");
60 }
61 if (name.trim().length() == 0) {
62 throw new IllegalArgumentException("invalid property name '" + name + "'");
63 }
64 if (value == null) {
65 throw new NullPointerException("value cannot be null.");
66 }
67 this.name = name;
68 this.value = value;
69 this.reverse = reverse;
70 }
71
72
73
74
75 public String getName() {
76 return name;
77 }
78
79
80
81
82 public ItemPropValue getValue() {
83 return value;
84 }
85
86 @Override
87 public String toJSON() {
88 return String.format(Locale.ROOT, "{ \"xpath\" : \"%s\", \"name\" : \"%s\", \"value\" : %s }", getXpath(), name,
89 value.toJSON());
90 }
91
92 @Override
93 public String toString() {
94 return toJSON();
95 }
96
97 @Override
98 public int hashCode() {
99 return name.hashCode() * value.hashCode() * 3;
100 }
101
102 @Override
103 public boolean equals(Object obj) {
104 if (obj == null) {
105 return false;
106 }
107 if (obj == this) {
108 return true;
109 }
110 if (obj instanceof ItemProp) {
111 final ItemProp./../../../../org/apache/any23/extractor/microdata/ItemProp.html#ItemProp">ItemProp other = (ItemProp) obj;
112 return name.equals(other.name) && value.equals(other.value);
113 }
114 return false;
115 }
116 }