Skip to content

Commit 5d07811

Browse files
committed
noticket: Minor InMemoryQueries cleanup
- Use switch expression in visitors - Relax generic bounds in `InMemoryQueries.toComparator()` (`T` need **not** extend `Entity<T>`)
1 parent ea69462 commit 5d07811

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

repository/src/main/java/tech/ydb/yoj/repository/db/list/InMemoryQueries.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,28 +103,20 @@ public Predicate<T> visitScalarExpr(@NonNull ScalarExpr<T> scalarExpr) {
103103

104104
@Override
105105
public Predicate<T> visitNullExpr(@NonNull NullExpr<T> nullExpr) {
106-
switch (nullExpr.getOperator()) {
107-
case IS_NULL:
108-
return nullExpr::isActualValueNull;
109-
case IS_NOT_NULL:
110-
return not(nullExpr::isActualValueNull);
111-
default:
112-
throw new UnsupportedOperationException("Unsupported operator in nullability expression: " + nullExpr.getOperator());
113-
}
106+
return switch (nullExpr.getOperator()) {
107+
case IS_NULL -> nullExpr::isActualValueNull;
108+
case IS_NOT_NULL -> not(nullExpr::isActualValueNull);
109+
};
114110
}
115111

116112
@Override
117113
public Predicate<T> visitListExpr(@NonNull ListExpr<T> listExpr) {
118114
Function<T, Comparable<?>> getActual = listExpr::getActualValue;
119115
List<Comparable<?>> expected = listExpr.getExpectedValues();
120-
switch (listExpr.getOperator()) {
121-
case IN:
122-
return obj -> expected.contains(getActual.apply(obj));
123-
case NOT_IN:
124-
return obj -> !expected.contains(getActual.apply(obj));
125-
default:
126-
throw new UnsupportedOperationException("Unsupported operator in filter expression: " + listExpr.getOperator());
127-
}
116+
return switch (listExpr.getOperator()) {
117+
case IN -> obj -> expected.contains(getActual.apply(obj));
118+
case NOT_IN -> obj -> !expected.contains(getActual.apply(obj));
119+
};
128120
}
129121

130122
@Override
@@ -148,7 +140,7 @@ public Predicate<T> visitNotExpr(@NonNull NotExpr<T> notExpr) {
148140
});
149141
}
150142

151-
public static <T extends Entity<T>> Comparator<T> toComparator(@NonNull OrderExpression<T> orderBy) {
143+
public static <T> Comparator<T> toComparator(@NonNull OrderExpression<T> orderBy) {
152144
if (orderBy.isUnordered()) {
153145
// Produces a randomly-ordering, but stable Comparator. UUID.randomUUID() collisions are extremely unlikely, so we ignore them.
154146
Map<Object, UUID> randomIds = new IdentityHashMap<>();

repository/src/main/java/tech/ydb/yoj/repository/db/list/ViewListResult.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ public ViewListResult<T, V> returnWithParams(@NonNull ListRequest.ListingParams<
4545
}
4646

4747
@NonNull
48-
private static <T extends Entity<T>, V extends Table.View> ViewSchema<V> getViewSchema(@NonNull ListRequest<T> request, @NonNull Class<V> viewClass) {
48+
private static <T extends Entity<T>, V extends Table.View> ViewSchema<V> getViewSchema(
49+
@NonNull ListRequest<T> request,
50+
@NonNull Class<V> viewClass
51+
) {
4952
if (!(request.getSchema() instanceof EntitySchema<?> entitySchema)) {
50-
throw new IllegalArgumentException("Expected ListRequest for an entity, but got a non-entity schema of type "
51-
+ "<" + request.getSchema().getClass().getName() + ">");
53+
throw new IllegalArgumentException("Expected ListRequest for an entity, but got a non-entity schema: " + request.getSchema());
5254
}
5355
return entitySchema.getViewSchema(viewClass);
5456
}

0 commit comments

Comments
 (0)