Skip to content

Commit 01ec902

Browse files
gselzerctrueden
authored andcommitted
Types: purge unused methods, simplify code
1 parent 794b425 commit 01ec902

File tree

1 file changed

+15
-50
lines changed
  • scijava-types/src/main/java/org/scijava/types

1 file changed

+15
-50
lines changed

scijava-types/src/main/java/org/scijava/types/Types.java

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static Class<?> raw(final Type type) {
127127
if (type == null) return null;
128128
if (type instanceof Class) return (Class<?>) type;
129129
final List<Class<?>> c = raws(type);
130-
if (c == null || c.size() == 0) return null;
130+
if (c.isEmpty()) return null;
131131
return c.get(0);
132132
}
133133

@@ -225,28 +225,6 @@ public static Type fieldType(final Field field, final Class<?> type) {
225225
return GenericTypeReflector.getExactFieldType(field, pType);
226226
}
227227

228-
/**
229-
* As {@link #fieldType(Field, Class)}, but with respect to the return type of
230-
* the given {@link Method} rather than a {@link Field}.
231-
*/
232-
public static Type methodReturnType(final Method method,
233-
final Class<?> type)
234-
{
235-
final Type pType = parameterizeRaw(type);
236-
return GenericTypeReflector.getExactReturnType(method, pType);
237-
}
238-
239-
/**
240-
* As {@link #fieldType(Field, Class)}, but with respect to the parameter
241-
* types of the given {@link Method} rather than a {@link Field}.
242-
*/
243-
public static Type[] methodParamTypes(final Method method,
244-
final Class<?> type)
245-
{
246-
final Type pType = parameterizeRaw(type);
247-
return GenericTypeReflector.getExactParameterTypes(method, pType);
248-
}
249-
250228
/**
251229
* Gets the given type's {@code n}th type parameter of the specified class.
252230
* <p>
@@ -358,9 +336,8 @@ public static Type greatestCommonSuperType(Type[] types,
358336
List<Type> sharedInterfaces = new ArrayList<>();
359337
Queue<Type> superInterfaces = new LinkedList<>();
360338
if (Types.raw(types[0]).isInterface()) superInterfaces.add(types[0]);
361-
else for (Type superT1 : Types.raw(types[0]).getGenericInterfaces())
362-
superInterfaces.add(superT1);
363-
while (superInterfaces.size() > 0) {
339+
else Collections.addAll(superInterfaces, Types.raw(types[0]).getGenericInterfaces());
340+
while (!superInterfaces.isEmpty()) {
364341
Type type = superInterfaces.remove();
365342
Type pType = Types.getExactSuperType(types[0], Types.raw(type));
366343
if (Types.isAssignable(types, pType) == -1) {
@@ -410,14 +387,15 @@ else for (Type superT1 : Types.raw(types[0]).getGenericInterfaces())
410387
// satisfying interface. Do note, however, that this does not prevent
411388
// multiple
412389
// satisfying interfaces at the same depth from being found.
413-
if (sharedInterfaces.size() == 0) for (Type superT1 : Types.raw(type)
414-
.getGenericInterfaces())
415-
superInterfaces.add(superT1);
390+
if (sharedInterfaces.isEmpty()){
391+
Collections.addAll(superInterfaces, Types.raw(type)
392+
.getGenericInterfaces());
393+
}
416394
}
417395
if (sharedInterfaces.size() == 1 && !wildcardSingleIface) {
418396
return sharedInterfaces.get(0);
419397
}
420-
else if (sharedInterfaces.size() > 0) {
398+
else if (!sharedInterfaces.isEmpty()) {
421399
// TODO: such a wildcard is technically illegal as a result of current
422400
// Java language specifications. See
423401
// https://stackoverflow.com/questions/6643241/why-cant-you-have-multiple-interfaces-in-a-bounded-wildcard-generic
@@ -471,7 +449,7 @@ public static Type[] typeParamsAgainstClass(Type src, Class<?> superclass) {
471449
public static Type[] getParams(Class<?> subType, Class<?> superErasure) {
472450
Type pt = parameterizeRaw(subType);
473451
Type superType = getExactSuperType(pt, superErasure);
474-
if (superType != null && superType instanceof ParameterizedType) {
452+
if (superType instanceof ParameterizedType) {
475453
return ((ParameterizedType) superType).getActualTypeArguments();
476454
}
477455
return new Type[0];
@@ -681,7 +659,7 @@ private static boolean isApplicableToRawTypes(final Type arg,
681659
for (final Class<?> destClass : destClasses) {
682660
final Optional<Class<?>> first = srcClasses.stream().filter(
683661
srcClass -> Types.isAssignable(srcClass, destClass)).findFirst();
684-
if (!first.isPresent()) {
662+
if (first.isEmpty()) {
685663
return false;
686664
}
687665
}
@@ -702,8 +680,7 @@ private static boolean isApplicableToParameterizedTypes(final Type arg,
702680
Type[] srcTypes = new Type[destTypes.length];
703681

704682
// get an array of the source argument types
705-
Type argType = arg;
706-
Type superType = Types.getExactSuperType(argType, Types.raw(param));
683+
Type superType = Types.getExactSuperType(arg, Types.raw(param));
707684
if (!(superType instanceof ParameterizedType)) return false;
708685
srcTypes = ((ParameterizedType) superType).getActualTypeArguments();
709686

@@ -757,9 +734,8 @@ private static boolean isApplicableToTypeParameter(final Type arg,
757734
{
758735
// add the type variable to the HashMap if it does not yet exist.
759736
if (!typeBounds.containsKey(param)) {
760-
final TypeVariable<?> newTypeVar = param;
761-
typeBounds.put(newTypeVar, new TypeVarFromParameterizedTypeInfo(
762-
newTypeVar));
737+
typeBounds.put(param, new TypeVarFromParameterizedTypeInfo(
738+
param));
763739
}
764740
// attempt to restrict the bounds of the type variable to the argument.
765741
// We call the fixBounds method the refuseWildcards flag to be true,
@@ -1010,7 +986,7 @@ public static ParameterizedType parameterize(final Class<?> rawType,
1010986
* @return The newly created {@link WildcardType}.
1011987
*/
1012988
public static WildcardType wildcard() {
1013-
return wildcard((Type) null, (Type) null);
989+
return wildcard(null, (Type) null);
1014990
}
1015991

1016992
/**
@@ -1134,23 +1110,12 @@ public static Map<TypeVariable<?>, Type> args(final Class<?> c,
11341110
* @param typeArgMappings the mapping used for parameterization
11351111
* @return {@link ParameterizedType}
11361112
*/
1137-
public static final ParameterizedType parameterize(final Class<?> raw,
1113+
public static ParameterizedType parameterize(final Class<?> raw,
11381114
final Map<TypeVariable<?>, Type> typeArgMappings)
11391115
{
11401116
return TypeUtils.parameterize(raw, typeArgMappings);
11411117
}
11421118

1143-
/**
1144-
* Returns the erasure of the given type as specified by
1145-
* {@link GenericTypeReflector#erase(Type)}.
1146-
*
1147-
* @param type the type to erase
1148-
* @return the erased type
1149-
*/
1150-
public static Class<?> erase(final Type type) {
1151-
return GenericTypeReflector.erase(type);
1152-
}
1153-
11541119
/**
11551120
* See {@link GenericTypeReflector#getExactSuperType(Type, Class)}
11561121
*

0 commit comments

Comments
 (0)