Assert
Assert.notNull(vo, "The loan information is empty"); Assert.notBlank(vo.getLoanId(), "The loan number is blank"); Assert.notEmpty(busiLoanApplyDto.getCustId(), "The customer number is empty!"); Assert.notNull(busiLoanApplyDto.getApplyTerm(), "The loan term is null!"); Assert.isTrue(0 != busiLoanApplyDto.getApplyTerm(), "The loan term is empty!"); Assert.notNull(busiLoanApplyDto.getLoanAmount(), "The loan amount is null!"); Assert.notEmpty(busiLoanApplyDto.getLoanCode(), "The loan application number is empty");
CommUtils (self-created class)
String validate = ValidationUtils.validate(signMemberInitDto); if (CommUtils.isNotEmpty(validate)){ log.error("Failed to initialize the contractor information, the reason is {}", validate); throw new ClmpException("Failed to initialize contractor information"); } IInitSignMember iInitSignMember = iInitSignMemberMap.get(signMemberInitDto.getCustType()); if (CommUtils.isEmpty(iInitSignMember)) { log.error("When the customer type is {}, the corresponding business processing class does not exist!", signMemberInitDto.getCustType()); throw new ClmpException("No corresponding business processing class"); }
public class CommUtils { public static String getCorrectAddress(String address) { if (StringUtils.isEmpty(address) || !(address.contains("-") & amp; & amp; address.contains(" & amp;"))) { return address; } String correctAddress = ""; StringBuilder sb = new StringBuilder(); //String address = "Hubei Province &42-Wuhan City &4201-Hongshan District &420111-Zhangjiawan Street &420111004-9 No. &4201110041000"; try { String[] split = address.split("-"); for (String s : split) { sb.append(s.substring(0, s.indexOf(" & amp;"))).append("/"); } correctAddress = sb.substring(0, sb.lastIndexOf("/")); } catch (Exception e) { e.printStackTrace(); } return correctAddress; } /** * Determine whether the object content is empty * The object is equal to null and is empty. * Object type supports array, string, * * @param obj * @return */ public static boolean isEmpty(Object obj) { if (obj == null) { return true; } if (obj.getClass().isArray()) { return Array.getLength(obj) == 0; } else if (obj instanceof String) { return ((String) obj).trim().length() == 0; } else if (obj instanceof CharSequence) { return ((CharSequence) obj).length() == 0; } else if (obj instanceof Collection) { return ((Collection) obj).isEmpty(); } else if (obj instanceof Map) { return ((Map) obj).isEmpty(); } else if (obj instanceof Set) { return ((Set) obj).isEmpty(); } else { return false; } } /** * Determine whether it is not empty */ public static boolean isNotEmpty(Object obj) { return !isEmpty(obj); } /** * Capitalize first letter. * * @param str * @return */ public static String capitalizeTheFirstLetter(String str) { char[] chs = str.toCharArray(); for (int i = 0; i < chs.length; ) { chs[i] = Character.toUpperCase(chs[i]); break; } return String.valueOf(chs); } /** * List<Map<String, String>> is sorted according to value * * @param list * @return */ public static List<Map<String, String>> sortList(List<Map<String, String>> list) { Collections.sort(list, new Comparator<Map<String, String>>() { @Override public int compare(Map<String, String> o1, Map<String, String> o2) { return o1.get("countScore").compareTo(o2.get("countScore")); } }); return list; } public static Map<String, String> getData(int num) { Map<String, String> map = new HashMap<String, String>(); map.put("countScore", String.valueOf(num)); return map; } public static Map<String, String> getDataMap(String s) { Map<String, String> map = new HashMap<String, String>(); map.put("countScore", s); return map; } public static Map<String, Integer> listDataNum(List<String> list) { Map<String, Integer> map = new HashMap<>(); for (String str : list) { //Counter, used to record the number of data Integer i = 1; if (map.get(str) != null) { i = map.get(str) + 1; } map.put(str, i); } return map; } /** * Remove the specified characters from the beginning of the specified string * * @param str original string * @param delStr The string to be deleted * @return */ public static String trimStringStart(String str, String delStr) { int delStrLength = delStr.length(); if (str.startsWith(delStr)) { str = str.substring(delStrLength); } if (str.endsWith(delStr)) { str = str.substring(0, str.length() - delStrLength); } return str; } /** * Remove the specified characters from the end of the specified string * * @param str original string * @param delStr The string to be deleted * @return */ private static String trimStringEnd(String str, String delStr) { int delStrLength = delStr.length(); if (str.endsWith(delStr)) { str = str.substring(0, str.length() - delStrLength); } return str; } /** * Determine whether each attribute in the class is empty * * @param o * @return */ public static boolean allFieldIsNULL(Object o) { try { for (Field field : o.getClass().getDeclaredFields()) { field.setAccessible(true); Object object = field.get(o); if (object instanceof CharSequence) { if (!org.springframework.util.ObjectUtils.isEmpty(object)) { return false; } } else { if (null != object) { return false; } } } } catch (Exception e) { System.out.println("Exception when judging object attribute is null"); } return true; } public static void main(String[] arg) { List<Map<String, String>> list = new ArrayList<Map<String, String>>(); list.add(getData(0)); list.add(getData(3)); list.add(getData(05)); list.add(getData(6)); list.add(getData(2)); System.out.println("before sorting" + list); sortList(list); System.out.println("After sorting" + list); List<Map<String, String>> list2 = new ArrayList<Map<String, String>>(); list2.add(getDataMap("hskjd")); list2.add(getDataMap("jhsc")); list2.add(getDataMap("woeuifjn")); list2.add(getDataMap("puch")); list2.add(getDataMap("wefwh")); System.out.println("before sorting" + list2); sortList(list2); System.out.println("After sorting" + list2); List<String> list3 = new ArrayList<>(); list3.add("aa"); list3.add("aa"); list3.add("aa"); list3.add("bb"); list3.add("cc"); list3.add("cc"); list3.add("dd"); list3.add("dd"); listDataNum(list3); String s1 = trimStringStart("27382684682752635", "27382684682"); String s = trimStringStart("sdahjhsd", "sda"); String s2 = trimStringStart("2738268468211752635111", "27382684682"); System.out.println("s----------------:" + s); System.out.println("s1----------------:" + s1); System.out.println("s2----------------:" + s2); } }