Skip to content

Commit

Permalink
Apply java 17 best praticles
Browse files Browse the repository at this point in the history
  • Loading branch information
velo committed Aug 21, 2024
1 parent 45af8a9 commit 934738e
Show file tree
Hide file tree
Showing 92 changed files with 352 additions and 413 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ private List evaluateSingleSource(
final List<Expression<?>> sources = Collections.<Expression<?>>singletonList(source);
final Iterable<?> iterable = iterables.values().iterator().next();
List<?> list;
if (iterable instanceof List) {
list = (List) iterable;
if (iterable instanceof List<?> list1) {
list = list1;
} else {
list = IteratorAdapter.asList(iterable.iterator());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public MultiComparator(Evaluator<Object[]> ev, boolean[] directions, boolean[] n

@Override
public int compare(T o1, T o2) {
if (o1 instanceof Object[]) {
return innerCompare(ev.evaluate((Object[]) o1), ev.evaluate((Object[]) o2));
if (o1 instanceof Object[] objects) {
return innerCompare(ev.evaluate(objects), ev.evaluate((Object[]) o2));
} else {
return innerCompare(ev.evaluate(o1), ev.evaluate(o2));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public BooleanBuilder clone() throws CloneNotSupportedException {
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o instanceof BooleanBuilder) {
return Objects.equals(((BooleanBuilder) o).getValue(), predicate);
} else if (o instanceof BooleanBuilder builder) {
return Objects.equals(builder.getValue(), predicate);
} else {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private void addLastJoin() {
public void addJoin(JoinType joinType, Expression<?> expr) {
addLastJoin();
if (!exprInJoins.contains(expr)) {
if (expr instanceof Path && ((Path<?>) expr).getMetadata().isRoot()) {
if (expr instanceof Path<?> path && path.getMetadata().isRoot()) {
exprInJoins.add(expr);
} else {
validate(expr);
Expand Down Expand Up @@ -378,8 +378,7 @@ public void setValidatingVisitor(ValidatingVisitor visitor) {

@Override
public boolean equals(Object o) {
if (o instanceof QueryMetadata) {
var q = (QueryMetadata) o;
if (o instanceof QueryMetadata q) {
return q.getFlags().equals(flags)
&& q.getGroupBy().equals(groupBy)
&& Objects.equals(q.getHaving(), having)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ public int hashCode() {
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o instanceof JoinExpression) {
var j = (JoinExpression) o;
} else if (o instanceof JoinExpression j) {
return Objects.equals(condition, j.condition)
&& Objects.equals(target, j.target)
&& Objects.equals(type, j.type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public int hashCode() {
public boolean equals(Object obj) {
if (obj == this) {
return true;
} else if (obj instanceof JoinFlag) {
return ((JoinFlag) obj).flag.equals(flag);
} else if (obj instanceof JoinFlag joinFlag) {
return joinFlag.flag.equals(flag);
} else {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ public int hashCode() {
public boolean equals(Object obj) {
if (obj == this) {
return true;
} else if (obj instanceof QueryFlag) {
var other = (QueryFlag) obj;
} else if (obj instanceof QueryFlag other) {
return other.position.equals(position) && other.flag.equals(flag);
} else {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ public <T> List<T> subList(List<T> list) {
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o instanceof QueryModifiers) {
var qm = (QueryModifiers) o;
} else if (o instanceof QueryModifiers qm) {
return Objects.equals(qm.getLimit(), limit) && Objects.equals(qm.getOffset(), offset);
} else {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ public final class Alias {
final Object current = aliasFactory.getCurrentAndReset();
if (arg instanceof CollectionPath) {
return (CollectionPath<D, SimpleExpression<D>>) arg; // NOSONAR
} else if (arg instanceof ManagedObject) {
return (CollectionPath<D, SimpleExpression<D>>) ((ManagedObject) arg).__mappedPath();
} else if (arg instanceof ManagedObject object) {
return (CollectionPath<D, SimpleExpression<D>>) object.__mappedPath();
} else {
return (CollectionPath<D, SimpleExpression<D>>) current;
}
Expand Down Expand Up @@ -242,8 +242,8 @@ public final class Alias {
final Object current = aliasFactory.getCurrentAndReset();
if (arg instanceof ListPath) {
return (ListPath<D, SimpleExpression<D>>) arg; // NOSONAR
} else if (arg instanceof ManagedObject) {
return (ListPath<D, SimpleExpression<D>>) ((ManagedObject) arg).__mappedPath();
} else if (arg instanceof ManagedObject object) {
return (ListPath<D, SimpleExpression<D>>) object.__mappedPath();
} else {
return (ListPath<D, SimpleExpression<D>>) current;
}
Expand Down Expand Up @@ -272,8 +272,8 @@ public final class Alias {
final Object current = aliasFactory.getCurrentAndReset();
if (arg instanceof MapPath) {
return (MapPath<K, V, SimpleExpression<V>>) arg; // NOSONAR
} else if (arg instanceof ManagedObject) {
return (MapPath<K, V, SimpleExpression<V>>) ((ManagedObject) arg).__mappedPath();
} else if (arg instanceof ManagedObject object) {
return (MapPath<K, V, SimpleExpression<V>>) object.__mappedPath();
} else {
return (MapPath<K, V, SimpleExpression<V>>) current;
}
Expand All @@ -291,8 +291,8 @@ public final class Alias {
final Object current = aliasFactory.getCurrentAndReset();
if (arg instanceof SetPath) {
return (SetPath<D, SimpleExpression<D>>) arg; // NOSONAR
} else if (arg instanceof ManagedObject) {
return (SetPath<D, SimpleExpression<D>>) ((ManagedObject) arg).__mappedPath();
} else if (arg instanceof ManagedObject object) {
return (SetPath<D, SimpleExpression<D>>) object.__mappedPath();
} else {
return (SetPath<D, SimpleExpression<D>>) current;
}
Expand Down Expand Up @@ -351,8 +351,8 @@ public final class Alias {
final Object current = aliasFactory.getCurrentAndReset();
if (arg instanceof EntityPath<?>) {
return (EntityPathBase<D>) arg; // NOSONAR
} else if (arg instanceof ManagedObject) {
return (EntityPathBase<D>) ((ManagedObject) arg).__mappedPath();
} else if (arg instanceof ManagedObject object) {
return (EntityPathBase<D>) object.__mappedPath();
} else {
return (EntityPathBase<D>) current;
}
Expand All @@ -364,8 +364,8 @@ private static <D, P extends Path<D>> P getPath(D arg) {
final Object current = aliasFactory.getCurrentAndReset();
if (arg instanceof Path<?>) {
return (P) arg;
} else if (arg instanceof ManagedObject) {
return (P) ((ManagedObject) arg).__mappedPath();
} else if (arg instanceof ManagedObject object) {
return (P) object.__mappedPath();
} else {
return (P) current;
}
Expand Down Expand Up @@ -415,8 +415,8 @@ public static <A> A alias(Class<A> cl, String var) {
@SuppressWarnings("unchecked")
public static <D> Expression<D> getAny(D arg) {
Object current = aliasFactory.getCurrentAndReset();
if (arg instanceof ManagedObject) {
return (Expression<D>) ((ManagedObject) arg).__mappedPath();
if (arg instanceof ManagedObject object) {
return (Expression<D>) object.__mappedPath();
} else if (current != null) {
return (Expression<D>) current;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,12 @@ protected AbstractGroupByTransformer(Expression<K> key, Expression<?>... express
projection.add(key);

for (Expression<?> expr : expressions) {
if (expr instanceof GroupExpression<?, ?>) {
GroupExpression<?, ?> groupExpr = (GroupExpression<?, ?>) expr;
if (expr instanceof GroupExpression<?, ?> groupExpr) {
groupExpressions.add(groupExpr);
Expression<?> colExpression = groupExpr.getExpression();
if (colExpression instanceof Operation
&& ((Operation) colExpression).getOperator() == Ops.ALIAS) {
projection.add(((Operation) colExpression).getArg(0));
if (colExpression instanceof Operation<?> operation
&& operation.getOperator() == Ops.ALIAS) {
projection.add(operation.getArg(0));
} else {
projection.add(colExpression);
}
Expand All @@ -100,8 +99,8 @@ protected static FactoryExpression<Tuple> withoutGroupExpressions(
final FactoryExpression<Tuple> expr) {
List<Expression<?>> args = new ArrayList<>(expr.getArgs().size());
for (Expression<?> arg : expr.getArgs()) {
if (arg instanceof GroupExpression) {
args.add(((GroupExpression) arg).getExpression());
if (arg instanceof GroupExpression<?, ?> expression) {
args.add(expression.getExpression());
} else {
args.add(arg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ public GroupImpl(List<GroupExpression<?, ?>> columnDefinitions, List<QPair<?, ?>
collector = coldef.createGroupCollector();
Expression<?> coldefExpr = coldef.getExpression();
groupCollectorMap.put(coldefExpr, collector);
if (coldefExpr instanceof Operation
&& ((Operation) coldefExpr).getOperator() == Ops.ALIAS) {
groupCollectorMap.put(((Operation) coldefExpr).getArg(1), collector);
if (coldefExpr instanceof Operation<?> operation && operation.getOperator() == Ops.ALIAS) {
groupCollectorMap.put(operation.getArg(1), collector);
}
}
groupCollectors.add(collector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public class CollectionAnyVisitor implements Visitor<Expression<?>, Context> {
private static <T> Path<T> replaceParent(Path<T> path, Path<?> parent) {
var metadata =
new PathMetadata(parent, path.getMetadata().getElement(), path.getMetadata().getPathType());
if (path instanceof CollectionExpression) {
CollectionExpression<?, ?> col = (CollectionExpression<?, ?>) path;
if (path instanceof CollectionExpression<?, ?> col) {
return Expressions.listPath(col.getParameter(0), SimplePath.class, metadata);
} else {
return ExpressionUtils.path(path.getType(), metadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public ConstantHidingExpression(FactoryExpression<T> expr) {
for (var i = 0; i < template.length; i++) {
Expression<?> arg = expr.getArgs().get(i);
Expression<?> unwrapped = unwrap(arg);
if (unwrapped instanceof Constant) {
template[i] = ((Constant<?>) unwrapped).getConstant();
if (unwrapped instanceof Constant<?> constant) {
template[i] = constant.getConstant();
} else if (unwrapped.equals(Expressions.TRUE)) {
template[i] = Boolean.TRUE;
} else if (unwrapped.equals(Expressions.FALSE)) {
Expand All @@ -64,8 +64,8 @@ public ConstantHidingExpression(FactoryExpression<T> expr) {

private static Expression<?> unwrap(Expression<?> expr) {
expr = ExpressionUtils.extract(expr);
if (expr instanceof Operation && ((Operation<?>) expr).getOperator() == Ops.ALIAS) {
return ((Operation<?>) expr).getArg(0);
if (expr instanceof Operation<?> operation && operation.getOperator() == Ops.ALIAS) {
return operation.getArg(0);
}
return expr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public T newInstance(Object... args) {
@SuppressWarnings("unchecked") // The expression type is an enum
var rv = (T) Enum.valueOf(getType().asSubclass(Enum.class), args[0].toString());
return rv;
} else if (args[0] instanceof Number) {
return values[((Number) args[0]).intValue()];
} else if (args[0] instanceof Number number) {
return values[number.intValue()];
} else {
@SuppressWarnings("unchecked")
var rv = (T) args[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ protected <T> T uniqueResult(CloseableIterator<T> it) {
public final boolean equals(Object o) {
if (o == this) {
return true;
} else if (o instanceof SubQueryExpression) {
SubQueryExpression<?> s = (SubQueryExpression<?>) o;
} else if (o instanceof SubQueryExpression<?> s) {
return s.getMetadata().equals(queryMixin.getMetadata());
} else {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ public T newInstance(Object... args) {
for (var i = 0; i < args.length; i++) {
Class<?> type = expr.getArgs().get(i).getType();
if (Enum.class.isAssignableFrom(type) && !type.isInstance(args[i])) {
if (args[i] instanceof String) {
args[i] = Enum.valueOf((Class) type, (String) args[i]);
} else if (args[i] instanceof Number) {
args[i] = getValues((Class) type)[((Number) args[i]).intValue()];
if (args[i] instanceof String string) {
args[i] = Enum.valueOf((Class) type, string);
} else if (args[i] instanceof Number number) {
args[i] = getValues((Class) type)[number.intValue()];
}
} else if (args[i] instanceof Number && !type.isInstance(args[i])) {
} else if (args[i] instanceof Number number && !type.isInstance(args[i])) {
if (type.equals(Boolean.class)) {
args[i] = ((Number) args[i]).intValue() > 0;
args[i] = number.intValue() > 0;
} else if (Number.class.isAssignableFrom(type)) {
args[i] = MathUtils.cast((Number) args[i], (Class) type);
args[i] = MathUtils.cast(number, (Class) type);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public Void visit(TemplateExpression<?> expr, List<Path<?>> paths) {

public Path<?> visit(Collection<?> exprs, List<Path<?>> paths) {
for (Object e : exprs) {
if (e instanceof Expression) {
((Expression<?>) e).accept(this, paths);
if (e instanceof Expression<?> expression) {
expression.accept(this, paths);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ public <P> Q set(ParamExpression<P> param, P value) {
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o instanceof QueryBase) {
var q = (QueryBase) o;
} else if (o instanceof QueryBase<?> q) {
return q.queryMixin.equals(queryMixin);
} else {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ private Path<?> normalizePath(Path<?> expr) {
@SuppressWarnings({"rawtypes", "unchecked"})
public <RT> Expression<RT> convert(Expression<RT> expr, Role role) {
if (expandAnyPaths) {
if (expr instanceof Path) {
expr = (Expression) normalizePath((Path) expr);
if (expr instanceof Path<?> path) {
expr = (Expression) normalizePath(path);
} else if (expr != null) {
expr = (Expression) expr.accept(replaceVisitor, null);
}
}
if (expr instanceof ProjectionRole<?>) {
return convert(((ProjectionRole) expr).getProjection(), role);
if (expr instanceof ProjectionRole pr) {
return convert((pr).getProjection(), role);
} else if (expr instanceof FactoryExpression<?>
&& !(expr instanceof FactoryExpressionAdapter<?>)) {
return FactoryExpressionUtils.wrap((FactoryExpression<RT>) expr);
Expand Down Expand Up @@ -437,8 +437,7 @@ public final T where(Predicate... o) {
public final boolean equals(Object o) {
if (o == this) {
return true;
} else if (o instanceof QueryMixin<?>) {
QueryMixin<?> q = (QueryMixin<?>) o;
} else if (o instanceof QueryMixin<?> q) {
return q.metadata.equals(metadata);
} else {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public <T> Publisher<T> transform(ReactiveResultTransformer<T> transformer) {
public final boolean equals(Object o) {
if (o == this) {
return true;
} else if (o instanceof SubQueryExpression) {
SubQueryExpression<?> s = (SubQueryExpression<?>) o;
} else if (o instanceof SubQueryExpression<?> s) {
return s.getMetadata().equals(queryMixin.getMetadata());
} else {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public Expression<?> visit(Path<?> expr, C context) {
var metadata = expr.getMetadata();
Path<?> parent = (Path) metadata.getParent().accept(this, context);
var element = metadata.getElement();
if (element instanceof Expression<?>) {
element = ((Expression<?>) element).accept(this, context);
if (element instanceof Expression<?> expression) {
element = expression.accept(this, context);
}
if (parent.equals(metadata.getParent()) && Objects.equals(element, metadata.getElement())) {
return expr;
Expand Down Expand Up @@ -155,8 +155,8 @@ public Expression<?> visit(SubQueryExpression<?> expr, C context) {
public Expression<?> visit(TemplateExpression<?> expr, C context) {
ArrayList args = new ArrayList<>();
for (Object arg : expr.getArgs()) {
if (arg instanceof Expression) {
args.add(((Expression<?>) arg).accept(this, context));
if (arg instanceof Expression<?> expression) {
args.add(expression.accept(this, context));
} else {
args.add(arg);
}
Expand Down
Loading

0 comments on commit 934738e

Please sign in to comment.