Example usage for java.lang Object toString

List of usage examples for java.lang Object toString

Introduction

In this page you can find the example usage for java.lang Object toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:Main.java

/**
 * Returns the value for key in dictionary as an int or the given default
 * value if no value is defined for the key.
 * //  w  ww .j  av  a  2s . 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 integer value for key in dict.
 */
public static int getInt(Map<String, Object> dict, String key, int defaultValue) {
    Object value = dict.get(key);

    if (value == null) {
        return defaultValue;
    } else {
        // Handles commas by casting them to an int
        return (int) Float.parseFloat(value.toString());
    }
}

From source file:org.sakaiproject.contentreview.urkund.client.SubmissionsResponse.java

static String ObjToString(Object o) {
    if (o != null) {
        return o.toString();
    }//  w ww. j  ava2s .com
    return "null";
}

From source file:org.exoplatform.social.client.api.util.SocialJSONDecodingSupport.java

/**
 * //ww  w  .ja v a 2  s. c  om
 * @author Ly Minh Phuong - http://phuonglm.net
 * @param <T>
 * @param clazz
 * @param jsonArrayContent
 * @return
 * @throws IOException
 * @throws ParseException
 */
public static <T extends Model> List<T> JSONArrayObjectParser(final Class<T> clazz, String jsonArrayContent)
        throws IOException, ParseException {
    JSONArray jsonResultArray = (JSONArray) JSONValue.parse(jsonArrayContent);
    List<T> result = new ArrayList<T>();
    for (Object jsonObject : jsonResultArray) {
        String jsonString = jsonObject.toString();
        result.add(parser(clazz, jsonString));
    }
    return result;
}

From source file:com.bstek.dorado.console.ConsoleConfigure.java

/**
 * boolean???/*  w ww  . j  a  va 2s  . c  o m*/
 * 
 * @param key
 *            ???
 */
public static boolean getBoolean(String key) {
    Object value = get(key);
    return (value instanceof Boolean) ? ((Boolean) value).booleanValue()
            : BooleanUtils.toBoolean((value == null) ? null : value.toString());
}

From source file:com.dtolabs.rundeck.core.common.NodeEntryFactory.java

/**
 * Create NodeEntryImpl from map data.  It will convert "tags" of type String as a comma separated list of tags, or
 * "tags" a collection of strings into a set.  It will remove properties excluded from allowed import.
 *
 * @param map input map data//from w w w  .ja va 2s  . co m
 *
 * @return
 *
 * @throws IllegalArgumentException
 */
