List of usage examples for java.lang Object toString
public String toString()
From source file:io.amira.zen.json.ZenJson.java
private static StringEntity buildString(Object obj) { try {/* w w w.j a v a 2s . co m*/ return new StringEntity(obj.toString(), "UTF8"); } catch (Exception e) { return null; } }
From source file:com.karura.framework.utils.JsHelper.java
private static String stringLiteral(Object value) { return STRING_LITERAL_BACKSLASH + value.toString().replaceAll(STRING_LITERAL_BACKSLASH, STRING_LITERAL_ESCAPE) + STRING_LITERAL_BACKSLASH;//from w ww .j a v a 2s . com }
From source file:com.roncoo.pay.utils.JsonUtils.java
/** * Map?,??Json,/*from w w w . j a v a 2 s . c om*/ * @param response * @param object * @throws IOException */ public static void responseJson(HttpServletResponse response, Object object) throws IOException { Object toJSON = JSONObject.toJSON(object); try { response.getWriter().write(toJSON.toString()); } catch (IOException e) { LOG.error(e); } }
From source file:Main.java
public static void addAttributes(Element element, Map<String, Object> map) { if (map != null) { for (Map.Entry<String, Object> entry : map.entrySet()) { Object attrValue = entry.getValue(); element.setAttribute(entry.getKey(), attrValue == null ? null : attrValue.toString()); }/* w ww . j a v a 2s .co m*/ } }
From source file:Main.java
public static String nullStrToEmpty(final Object o) { if (o == null) { return ""; }/* www .j av a 2 s. co m*/ if (o instanceof String) { return (String) o; } return o.toString(); }
From source file:com.microsoft.windowsazure.services.core.Configuration.java
public static Configuration load() throws IOException { Configuration config = new Configuration(); InputStream stream = Configuration.class.getClassLoader() .getResourceAsStream("META-INF/com.microsoft.windowsazure.properties"); if (stream != null) { Properties properties = new Properties(); properties.load(stream);/*from ww w. j ava 2s .c o m*/ for (Object key : properties.keySet()) { config.setProperty(key.toString(), properties.get(key)); } } return config; }
From source file:Main.java
public static boolean isEmpty(Object obj) { if (obj == null) { return true; }//from w w w . j av a 2s . c om if (obj instanceof String && obj.toString().length() == 0) { return true; } if (obj.getClass().isArray() && Array.getLength(obj) == 0) { return true; } if (obj instanceof Collection && ((Collection) obj).isEmpty()) { return true; } if (obj instanceof Map && ((Map) obj).isEmpty()) { return true; } if (obj instanceof SparseArray && ((SparseArray) obj).size() == 0) { return true; } if (obj instanceof SparseBooleanArray && ((SparseBooleanArray) obj).size() == 0) { return true; } if (obj instanceof SparseIntArray && ((SparseIntArray) obj).size() == 0) { return true; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { if (obj instanceof SparseLongArray && ((SparseLongArray) obj).size() == 0) { return true; } } return false; }
From source file:Main.java
public static boolean hasPermission(Context appContext, String appOpsServiceId) throws UnknownError { ApplicationInfo appInfo = appContext.getApplicationInfo(); String pkg = appContext.getPackageName(); int uid = appInfo.uid; Class appOpsClass = null;// www . jav a 2 s . c o m Object appOps = appContext.getSystemService("appops"); try { appOpsClass = Class.forName("android.app.AppOpsManager"); Method checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE, String.class); Field opValue = appOpsClass.getDeclaredField(appOpsServiceId); int value = (int) opValue.getInt(Integer.class); Object result = checkOpNoThrowMethod.invoke(appOps, value, uid, pkg); return Integer.parseInt(result.toString()) == 0; // AppOpsManager.MODE_ALLOWED } catch (ClassNotFoundException e) { throw new UnknownError("class not found"); } catch (NoSuchMethodException e) { throw new UnknownError("no such method"); } catch (NoSuchFieldException e) { throw new UnknownError("no such field"); } catch (InvocationTargetException e) { throw new UnknownError("invocation target"); } catch (IllegalAccessException e) { throw new UnknownError("illegal access"); } }
From source file:Main.java
/** * Sets the element value to node.//from w w w.j a v a 2 s .c o m * * @param node the node * @param elementName the element name * @param elementValue the element value */ public static void setElementValueToNode(XmlSerializer serializer, String elementName, Object elementValue) throws IOException { if (elementValue != null) { serializer.startTag(null, elementName).text(elementValue.toString()).endTag(null, elementName); } }
From source file:com.xebialabs.aphillips.usertype.examples.take3.ReadableStringBuilderUserType.java
private static StringBuilder nullSafeToStringBuilder(Object value) { return ((value != null) ? new StringBuilder(value.toString()) : null); }