Package io.nem.catapult.builders
Class GeneratorUtils
- java.lang.Object
-
- io.nem.catapult.builders.GeneratorUtils
-
public final class GeneratorUtils extends java.lang.ObjectGenerator utility class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceGeneratorUtils.ThrowingConsumer<T,E extends java.lang.Exception>Throwing consumer interface.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <E extends java.lang.RuntimeException>
java.lang.RuntimeExceptiongetExceptionToPropagate(java.lang.Exception exception)Gets a runtime exception to propagates from an exception.static <E extends java.lang.RuntimeException>
java.lang.RuntimeExceptiongetExceptionToPropagate(java.lang.Exception exception, java.util.function.Function<java.lang.Exception,E> wrap)Gets a runtime exception to propagates from an exception.static voidisFalse(boolean expression, java.lang.String message, java.lang.Object... values)Throws if the value is not false.static voidisTrue(boolean expression, java.lang.String message, java.lang.Object... values)Throws if the value is not true.static <T> voidnotNull(T object, java.lang.String message, java.lang.Object... values)Throws if the object is null.static <T> Tpropagate(java.util.concurrent.Callable<T> callable)Propagates checked exceptions as a runtime exception.static <T,E extends java.lang.RuntimeException>
Tpropagate(java.util.concurrent.Callable<T> callable, java.util.function.Function<java.lang.Exception,E> wrap)Propagates checked exceptions as a specific runtime exception.static byte[]serialize(GeneratorUtils.ThrowingConsumer<java.io.DataOutputStream,java.lang.Exception> consumer)Serializes data using a helper function to write to the stream.static <T extends java.lang.Enum<T> & BitMaskable>
longtoLong(java.lang.Class<T> enumClass, java.util.EnumSet<T> enumSet)Creates a bitwise representation for an EnumSet.static <T extends java.lang.Enum<T> & BitMaskable>
java.util.EnumSet<T>toSet(java.lang.Class<T> enumClass, long bitMaskValue)Creates a EnumSet from from a bit representation.
-
-
-
Method Detail
-
notNull
public static <T> void notNull(T object, java.lang.String message, java.lang.Object... values)Throws if the object is null.- Type Parameters:
T- Type of object.- Parameters:
object- Object to to check.message- Format string message.values- Format values.
-
isTrue
public static void isTrue(boolean expression, java.lang.String message, java.lang.Object... values)Throws if the value is not true.- Parameters:
expression- Expression to check.message- Format string message.values- Format values.
-
isFalse
public static void isFalse(boolean expression, java.lang.String message, java.lang.Object... values)Throws if the value is not false.- Parameters:
expression- Expression to check.message- Format string message.values- Format values.
-
toLong
public static <T extends java.lang.Enum<T> & BitMaskable> long toLong(java.lang.Class<T> enumClass, java.util.EnumSet<T> enumSet)
Creates a bitwise representation for an EnumSet.- Type Parameters:
T- Type of enum.- Parameters:
enumClass- Enum type.enumSet- EnumSet to convert to bit representation.- Returns:
- Long value of the EnumSet.
-
toSet
public static <T extends java.lang.Enum<T> & BitMaskable> java.util.EnumSet<T> toSet(java.lang.Class<T> enumClass, long bitMaskValue)
Creates a EnumSet from from a bit representation.- Type Parameters:
T- Enum type.- Parameters:
enumClass- Enum class.bitMaskValue- Bitmask value.- Returns:
- EnumSet representing the long value.
-
getExceptionToPropagate
public static <E extends java.lang.RuntimeException> java.lang.RuntimeException getExceptionToPropagate(java.lang.Exception exception, java.util.function.Function<java.lang.Exception,E> wrap)Gets a runtime exception to propagates from an exception.- Type Parameters:
E- Specific exception type.- Parameters:
exception- Exception to propagate.wrap- Function that wraps an exception in a runtime exception.- Returns:
- RuntimeException to throw.
-
getExceptionToPropagate
public static <E extends java.lang.RuntimeException> java.lang.RuntimeException getExceptionToPropagate(java.lang.Exception exception)
Gets a runtime exception to propagates from an exception.- Type Parameters:
E- Specific exception type.- Parameters:
exception- Exception to propagate.- Returns:
- RuntimeException to throw.
-
propagate
public static <T,E extends java.lang.RuntimeException> T propagate(java.util.concurrent.Callable<T> callable, java.util.function.Function<java.lang.Exception,E> wrap)Propagates checked exceptions as a specific runtime exception.- Type Parameters:
T- Return type.E- Specific exception type.- Parameters:
callable- Function to call.wrap- Function that wraps an exception in a runtime exception.- Returns:
- Function result.
-
propagate
public static <T> T propagate(java.util.concurrent.Callable<T> callable)
Propagates checked exceptions as a runtime exception.- Type Parameters:
T- Function return type.- Parameters:
callable- Function to call.- Returns:
- Function result.
-
serialize
public static byte[] serialize(GeneratorUtils.ThrowingConsumer<java.io.DataOutputStream,java.lang.Exception> consumer)
Serializes data using a helper function to write to the stream.- Parameters:
consumer- Helper function that writes data to DataOutputStream.- Returns:
- Byte array of data written.
-
-