Coverage Summary for Class: Util (net.sf.persism)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| Util | 100% (1/1) | 100% (11/11) | 77.8% (35/45) |
1 package net.sf.persism; 2 3 import java.sql.Connection; 4 import java.sql.ResultSet; 5 import java.sql.SQLException; 6 import java.sql.Statement; 7 import java.util.HashSet; 8 import java.util.List; 9 10 /** 11 * @author Dan Howard 12 * @since 4/1/12 6:48 AM 13 */ 14 final class Util { 15 16 private static final Log log = Log.getLogger(Util.class); 17 18 private Util() { 19 } 20 21 static void rollback(Connection con) { 22 try { 23 if (con != null && !con.getAutoCommit()) { 24 con.rollback(); 25 } 26 } catch (SQLException e1) { 27 log.error(e1.getMessage(), e1); 28 } 29 30 } 31 32 static boolean isNotEmpty(String s) { 33 return !isEmpty(s); 34 } 35 36 static boolean isEmpty(String s) { 37 return s == null || s.trim().length() == 0; 38 } 39 40 static void cleanup(Statement st, ResultSet rs) { 41 try { 42 if (rs != null) { 43 rs.close(); 44 } 45 } catch (SQLException e) { 46 log.error(e.getMessage(), e); 47 } 48 try { 49 if (st != null) { 50 st.close(); 51 } 52 } catch (SQLException e) { 53 log.error(e.getMessage(), e); 54 } 55 } 56 57 static void cleanup(ResultSet rs) { 58 try { 59 if (rs != null) { 60 rs.close(); 61 } 62 } catch (SQLException e) { 63 log.error(e.getMessage(), e); 64 } 65 } 66 67 public static boolean containsColumn(ResultSet rs, String column) { 68 try { 69 rs.findColumn(column); 70 return true; 71 } catch (SQLException sqlex) { 72 } 73 return false; 74 } 75 76 public static String camelToTitleCase(String text) { 77 78 StringBuilder sb = new StringBuilder(); 79 80 for (int i = 0; i < text.length(); i++) { 81 char c = text.charAt(i); 82 if (i == 0) { 83 sb.append(c); 84 } else { 85 if (Character.isUpperCase(c)) { 86 sb.append(" "); 87 } 88 sb.append(c); 89 } 90 } 91 return sb.toString(); 92 } 93 94 public static <T> boolean isRecord(Class<T> objectClass) { 95 // Java 8 test for isRecord since class.isRecord doesn't exist in Java 8 96 Class<?> sup = objectClass.getSuperclass(); 97 while (!sup.equals(Object.class)) { 98 if ("java.lang.Record".equals(sup.getName())) { 99 return true; 100 } 101 sup = sup.getSuperclass(); 102 } 103 return false; 104 } 105 106 public static void trimArray(String[] arr) { 107 // forget regex.... 108 for (int j = 0; j < arr.length; j++) { 109 arr[j] = arr[j].trim(); 110 } 111 } 112 113 // https://stackoverflow.com/questions/1075656/simple-way-to-find-if-two-different-lists-contain-exactly-the-same-elements 114 public static <T> boolean listEqualsIgnoreOrder(List<T> list1, List<T> list2) { 115 return new HashSet<>(list1).equals(new HashSet<>(list2)); 116 } 117 118 119 }