CheckUtils.java 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package cn.com.goldenwater.utils;
  2. import cn.com.goldenwater.exception.CheckException;
  3. import org.springframework.context.MessageSource;
  4. import java.util.Arrays;
  5. /**
  6. * @author HAIHUA2
  7. */
  8. public class CheckUtils {
  9. private static MessageSource resources;
  10. public static void setResources(MessageSource resources) {
  11. CheckUtils.resources = resources;
  12. }
  13. public static void check(boolean condition, String msgKey, Object... args) {
  14. if (!condition) {
  15. fail(msgKey, args);
  16. }
  17. }
  18. public static void notEmpty(String str, String msgKey, Object... args) {
  19. if (str == null || str.isEmpty()) {
  20. fail(msgKey, args);
  21. }
  22. }
  23. public static void notNull(Object obj, String msgKey, Object... args) {
  24. if (obj == null) {
  25. fail(msgKey, args);
  26. }
  27. }
  28. private static void fail(String msgKey, Object... args) {
  29. throw new CheckException(msgKey + ": " + Arrays.toString(args));
  30. // throw new CheckException(resources.getMessage(msgKey, args, Locale.CHINA));
  31. }
  32. }