Package net.solarnetwork.util
Class ObjectUtils
java.lang.Object
net.solarnetwork.util.ObjectUtils
Utilities for dealing with objects.
- Version:
- 1.1
- Author:
- matt
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T[]requireNonEmptyArgument(T[] arg, String argumentName) Require a non-empty array method argument.static <T extends Collection<?>>
TrequireNonEmptyArgument(T arg, String argumentName) Require a non-empty array method argument.static <T> TrequireNonNullArgument(T arg, String argumentName) Require a non-null method argument.
-
Constructor Details
-
ObjectUtils
public ObjectUtils()
-
-
Method Details
-
requireNonNullArgument
Require a non-null method argument.This is similar to
Objects.requireNonNull(Object, String)exceptargumentNameis just the name of the required argument and anIllegalArgumentExceptionis thrown instead of aNullPointerException. Example use:public Foo(Bar bar, Baz baz) { this.bar = ObjectUtils.requireNonNullArgument(bar, "bar"); this.baz = ObjectUtils.requireNonNullArgument(baz, "baz"); }- Type Parameters:
T- the argument type- Parameters:
arg- the argument to require to be non-nullargumentName- the name ofargto report in theIllegalArgumentExceptionifargis null- Returns:
arg- Throws:
IllegalArgumentException- ifargis null
-
requireNonEmptyArgument
Require a non-empty array method argument.This is similar to
Objects.requireNonNull(Object, String)exceptargumentNameis just the name of the required argument and anIllegalArgumentExceptionis thrown instead of aNullPointerException. Example use:public Foo(Bar[] bar) { this.bar = ObjectUtils.requireNonNullArgument(bar, "bar"); }- Type Parameters:
T- the argument type- Parameters:
arg- the argument to require to be non-emptyargumentName- the name ofargto report in theIllegalArgumentExceptionifargis null- Returns:
arg- Throws:
IllegalArgumentException- ifargis null or empty
-
requireNonEmptyArgument
Require a non-empty array method argument.This is similar to
Objects.requireNonNull(Object, String)exceptargumentNameis just the name of the required argument and anIllegalArgumentExceptionis thrown instead of aNullPointerException. Example use:public Foo(List<Bar> bar) { this.bar = ObjectUtils.requireNonNullArgument(bar, "bar"); }- Type Parameters:
T- the argument type- Parameters:
arg- the argument to require to be non-emptyargumentName- the name ofargto report in theIllegalArgumentExceptionifargis null- Returns:
arg- Throws:
IllegalArgumentException- ifargis null or empty
-