List of usage examples for java.lang Object toString
public String toString()
From source file:Main.java
/** * Sets the element value.// w w w .jav a2s . c o m * * @param node the node * @param elementValue the element value */ public static void setElementValue(XmlSerializer serializer, Object elementValue) throws IOException { if (elementValue != null) { serializer.text(elementValue.toString()); } }
From source file:Main.java
public static int getResourceId(String packageName, String resFileName, String parameterName) { if ((packageName != null) && (resFileName != null) && (parameterName != null)) try {/*from ww w . ja v a 2 s. com*/ Class localClass = Class.forName(packageName + "$" + resFileName); Field localField = localClass.getField(parameterName); Object localObject = localField.get(localClass.newInstance()); return Integer.parseInt(localObject.toString()); } catch (Exception e) { e.printStackTrace(); } return -1; }
From source file:Main.java
public static Element beanToXml(Document document, Object obj) throws ParserConfigurationException, InvocationTargetException, IllegalAccessException { String name = obj.getClass().getName(); Element rootElement = document.createElement(name); Method[] methods = obj.getClass().getMethods(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; String methodName = method.getName(); String fieldName = analyzeFieldName(methodName); Element fieldElement = document.createElement(fieldName); if (methodName.startsWith("get") && !"getClass".equals(methodName)) { Object value = method.invoke(obj); if (value != null && !"".equals(value.toString())) { fieldElement.setTextContent(value.toString()); } else { continue; }/* w w w. j a va 2 s.co m*/ } else { continue; } rootElement.appendChild(fieldElement); } return rootElement; }
From source file:Main.java
public static String asJson(Object value) throws Exception { if (value instanceof JSONArray || value instanceof JSONObject) { return value.toString(); }//w ww . j a v a 2 s . c o m return mapper.writeValueAsString(value); }
From source file:Main.java
public static Collection<String> addElementBeforeAndAfter(Collection<?> collection, String toAddBefore, String toAddAfter) {// w w w . j av a2s.c o m if (collection == null || collection.isEmpty()) { return Collections.emptyList(); } List<String> result = new ArrayList<>(collection.size()); for (Object o : collection) { StringBuilder stringBuilder = new StringBuilder( o.toString().length() + toAddBefore.length() + toAddAfter.length()); stringBuilder.append(toAddBefore); stringBuilder.append(o.toString().trim()); stringBuilder.append(toAddAfter); result.add(stringBuilder.toString()); } return result; }
From source file:Main.java
public static List<String> collectAsString(List<? extends Object> objects, String fieldName) { List<String> stringsAsAttribute = new ArrayList<String>(); String getterName = "get" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1, fieldName.length()); try {//from w w w.j av a2 s . c o m for (Object object : objects) { Method getterMethod = object.getClass().getMethod(getterName); Object result = getterMethod.invoke(object); stringsAsAttribute.add(result.toString()); } } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } return stringsAsAttribute; }
From source file:Main.java
/** * Utility method that return a String representation of a map. The elements * will be represented as "key = value"//from w w w . j av a 2s .c om * * @param map * The map to transform to a string * @return A csv string */ public static final String mapToString(Map map, String tabs) { if ((map == null) || (map.size() == 0)) { return ""; } StringBuffer sb = new StringBuffer(); Iterator iter = map.keySet().iterator(); while (iter.hasNext()) { Object key = iter.next(); sb.append(tabs); sb.append(key); Object value = map.get(key); sb.append(" = '").append(value.toString()).append("'\n"); } return sb.toString(); }
From source file:com.mseeworld.qzh.util.Debug.java
/** * ?/* w w w .ja va2s.co m*/ * @param obj * @date 2013-5-8 */ public static final void printf(Object obj) { if (obj != null) { System.out.println(obj.toString()); } }
From source file:mergedoc.Application.java
/** * ? Look & Feel ???//from w w w . j av a2s .c o m * @throws ClassNotFoundException LookAndFeel ???????? * @throws InstantiationException ???????????? * @throws IllegalAccessException ???????????? * @throws UnsupportedLookAndFeelException lnf.isSupportedLookAndFeel() ? false ?? */ private static void initSystemLookAndFeel() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); Toolkit.getDefaultToolkit().setDynamicLayout(true); // Windows ??? String osName = System.getProperty("os.name", ""); if (osName.indexOf("Windows") != -1) { Object propoFont = new FontUIResource("MS UI Gothic", Font.PLAIN, 12); Object fixedFont = new FontUIResource("MS Gothic", Font.PLAIN, 12); // ?????????? // ????? instanceof FontUIResource ? // ???UIDefaults ? Lazy Value ?????? for (Object keyObj : UIManager.getLookAndFeelDefaults().keySet()) { String key = keyObj.toString(); if (key.endsWith("font") || key.endsWith("Font")) { UIManager.put(key, propoFont); } } // ????? UIManager.put("OptionPane.messageFont", fixedFont); UIManager.put("TextPane.font", fixedFont); UIManager.put("TextArea.font", fixedFont); } }
From source file:Main.java
public static String getString(Map<String, Object> obj, String key) { try {/*from www . j a v a 2 s .c o m*/ Object resultObj = obj.get(key); if (resultObj != null) { String result = resultObj.toString(); return result; } else { return new String(""); } } catch (Exception e) { e.printStackTrace(); return null; } }