Package org.eclipse.net4j.util
Class ObjectUtil
java.lang.Object
org.eclipse.net4j.util.ObjectUtil
Various static helper methods.
- Author:
- Eike Stepper
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T[]appendtoArray(T[] array, T... elements) static Exceptionstatic booleanstatic <T> voidforEachSafe(Iterable<T> iterable, Consumer<T> consumer) static <T> voidforEachSafe(T[] array, Consumer<T> consumer) static inthashCode(int... values) A collision-free hash code for small sets (<=4) of small, positive integers (<=128)static inthashCode(long num) static intstatic <T> Tstatic booleanstatic <T extends Collection<?>>
booleanisEmpty(Collection<?> collection) static <T extends Map<?,?>>
booleanstatic <T> booleanisEmpty(T[] array) static booleannever()static <T> TnotNull(T object) static <T> TrequireNonNullElse(T obj, T defaultObj) static <T> TrequireNonNullElseGet(T obj, Supplier<? extends T> supplier) static intstatic <T extends Collection<?>>
intsize(Collection<?> collection) static <T extends Map<?,?>>
intstatic <T> intsize(T[] array) static <T> TAttempts to cast anobjectas an instance of the giventype.static <T,EX extends Throwable>
TAttempts to cast anobjectas an instance of the giventype.
-
Method Details
-
never
public static boolean never()- Since:
- 3.6
-
equals
-
hashCode
-
hashCode
public static int hashCode(int... values) A collision-free hash code for small sets (<=4) of small, positive integers (<=128)- Since:
- 3.2
-
hashCode
public static int hashCode(long num) -
appendtoArray
public static <T> T[] appendtoArray(T[] array, T... elements) -
isEmpty
public static <T> boolean isEmpty(T[] array) - Since:
- 3.1
-
isEmpty
- Since:
- 3.1
-
isEmpty
- Since:
- 3.1
-
isEmpty
- Since:
- 3.1
-
size
public static <T> int size(T[] array) - Since:
- 3.26
-
size
- Since:
- 3.26
-
size
- Since:
- 3.26
-
size
- Since:
- 3.26
-
close
- Since:
- 3.3
-
notNull
public static <T> T notNull(T object) - Since:
- 3.3
-
ifNotNull
- Since:
- 3.29
-
requireNonNullElse
public static <T> T requireNonNullElse(T obj, T defaultObj) - Since:
- 3.28
-
requireNonNullElseGet
- Since:
- 3.28
-
tryCast
Attempts to cast anobjectas an instance of the giventype.- Parameters:
object- an object to cast to sometypetype- the type to cast theobjectto- Returns:
- the
objectornullif it is not of the requiredtype - Since:
- 3.4
-
tryCast
public static <T,EX extends Throwable> T tryCast(Object object, Class<T> type, Supplier<EX> onFail) throws EX Attempts to cast anobjectas an instance of the giventype. If theobjectis not of the requiredtype, the givenonFailaction is executed.- Throws:
EX- Since:
- 3.29
-
forEachSafe
- Since:
- 3.13
-
forEachSafe
- Since:
- 3.13
-