Skip to content

Commit

Permalink
lambda can be replaced with method reference
Browse files Browse the repository at this point in the history
  • Loading branch information
msgui committed Feb 21, 2024
1 parent 8a9d733 commit b48108b
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ public enum ConditionType {

public enum RelationType implements BiPredicate<Object, Object> {

EQ("==", (v1, v2) -> {
return equals(v1, v2);
}),
EQ("==", RelationType::equals),

GT(">", (v1, v2) -> {
return compare(v1, v2) > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,7 @@ public Iterator<HugeEdge> query(Query query) {
ConditionQuery cq = cqs.get(0);
return this.query(cq);
}
return new FlatMapperIterator<>(cqs.iterator(), cq -> {
return this.query(cq);
});
return new FlatMapperIterator<>(cqs.iterator(), this::query);
}

private Iterator<HugeEdge> query(ConditionQuery query) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ final class IntMapBySegments implements IntMap {

private static final int DEFAULT_SEGMENTS = (IntSet.CPUS + 8) * 32;
private static final Function<Integer, IntMap> DEFAULT_CREATOR =
size -> new IntMapByFixedAddr(size);
IntMapByFixedAddr::new;

@SuppressWarnings("static-access")
private static final int BASE_OFFSET = UNSAFE.ARRAY_OBJECT_BASE_OFFSET;
Expand Down Expand Up @@ -232,7 +232,7 @@ private IntMap segment(int key) {

private IntMap segmentAt(int index) {
// volatile get this.maps[index]
long offset = (index << SHIFT) + BASE_OFFSET;
long offset = ((long) index << SHIFT) + BASE_OFFSET;
IntMap map = (IntMap) UNSAFE.getObjectVolatile(this.maps, offset);
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ final class IntSetBySegments implements IntSet {

private static final int DEFAULT_SEGMENTS = IntSet.CPUS * 100;
private static final Function<Integer, IntSet> DEFAULT_CREATOR =
size -> new IntSetByFixedAddr4Unsigned(size);
IntSetByFixedAddr4Unsigned::new;

@SuppressWarnings("static-access")
private static final int BASE_OFFSET = UNSAFE.ARRAY_OBJECT_BASE_OFFSET;
Expand Down Expand Up @@ -184,7 +184,7 @@ private IntSet segment(int key) {

private IntSet segmentAt(int index) {
// volatile get this.sets[index]
long offset = (index << SHIFT) + BASE_OFFSET;
long offset = ((long) index << SHIFT) + BASE_OFFSET;
IntSet set = (IntSet) UNSAFE.getObjectVolatile(this.sets, offset);
return set;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.hugegraph.backend.store.BackendFeatures;
import org.apache.hugegraph.backend.store.BackendMutation;
import org.apache.hugegraph.backend.store.BackendStoreProvider;
import org.apache.hugegraph.backend.store.BackendTable;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.exception.ConnectionException;
import org.apache.hugegraph.type.HugeType;
Expand Down Expand Up @@ -109,7 +110,7 @@ protected HbaseSessions.Session session(HugeType type) {
}

protected List<String> tableNames() {
return this.tables.values().stream().map(t -> t.table())
return this.tables.values().stream().map(BackendTable::table)

Check warning on line 113 in hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java#L113

Added line #L113 was not covered by tests
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public static class Edge extends CassandraTables.Edge {
private static final String LABEL = CassandraTable.formatKey(HugeKeys.LABEL);
private final List<String> keys = this.idColumnName().stream()
.filter(k -> k != HugeKeys.LABEL)
.map(k -> CassandraTable.formatKey(k))
.map(CassandraTable::formatKey)
.collect(Collectors.toList());
private final String prKeys = this.keys.stream()
.collect(Collectors.joining(","));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ public void testString() {
public void testType() {
Assert.assertEquals(HugeType.EDGE_OUT, Directions.OUT.type());
Assert.assertEquals(HugeType.EDGE_IN, Directions.IN.type());
Assert.assertThrows(IllegalArgumentException.class, () -> {
Directions.BOTH.type();
});
Assert.assertThrows(IllegalArgumentException.class, Directions.BOTH::type);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ public void testStringId() {
Assert.assertEquals(IdGenerator.of("test-id"), id);
Assert.assertNotEquals(IdGenerator.of("test-id2"), id);

Assert.assertThrows(IllegalArgumentException.class, () -> {
id.asLong();
});
Assert.assertThrows(IllegalArgumentException.class, id::asLong);

Assert.assertEquals("test-id", IdGenerator.asStoredString(id));
Assert.assertEquals(id, IdGenerator.ofStoredString("test-id",
Expand Down Expand Up @@ -123,9 +121,7 @@ public void testUuidId() {
Assert.assertNotEquals(id3, id);
Assert.assertNotEquals(id4, id);

Assert.assertThrows(UnsupportedOperationException.class, () -> {
id.asLong();
});
Assert.assertThrows(UnsupportedOperationException.class, id::asLong);

Assert.assertEquals("g14RU5KBSVeGkc95JY6Q6w==",
IdGenerator.asStoredString(id));
Expand All @@ -142,25 +138,17 @@ public void testObjectId() {
Assert.assertEquals(object, id.asObject());
Assert.assertEquals(object.hashCode(), id.hashCode());
Assert.assertEquals(object.toString(), id.toString());
Assert.assertTrue(id.equals(IdGenerator.of(object)));
Assert.assertFalse(id.equals(IdGenerator.of(object2)));
Assert.assertFalse(id.equals(object));
Assert.assertEquals(id, IdGenerator.of(object));
Assert.assertNotEquals(id, IdGenerator.of(object2));
Assert.assertNotEquals(id, object);

Assert.assertThrows(UnsupportedOperationException.class, () -> {
id.asString();
});
Assert.assertThrows(UnsupportedOperationException.class, () -> {
id.asLong();
});
Assert.assertThrows(UnsupportedOperationException.class, () -> {
id.asBytes();
});
Assert.assertThrows(UnsupportedOperationException.class, id::asString);
Assert.assertThrows(UnsupportedOperationException.class, id::asLong);
Assert.assertThrows(UnsupportedOperationException.class, id::asBytes);
Assert.assertThrows(UnsupportedOperationException.class, () -> {
id.compareTo(id);
});
Assert.assertThrows(UnsupportedOperationException.class, () -> {
id.length();
});
Assert.assertThrows(UnsupportedOperationException.class, id::length);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ public void testNotImplemented() {
TableBackendEntry entry = new TableBackendEntry(HugeType.VERTEX);
BackendColumn col = BackendColumn.of(new byte[]{1}, new byte[]{12});

Assert.assertThrows(NotImplementedException.class, () -> {
entry.columnsSize();
});
Assert.assertThrows(NotImplementedException.class, entry::columnsSize);
Assert.assertThrows(NotImplementedException.class, () -> {
entry.columns();
});
Expand All @@ -185,8 +183,6 @@ public void testNotImplemented() {
Assert.assertThrows(NotImplementedException.class, () -> {
entry.merge(entry);
});
Assert.assertThrows(NotImplementedException.class, () -> {
entry.clear();
});
Assert.assertThrows(NotImplementedException.class, entry::clear);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@ public void testIntFixedMapBySegmentsPut() {
for (int i = 0; i < capacity; i++) {
Assert.assertTrue(map.put(i, i * i));
Assert.assertEquals(i * i, map.get(i));
Assert.assertEquals(true, map.containsKey(i));
Assert.assertEquals(false, map.containsKey(i + 1));
Assert.assertTrue(map.containsKey(i));
Assert.assertFalse(map.containsKey(i + 1));

int u = -i - 1;
Assert.assertTrue(map.put(u, u));
Assert.assertEquals(u, map.get(u));
Assert.assertEquals(true, map.containsKey(u));
Assert.assertEquals(false, map.containsKey(u - 1));
Assert.assertTrue(map.containsKey(u));
Assert.assertFalse(map.containsKey(u - 1));
}

IntIterator values = map.values();
Expand Down Expand Up @@ -297,17 +297,17 @@ public void testIntFixedMapBySegmentsPutRandom() {

Assert.assertTrue(map.put(k, k * k));
Assert.assertEquals(k * k, map.get(k));
Assert.assertEquals(true, map.containsKey(k));
Assert.assertTrue(map.containsKey(k));

int u = -k - 1;
Assert.assertTrue(map.put(u, u));
Assert.assertEquals(u, map.get(u));
Assert.assertEquals(true, map.containsKey(u));
Assert.assertTrue(map.containsKey(u));

int r = i % 2 == 0 ? k : u;
Assert.assertEquals(true, map.containsKey(r));
Assert.assertTrue(map.containsKey(r));
Assert.assertTrue(map.remove(r));
Assert.assertEquals(false, map.containsKey(r));
Assert.assertFalse(map.containsKey(r));
}

return map.size();
Expand All @@ -330,9 +330,7 @@ public void testIntFixedMapBySegmentsKeys() {
Assert.assertEquals(Integer.MAX_VALUE - 1, iter.next());
Assert.assertFalse(iter.hasNext());

Assert.assertThrows(NoSuchElementException.class, () -> {
iter.next();
}, e -> {
Assert.assertThrows(NoSuchElementException.class, iter::next, e -> {
Assert.assertNull(e.getMessage());
});
}
Expand All @@ -359,9 +357,7 @@ public void testIntFixedMapBySegmentsKeysWithMultiSegs() {
}

Assert.assertFalse(iter.hasNext());
Assert.assertThrows(NoSuchElementException.class, () -> {
iter.next();
}, e -> {
Assert.assertThrows(NoSuchElementException.class, iter::next, e -> {
Assert.assertNull(e.getMessage());
});
}
Expand All @@ -380,9 +376,7 @@ public void testIntFixedMapBySegmentsValues() {
Assert.assertEquals(1, iter.next());
Assert.assertFalse(iter.hasNext());

Assert.assertThrows(NoSuchElementException.class, () -> {
iter.next();
}, e -> {
Assert.assertThrows(NoSuchElementException.class, iter::next, e -> {
Assert.assertNull(e.getMessage());
});
}
Expand All @@ -409,9 +403,7 @@ public void testIntFixedMapBySegmentsValuesWithMultiSegs() {
}

Assert.assertFalse(iter.hasNext());
Assert.assertThrows(NoSuchElementException.class, () -> {
iter.next();
}, e -> {
Assert.assertThrows(NoSuchElementException.class, iter::next, e -> {
Assert.assertNull(e.getMessage());
});
}
Expand Down Expand Up @@ -457,7 +449,6 @@ protected void afterExecute(Runnable r, Throwable t) {
}
}
};
;

AtomicInteger size = new AtomicInteger();
int mapSize = 100;
Expand Down

0 comments on commit b48108b

Please sign in to comment.