| 1 |
package ezvcard.io.json; |
| 2 |
|
| 3 |
import java.util.List; |
| 4 |
import java.util.Map; |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class JsonValue { |
| 36 |
private final boolean isNull; |
| 37 |
private final Object value; |
| 38 |
private final List<JsonValue> array; |
| 39 |
private final Map<String, JsonValue> object; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public JsonValue(Object value) { |
| 46 |
this.value = value; |
| 47 |
array = null; |
| 48 |
object = null; |
| 49 |
isNull = (value == null); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public JsonValue(List<JsonValue> array) { |
| 57 |
this.array = array; |
| 58 |
value = null; |
| 59 |
object = null; |
| 60 |
isNull = (array == null); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public JsonValue(Map<String, JsonValue> object) { |
| 68 |
this.object = object; |
| 69 |
value = null; |
| 70 |
array = null; |
| 71 |
isNull = (object == null); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public Object getValue() { |
| 79 |
return value; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
public List<JsonValue> getArray() { |
| 87 |
return array; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
public Map<String, JsonValue> getObject() { |
| 95 |
return object; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
public boolean isNull() { |
| 103 |
return isNull; |
| 104 |
} |
| 105 |
|
| 106 |
@Override |
| 107 |
public int hashCode() { |
| 108 |
final int prime = 31; |
| 109 |
int result = 1; |
| 110 |
result = prime * result + ((array == null) ? 0 : array.hashCode()); |
| 111 |
result = prime * result + (isNull ? 1231 : 1237); |
| 112 |
result = prime * result + ((object == null) ? 0 : object.hashCode()); |
| 113 |
result = prime * result + ((value == null) ? 0 : value.hashCode()); |
| 114 |
return result; |
| 115 |
} |
| 116 |
|
| 117 |
@Override |
| 118 |
public boolean equals(Object obj) { |
| 119 |
if (this == obj) |
| 120 |
return true; |
| 121 |
if (obj == null) |
| 122 |
return false; |
| 123 |
if (getClass() != obj.getClass()) |
| 124 |
return false; |
| 125 |
JsonValue other = (JsonValue) obj; |
| 126 |
if (array == null) { |
| 127 |
if (other.array != null) |
| 128 |
return false; |
| 129 |
} else if (!array.equals(other.array)) |
| 130 |
return false; |
| 131 |
if (isNull != other.isNull) |
| 132 |
return false; |
| 133 |
if (object == null) { |
| 134 |
if (other.object != null) |
| 135 |
return false; |
| 136 |
} else if (!object.equals(other.object)) |
| 137 |
return false; |
| 138 |
if (value == null) { |
| 139 |
if (other.value != null) |
| 140 |
return false; |
| 141 |
} else if (!value.equals(other.value)) |
| 142 |
return false; |
| 143 |
return true; |
| 144 |
} |
| 145 |
|
| 146 |
@Override |
| 147 |
public String toString() { |
| 148 |
if (isNull) { |
| 149 |
return "NULL"; |
| 150 |
} |
| 151 |
|
| 152 |
if (value != null) { |
| 153 |
return "VALUE = " + value; |
| 154 |
} |
| 155 |
|
| 156 |
if (array != null) { |
| 157 |
return "ARRAY = " + array; |
| 158 |
} |
| 159 |
|
| 160 |
if (object != null) { |
| 161 |
return "OBJECT = " + object; |
| 162 |
} |
| 163 |
|
| 164 |
return ""; |
| 165 |
} |
| 166 |
} |