1 28 29 package org.objectweb.util.explorer; 30 31 import java.net.MalformedURLException ; 32 import java.net.URL ; 33 import java.util.Arrays ; 34 import java.util.List ; 35 import java.util.Vector ; 36 37 import org.objectweb.util.explorer.core.common.lib.ClassResolver; 38 import org.objectweb.util.trace.TraceSystem; 39 40 48 public abstract class ExplorerUtils 49 { 50 51 57 63 69 84 protected static Object [] merge(Object [] a1, Object [] a2){ 85 List l = (a1==null ? new Vector () : Arrays.asList(a1)); 86 if(a2!=null && a2.length>0){ 87 l = new Vector (l); 88 for(int i=0 ; i<a2.length ; i++){ 89 if(!l.contains(a2[i])){ 90 l.add(a2[i]); 91 } 92 } 93 } 94 return l.toArray(); 95 } 96 97 98 104 119 public static Object [] mergeArrays(Object [] a1, Object [] a2){ 120 return merge(a1,a2); 121 } 122 123 127 public static String [] mergeArrays(String [] a1, String [] a2){ 128 Object [] result = merge(a1, a2); 129 return (String [])(Arrays.asList(result)).toArray(new String [result.length]); 130 } 131 132 136 public static String arrayToString(Object [] m){ 137 if(m!=null){ 138 StringBuffer sb = new StringBuffer (); 139 sb.append("{"); 140 for(int i=0 ; i<m.length ; i++){ 141 sb.append(m[i]); 142 if(i<m.length-1){ 143 sb.append(","); 144 } 145 } 146 sb.append("}"); 147 return sb.toString(); 148 } 149 return "null"; 150 } 151 152 160 public static boolean compareObjects(Object o1, Object o2){ 161 if(o1==null && o2==null) 162 return true; 163 if(o1!=null) 164 return o1.equals(o2); 165 return false; 166 } 167 168 173 public static int getHashCode(Object o){ 174 if(o!=null) 175 return o.hashCode(); 176 return 0; 177 } 178 179 182 public static String toString(Object o){ 183 return (o==null)?"null":o.toString(); 184 } 185 186 192 public static boolean isEmpty(String value){ 193 return value==null || value.equals(""); 194 } 195 196 205 public static URL getURL(String url){ 206 try { 207 URL theURL = ClassResolver.getResource(url); 208 if(theURL==null){ 209 theURL = new URL (url); 210 } 211 return theURL; 212 } catch (MalformedURLException e) { 213 TraceSystem.get("explorer").info(url + ": Resource not found!"); 214 } 215 return null; 216 } 217 } | Popular Tags |