Skip to content

Commit b82b59e

Browse files
committed
Code tidying
1 parent b51673e commit b82b59e

File tree

12 files changed

+37
-38
lines changed

12 files changed

+37
-38
lines changed

convex-core/src/main/java/convex/core/cpos/Belief.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,11 @@ public HashMap<AccountKey, SignedData<Order>> getOrdersHashMap() {
191191
@SuppressWarnings("unchecked")
192192
public static Collection<SignedData<Order>> extractOrders(ACell payload) {
193193
ArrayList<SignedData<Order>> result=new ArrayList<>();
194-
if (payload instanceof SignedData) {
195-
SignedData<?> sd=(SignedData<?>)payload;
194+
if (payload instanceof SignedData sd) {
196195
if (sd.getValue() instanceof Order) {
197196
result.add((SignedData<Order>) sd);
198197
}
199-
} else if (payload instanceof Belief) {
200-
Belief b=(Belief)payload;
198+
} else if (payload instanceof Belief b) {
201199
Index<AccountKey, SignedData<Order>> porders = b.getOrders();
202200
int n=porders.size();
203201
for (int i=0; i<n; i++) {

convex-core/src/main/java/convex/core/cvm/AccountStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public AccountStatus withParent(Address newParent) {
225225

226226
@Override
227227
public boolean equals(ACell o) {
228-
if (o instanceof AccountStatus) return equals((AccountStatus)o);
228+
if (o instanceof AccountStatus as) return equals(as);
229229
return Cells.equalsGeneric(this, o);
230230
}
231231

convex-core/src/main/java/convex/core/data/AExtensionValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ protected final long calcMemorySize() {
118118

119119
@Override
120120
public boolean equals(ACell a) {
121-
if (a instanceof AExtensionValue) return equals((AExtensionValue) a);
121+
if (a instanceof AExtensionValue ev) return equals(ev);
122122
return Cells.equalsGeneric(this, a);
123123
}
124124

convex-core/src/main/java/convex/core/data/AList.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ public AList<T> empty() {
5858
return Lists.empty();
5959
}
6060

61+
/**
62+
* Reverses this List, producing a Vector
63+
*/
64+
@Override
65+
public abstract AVector<T> reversed();
66+
6167
@Override
6268
public abstract AList<T> next();
6369

convex-core/src/main/java/convex/core/data/AMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public final boolean containsKey(Object key) {
8282

8383
@Override
8484
public final boolean containsValue(Object value) {
85-
if (value instanceof ACell) return containsValue((ACell)value);
85+
if (value instanceof ACell cell) return containsValue(cell);
8686
return false;
8787
}
8888

convex-core/src/main/java/convex/core/data/AVector.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ public AVector<T> empty() {
260260
return (AVector<T>) VectorLeaf.EMPTY;
261261
}
262262

263+
/**
264+
* Reverses this Vector, producing a List
265+
*/
263266
@Override
264267
public AList<T> reversed() {
265268
return convex.core.data.List.reverse(this);

convex-core/src/main/java/convex/core/data/Blob.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,9 @@ public static Blob createRandom(Random random, long length) {
268268

269269
@Override
270270
public Blob getChunk(long i) {
271-
if ((i == 0) && (count <= CHUNK_LENGTH))
272-
return this;
271+
if ((i == 0) && (count <= CHUNK_LENGTH)) {
272+
return this; // this must be the only chunk
273+
}
273274
long start = i * CHUNK_LENGTH;
274275
long take = Math.min(CHUNK_LENGTH, count - start);
275276
return slice(start, start + take);

convex-core/src/main/java/convex/core/data/BlobTree.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private BlobTree(Ref<ABlob>[] children, int shift, long count) {
4949
* @return New BlobTree instance
5050
*/
5151
public static BlobTree create(ABlob blob) {
52-
if (blob instanceof BlobTree) return (BlobTree) blob; // already a BlobTree
52+
if (blob instanceof BlobTree bt) return bt; // already a BlobTree
5353

5454
long length = blob.count();
5555
if (length<=Blob.CHUNK_LENGTH) throw new IllegalArgumentException("Can't make BlobTree for too small length: "+length);
@@ -294,9 +294,8 @@ public boolean equalsBytes(byte[] bytes, long byteOffset) {
294294
@Override
295295
public boolean equalsBytes(ABlob b) {
296296
if (b.count()!=count) return false;
297-
if (b instanceof BlobTree) {
298-
BlobTree bb=(BlobTree) b;
299-
return equals(bb);
297+
if (b instanceof BlobTree bt) {
298+
return equals(bt);
300299
}
301300

302301
assert (!b.isCanonical()) : "Canonical Blob of this size should be a BlobTree?";

convex-core/src/main/java/convex/core/data/Index.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ public Index<K, V> mergeDifferences(Index<K, V> b, MergeFunction<V> func) {
949949

950950
@Override
951951
public <R extends ACell> ADataStructure<R> map(Function<MapEntry<K, V>, R> mapper) {
952-
Index result=EMPTY;
952+
// Index result=EMPTY;
953953
// return result;
954954
throw new TODOException();
955955
}

convex-core/src/main/java/convex/core/util/JSONUtils.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,22 @@ public class JSONUtils {
5353
public static Object json(ACell o) {
5454
if (o == null)
5555
return null;
56-
if (o instanceof CVMLong)
57-
return ((CVMLong) o).longValue();
58-
if (o instanceof CVMBigInteger)
59-
return ((CVMBigInteger) o).big();
60-
if (o instanceof CVMDouble)
61-
return ((CVMDouble) o).doubleValue();
62-
if (o instanceof CVMBool)
63-
return ((CVMBool) o).booleanValue();
64-
if (o instanceof CVMChar)
65-
return ((CVMChar) o).toString();
66-
if (o instanceof Address)
67-
return (Long) ((Address) o).longValue();
68-
if (o instanceof AMap) {
69-
AMap<?, ?> m = (AMap<?, ?>) o;
56+
if (o instanceof CVMLong cvmLong)
57+
return cvmLong.longValue();
58+
if (o instanceof CVMBigInteger bi)
59+
return bi.big();
60+
if (o instanceof CVMDouble cd)
61+
return cd.doubleValue();
62+
if (o instanceof CVMBool bool)
63+
return bool.booleanValue();
64+
if (o instanceof CVMChar c)
65+
return c.toString();
66+
if (o instanceof Address a)
67+
return (Long) a.longValue();
68+
if (o instanceof AMap m) {
7069
return JSONUtils.jsonMap(m);
7170
}
72-
if (o instanceof ASequence) {
73-
ASequence<?> seq = (ASequence<?>) o;
71+
if (o instanceof ASequence seq) {
7472
long n = seq.count();
7573
ArrayList<Object> list = new ArrayList<>();
7674
for (long i = 0; i < n; i++) {

0 commit comments

Comments
 (0)