From b81e5f9bfae1320ce58ddd7cc15f5915f8316d10 Mon Sep 17 00:00:00 2001 From: XyperCode Date: Sun, 22 Oct 2023 16:52:56 +0200 Subject: [PATCH] Add copy implementation --- .idea/misc.xml | 3 ++- gradle.properties | 2 +- src/main/java/com/ultreon/data/types/BigDecType.java | 5 +++++ src/main/java/com/ultreon/data/types/BigIntType.java | 5 +++++ src/main/java/com/ultreon/data/types/BooleanType.java | 5 +++++ src/main/java/com/ultreon/data/types/ByteArrayType.java | 5 +++++ src/main/java/com/ultreon/data/types/ByteType.java | 5 +++++ src/main/java/com/ultreon/data/types/CharType.java | 5 +++++ src/main/java/com/ultreon/data/types/DoubleArrayType.java | 5 +++++ src/main/java/com/ultreon/data/types/DoubleType.java | 5 +++++ src/main/java/com/ultreon/data/types/FloatArrayType.java | 5 +++++ src/main/java/com/ultreon/data/types/FloatType.java | 5 +++++ src/main/java/com/ultreon/data/types/IType.java | 2 ++ src/main/java/com/ultreon/data/types/IntArrayType.java | 5 +++++ src/main/java/com/ultreon/data/types/IntType.java | 5 +++++ src/main/java/com/ultreon/data/types/ListType.java | 7 +++++++ src/main/java/com/ultreon/data/types/LongArrayType.java | 6 ++++++ src/main/java/com/ultreon/data/types/LongType.java | 5 +++++ src/main/java/com/ultreon/data/types/MapType.java | 6 ++++++ src/main/java/com/ultreon/data/types/ShortArrayType.java | 5 +++++ src/main/java/com/ultreon/data/types/ShortType.java | 5 +++++ src/main/java/com/ultreon/data/types/StringType.java | 5 ++++- src/main/java/com/ultreon/data/types/UUIDType.java | 5 +++++ 23 files changed, 108 insertions(+), 3 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 7ff2749..3b0baf8 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,5 @@ + - + \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index a6e14d2..65eaee2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -project_version=1.0.0 \ No newline at end of file +project_version=1.1.0 \ No newline at end of file diff --git a/src/main/java/com/ultreon/data/types/BigDecType.java b/src/main/java/com/ultreon/data/types/BigDecType.java index d442f70..a29294c 100644 --- a/src/main/java/com/ultreon/data/types/BigDecType.java +++ b/src/main/java/com/ultreon/data/types/BigDecType.java @@ -65,4 +65,9 @@ public boolean equals(Object other) { public int hashCode() { return Objects.hash(obj); } + + @Override + public BigDecType copy() { + return new BigDecType(obj); + } } diff --git a/src/main/java/com/ultreon/data/types/BigIntType.java b/src/main/java/com/ultreon/data/types/BigIntType.java index 8897294..38f051f 100644 --- a/src/main/java/com/ultreon/data/types/BigIntType.java +++ b/src/main/java/com/ultreon/data/types/BigIntType.java @@ -62,4 +62,9 @@ public boolean equals(Object other) { public int hashCode() { return Objects.hash(obj); } + + @Override + public BigIntType copy() { + return new BigIntType(obj); + } } diff --git a/src/main/java/com/ultreon/data/types/BooleanType.java b/src/main/java/com/ultreon/data/types/BooleanType.java index c49baf5..a6c9d56 100644 --- a/src/main/java/com/ultreon/data/types/BooleanType.java +++ b/src/main/java/com/ultreon/data/types/BooleanType.java @@ -51,4 +51,9 @@ public boolean equals(Object other) { public int hashCode() { return Objects.hash(obj); } + + @Override + public BooleanType copy() { + return new BooleanType(obj); + } } diff --git a/src/main/java/com/ultreon/data/types/ByteArrayType.java b/src/main/java/com/ultreon/data/types/ByteArrayType.java index 5c78e60..3da9791 100644 --- a/src/main/java/com/ultreon/data/types/ByteArrayType.java +++ b/src/main/java/com/ultreon/data/types/ByteArrayType.java @@ -59,4 +59,9 @@ public boolean equals(Object other) { public int hashCode() { return Arrays.hashCode(obj); } + + @Override + public ByteArrayType copy() { + return new ByteArrayType(obj.clone()); + } } diff --git a/src/main/java/com/ultreon/data/types/ByteType.java b/src/main/java/com/ultreon/data/types/ByteType.java index b6610f1..4e693ba 100644 --- a/src/main/java/com/ultreon/data/types/ByteType.java +++ b/src/main/java/com/ultreon/data/types/ByteType.java @@ -51,4 +51,9 @@ public boolean equals(Object other) { public int hashCode() { return Objects.hash(obj); } + + @Override + public ByteType copy() { + return new ByteType(obj); + } } diff --git a/src/main/java/com/ultreon/data/types/CharType.java b/src/main/java/com/ultreon/data/types/CharType.java index 3d40386..a5dcc06 100644 --- a/src/main/java/com/ultreon/data/types/CharType.java +++ b/src/main/java/com/ultreon/data/types/CharType.java @@ -51,4 +51,9 @@ public boolean equals(Object other) { public int hashCode() { return Objects.hash(obj); } + + @Override + public CharType copy() { + return new CharType(obj); + } } diff --git a/src/main/java/com/ultreon/data/types/DoubleArrayType.java b/src/main/java/com/ultreon/data/types/DoubleArrayType.java index 1784f33..34865b8 100644 --- a/src/main/java/com/ultreon/data/types/DoubleArrayType.java +++ b/src/main/java/com/ultreon/data/types/DoubleArrayType.java @@ -59,4 +59,9 @@ public boolean equals(Object other) { public int hashCode() { return Arrays.hashCode(obj); } + + @Override + public DoubleArrayType copy() { + return new DoubleArrayType(obj.clone()); + } } diff --git a/src/main/java/com/ultreon/data/types/DoubleType.java b/src/main/java/com/ultreon/data/types/DoubleType.java index 2f13637..21a28ff 100644 --- a/src/main/java/com/ultreon/data/types/DoubleType.java +++ b/src/main/java/com/ultreon/data/types/DoubleType.java @@ -51,4 +51,9 @@ public boolean equals(Object other) { public int hashCode() { return Objects.hash(obj); } + + @Override + public DoubleType copy() { + return new DoubleType(obj); + } } diff --git a/src/main/java/com/ultreon/data/types/FloatArrayType.java b/src/main/java/com/ultreon/data/types/FloatArrayType.java index 0852691..648bfb1 100644 --- a/src/main/java/com/ultreon/data/types/FloatArrayType.java +++ b/src/main/java/com/ultreon/data/types/FloatArrayType.java @@ -59,4 +59,9 @@ public boolean equals(Object other) { public int hashCode() { return Arrays.hashCode(obj); } + + @Override + public FloatArrayType copy() { + return new FloatArrayType(obj.clone()); + } } diff --git a/src/main/java/com/ultreon/data/types/FloatType.java b/src/main/java/com/ultreon/data/types/FloatType.java index 7fe71e8..96af56a 100644 --- a/src/main/java/com/ultreon/data/types/FloatType.java +++ b/src/main/java/com/ultreon/data/types/FloatType.java @@ -51,4 +51,9 @@ public boolean equals(Object other) { public int hashCode() { return Objects.hash(obj); } + + @Override + public FloatType copy() { + return new FloatType(obj); + } } diff --git a/src/main/java/com/ultreon/data/types/IType.java b/src/main/java/com/ultreon/data/types/IType.java index b56fd67..5092e8d 100644 --- a/src/main/java/com/ultreon/data/types/IType.java +++ b/src/main/java/com/ultreon/data/types/IType.java @@ -12,4 +12,6 @@ public interface IType { boolean equals(Object other); int hashCode(); + + IType copy(); } diff --git a/src/main/java/com/ultreon/data/types/IntArrayType.java b/src/main/java/com/ultreon/data/types/IntArrayType.java index b81d520..553cc09 100644 --- a/src/main/java/com/ultreon/data/types/IntArrayType.java +++ b/src/main/java/com/ultreon/data/types/IntArrayType.java @@ -59,4 +59,9 @@ public boolean equals(Object other) { public int hashCode() { return Arrays.hashCode(obj); } + + @Override + public IntArrayType copy() { + return new IntArrayType(obj.clone()); + } } diff --git a/src/main/java/com/ultreon/data/types/IntType.java b/src/main/java/com/ultreon/data/types/IntType.java index a138d83..fd28377 100644 --- a/src/main/java/com/ultreon/data/types/IntType.java +++ b/src/main/java/com/ultreon/data/types/IntType.java @@ -51,4 +51,9 @@ public boolean equals(Object other) { public int hashCode() { return Objects.hash(obj); } + + @Override + public IntType copy() { + return new IntType(obj); + } } diff --git a/src/main/java/com/ultreon/data/types/ListType.java b/src/main/java/com/ultreon/data/types/ListType.java index 9b6bdd2..a6b9ccf 100644 --- a/src/main/java/com/ultreon/data/types/ListType.java +++ b/src/main/java/com/ultreon/data/types/ListType.java @@ -10,6 +10,7 @@ import java.util.Iterator; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; public class ListType> implements IType>, Iterable { private final int id; @@ -157,4 +158,10 @@ public boolean equals(Object other) { public int hashCode() { return Objects.hash(id, obj); } + + @Override + @SuppressWarnings("unchecked") + public ListType copy() { + return new ListType(obj.stream().map(t -> (T) t.copy()).collect(Collectors.toList())); + } } diff --git a/src/main/java/com/ultreon/data/types/LongArrayType.java b/src/main/java/com/ultreon/data/types/LongArrayType.java index af551d9..fa99271 100644 --- a/src/main/java/com/ultreon/data/types/LongArrayType.java +++ b/src/main/java/com/ultreon/data/types/LongArrayType.java @@ -6,6 +6,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.util.Arrays; +import java.util.stream.Collectors; public class LongArrayType implements IType { private long[] obj; @@ -59,4 +60,9 @@ public boolean equals(Object other) { public int hashCode() { return Arrays.hashCode(obj); } + + @Override + public LongArrayType copy() { + return new LongArrayType(obj.clone()); + } } diff --git a/src/main/java/com/ultreon/data/types/LongType.java b/src/main/java/com/ultreon/data/types/LongType.java index 083e029..f073c26 100644 --- a/src/main/java/com/ultreon/data/types/LongType.java +++ b/src/main/java/com/ultreon/data/types/LongType.java @@ -51,4 +51,9 @@ public boolean equals(Object other) { public int hashCode() { return Objects.hash(obj); } + + @Override + public LongType copy() { + return new LongType(obj); + } } diff --git a/src/main/java/com/ultreon/data/types/MapType.java b/src/main/java/com/ultreon/data/types/MapType.java index e6402fa..7c99a41 100644 --- a/src/main/java/com/ultreon/data/types/MapType.java +++ b/src/main/java/com/ultreon/data/types/MapType.java @@ -11,6 +11,7 @@ import java.nio.charset.StandardCharsets; import java.util.*; import java.util.Map.Entry; +import java.util.stream.Collectors; public class MapType implements IType>> { private Map> obj; @@ -446,4 +447,9 @@ public boolean equals(Object other) { public int hashCode() { return Objects.hash(obj); } + + @Override + public MapType copy() { + return new MapType(obj.entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().copy(), (a, b) -> b))); + } } diff --git a/src/main/java/com/ultreon/data/types/ShortArrayType.java b/src/main/java/com/ultreon/data/types/ShortArrayType.java index 25b6622..a110cf6 100644 --- a/src/main/java/com/ultreon/data/types/ShortArrayType.java +++ b/src/main/java/com/ultreon/data/types/ShortArrayType.java @@ -59,4 +59,9 @@ public boolean equals(Object other) { public int hashCode() { return Arrays.hashCode(obj); } + + @Override + public ShortArrayType copy() { + return new ShortArrayType(obj.clone()); + } } diff --git a/src/main/java/com/ultreon/data/types/ShortType.java b/src/main/java/com/ultreon/data/types/ShortType.java index 347a3a6..0137489 100644 --- a/src/main/java/com/ultreon/data/types/ShortType.java +++ b/src/main/java/com/ultreon/data/types/ShortType.java @@ -51,4 +51,9 @@ public boolean equals(Object other) { public int hashCode() { return Objects.hash(obj); } + + @Override + public ShortType copy() { + return new ShortType(obj); + } } diff --git a/src/main/java/com/ultreon/data/types/StringType.java b/src/main/java/com/ultreon/data/types/StringType.java index 9ed0d2f..106d90f 100644 --- a/src/main/java/com/ultreon/data/types/StringType.java +++ b/src/main/java/com/ultreon/data/types/StringType.java @@ -47,5 +47,8 @@ public static StringType read(DataInputStream stream) throws IOException { return new StringType(new String(bytes, StandardCharsets.UTF_8)); } - + @Override + public StringType copy() { + return new StringType(obj); + } } diff --git a/src/main/java/com/ultreon/data/types/UUIDType.java b/src/main/java/com/ultreon/data/types/UUIDType.java index bbe6664..01ceca9 100644 --- a/src/main/java/com/ultreon/data/types/UUIDType.java +++ b/src/main/java/com/ultreon/data/types/UUIDType.java @@ -55,4 +55,9 @@ public boolean equals(Object other) { public int hashCode() { return Objects.hash(obj); } + + @Override + public UUIDType copy() { + return new UUIDType(new UUID(obj.getMostSignificantBits(), obj.getLeastSignificantBits())); + } }