forked from alibaba/COLA
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove ParamException and add Assert
- Loading branch information
fulan.zjf
committed
Jan 13, 2019
1 parent
eaff739
commit 47c1bfa
Showing
14 changed files
with
113 additions
and
82 deletions.
There are no files selected for viewing
8 changes: 0 additions & 8 deletions
8
cola-framework/cola-core/src/main/java/com/alibaba/cola/event/EventBus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/Assert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.alibaba.cola.exception; | ||
|
||
import org.springframework.util.CollectionUtils; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
/** | ||
* Assertion utility class that assists in validating arguments. | ||
* | ||
* <p>Useful for identifying programmer errors early and clearly at runtime. | ||
* | ||
* <p>For example, if the contract of a public method states it does not | ||
* allow {@code null} arguments, {@code Assert} can be used to validate that | ||
* contract. | ||
* | ||
* For example: | ||
* | ||
* <pre class="code"> | ||
* Assert.notNull(clazz, "The class must not be null"); | ||
* Assert.isTrue(i > 0, "The value must be greater than zero");</pre> | ||
* | ||
* This class is empowered by {@link org.springframework.util.Assert} | ||
* | ||
* @author Frank Zhang | ||
* @date 2019-01-13 11:49 AM | ||
*/ | ||
public abstract class Assert { | ||
|
||
/** | ||
* Assert a boolean expression, throwing {@code BizException} | ||
* | ||
* for example | ||
* | ||
* <pre class="code">Assert.isTrue(i != 0, errorCode.B_ORDER_illegalNumber, "The order number can not be zero");</pre> | ||
* | ||
* @param expression a boolean expression | ||
* @param errorCode | ||
* @param message the exception message to use if the assertion fails | ||
* @throws BizException if expression is {@code false} | ||
*/ | ||
public static void isTrue(boolean expression, ErrorCodeI errorCode, String message){ | ||
if (!expression) { | ||
throw new BizException(errorCode, message); | ||
} | ||
} | ||
|
||
public static void isTrue(boolean expression, String message) { | ||
isTrue(expression, BasicErrorCode.B_COMMON_ERROR, message); | ||
} | ||
|
||
public static void isTrue(boolean expression) { | ||
isTrue(expression, "[Assertion failed] - this expression must be true"); | ||
} | ||
|
||
public static void notNull(Object object, ErrorCodeI errorCode, String message) { | ||
if (object == null) { | ||
throw new BizException(errorCode, message); | ||
} | ||
} | ||
|
||
public static void notNull(Object object, String message) { | ||
notNull(object, BasicErrorCode.B_COMMON_ERROR, message); | ||
} | ||
|
||
public static void notNull(Object object){ | ||
notNull(object, BasicErrorCode.B_COMMON_ERROR, "[Assertion failed] - the argument "+object+" must not be null"); | ||
} | ||
|
||
public static void notEmpty(Collection<?> collection) { | ||
notEmpty(collection, | ||
"[Assertion failed] - this collection must not be empty: it must contain at least 1 element"); | ||
} | ||
|
||
public static void notEmpty(Collection<?> collection, String message) { | ||
if (CollectionUtils.isEmpty(collection)) { | ||
throw new BizException(message); | ||
} | ||
} | ||
|
||
public static void notEmpty(Map<?, ?> map, String message) { | ||
if (CollectionUtils.isEmpty(map)) { | ||
throw new BizException(message); | ||
} | ||
} | ||
|
||
public static void notEmpty(Map<?, ?> map) { | ||
notEmpty(map, "[Assertion failed] - this map must not be empty; it must contain at least one entry"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/BizException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/ParamException.java
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
cola-framework/cola-core/src/main/java/com/alibaba/cola/exception/Preconditions.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters