diff --git a/convex-core/src/main/java/convex/core/data/AList.java b/convex-core/src/main/java/convex/core/data/AList.java index 1b246706f..fa6c43508 100644 --- a/convex-core/src/main/java/convex/core/data/AList.java +++ b/convex-core/src/main/java/convex/core/data/AList.java @@ -59,7 +59,7 @@ public AList empty() { public abstract AList map(Function mapper); @Override - public abstract AList concat(ASequence vals); + public abstract AList concat(ASequence vals); @Override public abstract AList assoc(long i, T value); diff --git a/convex-core/src/main/java/convex/core/data/ASequence.java b/convex-core/src/main/java/convex/core/data/ASequence.java index 1bc8f0653..fe12761cd 100644 --- a/convex-core/src/main/java/convex/core/data/ASequence.java +++ b/convex-core/src/main/java/convex/core/data/ASequence.java @@ -79,7 +79,7 @@ public ASequence flatMap(Function ASequence concat(ASequence vals); + public abstract ASequence concat(ASequence vals); @Override public final boolean addAll(int index, Collection c) { diff --git a/convex-core/src/main/java/convex/core/data/AVector.java b/convex-core/src/main/java/convex/core/data/AVector.java index 56b457961..c689133c3 100644 --- a/convex-core/src/main/java/convex/core/data/AVector.java +++ b/convex-core/src/main/java/convex/core/data/AVector.java @@ -140,7 +140,7 @@ public AVector flatMap(Function AVector concat(ASequence b); + public abstract AVector concat(ASequence b); public abstract R reduce(BiFunction func, R value); @@ -212,11 +212,12 @@ public final AVector conj(R value) { return (AVector) append((T) value); } + @SuppressWarnings("unchecked") public AVector conjAll(ACollection xs) { if (xs instanceof ASequence) { - return concat((ASequence)xs); + return (AVector) concat((ASequence)xs); } - return concat(Vectors.create(xs)); + return (AVector) concat(Vectors.create(xs)); } @Override diff --git a/convex-core/src/main/java/convex/core/data/List.java b/convex-core/src/main/java/convex/core/data/List.java index 01b789254..a5ea85dfc 100644 --- a/convex-core/src/main/java/convex/core/data/List.java +++ b/convex-core/src/main/java/convex/core/data/List.java @@ -347,13 +347,13 @@ public AList map(Function mapper) { @SuppressWarnings("unchecked") @Override - public List concat(ASequence vals) { + public List concat(ASequence vals) { long n = RT.count(vals); - if (n==0) return (List) this; + if (n==0) return this; - AVector rvals; + AVector rvals; if (vals instanceof List) { - List vlist=(List) vals; + List vlist=(List) vals; if (count==0) return vlist; rvals = vlist.data; } else { @@ -363,7 +363,7 @@ public List concat(ASequence vals) { } } if (count>0) { - rvals=rvals.concat((AVector)data); + rvals=rvals.concat(data); } return List.reverse(rvals); } diff --git a/convex-core/src/main/java/convex/core/data/MapEntry.java b/convex-core/src/main/java/convex/core/data/MapEntry.java index c35c46f6a..a6f876b7e 100644 --- a/convex-core/src/main/java/convex/core/data/MapEntry.java +++ b/convex-core/src/main/java/convex/core/data/MapEntry.java @@ -290,10 +290,9 @@ public void visitElementRefs(Consumer> f) { f.accept((Ref) valueRef); } - @SuppressWarnings("unchecked") @Override - public AVector concat(ASequence b) { - if (b.isEmpty()) return (AVector) this; + public AVector concat(ASequence b) { + if (b.isEmpty()) return this; return toVector().concat(b); } diff --git a/convex-core/src/main/java/convex/core/data/VectorArray.java b/convex-core/src/main/java/convex/core/data/VectorArray.java index a2b859d1f..f75cb5512 100644 --- a/convex-core/src/main/java/convex/core/data/VectorArray.java +++ b/convex-core/src/main/java/convex/core/data/VectorArray.java @@ -151,7 +151,7 @@ public AVector map(Function mapper) } @Override - public AVector concat(ASequence b) { + public AVector concat(ASequence b) { return toVector().concat(b); } diff --git a/convex-core/src/main/java/convex/core/data/VectorLeaf.java b/convex-core/src/main/java/convex/core/data/VectorLeaf.java index 2badc6c81..ccefd1df0 100644 --- a/convex-core/src/main/java/convex/core/data/VectorLeaf.java +++ b/convex-core/src/main/java/convex/core/data/VectorLeaf.java @@ -145,11 +145,11 @@ public AVector append(T value) { @SuppressWarnings("unchecked") @Override - public AVector concat(ASequence b) { + public AVector concat(ASequence b) { // Maybe can optimise? long aLen = count(); long bLen = b.count(); - AVector result = (AVector) this; + AVector result = this; long i = aLen; long end = aLen + bLen; while (i < end) { @@ -157,7 +157,7 @@ public AVector concat(ASequence b) { int rn = Utils.checkedInt(Math.min(Vectors.CHUNK_SIZE, end - i)); if (rn == Vectors.CHUNK_SIZE) { // we can append a whole chunk. Not toVector in case of VectorArrays - result = result.appendChunk((VectorLeaf) b.subVector(i - aLen, rn).toVector()); + result = result.appendChunk((AVector) b.subVector(i - aLen, rn)); i += Vectors.CHUNK_SIZE; continue; } diff --git a/convex-core/src/main/java/convex/core/data/VectorTree.java b/convex-core/src/main/java/convex/core/data/VectorTree.java index a64cbe327..b07c8f0e5 100644 --- a/convex-core/src/main/java/convex/core/data/VectorTree.java +++ b/convex-core/src/main/java/convex/core/data/VectorTree.java @@ -293,21 +293,21 @@ public AVector append(T value) { @SuppressWarnings("unchecked") @Override - public AVector concat(ASequence b) { + public AVector concat(ASequence b) { long bLen = b.count(); - VectorTree result = (VectorTree) this; + VectorTree result = this; long bi = 0; while (bi < bLen) { if ((bi + Vectors.CHUNK_SIZE) <= bLen) { // can append a whole chunk - AVector chunk = b.subVector(bi, Vectors.CHUNK_SIZE); + AVector chunk = (AVector) b.subVector(bi, Vectors.CHUNK_SIZE); result = result.appendChunk(chunk); bi += Vectors.CHUNK_SIZE; } else { // we have less than a chunk left, so final result must be a VectorLeaf with the // current result as tail VectorLeaf head = (VectorLeaf) b.subVector(bi, bLen - bi).toVector(); - return ((VectorLeaf)head).withPrefix(result); + return ((VectorLeaf)head).withPrefix(result); } } return result; diff --git a/convex-core/src/test/java/convex/core/data/EncodingSizeTest.java b/convex-core/src/test/java/convex/core/data/EncodingSizeTest.java index 6676d6c9e..493780d9c 100644 --- a/convex-core/src/test/java/convex/core/data/EncodingSizeTest.java +++ b/convex-core/src/test/java/convex/core/data/EncodingSizeTest.java @@ -74,7 +74,7 @@ public static int size(ACell a) { } @Test public void testVectorTree() { - AVector a=Samples.MAX_EMBEDDED_VECTOR; + AVector a=Samples.MAX_EMBEDDED_VECTOR; for (int i=0; i<15; i++) { a=a.concat(Samples.MAX_EMBEDDED_VECTOR); } diff --git a/convex-core/src/test/java/convex/core/data/EncodingTest.java b/convex-core/src/test/java/convex/core/data/EncodingTest.java index 48938ee80..a6a7c4108 100644 --- a/convex-core/src/test/java/convex/core/data/EncodingTest.java +++ b/convex-core/src/test/java/convex/core/data/EncodingTest.java @@ -364,15 +364,15 @@ public void testFailedMissingEncoding() throws BadFormatException { doMultiEncodingTest(Vectors.of(1,2,3)); // Two non-embedded identical children - AVector v1=Vectors.of(1,Samples.NON_EMBEDDED_STRING,Samples.NON_EMBEDDED_STRING,Samples.INT_VECTOR_23); + AVector v1=Vectors.of(1,Samples.NON_EMBEDDED_STRING,Samples.NON_EMBEDDED_STRING,Samples.INT_VECTOR_23); doMultiEncodingTest(v1); // Moar layers - AVector v2=Vectors.of(7,Samples.NON_EMBEDDED_STRING,v1.concat(Samples.INT_VECTOR_23)); + AVector v2=Vectors.of(7,Samples.NON_EMBEDDED_STRING,v1.concat(Samples.INT_VECTOR_23)); doMultiEncodingTest(v2); // Mooooar layers - AVector v3=Vectors.of(13,v2,v1,Samples.KEY_PAIR.signData(v2)); + AVector v3=Vectors.of(13,v2,v1,Samples.KEY_PAIR.signData(v2)); doMultiEncodingTest(v3); // Wrap in transaction