1 13 package com.tonbeller.jpivot.util; 14 15 19 public class StringUtil { 20 21 26 public static String bracketsAround(String orig) { 27 if (orig.startsWith("[") && orig.endsWith("]")) 28 return orig; 29 return "[" + orig + "]"; 30 } 31 32 37 public static String [] splitUniqueName(String uniqueName) { 38 String str = uniqueName.trim(); 40 int l2 = str.length() - 1; 41 if (str.charAt(0)!= '[' || str.charAt(l2)!= ']' ) 42 return new String [] {uniqueName}; str = str.substring(1, l2); 45 String [] nameParts = str.split("\\]\\.\\["); 47 return nameParts; 48 } 49 50 56 public static String createUName(String [] strs, int n) { 57 if (n <= 0) 58 n = strs.length; 59 StringBuffer sb = new StringBuffer (); 60 for (int i = 0; i < n; i++) { 61 if (i > 0) 62 sb.append('.'); 63 sb.append('['); 64 sb.append(strs[i]); 65 sb.append(']'); 66 } 67 return sb.toString(); 68 } 69 70 75 public static String dimFromUName(String uName) { 76 String [] strs = splitUniqueName(uName); 77 return "[" + strs[0] + "]"; 78 } 79 80 85 public static String parentFromUName(String uName) { 86 String [] strs = splitUniqueName(uName); 87 int n = strs.length; 88 if (n < 3) 89 return null; return createUName(strs, n - 1); 91 } 92 93 } | Popular Tags |