All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tukeof.common.util.ObjectUtil Maven / Gradle / Ivy

The newest version!
package com.tukeof.common.util;

import java.util.Collection;
import java.util.Map;

public final class ObjectUtil {

    public static  T checkNotNull(T o, String name) {
        if (o == null) {
            throw new RuntimeException(name + " is null");
        }
        return o;
    }

    public static > T checkNotEmpty(T o, String name) {
        checkNotNull(o, name);
        if (o.isEmpty()) {
            throw new RuntimeException(name + " is empty");
        }
        return o;
    }

    public static  T[] checkNotEmpty(T[] o, String name) {
        checkNotNull(o, name);
        if (o.length == 0) {
            throw new RuntimeException(name + " is empty");
        }
        return o;
    }

    public static String checkNotBlank(String o, String name) {
        checkNotNull(o, name);
        if (o.trim().isEmpty()) {
            throw new RuntimeException(name + " is blank");
        }
        return o;
    }

    // check not < 0
    public static void checkNotNegative(long n, String name) {
        if (n < 0) {
            throw new RuntimeException(name + " is negative");
        }
    }

    // check not <= 0
    public static void requirePositive(long n, String name) {
        if (n <= 0) {
            throw new RuntimeException(name + " is not positive");
        }
    }

    // ==== ==== ==== ====    ==== ==== ==== ====    ==== ==== ==== ====

    public static boolean isBlank(String string) {
        return !isNotBlank(string);
    }

    public static boolean isNotBlank(String string) {
        return string != null && !string.trim().isEmpty();
    }

    public static  boolean isEmpty(T[] o) {
        return !isNotEmpty(o);
    }

    public static  boolean isEmpty(Collection o) {
        return !isNotEmpty(o);
    }

    public static boolean isEmpty(Map o) {
        return !isNotEmpty(o);
    }

    public static  boolean isNotEmpty(T[] o) {
        return o != null && o.length != 0;
    }

    public static  boolean isNotEmpty(Collection o) {
        return o != null && !o.isEmpty();
    }

    public static boolean isNotEmpty(Map o) {
        return o != null && !o.isEmpty();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy