diff --git a/convex-core/src/main/java/convex/core/data/ACollection.java b/convex-core/src/main/java/convex/core/data/ACollection.java index a076c3f8f..f078f1ed4 100644 --- a/convex-core/src/main/java/convex/core/data/ACollection.java +++ b/convex-core/src/main/java/convex/core/data/ACollection.java @@ -206,7 +206,7 @@ public Object[] toArray() { * @return The updated collection */ @Override - public abstract ACollection conj(R x); + public abstract ACollection conj(ACell x); /** * Maps a function over a collection, applying it to each element in turn. diff --git a/convex-core/src/main/java/convex/core/data/ADataStructure.java b/convex-core/src/main/java/convex/core/data/ADataStructure.java index 629d3baa4..7d34ff07b 100644 --- a/convex-core/src/main/java/convex/core/data/ADataStructure.java +++ b/convex-core/src/main/java/convex/core/data/ADataStructure.java @@ -56,7 +56,6 @@ public final boolean isEmpty() { return isCVMValue(); } - /** * Adds an element to this data structure, in the natural manner defined by the * general data structure type. e.g. append at the end of a vector. @@ -65,7 +64,7 @@ public final boolean isEmpty() { * @param x New element to add * @return The updated data structure, or null if a failure occurred due to invalid element type */ - public abstract ADataStructure conj(R x); + public abstract ADataStructure conj(ACell x); /** * Adds multiple elements to this data structure, in the natural manner defined by the @@ -77,10 +76,9 @@ public final boolean isEmpty() { * @param xs New elements to add * @return The updated data structure, or null if a failure occurred due to invalid element types */ - @SuppressWarnings("unchecked") - public ADataStructure conjAll(ACollection xs) { - ADataStructure result=(ADataStructure) this; - for (R x: xs) { + public ADataStructure conjAll(ACollection xs) { + ADataStructure result=this; + for (E x: xs) { result=result.conj(x); if (result==null) return null; } diff --git a/convex-core/src/main/java/convex/core/data/AHashSet.java b/convex-core/src/main/java/convex/core/data/AHashSet.java index 1c2e508a0..e6cf94493 100644 --- a/convex-core/src/main/java/convex/core/data/AHashSet.java +++ b/convex-core/src/main/java/convex/core/data/AHashSet.java @@ -21,8 +21,8 @@ protected AHashSet(long count) { protected abstract AHashSet mergeWith(AHashSet b, int setOp, int shift); @SuppressWarnings("unchecked") - public ASet includeAll(ASet elements) { - return (ASet) mergeWith((AHashSet) elements,OP_UNION); + public AHashSet includeAll(ASet elements) { + return mergeWith((AHashSet) elements,OP_UNION); }; protected final int reverseOp(int setOp) { @@ -62,10 +62,10 @@ public ASet excludeAll(ASet elements) { public abstract AHashSet toCanonical(); - public ASet conjAll(ACollection elements) { - if (elements instanceof AHashSet) return includeAll((AHashSet) elements); - @SuppressWarnings("unchecked") - AHashSet result=(AHashSet) this; + @SuppressWarnings("unchecked") + public AHashSet conjAll(ACollection elements) { + if (elements instanceof AHashSet) return includeAll((AHashSet)elements); + AHashSet result=this; long n=elements.count(); for (long i=0; i disjAll(ACollection b) { @SuppressWarnings("unchecked") @Override - public AHashSet conj(R a) { - return (AHashSet) includeRef((Ref) Ref.get(a)); + public AHashSet conj(ACell a) { + return includeRef(Ref.get((T)a)); } @Override @@ -100,10 +100,9 @@ public ASet exclude(ACell a) { return excludeRef(Ref.get(a)); } - @SuppressWarnings("unchecked") @Override - public AHashSet include(R a) { - return (AHashSet) includeRef((Ref) Ref.get(a)); + public AHashSet include(T a) { + return includeRef((Ref) Ref.get(a)); } /** 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 fa6c43508..d788c2d7d 100644 --- a/convex-core/src/main/java/convex/core/data/AList.java +++ b/convex-core/src/main/java/convex/core/data/AList.java @@ -45,7 +45,7 @@ public final AType getType() { * Returns a new list. */ @Override - public abstract AList conj(R x); + public abstract AList conj(ACell x); @Override public AList empty() { diff --git a/convex-core/src/main/java/convex/core/data/AMap.java b/convex-core/src/main/java/convex/core/data/AMap.java index 446b6997d..fdc834a81 100644 --- a/convex-core/src/main/java/convex/core/data/AMap.java +++ b/convex-core/src/main/java/convex/core/data/AMap.java @@ -301,11 +301,10 @@ public Set keySet() { * @return Updated map with the specified entry added, or null if the argument * is not a valid map entry */ - @SuppressWarnings("unchecked") - public ADataStructure conj(R x) { + public AMap conj(ACell x) { MapEntry me = RT.ensureMapEntry(x); if (me == null) return null; - return (ADataStructure) assocEntry(me); + return assocEntry(me); } /** 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 fe12761cd..30efe69db 100644 --- a/convex-core/src/main/java/convex/core/data/ASequence.java +++ b/convex-core/src/main/java/convex/core/data/ASequence.java @@ -231,10 +231,10 @@ public ACell[] toCellArray() { * Adds an element to the sequence in the natural position * * @param value Value to add - * @return Updated sequence + * @return Updated sequence, or null if value is invalid */ @Override - public abstract ASequence conj(R value); + public abstract ASequence conj(ACell value); /** * Produces a slice of this sequence, beginning with the specified start index and of the given length. diff --git a/convex-core/src/main/java/convex/core/data/ASet.java b/convex-core/src/main/java/convex/core/data/ASet.java index 194a0dfe3..f96df155b 100644 --- a/convex-core/src/main/java/convex/core/data/ASet.java +++ b/convex-core/src/main/java/convex/core/data/ASet.java @@ -42,7 +42,7 @@ public final byte getTag() { * @param a Value to include * @return Updated set */ - public abstract ASet include(R a); + public abstract ASet include(T a); /** * Updates the set to exclude the given element @@ -58,7 +58,7 @@ public final byte getTag() { * @param elements Elements to include * @return Updated set */ - public abstract ASet includeAll(ASet elements) ; + public abstract ASet includeAll(ASet elements) ; /** * Updates the set to exclude all the given elements. @@ -69,7 +69,7 @@ public final byte getTag() { public abstract ASet excludeAll(ASet elements) ; @Override - public abstract ASet conjAll(ACollection xs); + public abstract ASet conjAll(ACollection xs); /** * Removes all elements from this set, returning a new set. @@ -142,12 +142,12 @@ public final boolean contains(Object o) { public abstract ASet includeRef(Ref ref) ; @Override - public abstract ASet conj(R a); + public abstract ASet conj(ACell a); @SuppressWarnings("unchecked") @Override public ASet assoc(ACell key, ACell value) { - if (value==CVMBool.TRUE) return (ASet) include(key); + if (value==CVMBool.TRUE) return include((T) key); if (value==CVMBool.FALSE) return exclude((T) key); return null; } 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 c689133c3..812cc3b56 100644 --- a/convex-core/src/main/java/convex/core/data/AVector.java +++ b/convex-core/src/main/java/convex/core/data/AVector.java @@ -208,16 +208,16 @@ public AVector appendAll(List list) { @SuppressWarnings("unchecked") @Override - public final AVector conj(R value) { - return (AVector) append((T) value); + public final AVector conj(ACell value) { + return append((T) value); } @SuppressWarnings("unchecked") - public AVector conjAll(ACollection xs) { + public AVector conjAll(ACollection xs) { if (xs instanceof ASequence) { - return (AVector) concat((ASequence)xs); + return concat((ASequence)xs); } - return (AVector) concat(Vectors.create(xs)); + return 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 a5ea85dfc..486496f8c 100644 --- a/convex-core/src/main/java/convex/core/data/List.java +++ b/convex-core/src/main/java/convex/core/data/List.java @@ -305,8 +305,8 @@ public int estimatedEncodingSize() { * @return Updated list */ @Override - public List conj(R value) { - return new List((AVector) data.conj(value)); + public List conj(ACell value) { + return new List(data.conj(value)); } @Override @@ -314,7 +314,7 @@ public AList cons(T x) { return new List((AVector) data.conj(x)); } - public List conjAll(ACollection xs) { + public List conjAll(ACollection xs) { return reverse(data.conjAll(xs)); } diff --git a/convex-core/src/main/java/convex/core/data/Sets.java b/convex-core/src/main/java/convex/core/data/Sets.java index 5863be821..54c185163 100644 --- a/convex-core/src/main/java/convex/core/data/Sets.java +++ b/convex-core/src/main/java/convex/core/data/Sets.java @@ -32,7 +32,6 @@ public static Ref> emptyRef() { return (Ref)EMPTY_REF; } - @SuppressWarnings("unchecked") @SafeVarargs public static ASet of(Object... elements) { int n=elements.length; @@ -49,7 +48,7 @@ public static ASet of(ACell... elements) { int n=elements.length; ASet result=empty(); for (int i=0; i) result.conj(elements[i]); + result=(ASet) result.conj((T) elements[i]); } return result; } @@ -95,7 +94,7 @@ public static ASet fromCollection(Collection source) { @SuppressWarnings("unchecked") private static ASet fromCollection(ACountable source) { long n=source.count(); - ASet set=EMPTY; + ASet set=EMPTY; for (long i=0; i ASet include(R a) { + public ASet include(K a) { return getCanonicalSet().include(a); } - protected ASet getCanonicalSet() { + protected ASet getCanonicalSet() { return getCanonical(); } - @SuppressWarnings("unchecked") @Override public ASet exclude(ACell a) { return (ASet) getCanonicalSet().exclude(a); } @Override - public ASet includeAll(ASet elements) { + public ASet includeAll(ASet elements) { return getCanonicalSet().includeAll(elements); } @@ -54,7 +53,7 @@ public ASet excludeAll(ASet elements) { } @Override - public ASet conjAll(ACollection xs) { + public ASet conjAll(ACollection xs) { return getCanonicalSet().conjAll(xs); } @@ -82,7 +81,7 @@ public ASet includeRef(Ref ref) { } @Override - public ASet conj(R a) { + public ASet conj(ACell a) { return getCanonicalSet().conj(a); } @@ -104,7 +103,6 @@ public boolean containsAll(ASet b) { return getCanonicalSet().containsAll(b); } - @SuppressWarnings("unchecked") @Override public ASet slice(long start, long end) { return (ASet) getCanonicalSet().slice(start,end); diff --git a/convex-core/src/test/java/convex/core/data/AdversarialDataTest.java b/convex-core/src/test/java/convex/core/data/AdversarialDataTest.java index abccf6917..cb9e22df6 100644 --- a/convex-core/src/test/java/convex/core/data/AdversarialDataTest.java +++ b/convex-core/src/test/java/convex/core/data/AdversarialDataTest.java @@ -126,7 +126,7 @@ public class AdversarialDataTest { // Inserting non-CVM values into existing valid sets invalidTest(Sets.of(1,2,3,4).include(NON_CVM)); - invalidTest(Samples.LONG_SET_100.include(NON_CVM)); + invalidTest(Samples.LONG_SET_100.conj(NON_CVM)); } @Test public void testBadKeywords() {