Skip to content

Commit

Permalink
Deleted CommonUtil.java and restored JavaUtil to previous state.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lur1an committed Nov 18, 2022
1 parent a4b065f commit dbe627d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 81 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;

import org.apache.commons.lang3.ClassUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Provides type operations, mainly checks and casts for Java Primitives, to be used in the templates
*
*/
public class JavaUtil extends CommonUtil {
public class JavaUtil {

/**
* Logger for this class
*/
private static final Logger LOG = LoggerFactory.getLogger(JavaUtil.class);

/**
* The constructor.
Expand Down Expand Up @@ -54,7 +62,7 @@ public String boxJavaPrimitives(Class<?> pojoClass, String fieldName) throws NoS

if (pojoClass == null) {
throw new IllegalAccessError(
"Class object is null. Cannot generate template as it might obviously depend on reflection.");
"Class object is null. Cannot generate template as it might obviously depend on reflection.");
}

if (equalsJavaPrimitive(pojoClass, fieldName)) {
Expand Down Expand Up @@ -114,7 +122,7 @@ public boolean equalsJavaPrimitiveOrWrapper(String simpleType) {
* @throws SecurityException if the field cannot be accessed.
*/
public boolean equalsJavaPrimitive(Class<?> pojoClass, String fieldName)
throws NoSuchFieldException, SecurityException {
throws NoSuchFieldException, SecurityException {

if (pojoClass == null) {
return false;
Expand Down Expand Up @@ -161,10 +169,10 @@ public boolean equalsJavaPrimitiveIncludingArrays(String simpleType) {
* @throws SecurityException if the field cannot be accessed.
*/
public boolean equalsJavaPrimitiveIncludingArrays(Class<?> pojoClass, String fieldName)
throws NoSuchFieldException, SecurityException {
throws NoSuchFieldException, SecurityException {

return equalsJavaPrimitive(pojoClass, fieldName) || (pojoClass.getDeclaredField(fieldName).getType().isArray()
&& pojoClass.getDeclaredField(fieldName).getType().getComponentType().isPrimitive());
&& pojoClass.getDeclaredField(fieldName).getType().getComponentType().isPrimitive());
}

/**
Expand Down Expand Up @@ -198,7 +206,7 @@ public String castJavaPrimitives(String simpleType, String varName) throws Class
* @throws SecurityException if the field cannot be accessed.
*/
public String castJavaPrimitives(Class<?> pojoClass, String fieldName)
throws NoSuchFieldException, SecurityException {
throws NoSuchFieldException, SecurityException {

if (equalsJavaPrimitive(pojoClass, fieldName)) {
return String.format("((%1$s)%2$s)", boxJavaPrimitives(pojoClass, fieldName), fieldName);
Expand All @@ -207,6 +215,31 @@ public String castJavaPrimitives(Class<?> pojoClass, String fieldName)
}
}

/**
* @param pojoClass {@link Class} the class object of the pojo
* @param fieldName {@link String} the name of the field
* @return true if the field is an instance of java.utils.Collections
* @throws NoSuchFieldException indicating something awefully wrong in the used model
* @throws SecurityException if the field cannot be accessed.
*/
public boolean isCollection(Class<?> pojoClass, String fieldName) throws NoSuchFieldException, SecurityException {

if (pojoClass == null) {
return false;
}

Field field = pojoClass.getDeclaredField(fieldName);
if (field == null) {
field = pojoClass.getField(fieldName);
}
if (field == null) {
return false;
} else {
return Collection.class.isAssignableFrom(field.getType());
}

}

/**
* Returns the Ext Type to a given java type
*
Expand Down Expand Up @@ -301,7 +334,7 @@ public String getReturnType(Class<?> pojoClass, String methodName) throws NoSuch

if (pojoClass == null) {
throw new IllegalAccessError(
"Class object is null. Cannot generate template as it might obviously depend on reflection.");
"Class object is null. Cannot generate template as it might obviously depend on reflection.");
}
String s = "-";
Method method = findMethod(pojoClass, methodName);
Expand All @@ -324,11 +357,11 @@ public String getReturnType(Class<?> pojoClass, String methodName) throws NoSuch
*/
@SuppressWarnings("unchecked")
public String getReturnTypeOfMethodAnnotatedWith(Class<?> pojoClass, String annotatedClassName)
throws ClassNotFoundException {
throws ClassNotFoundException {

if (pojoClass == null) {
throw new IllegalAccessError(
"Class object is null. Cannot generate template as it might obviously depend on reflection.");
"Class object is null. Cannot generate template as it might obviously depend on reflection.");
}

Method[] methods = pojoClass.getDeclaredMethods();
Expand Down Expand Up @@ -381,7 +414,7 @@ private Method findMethod(Class<?> pojoClass, String methodName) {

if (pojoClass == null) {
throw new IllegalAccessError(
"Class object is null. Cannot generate template as it might obviously depend on reflection.");
"Class object is null. Cannot generate template as it might obviously depend on reflection.");
}
for (Method m : pojoClass.getMethods()) {
if (m.getName().equals(methodName)) {
Expand All @@ -391,6 +424,22 @@ private Method findMethod(Class<?> pojoClass, String methodName) {
return null;
}

/**
* Checks whether the class given by the full qualified name is an enum
*
* @param className full qualified class name
* @return <code>true</code> if the class is an enum, <code>false</code> otherwise
*/
public boolean isEnum(String className) {

try {
return ClassUtils.getClass(className).isEnum();
} catch (ClassNotFoundException e) {
LOG.warn("{}: Could not find {}", e.getMessage(), className);
return false;
}
}

/**
* Returns the first enum value of an enum class
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Provides operations to identify and process SQL specific information
*
*/
public class SQLUtil extends CommonUtil {
public class SQLUtil {

private static int DEFAULT_FIELD_LENGTH = 255;

Expand Down

0 comments on commit dbe627d

Please sign in to comment.