Skip to content

Commit 06cf828

Browse files
Treiblesschorlegselzer
authored andcommitted
Rename satisfies to isApplicable to match with java naming
1 parent 930e6c5 commit 06cf828

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
@@ -791,14 +791,14 @@ public static boolean isInstance(final Object obj, final Class<?> dest) {
791791
* @return -1 if the args satisfy the params, otherwise the index of the arg
792792
* that does not satisfy its parameter.
793793
*/
794-
public static int satisfies(final Type[] args, final Type[] params) {
794+
public static int isApplicable(final Type[] args, final Type[] params) {
795795
// create a HashMap to monitor the restrictions of the type variables.
796796
final HashMap<TypeVariable<?>, TypeVarInfo> typeBounds = new HashMap<>();
797797

798-
return satisfies(args, params, typeBounds);
798+
return isApplicable(args, params, typeBounds);
799799
}
800800

801-
public static int satisfies(final Type[] args, final Type[] params,
801+
public static int isApplicable(final Type[] args, final Type[] params,
802802
final HashMap<TypeVariable<?>, TypeVarInfo> typeBounds)
803803
{
804804
if (args.length != params.length) {
@@ -809,21 +809,21 @@ public static int satisfies(final Type[] args, final Type[] params,
809809
Type arg = args[i];
810810
Type param = params[i];
811811
// First, check raw type assignability.
812-
if (!satisfiesRawTypes(arg, param)) return i;
812+
if (!isApplicableToRawTypes(arg, param)) return i;
813813

814814
if (param instanceof ParameterizedType) {
815-
if (!satisfiesParameterizedTypes(arg, (ParameterizedType) param,
815+
if (!isApplicableToParameterizedTypes(arg, (ParameterizedType) param,
816816
typeBounds)) return i;
817817
}
818818
else if (param instanceof TypeVariable) {
819-
if (!satisfiesTypeVariable(arg, (TypeVariable<?>) param,
819+
if (!isApplicableToTypeVariable(arg, (TypeVariable<?>) param,
820820
typeBounds)) return i;
821821
}
822822
else if (param instanceof WildcardType) {
823-
if (!satisfiesWildcardType(arg, (WildcardType) param)) return i;
823+
if (!isApplicableToWildcardType(arg, (WildcardType) param)) return i;
824824
}
825825
else if (param instanceof GenericArrayType) {
826-
if (!satisfiesGenericArrayType(arg, (GenericArrayType) param,
826+
if (!isApplicableToGenericArrayType(arg, (GenericArrayType) param,
827827
typeBounds)) return i;
828828
}
829829
final Type t = TypeToken.of(param).resolveType(arg).getType();
@@ -832,13 +832,13 @@ else if (param instanceof GenericArrayType) {
832832
return -1;
833833
}
834834

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

841-
private static boolean satisfiesRawTypes(final Type arg, final Type param) {
841+
private static boolean isApplicableToRawTypes(final Type arg, final Type param) {
842842
final List<Class<?>> srcClasses = Types.raws(arg);
843843
final List<Class<?>> destClasses = Types.raws(param);
844844
for (final Class<?> destClass : destClasses) {
@@ -851,7 +851,7 @@ private static boolean satisfiesRawTypes(final Type arg, final Type param) {
851851
return true;
852852
}
853853

854-
private static boolean satisfiesParameterizedTypes(final Type arg,
854+
private static boolean isApplicableToParameterizedTypes(final Type arg,
855855
final ParameterizedType param,
856856
final HashMap<TypeVariable<?>, TypeVarInfo> typeBounds)
857857
{
@@ -881,15 +881,15 @@ private static boolean satisfiesParameterizedTypes(final Type arg,
881881
if (destType instanceof TypeVariable<?>) {
882882
final Type srcType = srcTypes[i];
883883
final TypeVariable<?> destTypeVar = (TypeVariable<?>) destType;
884-
if (!satisfiesTypeParameter(srcType, destTypeVar, typeBounds))
884+
if (!isApplicableToTypeParameter(srcType, destTypeVar, typeBounds))
885885
return false;
886886
ignoredIndices.add(i);
887887
}
888888
}
889889
srcTypes = filterIndices(srcTypes, ignoredIndices);
890890
destTypes = filterIndices(destTypes, ignoredIndices);
891891
// recursively run satisfies on these arrays
892-
return satisfies(srcTypes, destTypes, typeBounds) == -1;
892+
return isApplicable(srcTypes, destTypes, typeBounds) == -1;
893893
}
894894

895895
/**
@@ -907,7 +907,7 @@ private static boolean satisfiesParameterizedTypes(final Type arg,
907907
* @return {@code boolean} - true if the replacement of {@code param} with
908908
* {@code arg} is allowed.
909909
*/
910-
private static boolean satisfiesTypeParameter(final Type arg,
910+
private static boolean isApplicableToTypeParameter(final Type arg,
911911
final TypeVariable<?> param,
912912
final HashMap<TypeVariable<?>, TypeVarInfo> typeBounds)
913913
{
@@ -926,11 +926,11 @@ private static boolean satisfiesTypeParameter(final Type arg,
926926
// if the type variable refers to some parameterized type (e.g. T extends
927927
// List<?>), call satisfiesTypeParameters on the bounds of param that
928928
// are ParameterizedTypes.
929-
if(!satisfiesTypeVariableBounds(arg, param, typeBounds)) return false;
929+
if(!isApplicableToTypeVariableBounds(arg, param, typeBounds)) return false;
930930
return true;
931931
}
932932

933-
private static boolean satisfiesTypeVariable(final Type arg,
933+
private static boolean isApplicableToTypeVariable(final Type arg,
934934
final TypeVariable<?> param,
935935
final HashMap<TypeVariable<?>, TypeVarInfo> typeBounds)
936936
{
@@ -947,7 +947,7 @@ private static boolean satisfiesTypeVariable(final Type arg,
947947
// if the type variable refers to some parameterized type (e.g. T extends
948948
// List<?>), call satisfiesTypeParameters on the bounds of param that
949949
// are ParameterizedTypes.
950-
if(!satisfiesTypeVariableBounds(arg, param, typeBounds)) return false;
950+
if(!isApplicableToTypeVariableBounds(arg, param, typeBounds)) return false;
951951
return true;
952952
}
953953

@@ -964,7 +964,7 @@ private static boolean satisfiesTypeVariable(final Type arg,
964964
* @return {@code boolean} - true if {@code arg} can satisfy the bounds of
965965
* {@code param}.
966966
*/
967-
private static boolean satisfiesTypeVariableBounds(final Type arg,
967+
private static boolean isApplicableToTypeVariableBounds(final Type arg,
968968
final TypeVariable<?> param,
969969
final HashMap<TypeVariable<?>, TypeVarInfo> typeBounds)
970970
{
@@ -983,17 +983,17 @@ private static boolean satisfiesTypeVariableBounds(final Type arg,
983983
return false;
984984
}
985985
if (paramBoundTypes[i] instanceof TypeVariable<?> &&
986-
!satisfiesTypeParameter(argType,
986+
!isApplicableToTypeParameter(argType,
987987
(TypeVariable<?>) paramBoundTypes[i], typeBounds)) return false;
988-
else if (satisfies(new Type[] { argType }, new Type[] {
988+
else if (isApplicable(new Type[] { argType }, new Type[] {
989989
paramBoundTypes[i] }, typeBounds) != -1) return false;
990990
}
991991
}
992992
}
993993
return true;
994994
}
995995

996-
private static boolean satisfiesWildcardType(final Type arg,
996+
private static boolean isApplicableToWildcardType(final Type arg,
997997
final WildcardType param)
998998
{
999999
final Type[] upperBounds = param.getUpperBounds();
@@ -1013,7 +1013,7 @@ private static boolean satisfiesWildcardType(final Type arg,
10131013
return true;
10141014
}
10151015

1016-
private static boolean satisfiesGenericArrayType(final Type arg,
1016+
private static boolean isApplicableToGenericArrayType(final Type arg,
10171017
final GenericArrayType param,
10181018
final HashMap<TypeVariable<?>, TypeVarInfo> typeBounds)
10191019
{
@@ -1026,15 +1026,15 @@ private static boolean satisfiesGenericArrayType(final Type arg,
10261026
final ParameterizedType argType = (ParameterizedType) argComponent;
10271027
final ParameterizedType paramType = (ParameterizedType) paramComponent;
10281028

1029-
if (!satisfiesParameterizedTypes(argType, paramType, typeBounds))
1029+
if (!isApplicableToParameterizedTypes(argType, paramType, typeBounds))
10301030
return false;
10311031
}
10321032

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

1037-
if (!satisfiesTypeVariable(argComponent, paramType, typeBounds))
1037+
if (!isApplicableToTypeVariable(argComponent, paramType, typeBounds))
10381038
return false;
10391039
}
10401040

0 commit comments

Comments
 (0)