@SuppressWarnings("unchecked")
public static NodeEntryImpl createFromMap(final Map<String, Object> map) throws IllegalArgumentException {
    final NodeEntryImpl nodeEntry = new NodeEntryImpl();
    final HashMap<String, Object> newmap = new HashMap<String, Object>(map);
    for (final String excludeProp : excludeProps) {
        newmap.remove(excludeProp);
    }
    if (null != newmap.get("tags") && newmap.get("tags") instanceof String) {
        String tags = (String) newmap.get("tags");
        String[] data;
        if ("".equals(tags.trim())) {
            data = new String[0];
        } else {
            data = tags.split(",");
        }
        final HashSet set = new HashSet();
        for (final String s : data) {
            if (null != s && !"".equals(s.trim())) {
                set.add(s.trim());
            }
        }
        newmap.put("tags", set);
    } else if (null != newmap.get("tags") && newmap.get("tags") instanceof Collection) {
        Collection tags = (Collection) newmap.get("tags");
        HashSet data = new HashSet();
        for (final Object tag : tags) {
            if (null != tag && !"".equals(tag.toString().trim())) {
                data.add(tag.toString().trim());
            }
        }
        newmap.put("tags", data);
    } else if (null != newmap.get("tags")) {
        Object o = newmap.get("tags");
        newmap.put("tags", new HashSet(Arrays.asList(o.toString().trim())));
    }
    try {
        BeanUtils.populate(nodeEntry, newmap);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
    if (null == nodeEntry.getNodename()) {
        throw new IllegalArgumentException("Required property 'nodename' was not specified");
    }
    if (null == nodeEntry.getHostname()) {
        throw new IllegalArgumentException("Required property 'hostname' was not specified");
    }
    if (null == nodeEntry.getAttributes()) {
        nodeEntry.setAttributes(new HashMap<String, String>());
    }

    //populate attributes with any keys outside of nodeprops
    for (final Map.Entry<String, Object> entry : newmap.entrySet()) {
        if (!ResourceXMLConstants.allPropSet.contains(entry.getKey())) {
            nodeEntry.setAttribute(entry.getKey(), (String) entry.getValue());
        }
    }

    return nodeEntry;
}

From source file:de.vandermeer.asciitable.commons.ArrayTransformations.java

/**
 * Takes an object (used as a string) and returns a string array with wrapped lines of max length.
 * The wrapping is done using StringUtils and WordUtils so that words are not broken into characters.
 * @param length max length of a string in the returned array
 * @param obj input object, null and empty objects are allowed
 * @return string array with wrapped strings: null of input object was null or its toString() returned null, empty array if empty string, array with lines of wrappings otherwise
 *//*  w  ww.ja  va  2 s  . c o m*/
public static final String[] WRAP_LINES(final int length, Object obj) {
    if (obj == null || obj.toString() == null) {
        return null;
    }
    if ("".equals(obj)) {
        return new String[] {};
    }
    return StringUtils.split(WordUtils.wrap(obj.toString(), length, "\n", true), "\n");
}

From source file:org.dcache.xrootd.spring.ChannelHandlerFactoryFactoryBean.java

private static Properties toProperties(final Map<String, Object> env) {
    Replaceable replaceable = new Replaceable() {
        @Override/*from w w  w. j  a va  2  s .c  o  m*/
        public String getReplacement(String name) {
            Object value = env.get(name);
            return (value == null) ? null : value.toString().trim();
        }
    };

    Properties properties = new Properties();
    for (Map.Entry<String, Object> e : env.entrySet()) {
        String key = e.getKey();
        String value = String.valueOf(e.getValue());
        properties.put(key, Formats.replaceKeywords(value, replaceable));
    }

    return properties;
}

From source file:com.betfair.testing.utils.cougar.assertions.AssertionUtils.java

private static void doJsonSorting(JSONObject doc, String x)
        throws XPathExpressionException, IOException, JSONException {
    JXPathContext ctx = JXPathContext.newContext(doc);
    String parentX = x.substring(0, x.lastIndexOf("/"));
    if ("".equals(parentX)) {
        parentX = "/";
    }//from  www .  j  a  v  a 2 s . c o  m
    String childName = x.substring(x.lastIndexOf("/") + 1);
    Iterator it = ctx.iterate(parentX);
    while (it.hasNext()) {
        JSONObject p = (JSONObject) it.next();
        JSONArray n = p.getJSONArray(childName);
        List allKids = new ArrayList<>(n.length());
        for (int j = 0; j < n.length(); j++) {
            allKids.add(n.get(j));
        }
        Collections.sort(allKids, new Comparator<Object>() {
            @Override
            public int compare(Object o1, Object o2) {
                return o1.toString().compareTo(o2.toString());
            }
        });
        JSONArray newArray = new JSONArray(allKids);
        p.put(childName, newArray);
    }
}

From source file:com.storageroomapp.client.util.JsonSimpleUtil.java

/**
 * Convenience method for pulling a Calendar value off of a JSONObject
 * @param obj the JSONObject received from the server
 * @param key the String key of the value we want
 * @return the Calendar value, or null if not found or not a proper timestamp
 *//*from w w  w.j a va 2 s.  c  o m*/
static public Calendar parseJsonTimeValue(JSONObject obj, String key) {
    if ((obj == null) || (key == null)) {
        return null;
    }
    Calendar value = null;
    Object valueObj = obj.get(key);
    if (valueObj != null) {
        String valueStr = valueObj.toString();
        value = StorageRoomUtil.storageRoomTimeStringToCalendar(valueStr);
    }
    return value;

}

From source file:com.storageroomapp.client.util.JsonSimpleUtil.java

/**
 * Convenience method for pulling a Calendar value off of a JSONObject
 * @param obj the JSONObject received from the server
 * @param key the String key of the value we want
 * @return the Calendar value, or null if not found or not a proper timestamp
 *//*from w  w w . j  av  a2s  . co  m*/
static public Calendar parseJsonDateValue(JSONObject obj, String key) {
    if ((obj == null) || (key == null)) {
        return null;
    }
    Calendar value = null;
    Object valueObj = obj.get(key);
    if (valueObj != null) {
        String valueStr = valueObj.toString();
        value = StorageRoomUtil.storageRoomDateStringToCalendar(valueStr);
    }
    return value;

}