Skip to content

Commit dd29cf8

Browse files
Treiblesschorlectrueden
authored andcommitted
Rename satisfies to isApplicable to match with java naming
1 parent 82adae5 commit dd29cf8

5 files changed

Lines changed: 119 additions & 111 deletions

File tree

src/main/java/org/scijava/ops/base/DefaultOpTypeMatchingService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public boolean typesMatch(final OpCandidate candidate) {
148148
return false;
149149
}
150150

151-
int conflictingIndex = Types.satisfies(refArgTypes, candidateArgTypes);
151+
int conflictingIndex = Types.isApplicable(refArgTypes, candidateArgTypes);
152152
if (conflictingIndex != -1) {
153153
final Type to = refArgTypes[conflictingIndex];
154154
final Type from = candidateArgTypes[conflictingIndex];
@@ -342,7 +342,7 @@ private boolean outputsMatch(final OpCandidate candidate) {
342342
return false;
343343
}
344344

345-
int conflictingIndex = Types.satisfies(candidateOutTypes, refOutTypes);
345+
int conflictingIndex = Types.isApplicable(candidateOutTypes, refOutTypes);
346346
if (conflictingIndex != -1) {
347347
final Type to = refOutTypes[conflictingIndex];
348348
final Type from = candidateOutTypes[conflictingIndex];

src/main/java/org/scijava/ops/base/OpRef.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public String getLabel() {
131131

132132
/**
133133
* Determines whether the specified type satisfies the op's required types
134-
* using {@link Types#satisfies(Type[], Type[])}.
134+
* using {@link Types#isApplicable(Type[], Type[])}.
135135
*/
136136
public boolean typesMatch(final Class<?> opClass) {
137137
if (types == null)

src/main/java/org/scijava/util/TypeUtils.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ private TypeUtils() {
117117
* </ul>
118118
*
119119
* @param src
120-
* raw type representing parameterized of which assignment should
121-
* be checked
120+
* raw type representing the parameterized type of which
121+
* assignment should be checked
122122
* @param dest
123123
* the parameterized type for which assignment should be checked
124124
* to
@@ -222,19 +222,27 @@ private static void inferTypeVariables(Type[] types, Type[] inferFrom, Map<TypeV
222222
}
223223
}
224224

225-
// Bounds could also contain type vars, hence possibly go into recursion
225+
// Bounds could also contain type vars, hence possibly go into
226+
// recursion
226227
for (Type bound : varType.getBounds()) {
227228
if (bound instanceof TypeVariable && typeAssigns.get((TypeVariable<?>) bound) != null) {
228-
// If the bound of the current var (let's call it A) to infer is also a var (let's call it B):
229-
// If we already encountered B, we check if the current type to infer from is assignable to
230-
// the already inferred type for B. In this case we do not require equality as one var is
231-
// bounded by another and it is not the same. E.g. assume we want to infer the types of vars:
232-
// A extends Number, B extends A
229+
// If the bound of the current var (let's call it A) to
230+
// infer is also a var (let's call it B):
231+
// If we already encountered B, we check if the current
232+
// type to infer from is assignable to
233+
// the already inferred type for B. In this case we do
234+
// not require equality as one var is
235+
// bounded by another and it is not the same. E.g.
236+
// assume we want to infer the types of vars:
237+
// A extends Number, B extends A
233238
// From types:
234-
// Number, Double
235-
// First A is bound to Number, next B to Double. Then we check the bounds for B. We encounter A,
236-
// for which we already inferred Number. Hence, it suffices to check whether Double can be assigned
237-
// to Number, it does not have to be equal as it is just a transitive bound for B.
239+
// Number, Double
240+
// First A is bound to Number, next B to Double. Then we
241+
// check the bounds for B. We encounter A,
242+
// for which we already inferred Number. Hence, it
243+
// suffices to check whether Double can be assigned
244+
// to Number, it does not have to be equal as it is just
245+
// a transitive bound for B.
238246
Type typeAssignForBound = typeAssigns.get((TypeVariable<?>) bound);
239247
if (!Types.isAssignable(from, typeAssignForBound)) {
240248
throw new TypeInferenceException();
@@ -260,7 +268,7 @@ private static void inferTypeVariables(Type[] types, Type[] inferFrom, Map<TypeV
260268
}
261269
}
262270
// Check if the inferred types satisfy their bounds
263-
if (!Types.satisfies(typeAssigns)) {
271+
if (!Types.typesSatisfyVariables(typeAssigns)) {
264272
throw new TypeInferenceException();
265273
}
266274
}

src/main/java/org/scijava/util/Types.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -793,14 +793,14 @@ public static boolean isInstance(final Object obj, final Class<?> dest) {
793793
* @return -1 if the args satisfy the params, otherwise the index of the arg
794794
* that does not satisfy its parameter.
795795
*/
796-
public static int satisfies(final Type[] args, final Type[] params) {
796+
public static int isApplicable(final Type[] args, final Type[] params) {
797797
// create a HashMap to monitor the restrictions of the type variables.
798798
final HashMap<TypeVariable<?>, TypeVarInfo> typeBounds = new HashMap<>();
799799

800-
return satisfies(args, params, typeBounds);
800+
return isApplicable(args, params, typeBounds);
801801
}
802802

803-
public static int satisfies(final Type[] args, final Type[] params,
803+
public static int isApplicable(final Type[] args, final Type[] params,
804804
final HashMap<TypeVariable<?>, TypeVarInfo> typeBounds)
805805
{
806806
if (args.length != params.length) {
@@ -811,21 +811,21 @@ public static int satisfies(final Type[] args, final Type[] params,
811811
Type arg = args[i];
812812
Type param = params[i];
813813
// First, check raw type assignability.
814-
if (!satisfiesRawTypes(arg, param)) return i;
814+
if (!isApplicableToRawTypes(arg, param)) return i;
815815

816816
if (param instanceof ParameterizedType) {
817-
if (!satisfiesParameterizedTypes(arg, (ParameterizedType) param,
817+
if (!isApplicableToParameterizedTypes(arg, (ParameterizedType) param,
818818
typeBounds)) return i;
819819
}
820820
else if (param instanceof TypeVariable) {
821-
if (!satisfiesTypeVariable(arg, (TypeVariable<?>) param,
821+
if (!isApplicableToTypeVariable(arg, (TypeVariable<?>) param,
822822
typeBounds)) return i;
823823
}
824824
else if (param instanceof WildcardType) {
825-
if (!satisfiesWildcardType(arg, (WildcardType) param)) return i;
825+
if (!isApplicableToWildcardType(arg, (WildcardType) param)) return i;
826826
}
827827
else if (param instanceof GenericArrayType) {
828-
if (!satisfiesGenericArrayType(arg, (GenericArrayType) param,
828+
if (!isApplicableToGenericArrayType(arg, (GenericArrayType) param,
829829
typeBounds)) return i;
830830
}
831831
final Type t = TypeToken.of(param).resolveType(arg).getType();
@@ -834,13 +834,13 @@ else if (param instanceof GenericArrayType) {
834834
return -1;
835835
}
836836

837-
public static boolean satisfies(
837+
public static boolean typesSatisfyVariables(
838838
final Map<TypeVariable<?>, Type> typeVarAssigns)
839839
{
840840
return TypeUtils.typesSatisfyVariables(typeVarAssigns);
841841
}
842842

843-
private static boolean satisfiesRawTypes(final Type arg, final Type param) {
843+
private static boolean isApplicableToRawTypes(final Type arg, final Type param) {
844844
final List<Class<?>> srcClasses = Types.raws(arg);
845845
final List<Class<?>> destClasses = Types.raws(param);
846846
for (final Class<?> destClass : destClasses) {
@@ -853,7 +853,7 @@ private static boolean satisfiesRawTypes(final Type arg, final Type param) {
853853
return true;
854854
}
855855

856-
private static boolean satisfiesParameterizedTypes(final Type arg,
856+
private static boolean isApplicableToParameterizedTypes(final Type arg,
857857
final ParameterizedType param,
858858
final HashMap<TypeVariable<?>, TypeVarInfo> typeBounds)
859859
{
@@ -883,15 +883,15 @@ private static boolean satisfiesParameterizedTypes(final Type arg,
883883
if (destType instanceof TypeVariable<?>) {
884884
final Type srcType = srcTypes[i];
885885
final TypeVariable<?> destTypeVar = (TypeVariable<?>) destType;
886-
if (!satisfiesTypeParameter(srcType, destTypeVar, typeBounds))
886+
if (!isApplicableToTypeParameter(srcType, destTypeVar, typeBounds))
887887
return false;
888888
ignoredIndices.add(i);
889889
}
890890
}
891891
srcTypes = filterIndices(srcTypes, ignoredIndices);
892892
destTypes = filterIndices(destTypes, ignoredIndices);
893893
// recursively run satisfies on these arrays
894-
return satisfies(srcTypes, destTypes, typeBounds) == -1;
894+
return isApplicable(srcTypes, destTypes, typeBounds) == -1;
895895
}
896896

897897
/**
@@ -909,7 +909,7 @@ private static boolean satisfiesParameterizedTypes(final Type arg,
909909
* @return {@code boolean} - true if the replacement of {@code param} with
910910
* {@code arg} is allowed.
911911
*/
912-
private static boolean satisfiesTypeParameter(final Type arg,
912+
private static boolean isApplicableToTypeParameter(final Type arg,
913913
final TypeVariable<?> param,
914914
final HashMap<TypeVariable<?>, TypeVarInfo> typeBounds)
915915
{
@@ -928,11 +928,11 @@ private static boolean satisfiesTypeParameter(final Type arg,
928928
// if the type variable refers to some parameterized type (e.g. T extends
929929
// List<?>), call satisfiesTypeParameters on the bounds of param that
930930
// are ParameterizedTypes.
931-
if(!satisfiesTypeVariableBounds(arg, param, typeBounds)) return false;
931+
if(!isApplicableToTypeVariableBounds(arg, param, typeBounds)) return false;
932932
return true;
933933
}
934934

935-
private static boolean satisfiesTypeVariable(final Type arg,
935+
private static boolean isApplicableToTypeVariable(final Type arg,
936936
final TypeVariable<?> param,
937937
final HashMap<TypeVariable<?>, TypeVarInfo> typeBounds)
938938
{
@@ -949,7 +949,7 @@ private static boolean satisfiesTypeVariable(final Type arg,
949949
// if the type variable refers to some parameterized type (e.g. T extends
950950
// List<?>), call satisfiesTypeParameters on the bounds of param that
951951
// are ParameterizedTypes.
952-
if(!satisfiesTypeVariableBounds(arg, param, typeBounds)) return false;
952+
if(!isApplicableToTypeVariableBounds(arg, param, typeBounds)) return false;
953953
return true;
954954
}
955955

@@ -966,7 +966,7 @@ private static boolean satisfiesTypeVariable(final Type arg,
966966
* @return {@code boolean} - true if {@code arg} can satisfy the bounds of
967967
* {@code param}.
968968
*/
969-
private static boolean satisfiesTypeVariableBounds(final Type arg,
969+
private static boolean isApplicableToTypeVariableBounds(final Type arg,
970970
final TypeVariable<?> param,
971971
final HashMap<TypeVariable<?>, TypeVarInfo> typeBounds)
972972
{
@@ -985,17 +985,17 @@ private static boolean satisfiesTypeVariableBounds(final Type arg,
985985
return false;
986986
}
987987
if (paramBoundTypes[i] instanceof TypeVariable<?> &&
988-
!satisfiesTypeParameter(argType,
988+
!isApplicableToTypeParameter(argType,
989989
(TypeVariable<?>) paramBoundTypes[i], typeBounds)) return false;
990-
else if (satisfies(new Type[] { argType }, new Type[] {
990+
else if (isApplicable(new Type[] { argType }, new Type[] {
991991
paramBoundTypes[i] }, typeBounds) != -1) return false;
992992
}
993993
}
994994
}
995995
return true;
996996
}
997997

998-
private static boolean satisfiesWildcardType(final Type arg,
998+
private static boolean isApplicableToWildcardType(final Type arg,
999999
final WildcardType param)
10001000
{
10011001
final Type[] upperBounds = param.getUpperBounds();
@@ -1015,7 +1015,7 @@ private static boolean satisfiesWildcardType(final Type arg,
10151015
return true;
10161016
}
10171017

1018-
private static boolean satisfiesGenericArrayType(final Type arg,
1018+
private static boolean isApplicableToGenericArrayType(final Type arg,
10191019
final GenericArrayType param,
10201020
final HashMap<TypeVariable<?>, TypeVarInfo> typeBounds)
10211021
{
@@ -1028,15 +1028,15 @@ private static boolean satisfiesGenericArrayType(final Type arg,
10281028
final ParameterizedType argType = (ParameterizedType) argComponent;
10291029
final ParameterizedType paramType = (ParameterizedType) paramComponent;
10301030

1031-
if (!satisfiesParameterizedTypes(argType, paramType, typeBounds))
1031+
if (!isApplicableToParameterizedTypes(argType, paramType, typeBounds))
10321032
return false;
10331033
}
10341034

10351035
else if (paramComponent instanceof TypeVariable) {
10361036
// TODO are these casts safe?
10371037
final TypeVariable<?> paramType = (TypeVariable<?>) paramComponent;
10381038

1039-
if (!satisfiesTypeVariable(argComponent, paramType, typeBounds))
1039+
if (!isApplicableToTypeVariable(argComponent, paramType, typeBounds))
10401040
return false;
10411041
}
10421042

0 commit comments

Comments
 (0)