Skip to content

Commit 9102fa2

Browse files
committed
#59 Rename all Util classes to Utils
1 parent e57759e commit 9102fa2

28 files changed

+372
-372
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ public static void main(String... args) {
6767

6868
```java
6969
public static void main(String... args) {
70-
AbstractArrayProperties arrayInfo = ArrayTypeUtil.getArrayProperty(String[][].class);
70+
AbstractArrayProperties arrayInfo = ArrayTypeUtils.getArrayProperty(String[][].class);
7171
// Outputs: "Component = class java.lang.String, dimension = 2"
7272
System.out.println("Component = " + arrayInfo.getComponentType() + ", dimension = " + arrayInfo.getDimension());
7373

7474
Type listType = new TypeReference<List<String>>() { }.getType();
75-
Type doubleArr = ArrayTypeUtil.createArrayType(listType, 3);
75+
Type doubleArr = ArrayTypeUtils.createArrayType(listType, 3);
7676
// Outputs: "Created type: java.util.List<java.lang.String>[][][]"
7777
System.out.println("Created type: " + doubleArr);
7878
}

Diff for: src/main/java/ch/jalu/typeresolver/CommonTypeUtil.java renamed to src/main/java/ch/jalu/typeresolver/CommonTypeUtils.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ch.jalu.typeresolver;
22

3-
import ch.jalu.typeresolver.array.ArrayTypeUtil;
3+
import ch.jalu.typeresolver.array.ArrayTypeUtils;
44

55
import javax.annotation.Nullable;
66
import java.lang.reflect.GenericArrayType;
@@ -11,9 +11,9 @@
1111
/**
1212
* Contains simple utility methods for Type objects.
1313
*/
14-
public final class CommonTypeUtil {
14+
public final class CommonTypeUtils {
1515

16-
private CommonTypeUtil() {
16+
private CommonTypeUtils() {
1717
}
1818

1919
/**
@@ -63,7 +63,7 @@ public static Class<?> getDefinitiveClass(Type type) {
6363
GenericArrayType gat = (GenericArrayType) type;
6464
Class<?> componentAsClass = getDefinitiveClass(gat.getGenericComponentType());
6565
if (componentAsClass != null) {
66-
return ArrayTypeUtil.createArrayClass(componentAsClass);
66+
return ArrayTypeUtils.createArrayClass(componentAsClass);
6767
}
6868
}
6969
return null;

Diff for: src/main/java/ch/jalu/typeresolver/EnumUtil.java renamed to src/main/java/ch/jalu/typeresolver/EnumUtils.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
/**
1010
* Utilities for enum classes.
1111
*/
12-
public final class EnumUtil {
12+
public final class EnumUtils {
1313

14-
private EnumUtil() {
14+
private EnumUtils() {
1515
}
1616

1717
/**
@@ -43,10 +43,10 @@ public static <T> Optional<T> tryValueOf(@Nullable Class<T> clazz, @Nullable Str
4343
* Class<?> class1 = NumericShaper.Range.class;
4444
* Class<?> class2 = NumericShaper.Range.ETHIOPIC.getClass(); // NumericShaper$Range$1.class
4545
*
46-
* EnumUtil.isEnumOrEnumEntryType(class1) = true
47-
* EnumUtil.isEnumOrEnumEntryType(class2) = true
48-
* EnumUtil.isEnumOrEnumEntryType(null) = false
49-
* EnumUtil.isEnumOrEnumEntryType(int.class) = false
46+
* EnumUtils.isEnumOrEnumEntryType(class1) = true
47+
* EnumUtils.isEnumOrEnumEntryType(class2) = true
48+
* EnumUtils.isEnumOrEnumEntryType(null) = false
49+
* EnumUtils.isEnumOrEnumEntryType(int.class) = false
5050
* }</pre>
5151
*
5252
* @param clazz the class to inspect, or null
@@ -64,10 +64,10 @@ public static boolean isEnumOrEnumEntryType(@Nullable Class<?> clazz) {
6464
* Class<?> class1 = NumericShaper.Range.class;
6565
* Class<?> class2 = NumericShaper.Range.ETHIOPIC.getClass(); // NumericShaper$Range$1.class
6666
*
67-
* EnumUtil.asEnumType(class1) = Optional.of(NumericShaper.Range.class)
68-
* EnumUtil.asEnumType(class2) = Optional.of(NumericShaper.Range.class)
69-
* EnumUtil.asEnumType(null) = Optional.empty()
70-
* EnumUtil.asEnumType(int.class) = Optional.empty()
67+
* EnumUtils.asEnumType(class1) = Optional.of(NumericShaper.Range.class)
68+
* EnumUtils.asEnumType(class2) = Optional.of(NumericShaper.Range.class)
69+
* EnumUtils.asEnumType(null) = Optional.empty()
70+
* EnumUtils.asEnumType(int.class) = Optional.empty()
7171
* }</pre>
7272
* <p>
7373
* Note: to always get the actual enum class of an enum entry, use {@link Enum#getDeclaringClass}.

Diff for: src/main/java/ch/jalu/typeresolver/TypeInfo.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ch.jalu.typeresolver;
22

3-
import ch.jalu.typeresolver.array.ArrayTypeUtil;
3+
import ch.jalu.typeresolver.array.ArrayTypeUtils;
44
import ch.jalu.typeresolver.typeimpl.ParameterizedTypeImpl;
55

66
import javax.annotation.Nullable;
@@ -133,7 +133,7 @@ public Class<?> getTypeArgumentAsClass(int index) {
133133
*/
134134
@Nullable
135135
public Class<?> toClass() {
136-
return TypeToClassUtil.getSafeToWriteClass(type);
136+
return TypeToClassUtils.getSafeToWriteClass(type);
137137
}
138138

139139
/**
@@ -151,7 +151,7 @@ public Class<?> toClass() {
151151
* @return the type as Class which is safe for reading (e.g. getting field value or reading from a collection)
152152
*/
153153
public Class<?> getSafeToReadClass() {
154-
return TypeToClassUtil.getSafeToReadClass(type);
154+
return TypeToClassUtils.getSafeToReadClass(type);
155155
}
156156

157157
/**
@@ -225,7 +225,7 @@ public TypeInfo resolveSuperclass(Class<?> clazz) {
225225

226226
if (clazz.isArray()) {
227227
TypeInfo resolvedComponent = getComponentType().resolveSuperclass(clazz.getComponentType());
228-
return of(ArrayTypeUtil.createArrayType(resolvedComponent.getType()));
228+
return of(ArrayTypeUtils.createArrayType(resolvedComponent.getType()));
229229
} else if (clazz.getTypeParameters().length > 0) {
230230
TypeVariableResolver resolver = getOrInitResolver();
231231
return new TypeInfo(new ParameterizedTypeImpl(clazz,

Diff for: src/main/java/ch/jalu/typeresolver/TypeToClassUtil.java renamed to src/main/java/ch/jalu/typeresolver/TypeToClassUtils.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ch.jalu.typeresolver;
22

3-
import ch.jalu.typeresolver.array.ArrayTypeUtil;
3+
import ch.jalu.typeresolver.array.ArrayTypeUtils;
44

55
import javax.annotation.Nullable;
66
import java.lang.reflect.GenericArrayType;
@@ -12,9 +12,9 @@
1212
import java.util.Objects;
1313
import java.util.function.Function;
1414

15-
public final class TypeToClassUtil {
15+
public final class TypeToClassUtils {
1616

17-
private TypeToClassUtil() {
17+
private TypeToClassUtils() {
1818
}
1919

2020
/**
@@ -30,15 +30,15 @@ public static Class<?> getSafeToWriteClass(@Nullable Type type) {
3030
return (Class<?>) type;
3131
} else if (type instanceof ParameterizedType) {
3232
ParameterizedType pt = (ParameterizedType) type;
33-
return CommonTypeUtil.getRawType(pt);
33+
return CommonTypeUtils.getRawType(pt);
3434
} else if (type instanceof WildcardType) {
3535
WildcardType wt = (WildcardType) type;
36-
return getFirstNonNull(TypeToClassUtil::getSafeToWriteClass, wt.getLowerBounds());
36+
return getFirstNonNull(TypeToClassUtils::getSafeToWriteClass, wt.getLowerBounds());
3737
} else if (type instanceof GenericArrayType) {
3838
GenericArrayType gat = (GenericArrayType) type;
3939
Class<?> componentAsClass = getSafeToWriteClass(gat.getGenericComponentType());
4040
if (componentAsClass != null) {
41-
return ArrayTypeUtil.createArrayClass(componentAsClass);
41+
return ArrayTypeUtils.createArrayClass(componentAsClass);
4242
}
4343
}
4444
return null;
@@ -62,23 +62,23 @@ private static Class<?> getSafeToReadClassOrNull(@Nullable Type type) {
6262
return (Class<?>) type;
6363
} else if (type instanceof ParameterizedType) {
6464
ParameterizedType pt = (ParameterizedType) type;
65-
return CommonTypeUtil.getRawType(pt);
65+
return CommonTypeUtils.getRawType(pt);
6666
} else if (type instanceof WildcardType) {
6767
WildcardType wt = (WildcardType) type;
68-
if (CommonTypeUtil.hasExplicitUpperBound(wt)) {
69-
return getFirstNonNull(TypeToClassUtil::getSafeToReadClassOrNull, wt.getUpperBounds());
68+
if (CommonTypeUtils.hasExplicitUpperBound(wt)) {
69+
return getFirstNonNull(TypeToClassUtils::getSafeToReadClassOrNull, wt.getUpperBounds());
7070
}
7171
} else if (type instanceof TypeVariable<?>) {
7272
TypeVariable<?> tv = (TypeVariable<?>) type;
73-
return getFirstNonNull(TypeToClassUtil::getSafeToReadClassOrNull, tv.getBounds());
73+
return getFirstNonNull(TypeToClassUtils::getSafeToReadClassOrNull, tv.getBounds());
7474
} else if (type instanceof GenericArrayType) {
7575
GenericArrayType gat = (GenericArrayType) type;
7676
Class<?> componentAsClass = getSafeToReadClassOrNull(gat.getGenericComponentType());
7777
// componentAsClass usually isn't null because the component type of GenericArrayType is normally either a
7878
// ParameterizedType or a TypeVariable. If a type variable is unbounded, the JRE sets Object as the bound.
7979
// However, if the type was somehow resolved we might have an array of wildcard, for example.
8080
if (componentAsClass != null) {
81-
return ArrayTypeUtil.createArrayClass(componentAsClass);
81+
return ArrayTypeUtils.createArrayClass(componentAsClass);
8282
}
8383
return Object[].class;
8484
}

Diff for: src/main/java/ch/jalu/typeresolver/TypeVariableResolver.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ch.jalu.typeresolver;
22

3-
import ch.jalu.typeresolver.array.ArrayTypeUtil;
3+
import ch.jalu.typeresolver.array.ArrayTypeUtils;
44
import ch.jalu.typeresolver.typeimpl.ParameterizedTypeImpl;
55
import ch.jalu.typeresolver.typeimpl.WildcardTypeImpl;
66

@@ -16,7 +16,7 @@
1616
import java.util.Objects;
1717
import java.util.Set;
1818

19-
import static ch.jalu.typeresolver.CommonTypeUtil.getRawType;
19+
import static ch.jalu.typeresolver.CommonTypeUtils.getRawType;
2020

2121
/**
2222
* Allows to resolve type variables to actual classes from previous context (extension of a class with a type parameter,
@@ -64,7 +64,7 @@ Type resolve(Type type) {
6464
} else if (type instanceof GenericArrayType) {
6565
GenericArrayType gat = (GenericArrayType) type;
6666
Type resolvedComponentType = resolve(gat.getGenericComponentType());
67-
return ArrayTypeUtil.createArrayType(resolvedComponentType);
67+
return ArrayTypeUtils.createArrayType(resolvedComponentType);
6868
}
6969
return type;
7070
}

Diff for: src/main/java/ch/jalu/typeresolver/TypeVisitor.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package ch.jalu.typeresolver;
22

33
import ch.jalu.typeresolver.array.ArrayTypeProperties;
4-
import ch.jalu.typeresolver.array.ArrayTypeUtil;
4+
import ch.jalu.typeresolver.array.ArrayTypeUtils;
55

66
import javax.annotation.Nullable;
77
import java.io.Serializable;
@@ -45,7 +45,7 @@ static Set<Type> gatherAllTypes(Type type, TypeVariableResolver resolver) {
4545
*/
4646
static <E, C extends Collection<? super E>> C gatherAllTypes(Type type, TypeVariableResolver resolver,
4747
C collection, Function<Type, E> typeToElementFn) {
48-
if (CommonTypeUtil.getDefinitiveClass(type) != null) {
48+
if (CommonTypeUtils.getDefinitiveClass(type) != null) {
4949
Consumer<Type> typeConsumer = aType -> {
5050
E typeAsElement = typeToElementFn.apply(resolver.resolve(aType));
5151
collection.add(typeAsElement);
@@ -57,7 +57,7 @@ static <E, C extends Collection<? super E>> C gatherAllTypes(Type type, TypeVari
5757
}
5858

5959
static void visitAllTypes(Type type, TypeVariableResolver resolver, Consumer<Type> typeConsumer) {
60-
if (CommonTypeUtil.getDefinitiveClass(type) != null) {
60+
if (CommonTypeUtils.getDefinitiveClass(type) != null) {
6161
visitClassesRecursively(type, aType -> typeConsumer.accept(resolver.resolve(aType)));
6262
}
6363
}
@@ -67,28 +67,28 @@ private static void visitClassesRecursively(@Nullable Type type, Consumer<Type>
6767
return;
6868
}
6969

70-
Class<?> typeAsClass = CommonTypeUtil.getDefinitiveClass(type);
70+
Class<?> typeAsClass = CommonTypeUtils.getDefinitiveClass(type);
7171
if (!typeAsClass.isArray()) {
7272
typeConsumer.accept(type);
7373
visitClassesRecursively(typeAsClass.getGenericSuperclass(), typeConsumer);
7474
for (Type genericInterface : typeAsClass.getGenericInterfaces()) {
7575
visitClassesRecursively(genericInterface, typeConsumer);
7676
}
7777
} else {
78-
ArrayTypeProperties arrayProperties = ArrayTypeUtil.getArrayProperty(type);
78+
ArrayTypeProperties arrayProperties = ArrayTypeUtils.getArrayProperty(type);
7979
List<Type> componentTypeList = gatherAllTypesOfComponent(arrayProperties);
8080

8181
// An array like Double[][] is also a Number[][] or an Object[][], but only for the same dimension
8282
for (Type component : componentTypeList) {
83-
Type arrayType = ArrayTypeUtil.createArrayType(component, arrayProperties.getDimension());
83+
Type arrayType = ArrayTypeUtils.createArrayType(component, arrayProperties.getDimension());
8484
typeConsumer.accept(arrayType);
8585
}
8686

8787
// Arrays implement Serializable & Cloneable, so a Double[][] is also a Serializable[] and a Serializable...
8888
List<Type> arrayClassParents = Arrays.asList(Serializable.class, Cloneable.class, Object.class);
8989
for (int dimension = arrayProperties.getDimension() - 1; dimension >= 0; --dimension) {
9090
for (Type arrayClassParent : arrayClassParents) {
91-
Type arrayType = ArrayTypeUtil.createArrayType(arrayClassParent, dimension);
91+
Type arrayType = ArrayTypeUtils.createArrayType(arrayClassParent, dimension);
9292
typeConsumer.accept(arrayType);
9393
}
9494
}
@@ -103,7 +103,7 @@ private static List<Type> gatherAllTypesOfComponent(ArrayTypeProperties arrayPro
103103
// If we were based on something like List[][] we won't get Object in the components since List is an interface,
104104
// but List[][] is also an Object[][] so we add it here, making sure NOT to do so for primitive component types
105105
// (e.g. float[][] is not an Object[][])
106-
if (!CommonTypeUtil.getDefinitiveClass(arrayProperties.getComponentType()).isPrimitive()
106+
if (!CommonTypeUtils.getDefinitiveClass(arrayProperties.getComponentType()).isPrimitive()
107107
&& !typesOfComponent.contains(Object.class)) {
108108
typesOfComponent.add(Object.class);
109109
}

Diff for: src/main/java/ch/jalu/typeresolver/array/ArrayClassProperties.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* ArrayClassProperties arrayProps1 = new ArrayClassProperties(String.class);
1212
* // arrayProps2 = new ArrayClassProperties(String.class, 0)}</pre>
1313
*
14-
* @see ArrayTypeUtil#getArrayProperty
14+
* @see ArrayTypeUtils#getArrayProperty
1515
*/
1616
public class ArrayClassProperties implements ArrayTypeProperties {
1717

Diff for: src/main/java/ch/jalu/typeresolver/array/ArrayTypeUtil.java renamed to src/main/java/ch/jalu/typeresolver/array/ArrayTypeUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
/**
1010
* Utilities for array types.
1111
*/
12-
public final class ArrayTypeUtil {
12+
public final class ArrayTypeUtils {
1313

14-
private ArrayTypeUtil() {
14+
private ArrayTypeUtils() {
1515
}
1616

1717
/**

Diff for: src/main/java/ch/jalu/typeresolver/array/GenericArrayTypeProperties.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* GenericArrayTypeProperties arrayProps = new GenericArrayTypeProperties(stringListArray);
1414
* // arrayProps = new GenericArrayTypeProperties(stringList, 2)}</pre>
1515
*
16-
* @see ArrayTypeUtil#getArrayProperty
16+
* @see ArrayTypeUtils#getArrayProperty
1717
*/
1818
public class GenericArrayTypeProperties implements ArrayTypeProperties {
1919

Diff for: src/main/java/ch/jalu/typeresolver/classutil/ClassType.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public enum ClassType {
2424
* @Test void demo() throws Exception {
2525
* Test ann = getClass().getDeclaredMethod("demo").getAnnotation(Test.class);
2626
* System.out.println(ann.getClass()); // Prints something like "$Proxy9"
27-
* System.out.println(ClassUtil.getType(ann.getClass())); // Prints PROXY_CLASS
27+
* System.out.println(ClassUtils.getType(ann.getClass())); // Prints PROXY_CLASS
2828
* }}</pre>
2929
*/
3030
ANNOTATION,

Diff for: src/main/java/ch/jalu/typeresolver/classutil/ClassTypeCallback.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* are of interest.
1010
*
1111
* @param <R> the result type of the callback
12-
* @see ClassUtil#processClassByType
12+
* @see ClassUtils#processClassByType
1313
*/
1414
public abstract class ClassTypeCallback<R> {
1515

@@ -98,7 +98,7 @@ public R forProxyClass(Class<?> proxyClass) {
9898
}
9999

100100
/**
101-
* Called when the class to process is a "regular class", as explained in {@link ClassUtil#isRegularJavaClass}.
101+
* Called when the class to process is a "regular class", as explained in {@link ClassUtils#isRegularJavaClass}.
102102
*
103103
* @param regularClass the Java class
104104
* @return result or null

Diff for: src/main/java/ch/jalu/typeresolver/classutil/ClassUtil.java renamed to src/main/java/ch/jalu/typeresolver/classutil/ClassUtils.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ch.jalu.typeresolver.classutil;
22

3-
import ch.jalu.typeresolver.EnumUtil;
3+
import ch.jalu.typeresolver.EnumUtils;
44
import ch.jalu.typeresolver.array.ArrayClassProperties;
55

66
import javax.annotation.Nullable;
@@ -11,9 +11,9 @@
1111
/**
1212
* Various utilities to load and inspect {@link Class} objects.
1313
*/
14-
public final class ClassUtil {
14+
public final class ClassUtils {
1515

16-
private ClassUtil() {
16+
private ClassUtils() {
1717
}
1818

1919
/**
@@ -124,7 +124,7 @@ public static String getSemanticName(@Nullable Object object) {
124124
/**
125125
* Returns a human-friendly string representation of the given class, or of the most meaningful associated type.
126126
* Concretely, this means any synthetic classes for enum entries are replaced by the enum type itself, as returned
127-
* by {@link EnumUtil#asEnumType}.
127+
* by {@link EnumUtils#asEnumType}.
128128
* <p>
129129
* Prefer using {@link #getSemanticName(Object)} whenever possible, as more semantic types can be inferred based
130130
* on an object.
@@ -133,8 +133,8 @@ public static String getSemanticName(@Nullable Object object) {
133133
* @return semantic type as class name, or "null" as string (never null itself)
134134
*/
135135
public static String getSemanticName(@Nullable Class<?> clazz) {
136-
return EnumUtil.asEnumType(clazz)
137-
.map(ClassUtil::createNameOfSemanticType)
136+
return EnumUtils.asEnumType(clazz)
137+
.map(ClassUtils::createNameOfSemanticType)
138138
.orElseGet(() -> createNameOfSemanticType(clazz));
139139
}
140140

Diff for: src/main/java/ch/jalu/typeresolver/typeimpl/ParameterizedTypeBuilder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ch.jalu.typeresolver.typeimpl;
22

3-
import ch.jalu.typeresolver.CommonTypeUtil;
3+
import ch.jalu.typeresolver.CommonTypeUtils;
44
import ch.jalu.typeresolver.TypeInfo;
55

66
import javax.annotation.Nullable;
@@ -41,7 +41,7 @@ public class ParameterizedTypeBuilder {
4141
* @param parameterizedType the parameterized type to start the builder off with
4242
*/
4343
public ParameterizedTypeBuilder(ParameterizedType parameterizedType) {
44-
this.rawType = CommonTypeUtil.getRawType(parameterizedType);
44+
this.rawType = CommonTypeUtils.getRawType(parameterizedType);
4545
this.ownerType = parameterizedType.getOwnerType();
4646
this.typeParameters = rawType.getTypeParameters();
4747
this.newTypeArguments = parameterizedType.getActualTypeArguments().clone();

0 commit comments

Comments
 (0)