List of usage examples for java.lang Object toString
public String toString()
From source file:Main.java
public static String[] asArray(Object object) { if (object == null) { return null; }//from w w w . ja v a2s. c o m Class componentType = object.getClass().getComponentType(); if (String.class.equals(componentType)) { return (String[]) object; } else if (componentType != null) { Object[] objects = (Object[]) object; String[] result = new String[objects.length]; for (int i = 0; i < objects.length; i++) { Object o = objects[i]; if (o == null) { continue; } result[i] = o.toString(); } return result; } else if (object instanceof Collection) { Collection collection = (Collection) object; String[] result = new String[collection.size()]; Iterator iterator = collection.iterator(); for (int i = 0; i < result.length; i++) { Object next = iterator.next(); if (next == null) { continue; } result[i] = next.toString(); } return result; } else { String string = object.toString().trim(); String[] split = string.split("\\s*,\\s*"); return split; } }
From source file:Main.java
public static final short objectToShort(Object o) { if (o instanceof Number) return ((Number) o).shortValue(); try {/*from w w w . jav a2 s .c o m*/ if (o == null) return -1; else return Short.parseShort(o.toString()); } catch (NumberFormatException e) { e.printStackTrace(); return -1; } }
From source file:Main.java
/** * Convert an object to string.//from w ww . ja v a2 s .c o m * @param obj an object. * @return the result string. */ public static String otos(Object obj) { try { if (obj == null) return ""; if (obj instanceof byte[]) return new String((byte[]) obj, "UTF-8"); return obj.toString(); } catch (Exception e) { return ""; } }
From source file:net.longfalcon.newsj.util.ArrayUtil.java
public static <T> String stringify(Collection<T> collection, String delimiter) { StringBuilder sb = new StringBuilder(); Iterator<T> iterator = collection.iterator(); while (iterator.hasNext()) { T next = iterator.next();/* w w w .j a v a 2 s .c om*/ if (next instanceof Object[]) { Object[] nextArr = (Object[]) next; for (Object o : nextArr) { sb.append(o.toString()).append(","); } sb.append(delimiter); } else { sb.append(next.toString()).append(delimiter); } } return sb.toString(); }
From source file:Validator.java
public static boolean isEmpty(Object value) { if (value == null) { return true; } else if (value.toString().trim().length() == 0) { return true; }// ww w . j a va 2s . c o m return false; }
From source file:com.clover.sdk.v3.JsonHelper.java
public static Object toJSON(Object object) { if (object instanceof Map) { JSONObject json = new JSONObject(); Map map = (Map) object; for (Object key : map.keySet()) { try { json.putOpt(key.toString(), toJSON(map.get(key))); } catch (JSONException e) { /* ignore for now */ } }// w ww .j a v a 2 s . co m return json; } else if (object instanceof Iterable) { JSONArray json = new JSONArray(); for (Object value : ((Iterable) object)) { json.put(value); } return json; } else if (object instanceof Enum) { return ((Enum) object).name(); } else { return object; } }
From source file:com.linkedin.pinot.common.segment.fetcher.SegmentFetcherFactory.java
public static void initSegmentFetcherFactory(Configuration pinotHelixProperties) { Configuration segmentFetcherFactoryConfig = pinotHelixProperties .subset(CommonConstants.Server.PREFIX_OF_CONFIG_OF_SEGMENT_FETCHER_FACTORY); Iterator segmentFetcherFactoryConfigIterator = segmentFetcherFactoryConfig.getKeys(); while (segmentFetcherFactoryConfigIterator.hasNext()) { Object configKeyObject = segmentFetcherFactoryConfigIterator.next(); try {//from www .j a va 2 s. c o m String segmentFetcherConfigKey = configKeyObject.toString(); String protocol = segmentFetcherConfigKey.split(".", 2)[0]; if (!SegmentFetcherFactory.containsProtocol(protocol)) { SegmentFetcherFactory .initSegmentFetcher(new ConfigurationMap(segmentFetcherFactoryConfig.subset(protocol))); } } catch (Exception e) { LOGGER.error("Got exception to process the key: " + configKeyObject); } } }
From source file:com.xafero.vee.cmd.MainApp.java
private static void execute(String fileName) throws FileNotFoundException, ScriptException { File file = (new File(fileName)).getAbsoluteFile(); if (!file.exists()) throw new FileNotFoundException("There's no file named '" + file + "'!"); String extension = Files.getExtension(file); ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngine engine = mgr.getEngineByExtension(extension); Bindings env = engine.createBindings(); inject(env, file);//from w w w.j a v a 2s .c om try { Object result = engine.eval(new FileReader(file), env); if (result != null) System.out.println(result.toString()); } catch (ScriptException e) { throw e; } }
From source file:Main.java
private static String objectToString(Object o, boolean quoteStrings) { if (o == null) { return "null"; }// www.j a v a 2s . c om if (o instanceof Number) { return o.toString(); } if (quoteStrings) { return "'" + o.toString().replaceAll(",", "%2C") + "'"; } else { return o.toString(); } }
From source file:com.apporiented.hermesftp.FtpServerApp.java
private static void logOptions(FtpServerOptions aOptions) { log.info(aOptions.getAppTitle());// w w w. j av a 2 s. c o m log.info("Version " + aOptions.getAppVersion()); log.info("Build info: " + aOptions.getAppBuildInfo()); log.info("OS name: " + System.getProperty("os.name")); log.info("OS file encoding (System): " + System.getProperty("file.encoding")); log.info("OS file encoding (NIO): " + Charset.defaultCharset().name()); log.info("Ftp server options:"); Set<Object> keyset = aOptions.getProperties().keySet(); for (Object key : keyset) { String value = aOptions.getProperty(key.toString()); log.info(" " + key + ": " + value); } }