Package cn.sliew.milky.common.check
Enum Asserts
- java.lang.Object
-
- java.lang.Enum<Asserts>
-
- cn.sliew.milky.common.check.Asserts
-
- All Implemented Interfaces:
Serializable,Comparable<Asserts>
public enum Asserts extends Enum<Asserts>
Conditional failures explained guava cache的一篇关于条件检查失败的描述。在大多数时候if (!condition) throw new RuntimeException();即可。 但是深入思考下去,关于条件检查也有不同的区别。1. 检查调用者是否遵照方法声明正确地使用,如注释的要求或者@NonNull,@Nullable等规范 2. 类内断言。如果类本身出现异常,如错误的状态等。常见的有后置检查,类不变量,私有方法的内部检查 3. 确认检查。当不确定使用的api是否满足条件时做的处理,如果满足条件则调用,不满足则不调用。 4. 测试断言。测试代码中使用,确保测试代码正确执行。 5. 异常结果。当调用方法正常返回时,但是返回的结果是错误的,比如两个int类型相加,返回结果因为溢出而错误, 但是程序没有任何异常抛出。
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidasserts(boolean assertion)static voidasserts(boolean assertion, Supplier<Object> errorMessage)static AssertsvalueOf(String name)Returns the enum constant of this type with the specified name.static Asserts[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Method Detail
-
values
public static Asserts[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (Asserts c : Asserts.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static Asserts valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
asserts
public static void asserts(boolean assertion)
-
-