|  | 
|  | 1 | +package com.javaquery.util; | 
|  | 2 | + | 
|  | 3 | +import com.javaquery.util.collection.Collections; | 
|  | 4 | +import com.javaquery.util.collection.function.ExecutableFunction; | 
|  | 5 | +import com.javaquery.util.string.Strings; | 
|  | 6 | + | 
|  | 7 | +import java.util.Collection; | 
|  | 8 | +import java.util.Map; | 
|  | 9 | + | 
|  | 10 | +/** | 
|  | 11 | + * Wrapper class for {@link Objects}, {@link Strings} and {@link Collections} utility classes. | 
|  | 12 | + * @author javaquery | 
|  | 13 | + * @since 1.2.5 | 
|  | 14 | + */ | 
|  | 15 | +public class Is { | 
|  | 16 | + | 
|  | 17 | +    /** | 
|  | 18 | +     * Returns {@code true} if the provided reference is {@code null} otherwise returns {@code false}. | 
|  | 19 | +     * | 
|  | 20 | +     * @param obj a reference to be checked against {@code null} | 
|  | 21 | +     * @return {@code true} if the provided reference is {@code null} otherwise {@code false} | 
|  | 22 | +     */ | 
|  | 23 | +    public static boolean isNull(Object obj) { | 
|  | 24 | +        return Objects.isNull(obj); | 
|  | 25 | +    } | 
|  | 26 | + | 
|  | 27 | +    /** | 
|  | 28 | +     * Returns {@code true} if the provided reference is non-{@code null} otherwise returns {@code | 
|  | 29 | +     * false}. | 
|  | 30 | +     * | 
|  | 31 | +     * @param obj a reference to be checked against {@code null} | 
|  | 32 | +     * @return {@code true} if the provided reference is non-{@code null} otherwise {@code false} | 
|  | 33 | +     */ | 
|  | 34 | +    public static boolean nonNull(Object obj) { | 
|  | 35 | +        return Objects.nonNull(obj); | 
|  | 36 | +    } | 
|  | 37 | + | 
|  | 38 | +    /** | 
|  | 39 | +     * Returns {@code true} if the provided String is {@code null} or empty otherwise returns {@code | 
|  | 40 | +     * false}. | 
|  | 41 | +     * | 
|  | 42 | +     * @param str a String to be checked against {@code null} or empty | 
|  | 43 | +     * @return {@code true} if the provided String is {@code null} or empty otherwise {@code false} | 
|  | 44 | +     */ | 
|  | 45 | +    public static boolean nullOrEmpty(String str) { | 
|  | 46 | +        return Strings.nullOrEmpty(str); | 
|  | 47 | +    } | 
|  | 48 | + | 
|  | 49 | +    /** | 
|  | 50 | +     * Execute code if the provided String is {@code null} or empty. | 
|  | 51 | +     * @param str a String to be checked against {@code null} or empty | 
|  | 52 | +     * @param executableFunction lambda function given executed if the provided String is {@code null} or empty. | 
|  | 53 | +     */ | 
|  | 54 | +    public static void nullOrEmpty(String str, ExecutableFunction executableFunction){ | 
|  | 55 | +        Strings.nullOrEmpty(str, executableFunction); | 
|  | 56 | +    } | 
|  | 57 | + | 
|  | 58 | +    /** | 
|  | 59 | +     * Checks if the provided String is {@code null} or empty. | 
|  | 60 | +     * @param str a String to be checked against {@code null} or empty | 
|  | 61 | +     * @param defaultValue - if the provided String is {@code null} or empty then this value will be returned. | 
|  | 62 | +     * @return provided String if non-{@code null} and non-empty otherwise defaultValue | 
|  | 63 | +     */ | 
|  | 64 | +    public static String nullOrEmpty(String str, String defaultValue){ | 
|  | 65 | +        return Strings.nullOrEmpty(str, defaultValue); | 
|  | 66 | +    } | 
|  | 67 | + | 
|  | 68 | +    /** | 
|  | 69 | +     * Returns {@code true} if the provided String is non-{@code null} and non-empty otherwise returns | 
|  | 70 | +     * {@code false}. | 
|  | 71 | +     * | 
|  | 72 | +     * @param str a String to be checked against non-{@code null} and non-empty | 
|  | 73 | +     * @return {@code true} if the provided String is non-{@code null} and non-empty otherwise {@code | 
|  | 74 | +     *     false} | 
|  | 75 | +     */ | 
|  | 76 | +    public static boolean nonNullNonEmpty(String str) { | 
|  | 77 | +        return Strings.nonNullNonEmpty(str); | 
|  | 78 | +    } | 
|  | 79 | + | 
|  | 80 | +    /** | 
|  | 81 | +     * Execute code if the provided String is non-{@code null} and non-empty. | 
|  | 82 | +     * @param str a String to be checked against non-{@code null} and non-empty | 
|  | 83 | +     * @param executableFunction lambda function given executed if the provided String is non-{@code null} and non-empty. | 
|  | 84 | +     */ | 
|  | 85 | +    public static void nonNullNonEmpty(String str, ExecutableFunction executableFunction) { | 
|  | 86 | +        Strings.nonNullNonEmpty(str, executableFunction); | 
|  | 87 | +    } | 
|  | 88 | + | 
|  | 89 | +    /** | 
|  | 90 | +     * Checks if the provided String is non-{@code null} and non-empty. | 
|  | 91 | +     * @param str a String to be checked against non-{@code null} and non-empty | 
|  | 92 | +     * @param defaultValue - if the provided String is non-{@code null} and non-empty then this value will be returned. | 
|  | 93 | +     * @return provided String if non-{@code null} and non-empty otherwise defaultValue | 
|  | 94 | +     */ | 
|  | 95 | +    public static String nonNullNonEmpty(String str, String defaultValue){ | 
|  | 96 | +        return Strings.nonNullNonEmpty(str, defaultValue); | 
|  | 97 | +    } | 
|  | 98 | + | 
|  | 99 | +    /** | 
|  | 100 | +     * Returns {@code true} if the provided Collection [List, Set] is {@code null} or empty otherwise | 
|  | 101 | +     * returns {@code false}. | 
|  | 102 | +     * | 
|  | 103 | +     * @param collection a Collection [List, Set] to be checked against {@code null} or empty | 
|  | 104 | +     * @return {@code true} if the provided Collection [List, Set] is {@code null} or empty otherwise | 
|  | 105 | +     *     {@code false} | 
|  | 106 | +     */ | 
|  | 107 | +    public static boolean nullOrEmpty(Collection<?> collection) { | 
|  | 108 | +        return Collections.nullOrEmpty(collection); | 
|  | 109 | +    } | 
|  | 110 | + | 
|  | 111 | +    /** | 
|  | 112 | +     * Execute code if the provided Collection [List, Set] is {@code null} or empty. | 
|  | 113 | +     * @param collection a Collection [List, Set] to be checked against {@code null} or empty | 
|  | 114 | +     * @param executableFunction lambda function given executed if the provided Collection [List, Set] is {@code null} or empty. | 
|  | 115 | +     */ | 
|  | 116 | +    public static void nullOrEmpty(Collection<?> collection, ExecutableFunction executableFunction) { | 
|  | 117 | +        Collections.nullOrEmpty(collection, executableFunction); | 
|  | 118 | +    } | 
|  | 119 | + | 
|  | 120 | +    /** | 
|  | 121 | +     * Returns {@code true} if the provided Collection [List, Set] is non-{@code null} and non-empty | 
|  | 122 | +     * otherwise returns {@code false}. | 
|  | 123 | +     * | 
|  | 124 | +     * @param collection a Collection [List, Set] to be checked against non-{@code null} and non-empty | 
|  | 125 | +     * @return {@code true} if the provided Collection [List, Set] is non-{@code null} and non-empty | 
|  | 126 | +     *     otherwise {@code false} | 
|  | 127 | +     */ | 
|  | 128 | +    public static boolean nonNullNonEmpty(Collection<?> collection) { | 
|  | 129 | +        return Collections.nonNullNonEmpty(collection); | 
|  | 130 | +    } | 
|  | 131 | + | 
|  | 132 | +    /** | 
|  | 133 | +     * Execute code if the provided Collection [List, Set] is non-{@code null} and non-empty. | 
|  | 134 | +     * @param collection collection a Collection [List, Set] to be checked against non-{@code null} and non-empty | 
|  | 135 | +     * @param executableFunction lambda function given executed if the provided Collection [List, Set] is non-{@code null} and non-empty. | 
|  | 136 | +     */ | 
|  | 137 | +    public static void nonNullNonEmpty(Collection<?> collection, ExecutableFunction executableFunction){ | 
|  | 138 | +        Collections.nonNullNonEmpty(collection, executableFunction); | 
|  | 139 | +    } | 
|  | 140 | + | 
|  | 141 | +    /** | 
|  | 142 | +     * Returns {@code true} if the provided Map is {@code null} or empty otherwise returns {@code | 
|  | 143 | +     * false}. | 
|  | 144 | +     * | 
|  | 145 | +     * @param map a Map to be checked against {@code null} or empty | 
|  | 146 | +     * @return {@code true} if the provided Map is {@code null} and empty otherwise * returns {@code | 
|  | 147 | +     *     false} | 
|  | 148 | +     */ | 
|  | 149 | +    public static boolean nullOrEmpty(Map<?, ?> map) { | 
|  | 150 | +        return Collections.nullOrEmpty(map); | 
|  | 151 | +    } | 
|  | 152 | + | 
|  | 153 | +    /** | 
|  | 154 | +     * Execute code if the provided Map is {@code null} or empty | 
|  | 155 | +     * @param map a Map to be checked against {@code null} or empty | 
|  | 156 | +     * @param executableFunction lambda function given executed if the provided Map is {@code null} or empty | 
|  | 157 | +     */ | 
|  | 158 | +    public static void nullOrEmpty(Map<?, ?> map, ExecutableFunction executableFunction){ | 
|  | 159 | +        Collections.nullOrEmpty(map, executableFunction); | 
|  | 160 | +    } | 
|  | 161 | + | 
|  | 162 | +    /** | 
|  | 163 | +     * Returns {@code true} if the provided Map is non-{@code null} and non-empty otherwise returns | 
|  | 164 | +     * {@code false}. | 
|  | 165 | +     * | 
|  | 166 | +     * @param map a Map to be checked against non-{@code null} and non-empty | 
|  | 167 | +     * @return {@code true} if the provided Map is non-{@code null} and non-empty otherwise {@code | 
|  | 168 | +     *     false} | 
|  | 169 | +     */ | 
|  | 170 | +    public static boolean nonNullNonEmpty(Map<?, ?> map) { | 
|  | 171 | +        return Collections.nonNullNonEmpty(map); | 
|  | 172 | +    } | 
|  | 173 | + | 
|  | 174 | +    /** | 
|  | 175 | +     * Execute code if the provided Map is non-{@code null} and non-empty | 
|  | 176 | +     * @param map  a Map to be checked against non-{@code null} and non-empty | 
|  | 177 | +     * @param executableFunction lambda function given executed if the provided Map is non-{@code null} and non-empty | 
|  | 178 | +     */ | 
|  | 179 | +    public static void nonNullNonEmpty(Map<?, ?> map, ExecutableFunction executableFunction){ | 
|  | 180 | +        Collections.nonNullNonEmpty(map, executableFunction); | 
|  | 181 | +    } | 
|  | 182 | +} | 
0 commit comments