Skip to content

Commit

Permalink
Make AmValue.Counter.getValue() return long (#3)
Browse files Browse the repository at this point in the history
* Make AmValue.Counter.getValue() return long
  • Loading branch information
takeeasyman authored Nov 6, 2023
1 parent 2e9aa7a commit d08ebde
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 18 deletions.
6 changes: 3 additions & 3 deletions lib/src/main/java/org/automerge/AmValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ public String toString() {
public static class Counter extends AmValue {
private org.automerge.Counter value;

public org.automerge.Counter getValue() {
return value;
public long getValue() {
return value.getValue();
}

@Override
public String toString() {
return "Counter [value=" + value + "]";
return "Counter [value=" + value.getValue() + "]";
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/test/java/org/automerge/TestGet.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void set(Transaction tx, ObjectId obj, long idx) {

@Override
public void check(AmValue value) {
Assertions.assertEquals(new Counter(1), ((AmValue.Counter) value).getValue());
Assertions.assertEquals(1, ((AmValue.Counter) value).getValue());
}
});
// Timestamp
Expand Down
4 changes: 2 additions & 2 deletions lib/src/test/java/org/automerge/TestIncrement.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public void setup() {
public void testIncrementInMap() {
tx.set(ObjectId.ROOT, "key", new Counter(10));
tx.increment(ObjectId.ROOT, "key", 5);
Assertions.assertEquals(new Counter(15), ((AmValue.Counter) doc.get(ObjectId.ROOT, "key").get()).getValue());
Assertions.assertEquals(15, ((AmValue.Counter) doc.get(ObjectId.ROOT, "key").get()).getValue());
}

@Test
public void testIncrementInList() {
ObjectId list = tx.set(ObjectId.ROOT, "list", ObjectType.LIST);
tx.insert(list, 0, new Counter(10));
tx.increment(list, 0, 5);
Assertions.assertEquals(new Counter(15), ((AmValue.Counter) doc.get(list, 0).get()).getValue());
Assertions.assertEquals(15, ((AmValue.Counter) doc.get(list, 0).get()).getValue());
}
}
2 changes: 1 addition & 1 deletion lib/src/test/java/org/automerge/TestInsert.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testInsertNullInList() {
@Test
public void testInsertCounterInList() {
tx.insert(list, 0, new Counter(10));
Assertions.assertEquals(new Counter(10), ((AmValue.Counter) doc.get(list, 0).get()).getValue());
Assertions.assertEquals(10, ((AmValue.Counter) doc.get(list, 0).get()).getValue());
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion lib/src/test/java/org/automerge/TestListItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void assertItems(AmValue[] items) {
Assertions.assertEquals(1.2, ((AmValue.F64) items[5]).getValue());
Assertions.assertEquals("somestring", ((AmValue.Str) items[6]).getValue());
Assertions.assertInstanceOf(AmValue.Null.class, items[7]);
Assertions.assertEquals(new Counter(10), ((AmValue.Counter) items[8]).getValue());
Assertions.assertEquals(10, ((AmValue.Counter) items[8]).getValue());
Assertions.assertEquals(map, ((AmValue.Map) items[9]).getId());
Assertions.assertEquals(subList, ((AmValue.List) items[10]).getId());
Assertions.assertEquals(text, ((AmValue.Text) items[11]).getId());
Expand Down
2 changes: 1 addition & 1 deletion lib/src/test/java/org/automerge/TestMapEntries.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void assertMapEntries(MapEntry[] entries) {
Assertions.assertArrayEquals("bytes".getBytes(), ((AmValue.Bytes) bytesEntry.getValue()).getValue());

MapEntry counterEntry = entrysByKey.get("counter");
Assertions.assertEquals(new Counter(10), ((AmValue.Counter) counterEntry.getValue()).getValue());
Assertions.assertEquals(10, ((AmValue.Counter) counterEntry.getValue()).getValue());

MapEntry dateEntry = entrysByKey.get("date");
Assertions.assertEquals(dateValue, ((AmValue.Timestamp) dateEntry.getValue()).getValue());
Expand Down
2 changes: 1 addition & 1 deletion lib/src/test/java/org/automerge/TestMarks.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void testCreateMarks() {

Mark counterMark = marks.get(2);
assertMark(counterMark, 1, 5, "counter",
value -> Assertions.assertEquals(((AmValue.Counter) value).getValue().getValue(), 5));
value -> Assertions.assertEquals(((AmValue.Counter) value).getValue(), 5));

Mark dateMark = marks.get(3);
assertMark(dateMark, 1, 5, "date",
Expand Down
6 changes: 3 additions & 3 deletions lib/src/test/java/org/automerge/TestPatches.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void testSetInMap() {
});

assertPutMap(patches.get(7), ObjectId.ROOT, emptyPath(), "counter", (AmValue value) -> {
Assertions.assertEquals(((AmValue.Counter) value).getValue().getValue(), 3);
Assertions.assertEquals(((AmValue.Counter) value).getValue(), 3);
});

assertPutMap(patches.get(8), ObjectId.ROOT, emptyPath(), "timestamp", (AmValue value) -> {
Expand Down Expand Up @@ -146,7 +146,7 @@ public void testSetInList() {
});

assertSetInList(patches.get(8), list, PathBuilder.root("list").build(), 7, (AmValue value) -> {
Assertions.assertEquals(((AmValue.Counter) value).getValue().getValue(), 3);
Assertions.assertEquals(((AmValue.Counter) value).getValue(), 3);
});

assertSetInList(patches.get(9), list, PathBuilder.root("list").build(), 8, (AmValue value) -> {
Expand Down Expand Up @@ -210,7 +210,7 @@ public void testInsertInList() {
Assertions.assertArrayEquals(((AmValue.Bytes) values.get(4)).getValue(), "bytes".getBytes());
Assertions.assertEquals(((AmValue.Bool) values.get(5)).getValue(), true);
Assertions.assertInstanceOf(AmValue.Null.class, values.get(6));
Assertions.assertEquals(((AmValue.Counter) values.get(7)).getValue().getValue(), 3);
Assertions.assertEquals(((AmValue.Counter) values.get(7)).getValue(), 3);
Assertions.assertEquals(((AmValue.Timestamp) values.get(8)).getValue(), now);
Assertions.assertEquals(((AmValue.List) values.get(9)).getId(), innerList);
Assertions.assertEquals(((AmValue.Map) values.get(10)).getId(), map);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/test/java/org/automerge/TestSetList.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void testSetDateInList() {
@Test
public void testSetCounterInList() {
tx.set(list, 0, new Counter(10));
Assertions.assertEquals(new Counter(10), ((AmValue.Counter) doc.get(list, 0).get()).getValue());
Assertions.assertEquals(10, ((AmValue.Counter) doc.get(list, 0).get()).getValue());
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions lib/src/test/java/org/automerge/TestSplice.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public void testSpliceDate() {
@Test
public void testSpliceCounter() {
testSplice2(NewValue.counter(1), NewValue.counter(2), (elem1, elem2) -> {
Assertions.assertEquals(new Counter(1), ((AmValue.Counter) elem1).getValue());
Assertions.assertEquals(new Counter(2), ((AmValue.Counter) elem2).getValue());
Assertions.assertEquals(1, ((AmValue.Counter) elem1).getValue());
Assertions.assertEquals(2, ((AmValue.Counter) elem2).getValue());
});
}
}
Expand Down
3 changes: 1 addition & 2 deletions lib/src/test/java/org/automerge/TestTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ public final void setNullInMap() {
@Test
public final void setCounterInMap() {
tx.set(ObjectId.ROOT, "counter", new Counter(10));
Assertions.assertEquals(new Counter(10),
((AmValue.Counter) doc.get(ObjectId.ROOT, "counter").get()).getValue());
Assertions.assertEquals(10, ((AmValue.Counter) doc.get(ObjectId.ROOT, "counter").get()).getValue());
}

@Test
Expand Down

0 comments on commit d08ebde

Please sign in to comment.