List of usage examples for java.lang Object toString
public String toString()
From source file:Main.java
/** * Paranoid version of tostring()// ww w.ja v a 2s.c o m * * @param obj * Object * @return String * */ private static String getPrettyObjectValue(final Object obj) { try { return obj.toString(); } catch (final Throwable t) { // either obj is null or has a very strange toString() method. return ""; } }
From source file:Main.java
public static boolean doBoolean(Object obj, boolean defValue) { return obj != null ? Boolean.parseBoolean(obj.toString()) : defValue; }
From source file:Main.java
public static String join(Collection<? extends Object> list, String separator) { StringBuilder sb = new StringBuilder(); for (Object o : list) { sb.append(o.toString()); sb.append(separator);/*from w ww. jav a 2 s .c om*/ } if (sb.length() > 0 && separator.length() > 0) { sb.delete(sb.length() - separator.length(), sb.length()); } return sb.toString(); }
From source file:Main.java
/** * @return//from w w w .j av a 2 s .co m */ public static String getBasePath() { Map<String, Object> map = threadLocal.get(); if (map == null) { return null; } Object o = map.get(BASEPATH_KEY); return o == null ? null : o.toString(); }
From source file:Main.java
public static boolean checkObj(Object object) { boolean result = false; if (null != object && !object.toString().equals("anyType{}")) { result = true;/*from w w w. j av a 2 s.c om*/ } return result; }
From source file:Main.java
/** * Returns the maximum length of any element in a Collection. * * @param collection the collection in question * @return the length of the longest element *//*w w w . ja va 2 s. c om*/ public static int getMaximumElementLength(final Collection<String> collection) { int max = 0; for (Object object : collection) { if (object.toString().length() > max) { max = object.toString().length(); } } return max; }
From source file:Main.java
public static String nullStrToEmpty(Object str) { return (str == null ? "" : (str instanceof String ? (String) str : str.toString())); }
From source file:Main.java
public static <T> T single(Collection<T> cl, boolean force, Object msg) { String amsg = msg == null ? "" : "," + msg.toString(); if (cl.isEmpty()) { if (force) { throw new RuntimeException("force:" + cl + amsg); } else {//from w w w .j a va 2 s .com return null; } } else if (cl.size() > 1) { throw new RuntimeException("tomuch:" + cl + amsg); } else { return cl.iterator().next(); } }
From source file:Main.java
/** * Creates new collection that contains only element whose string * representation starts with prefix It uses raw collection - not * parameterized. There is no {@link SuppressWarnings} annotation so IDE * will probably report rawtype and/or unchecked warnings. * /*from ww w. j a va 2 s . c om*/ * @param c * raw collection to create prefixed collection from * @param prefix * to use as filter * @return collection without nulls */ public static Collection withPrefixRaw(Collection c, String prefix) { Collection prefixed = new ArrayList(); Iterator iterator = c.iterator(); while (iterator.hasNext()) { Object o = iterator.next(); if (o != null && o.toString().startsWith(prefix)) { prefixed.add(o); } } return prefixed; }
From source file:edu.stanford.muse.util.VizUtils.java
public static String getAddressBook(JSONObject data) { try {//from ww w . ja v a2s. c o m JSONObject addressBookJSON = data.getJSONObject("addressBook"); Object entries = addressBookJSON.get("entries"); return entries.toString(); } catch (JSONException e) { System.out.println(e.getStackTrace()); return "null"; } }