List of usage examples for java.lang Object toString
public String toString()
From source file:Main.java
/** * Returns the value for key in dictionary as a float array or the given default * value if no value is defined for the key. * /*from ww w . ja v a2s.c o m*/ * @param dict * Dictionary that contains the key, value pairs. * @param key * Key whose value should be returned. * @param defaultValue * Default value to return if the key is undefined. * @return Returns the float array value for key in dict. */ public static float[] getFloatArray(Map<String, Object> dict, String key, float[] defaultValue, String separator) { Object value = dict.get(key); if (value == null) { return defaultValue; } else { String[] floatChars = value.toString().split(separator); float[] result = new float[floatChars.length]; for (int i = 0; i < floatChars.length; i++) { result[i] = Float.parseFloat(floatChars[i]); } return result; } }
From source file:com.wxxr.nirvana.json.TestUtils.java
/** * normalizes a string so that strings generated on different platforms can * be compared. any group of one or more space, tab, \r, and \n characters * are converted to a single space character * /* w ww . j av a 2s . co m*/ * @param obj * the object to be normalized. normalize will perform its * operation on obj.toString().trim() ; * @param appendSpace * @return the normalized string */ public static String normalize(Object obj, boolean appendSpace) { Matcher matcher = WHITESPACE_BLOCK.matcher(StringUtils.trim(obj.toString())); /* FIXME: appendSpace has been always ignored, uncommenting the following line will cause dozen of test fails if (appendSpace) { return matcher.replaceAll(" "); } */ return matcher.replaceAll(""); }
From source file:com.twosigma.beaker.mimetype.MIMEContainer.java
protected static MIMEContainer addMimeType(String mime, Object code) { return new MIMEContainer(mime, code.toString()); }
From source file:com.vel9studios.levani.popularmovies.util.AppUtils.java
/** * movie objects may contain fields which contain "something" but are actually null: * e.g. response will read: "overview":null * * The presence of null means that get(key) won't actually return a null value. * Instead the get(key) method returns a JSONObject with the value of null. The toString() then * returns "null" string.//from w w w .ja v a 2s. co m * * This rather confusing API characteristic (if something is null.. maybe don't include it in the response?) * still allows us to: * * a. check for null * b. handle gracefully * * @param movieObj current JSONObject containing movie data * @param key key with which to retrieve a portion of the movie JSONObject * @return String value * @throws JSONException */ public static String parseMovieContents(JSONObject movieObj, String key) throws JSONException { String content; Object subMovieObj = movieObj.get(key); if (subMovieObj != null && !subMovieObj.toString().equalsIgnoreCase(AppConstants.JSON_PARSE_NULL)) content = subMovieObj.toString(); else content = AppConstants.JSON_PARSE_STRING_NO_DATA; return content; }
From source file:Main.java
public static LinkedHashMap<String, String> convertBeans(Object bean) { if (bean == null) return null; try {/*w w w . j a va 2 s . com*/ LinkedHashMap<String, String> returnMap = new LinkedHashMap<String, String>(); Class<? extends Object> clazz = bean.getClass(); List<Field> fleids = new ArrayList<Field>(); for (Class<?> c = clazz; c != Object.class; c = c.getSuperclass()) { fleids.addAll(Arrays.asList(c.getDeclaredFields())); } for (Field field : fleids) { String value = ""; field.setAccessible(true); try { Object result = field.get(bean); if (result == null) continue; value = result.toString(); } catch (IllegalAccessException e) { e.printStackTrace(); } // MLogUtil.e("field.getName() "+field.getName()); // MLogUtil.e("value "+value); returnMap.put(field.getName(), value); field.setAccessible(false); } return returnMap; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String toString(Collection<?> c, char separator) { if (c == null) { return null; }/*from www . j av a2s.c om*/ StringBuilder sb = new StringBuilder(); for (Object o : c) { if (o != null) { if (sb.length() > 0) { sb.append(separator); } sb.append(o.toString()); } } return sb.toString(); }
From source file:net.sourceforge.fenixedu.dataTransferObject.externalServices.TeacherPublicationsInformation.java
public static Map<Teacher, List<String>> getTeacherPublicationsInformations(Set<Teacher> teachers) { Map<Teacher, List<String>> teacherPublicationsInformationMap = new HashMap<Teacher, List<String>>(); Client client = ClientBuilder.newClient(); WebTarget resource = client.target(BASE_URL); List<String> teacherIds = new ArrayList<String>(); for (Teacher teacher : teachers) { teacherIds.add(teacher.getTeacherId()); }//www.j av a 2s. co m resource = resource.path(CURRICULUM_PATH).queryParam("istids", StringUtils.join(teacherIds, ",")); try { String allPublications = resource.request().get(String.class); JSONParser parser = new JSONParser(); for (Object teacherPublications : (JSONArray) parser.parse(allPublications)) { JSONObject teacherPublicationsInfo = (JSONObject) teacherPublications; final String username = (String) teacherPublicationsInfo.get("istID"); final Teacher teacher = Teacher.readByIstId(username); JSONArray preferredPublications = (JSONArray) teacherPublicationsInfo.get("preferred"); List<String> teacherPublicationsList = new ArrayList<String>(); for (Object publication : preferredPublications) { teacherPublicationsList.add(publication.toString()); } teacherPublicationsInformationMap.put(teacher, teacherPublicationsList); } } catch (ParseException e) { logger.error(e.getMessage(), e); } finally { client.close(); } return teacherPublicationsInformationMap; }
From source file:Main.java
/** * This//from ww w. ja va 2s. c o m * @param collection * @return */ public static String[] toStringArray(Collection<? extends Object> collection) { String[] strArray = new String[collection.size()]; int index = 0; for (Object obj : collection) { if (obj == null) { strArray[index] = "null"; } else { strArray[index] = obj.toString(); } index++; } return strArray; }
From source file:Main.java
public static Map<String, String> convertBean(Object bean) { if (bean == null) return null; try {//w w w. jav a 2 s. com Class<? extends Object> clazz = bean.getClass(); Map<String, String> returnMap = new HashMap<String, String>(); List<Field> fleids = new ArrayList<Field>(); for (Class<?> c = clazz; c != Object.class; c = c.getSuperclass()) { fleids.addAll(Arrays.asList(c.getDeclaredFields())); } for (Field field : fleids) { String value = ""; field.setAccessible(true); try { Object result = field.get(bean); if (result == null) continue; value = result.toString(); } catch (IllegalAccessException e) { e.printStackTrace(); } // MLogUtil.e("field.getName() "+field.getName()); // MLogUtil.e("value "+value); returnMap.put(field.getName(), value); field.setAccessible(false); } return returnMap; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
/** * <p>//from ww w. j av a 2 s .c o m * Joins the elements of the provided {@code Iterator} into a single String * containing the provided elements. * </p> * * <p> * No delimiter is added before or after the list. Null objects or empty * strings within the iteration are represented by empty strings. * </p> * * @param iterator * the {@code Iterator} of values to join together, may be null * @param separator * the separator character to use * @return the joined String, {@code null} if null iterator input */ public static String join(Iterator<?> iterator, char separator) { if (iterator == null) { return null; } if (!iterator.hasNext()) { return EMPTY; } Object first = iterator.next(); if (!iterator.hasNext()) { return first == null ? EMPTY : first.toString(); } StringBuilder buf = new StringBuilder(256); if (first != null) { buf.append(first); } while (iterator.hasNext()) { buf.append(separator); Object obj = iterator.next(); if (obj != null) { buf.append(obj); } } return buf.toString(); }