mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-04-14 06:33:34 +02:00
Validator Methods erwarten nun einen Parameter
Die Methoden in `Validator` erwarten nun als zweiten Parameter den Namen des Parameters, der geprüft wird. Dadurch sollen die Methoden hilfreicher werden, indem geneuere Fehlermeldungen generiert werden können.
This commit is contained in:
@@ -156,7 +156,7 @@ public class Zeichenfenster extends JFrame {
|
||||
* @param displayDevice Das Anzeigegerät für das Fenster.
|
||||
*/
|
||||
public Zeichenfenster( Zeichenleinwand canvas, String title, GraphicsDevice displayDevice ) {
|
||||
super(Validator.requireNotNull(displayDevice).getDefaultConfiguration());
|
||||
super(Validator.requireNotNull(displayDevice, "displayDevice").getDefaultConfiguration());
|
||||
this.displayDevice = displayDevice;
|
||||
|
||||
Validator.requireNotNull(canvas, "Every Zeichenfenster needs a Zeichenleinwand, but got <null>.");
|
||||
|
||||
@@ -24,7 +24,7 @@ public abstract class Animation<T> extends Constants implements Updatable {
|
||||
|
||||
public Animation( DoubleUnaryOperator easing ) {
|
||||
this.runtime = Constants.DEFAULT_ANIM_RUNTIME;
|
||||
this.easing = Validator.requireNotNull(easing);
|
||||
this.easing = Validator.requireNotNull(easing, "easing");
|
||||
}
|
||||
|
||||
public Animation( int runtime ) {
|
||||
@@ -34,7 +34,7 @@ public abstract class Animation<T> extends Constants implements Updatable {
|
||||
|
||||
public Animation( int runtime, DoubleUnaryOperator easing ) {
|
||||
this.runtime = runtime;
|
||||
this.easing = Validator.requireNotNull(easing);
|
||||
this.easing = Validator.requireNotNull(easing, "easing");
|
||||
}
|
||||
|
||||
public int getRuntime() {
|
||||
|
||||
@@ -10,7 +10,7 @@ public class AnimationFacade<S> extends Animation<S> {
|
||||
|
||||
public AnimationFacade( Animation<S> anim, int runtime, DoubleUnaryOperator easing ) {
|
||||
super(runtime, easing);
|
||||
this.anim = Validator.requireNotNull(anim);
|
||||
this.anim = Validator.requireNotNull(anim, "anim");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -123,8 +123,8 @@ public class Animations {
|
||||
}
|
||||
|
||||
public static final <T> Future<T> animateProperty( T target, final double from, final double to, int runtime, DoubleUnaryOperator easing, DoubleConsumer propSetter ) {
|
||||
Validator.requireNotNull(target);
|
||||
Validator.requireNotNull(propSetter);
|
||||
Validator.requireNotNull(target, "target");
|
||||
Validator.requireNotNull(propSetter, "propSetter");
|
||||
return play(target, runtime, easing, ( e ) -> propSetter.accept(Constants.interpolate(from, to, e)));
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public class Music implements Audio {
|
||||
* @see ResourceStreamProvider#getResourceURL(String)
|
||||
*/
|
||||
public Music( String audioSource ) {
|
||||
Validator.requireNotNull(audioSource);
|
||||
Validator.requireNotNull(audioSource, "audioSource");
|
||||
this.audioSource = audioSource;
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ public class Sound implements Audio {
|
||||
* @see ResourceStreamProvider#getResourceURL(String)
|
||||
*/
|
||||
public Sound( String source ) {
|
||||
Validator.requireNotNull(source);
|
||||
Validator.requireNotNull(source, "source");
|
||||
this.audioSource = source;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ public final class Log {
|
||||
* mindestens herabgesenkt werden sollen.
|
||||
*/
|
||||
public static void enableGlobalLevel( Level level ) {
|
||||
int lvl = Validator.requireNotNull(level).intValue();
|
||||
int lvl = Validator.requireNotNull(level, "level").intValue();
|
||||
ensureRootLoggerInitialized();
|
||||
|
||||
// Decrease level of root level ConsoleHandlers for output
|
||||
|
||||
@@ -6,35 +6,55 @@ import java.util.function.Supplier;
|
||||
/**
|
||||
* Statische Methoden, um Methodenparameter auf Gültigkeit zu prüfen.
|
||||
*/
|
||||
@SuppressWarnings( "UnusedReturnValue" )
|
||||
@SuppressWarnings( {"unused", "UnusedReturnValue"} )
|
||||
public class Validator {
|
||||
|
||||
public static final <T> T requireNotNull( T obj ) {
|
||||
return Objects.requireNonNull(obj);
|
||||
public static final <T> T requireNotNull( T obj, CharSequence paramName ) {
|
||||
return requireNotNull(obj, () -> "Parameter <%s> may not be null.".format(paramName.toString()));
|
||||
}
|
||||
|
||||
public static final <T> T requireNotNull( T obj, CharSequence msg ) {
|
||||
return Objects.requireNonNull(obj, msg::toString);
|
||||
public static final <T> T requireNotNull( T obj, CharSequence paramName, CharSequence msg ) {
|
||||
return requireNotNull(obj, () -> msg.toString().format(paramName.toString()));
|
||||
}
|
||||
|
||||
public static final <T> T requireNotNull( T obj, Supplier<String> msg ) {
|
||||
return Objects.requireNonNull(obj, msg);
|
||||
if( obj == null ) {
|
||||
throw new NullPointerException(msg == null ? "Parameter may nut be null." : msg.get());
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static final String requireNotEmpty( String str ) {
|
||||
return requireNotEmpty(str, (Supplier<String>) null);
|
||||
public static final String requireNotEmpty( String str, CharSequence paramName ) {
|
||||
return requireNotEmpty(str, () -> String.format("Parameter <%s> may not be empty string (<%s> provided)", paramName, str));
|
||||
}
|
||||
|
||||
public static final String requireNotEmpty( String str, CharSequence msg ) {
|
||||
return requireNotEmpty(str, msg::toString);
|
||||
public static final String requireNotEmpty( String str, CharSequence paramName, CharSequence msg ) {
|
||||
return requireNotEmpty(str, () -> msg.toString().format(paramName.toString()));
|
||||
}
|
||||
|
||||
public static final String requireNotEmpty( String str, Supplier<String> msg ) {
|
||||
if( str.isEmpty() )
|
||||
if( str.isEmpty() ) {
|
||||
throw new IllegalArgumentException(msg == null ? String.format("Parameter may not be empty string (<%s> provided)", str) : msg.get());
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static final <T> T[] requireNotEmpty( T[] arr, CharSequence paramName ) {
|
||||
return requireNotEmpty(arr, () -> String.format("Parameter <%s> may not be empty", paramName));
|
||||
}
|
||||
|
||||
public static final <T> T[] requireNotEmpty( T[] arr, CharSequence paramName, CharSequence msg ) {
|
||||
return requireNotEmpty(arr, () -> msg.toString().format(paramName.toString()));
|
||||
}
|
||||
|
||||
public static final <T> T[] requireNotEmpty( T[] arr, Supplier<String> msg ) {
|
||||
if( arr.length == 0 )
|
||||
throw new IllegalArgumentException(msg == null ? "Parameter array may not be empty" : msg.get());
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static final int requirePositive( int i ) {
|
||||
return requirePositive(i, (Supplier<String>) null);
|
||||
}
|
||||
@@ -139,21 +159,6 @@ public class Validator {
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
public static final <T> T[] requireNotEmpty( T[] arr ) {
|
||||
return requireNotEmpty(arr, (Supplier<String>) null);
|
||||
}
|
||||
|
||||
public static final <T> T[] requireNotEmpty( T[] arr, CharSequence msg ) {
|
||||
return requireNotEmpty(arr, msg::toString);
|
||||
}
|
||||
|
||||
public static final <T> T[] requireNotEmpty( T[] arr, Supplier<String> msg ) {
|
||||
if( arr.length == 0 )
|
||||
throw new IllegalArgumentException(msg == null ? "Parameter array may not be empty" : msg.get());
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static final <T> T[] requireSize( T[] arr, int size ) {
|
||||
return requireSize(arr, size, (Supplier<String>) null);
|
||||
}
|
||||
@@ -168,20 +173,6 @@ public class Validator {
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static final <T> T[] requireValid( T[] arr ) {
|
||||
return requireValid(arr, (Supplier<String>) null);
|
||||
}
|
||||
|
||||
public static final <T> T[] requireValid( T[] arr, CharSequence msg ) {
|
||||
return requireValid(arr, msg::toString);
|
||||
}
|
||||
|
||||
public static final <T> T[] requireValid( T[] arr, Supplier<String> msg ) {
|
||||
if( arr == null || arr.length > 0 )
|
||||
throw new IllegalArgumentException(msg == null ? "Parameter array may not be null or empty" : msg.get());
|
||||
return arr;
|
||||
}
|
||||
|
||||
private Validator() {
|
||||
}
|
||||
|
||||
|
||||
@@ -76,8 +76,8 @@ public class EventDispatcher<E, L extends Listener<E>> {
|
||||
}
|
||||
|
||||
public void registerEventType( String eventKey, BiConsumer<E, L> dispatcher ) {
|
||||
Validator.requireNotNull(eventKey);
|
||||
Validator.requireNotNull(dispatcher);
|
||||
Validator.requireNotNull(eventKey, "eventKey");
|
||||
Validator.requireNotNull(dispatcher, "dispatcher");
|
||||
|
||||
if( !eventRegistered(eventKey) ) {
|
||||
eventRegistry.put(eventKey, dispatcher);
|
||||
@@ -102,8 +102,8 @@ public class EventDispatcher<E, L extends Listener<E>> {
|
||||
}
|
||||
|
||||
public void dispatchEvent( String eventKey, final E event ) {
|
||||
Validator.requireNotNull(eventKey);
|
||||
Validator.requireNotNull(event);
|
||||
Validator.requireNotNull(eventKey, "eventKey");
|
||||
Validator.requireNotNull(event, "event");
|
||||
|
||||
if( eventRegistered(eventKey) ) {
|
||||
final BiConsumer<E, L> dispatcher = eventRegistry.get(eventKey);
|
||||
|
||||
Reference in New Issue
Block a user