1 18 package sync4j.framework.engine; 19 20 import java.util.ArrayList ; 21 22 27 public final class Util { 28 35 public static boolean[] createArrayOfBooleans(String [] string_values) { 36 boolean[] array = new boolean[string_values.length]; 37 38 for(int i=0; i<string_values.length; ++i) { 39 array[i] = Boolean.getBoolean(string_values[i]); 40 } 42 return array; 43 } 45 52 public static char[] createArrayOfCharacters(String [] string_values) { 53 char[] array = new char[string_values.length]; 54 55 for(int i=0; i<string_values.length; ++i) { 56 array[i] = (string_values[i].length()>0) ? string_values[i].charAt(0) : ' '; 57 } 59 return array; 60 } 62 69 public static double[] createArrayOfDoubles(String [] string_values) { 70 double[] array = new double[string_values.length]; 71 72 for(int i=0; i<string_values.length; ++i) { 73 array[i] = Double.parseDouble(string_values[i]); 74 } 76 return array; 77 } 79 86 public static float[] createArrayOfFloats(String [] string_values) { 87 float[] array = new float[string_values.length]; 88 89 for(int i=0; i<string_values.length; ++i) { 90 array[i] = Float.parseFloat(string_values[i]); 91 } 93 return array; 94 } 96 103 public static int[] createArrayOfIntegers(String [] string_values) { 104 int[] array = new int[string_values.length]; 105 106 for(int i=0; i<string_values.length; ++i) { 107 array[i] = Integer.parseInt(string_values[i]); 108 } 110 return array; 111 } 113 120 public static long[] createArrayOfLongs(String [] string_values) { 121 long[] array = new long[string_values.length]; 122 123 for(int i=0; i<string_values.length; ++i) { 124 array[i] = Long.parseLong(string_values[i]); 125 } 127 return array; 128 } 130 132 148 public static String makeCapitalizedString(String [] words) { 149 StringBuffer sb = new StringBuffer (); 150 151 for(int i=0; i<words.length; ++i) { 152 if (words[i] != null) sb.append(capitalizeWord(words[i])); 153 } 155 return sb.toString(); 156 } 157 158 171 public static String capitalizeWord(String word) { 172 int len = word.length(); 173 174 if (len == 1) return word.toUpperCase(); 175 176 return word.substring(0, 1).toUpperCase() + 177 word.substring(1 ) ; 178 } 179 180 188 public static String arrayToString(Object [] array) { 189 ArrayList arrayList = new ArrayList (); 190 191 for (int i=0; i<array.length; ++i) { 192 arrayList.add(array[i]); 193 } 194 195 return arrayList.toString(); 196 } 197 } | Popular Tags |