Skip to content

Commit

Permalink
Code cleanup: generics and warnings removal
Browse files Browse the repository at this point in the history
Signed-off-by: Tomáš Kraus <tomas.kraus@oracle.com>
  • Loading branch information
Tomas-Kraus authored and lukasj committed Oct 17, 2023
1 parent 1c38e0f commit 5b39993
Show file tree
Hide file tree
Showing 13 changed files with 415 additions and 341 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@
public class BasicTypeHelperImpl {

/** Set of numeric types and its wrapper classes. */
private static Set numericTypes = new HashSet();
private static final Set<Class<?>> numericTypes = new HashSet<>();
/** Set of integral types and its wrapper classes. */
private static Set integralTypes = new HashSet();
private static final Set<Class<?>> integralTypes = new HashSet<>();
/** Set of floating point types and its wrapper classes. */
private static Set floatingPointTypes = new HashSet();
private static final Set<Class<? extends Number>> floatingPointTypes = new HashSet<>();
/** Set of date classes. */
private static Set dateClasses = new HashSet();
private static final Set<Class<?>> dateClasses = new HashSet<>();
/** Set of time classes. */
private static Set timeClasses = new HashSet();
private static final Set<Class<?>> timeClasses = new HashSet<>();
/** Maps primtives types to their wrapper classes. */
private static Map<Class<?>, Class<?>> primitiveToWrapper = new HashMap<>();
private static final Map<Class<?>, Class<?>> primitiveToWrapper = new HashMap<>();
/** Maps wrapper classes to their primitive types. */
private static Map<Class<?>, Class<?>> wrapperToPrimitive = new HashMap<>();
private static final Map<Class<?>, Class<?>> wrapperToPrimitive = new HashMap<>();

static {
// Initialize set of integral types plus their wrapper classes
Expand Down Expand Up @@ -123,135 +123,135 @@ public String getTypeName(Object type) {
public Class<?> getJavaClass(Object type) {
Class<?> clazz = null;
if (type instanceof Class) {
clazz = (Class)type;
clazz = (Class<?>)type;
} else if (type instanceof ClassDescriptor) {
clazz = ((ClassDescriptor)type).getJavaClass();
}
return clazz;
}

/** Returns the Object type representation.*/
public Object getObjectType() {
public Class<?> getObjectType() {
return Object.class;
}

/** Returns the boolean type representation.*/
public Object getBooleanType() {
public Class<?> getBooleanType() {
return boolean.class;
}

/** Returns the Boolean class representation.*/
public Object getBooleanClassType() {
public Class<?> getBooleanClassType() {
return Boolean.class;
}

/** Returns the char type representation.*/
public Object getCharType() {
public Class<?> getCharType() {
return char.class;
}

/** Returns the Date type representation.*/
public Object getSQLDateType() {
public Class<?> getSQLDateType() {
return java.sql.Date.class;
}

/** Returns the Time type representation.*/
public Object getTimeType() {
public Class<?> getTimeType() {
return java.sql.Time.class;
}

/** Returns the timestamp type representation.*/
public Object getTimestampType() {
public Class<?> getTimestampType() {
return java.sql.Timestamp.class;
}

/** Returns the Character class representation.*/
public Object getCharacterClassType() {
public Class<?> getCharacterClassType() {
return Character.class;
}

/** Returns the byte type representation.*/
public Object getByteType() {
public Class<?> getByteType() {
return byte.class;
}

/** Returns the Byte class representation.*/
public Object getByteClassType() {
public Class<?> getByteClassType() {
return Byte.class;
}

/** Returns the short type representation.*/
public Object getShortType() {
public Class<?> getShortType() {
return short.class;
}

/** Returns the Short class representation.*/
public Object getShortClassType() {
public Class<?> getShortClassType() {
return Short.class;
}

/** Returns the int type representation.*/
public Object getIntType() {
public Class<?> getIntType() {
return int.class;
}

/** Returns the Inter class representation.*/
public Object getIntegerClassType() {
public Class<?> getIntegerClassType() {
return Integer.class;
}

/** Returns the long type representation.*/
public Object getLongType() {
public Class<?> getLongType() {
return long.class;
}

/** Returns the type representation of class Long.*/
public Object getLongClassType() {
public Class<?> getLongClassType() {
return Long.class;
}

/** Returns the type representation of class Map.Entry.*/
public Object getMapEntryType(){
public Class<?> getMapEntryType(){
return Map.Entry.class;
}

/** Returns the float type representation.*/
public Object getFloatType() {
public Class<?> getFloatType() {
return float.class;
}

/** Returns the type representation of class Float.*/
public Object getFloatClassType() {
public Class<?> getFloatClassType() {
return Float.class;
}

/** Returns the double type representation.*/
public Object getDoubleType() {
public Class<?> getDoubleType() {
return double.class;
}

/** Returns the type representation of class Double.*/
public Object getDoubleClassType() {
public Class<?> getDoubleClassType() {
return Double.class;
}

/** Returns the String type representation.*/
public Object getStringType() {
public Class<?> getStringType() {
return String.class;
}

/** Returns the BigInteger type representation.*/
public Object getBigIntegerType() {
public Class<?> getBigIntegerType() {
return BigInteger.class;
}

/** Returns the BigDecimal type representation.*/
public Object getBigDecimalType() {
public Class<?> getBigDecimalType() {
return BigDecimal.class;
}

/** Returns the java.util.Date type representation.*/
public Object getDateType() {
public Class<?> getDateType() {
return Date.class;
}

Expand Down Expand Up @@ -327,7 +327,7 @@ public boolean isIntType(Object type) {
/**
* Returns true if type is the int primitive type or the Integer wrapper class
*/
public boolean isIntegerType(Object type) {
public boolean isIntegerType(Class<?> type) {
return isIntType(type);
}

Expand Down Expand Up @@ -477,6 +477,12 @@ public Object extendedBinaryNumericPromotion(Object left, Object right) {
return promoted;
}

// extendedBinaryNumericPromotion with class cast, shortcut for CriteriaBuilderImpl
@SuppressWarnings("unchecked")
public <T> Class<T> extendedBinaryNumericPromotionClass(Class<?> left, Class<?> right) {
return (Class<T>) extendedBinaryNumericPromotion(left, right);
}

// Helper methods

/** Returns the primitive for the specified wrapper class. */
Expand All @@ -494,7 +500,7 @@ protected Object binaryNumericPromotion(Object left, Object right) {
if ((left == null) || (right == null)) {
return null;
}
Object type = null;
Class<?> type = null;

if (left == getDoubleType() || right == getDoubleType()) {
type = getDoubleType();
Expand All @@ -507,5 +513,6 @@ protected Object binaryNumericPromotion(Object left, Object right) {
}
return type;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
// - New Jakarta Persistence 3.2 Features
package org.eclipse.persistence.internal.jpa.querydef;

import java.io.Serial;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
Expand All @@ -31,7 +33,6 @@
import jakarta.persistence.criteria.Root;
import jakarta.persistence.metamodel.EntityType;
import jakarta.persistence.metamodel.Metamodel;

import org.eclipse.persistence.expressions.ExpressionBuilder;

/**
Expand All @@ -50,6 +51,7 @@
*/
public abstract class AbstractQueryImpl<T> extends CommonAbstractCriteriaImpl<T> implements AbstractQuery<T> {

@Serial
private static final long serialVersionUID = -5270020290752637882L;

protected ResultType queryResult;
Expand All @@ -65,7 +67,7 @@ protected enum ResultType{

public AbstractQueryImpl(Metamodel metamodel, ResultType queryResult, CriteriaBuilderImpl queryBuilder, Class<T> resultType){
super(metamodel, queryBuilder, resultType);
this.roots = new HashSet<Root<?>>();
this.roots = new HashSet<>();
this.queryResult = queryResult;
this.baseExpression = new ExpressionBuilder();
}
Expand Down Expand Up @@ -98,10 +100,8 @@ public AbstractQuery<T> groupBy(List<Expression<?>> grouping){
*/
@Override
public AbstractQuery<T> groupBy(Expression<?>... grouping){
this.groupBy = new ArrayList<Expression<?>>();
for (Expression<?> exp : grouping){
this.groupBy.add(exp);
}
this.groupBy = new ArrayList<>();
Collections.addAll(this.groupBy, grouping);
return this;
}

Expand Down Expand Up @@ -147,7 +147,7 @@ public AbstractQuery<T> having(List<Predicate> restrictions) {
return this;
}

public abstract void addJoin(FromImpl join);
public abstract void addJoin(FromImpl<?, ?> join);

/**
* Specify whether duplicate query results will be eliminated. A true value
Expand All @@ -173,15 +173,15 @@ protected org.eclipse.persistence.expressions.Expression getBaseExpression() {
return getBaseExpression(null);
}

protected org.eclipse.persistence.expressions.Expression getBaseExpression(Root root) {
protected org.eclipse.persistence.expressions.Expression getBaseExpression(Root<?> root) {
if (this.roots.isEmpty()) {
baseExpression = new ExpressionBuilder();
} else if (this.roots.size() == 1) {
baseExpression = ((RootImpl) this.roots.iterator().next()).getCurrentNode();
baseExpression = ((RootImpl<?>) this.roots.iterator().next()).getCurrentNode();
} else if (root != null) {
for (Root r : this.roots) {
for (Root<?> r : this.roots) {
if (r == root) {
baseExpression = ((RootImpl) r).getCurrentNode();
baseExpression = ((RootImpl<?>) r).getCurrentNode();
}
}
}
Expand All @@ -195,7 +195,7 @@ protected org.eclipse.persistence.expressions.Expression getBaseExpression(Root
@Override
public List<Expression<?>> getGroupList(){
if (this.groupBy == null){
this.groupBy = new ArrayList<Expression<?>>();
this.groupBy = new ArrayList<>();
}
return this.groupBy;
}
Expand All @@ -222,10 +222,8 @@ public Set<Root<?>> getRoots(){
}

@Override
protected void integrateRoot(RootImpl root) {
if (!this.roots.contains(root)) {
this.roots.add(root);
}
protected void integrateRoot(RootImpl<?> root) {
this.roots.add(root);
}

/**
Expand All @@ -239,7 +237,7 @@ public boolean isDistinct(){
return this.distinct;
}

protected void findJoins(FromImpl root) {
protected void findJoins(FromImpl<?, ?> root) {
root.findJoins(this);
}

Expand Down

0 comments on commit 5b39993

Please sign in to comment.