summaryrefslogtreecommitdiff
path: root/src/test/java/au/id/zancanaro/javacheck/object/SubObject.java
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@zancanaro.id.au>2015-06-09 17:33:56 +1000
committerCarlo Zancanaro <carlo@zancanaro.id.au>2015-06-09 17:33:56 +1000
commitdd9f72b94eb7b2c37061c80457e74e8d7ac3e18f (patch)
tree17ac650c0c4a5045b1cbf0ef5c194b0ea7f7acd3 /src/test/java/au/id/zancanaro/javacheck/object/SubObject.java
parent813e523e9e57dc38f81afc53340e216b948d87cf (diff)
Add an ObjectGenerator<>, and related machinery (also a mapOf generator)
Diffstat (limited to 'src/test/java/au/id/zancanaro/javacheck/object/SubObject.java')
-rw-r--r--src/test/java/au/id/zancanaro/javacheck/object/SubObject.java44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/test/java/au/id/zancanaro/javacheck/object/SubObject.java b/src/test/java/au/id/zancanaro/javacheck/object/SubObject.java
new file mode 100644
index 0000000..bdf2ce8
--- /dev/null
+++ b/src/test/java/au/id/zancanaro/javacheck/object/SubObject.java
@@ -0,0 +1,44 @@
+package au.id.zancanaro.javacheck.object;
+
+import java.util.*;
+
+public class SubObject<T> {
+ public final Map<String, List<T>> obj;
+
+ public SubObject(Map<String, List<T>> obj) {
+ this.obj = obj;
+ }
+
+ public SubObject<T> add(SubObject<T> other) {
+ Map<String, List<T>> values = new HashMap<>(obj);
+ for (Map.Entry<String, List<T>> entry : other.obj.entrySet()) {
+ String key = entry.getKey();
+ if (values.containsKey(key)) {
+ List<T> result = new ArrayList<>(values.get(key));
+ result.addAll(entry.getValue());
+ values.put(key, Collections.unmodifiableList(result));
+ } else {
+ values.put(key, entry.getValue());
+ }
+ }
+ return new SubObject<>(Collections.unmodifiableMap(values));
+ }
+
+ @Override
+ public String toString() {
+ return obj.toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ SubObject subObject = (SubObject) o;
+ return obj.equals(subObject.obj);
+ }
+
+ @Override
+ public int hashCode() {
+ return obj.hashCode();
+ }
+}