mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-04-14 14:43:33 +02:00
Refactorings
This commit is contained in:
@@ -14,7 +14,7 @@ import java.util.concurrent.ExecutionException;
|
|||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
|
|
||||||
@SuppressWarnings( "unchecked" )
|
@SuppressWarnings( "unused" )
|
||||||
public class Animations {
|
public class Animations {
|
||||||
|
|
||||||
public static final <T> Future<T> animateProperty( String propName, T target, double to, int runtime, DoubleUnaryOperator easing ) {
|
public static final <T> Future<T> animateProperty( String propName, T target, double to, int runtime, DoubleUnaryOperator easing ) {
|
||||||
@@ -92,27 +92,28 @@ public class Animations {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final <T, R> R callGetter( T target, String propName, Class<R> propType ) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
@SuppressWarnings( "unchecked" )
|
||||||
|
private static <T, R> R callGetter( T target, String propName, Class<R> propType ) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||||
String getterName = makeMethodName("get", propName);
|
String getterName = makeMethodName("get", propName);
|
||||||
Method getter = target.getClass().getMethod(getterName);
|
Method getter = target.getClass().getMethod(getterName);
|
||||||
if( getter != null && getter.getReturnType().equals(propType) ) {
|
if( getter.getReturnType().equals(propType) ) {
|
||||||
return (R) getter.invoke(target);
|
return (R) getter.invoke(target);
|
||||||
} else {
|
} else {
|
||||||
throw new NoSuchMethodException(String.format("No getter for property <%s> found.", propName));
|
throw new NoSuchMethodException(String.format("No getter for property <%s> found.", propName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final <T, R> Method findSetter( T target, String propName, Class<R> propType ) throws NoSuchMethodException {
|
private static <T, R> Method findSetter( T target, String propName, Class<R> propType ) throws NoSuchMethodException {
|
||||||
String setterName = makeMethodName("set", propName);
|
String setterName = makeMethodName("set", propName);
|
||||||
Method setter = target.getClass().getMethod(setterName, propType);
|
Method setter = target.getClass().getMethod(setterName, propType);
|
||||||
if( setter != null && setter.getReturnType().equals(void.class) && setter.getParameterCount() == 1 ) {
|
if( setter.getReturnType().equals(void.class) && setter.getParameterCount() == 1 ) {
|
||||||
return setter;
|
return setter;
|
||||||
} else {
|
} else {
|
||||||
throw new NoSuchMethodException(String.format("No setter for property <%s> found.", propName));
|
throw new NoSuchMethodException(String.format("No setter for property <%s> found.", propName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String makeMethodName( String prefix, String propName ) {
|
private static String makeMethodName( String prefix, String propName ) {
|
||||||
String firstChar = propName.substring(0, 1).toUpperCase();
|
String firstChar = propName.substring(0, 1).toUpperCase();
|
||||||
String tail = "";
|
String tail = "";
|
||||||
if( propName.length() > 1 ) {
|
if( propName.length() > 1 ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user