sdk-common / com.tomtom.online.sdk.common.util / Preconditions

Preconditions

class Preconditions

Utility class to aid with object comparison with null object handling.

Author
place

Functions

checkAndGetInstanceOf

static fun <T : Any!> checkAndGetInstanceOf(object: Any!, clazz: Class<T>!): T

checkAndGetInstanceOfWithoutException

static fun <T : Any!> checkAndGetInstanceOfWithoutException(object: Any!, clazz: Class<T>!): T

checkNotNull

static fun checkNotNull(obj: Any!, varName: String!): Unitstatic fun <T : Any!> checkNotNull(reference: T): T

Ensures that an object reference passed as a parameter to the calling method is not null.

collectionIsEmpty

static fun collectionIsEmpty(col: MutableCollection<*>!): Boolean

emptyIfNull

static fun <T : Any!> emptyIfNull(iterable: MutableIterable<T>!): MutableIterable<T>!

hashCodeOfObject

static fun hashCodeOfObject(o: Any!): Int

isEmpty

static fun isEmpty(s: CharSequence!): Boolean

isEqual

static fun isEqual(o1: Any!, o2: Any!): Boolean

Check if two objects are equal. This handles the objects being null. When not null the objects equals() method is used.

isNotEmpty

static fun isNotEmpty(s: CharSequence!): Boolean

isNotNull

static fun isNotNull(object: Any!): Boolean

nonNullOr

static fun <T : Any!> nonNullOr(value: T?, defaultValue: T): T

requireNonNull

static fun <T : Any!> requireNonNull(object: T, message: String!): T

Checks if the given object is not null. If the object is not null then it's returned, throw IllegalArgumentException otherwise with the specified message.

requireNotEmpty

static fun <T : CharSequence!> requireNotEmpty(charSequence: T?, message: String): T

Checks if the given charseqence is not empty. If the object is empty or null then IllegalArgumentException is thrown with the specified message.

requireNull

static fun <T : Any!> requireNull(object: T, message: String): Unit

Checks if the given object is null. If the object is not null then IllegalArgumentException is thrown with the specified message.

requireTrue

static fun requireTrue(precondition: Boolean, message: String): Unit

Checks if the given precondition is true. If the object is false then IllegalArgumentException is thrown with the specified message.