lmw
2023-04-03 16ea883d3c03fd8b910f9282aa1bc08378d40d54
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.beloo.widget.chipslayoutmanager.util;
 
import android.text.TextUtils;
 
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
 
public class AssertionUtils {
    private AssertionUtils() {}
 
    public static <T> void assertNotNull(@Nullable T object, @NonNull String parameterName) throws AssertionError {
        if (object == null)
            throw new AssertionError(parameterName + " can't be null.");
    }
 
    public static <T> void assertInstanceOf(@NonNull T object, @NonNull Class<?> clazz, @NonNull String parameterName) throws AssertionError {
        check(!clazz.isInstance(object), parameterName + " is not instance of " + clazz.getName() + ".");
    }
 
    public static <T> void assertNotEquals(@NonNull T object, @NonNull T anotherObject, @NonNull String parameterName) throws AssertionError {
        check(object == anotherObject || object.equals(anotherObject), parameterName + " can't be equal to " + String.valueOf(anotherObject) + ".");
    }
 
    public static void assertNotEmpty(String text, String parameterName) throws AssertionError {
        check(TextUtils.isEmpty(text) || TextUtils.isEmpty(text.trim()), parameterName + " can't be empty.");
    }
 
    public static void check(boolean b, @NonNull String message) {
        if (b)
            throw new AssertionError(message);
    }
}