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:com.ocs.dynamo.utils.PasteUtils.java

/**
 * Splits an input object into its separate values - the values can be separated by any kind of
 * whitespace/*from  w w  w.j  ava 2 s .com*/
 * 
 * @param input
 * @return
 */
public static String[] split(Object input) {
    if (input == null) {
        return null;
    }
    String temp = input.toString();
    //
    StringBuilder b = new StringBuilder();
    for (int i = 0; i < temp.length(); i++) {
        String s = new String(new char[] { temp.charAt(i) });
        if (org.apache.commons.lang.StringUtils.isWhitespace(s)) {
            if (i == 0) {
                b.append("#");
            } else {
                String t = new String(new char[] { temp.charAt(i - 1) });
                if (org.apache.commons.lang.StringUtils.isWhitespace(t)) {
                    b.append("#");
                }
            }
        }
        b.append(temp.charAt(i));
    }

    String[] result = b.toString().replaceAll("\\s+", " ").split(" ");
    for (int i = 0; i < result.length; i++) {
        result[i] = result[i].replace('#', ' ').trim();
    }
    return result;
}

From source file:adalid.util.info.JavaInfo.java

private static Map<String, Object> sort(Attributes attributes) {
    Object object;/*from  w  w w . j ava 2s.c  om*/
    Map<String, Object> map = new TreeMap<>();
    for (Object key : attributes.keySet()) {
        object = attributes.get(key);
        map.put(key.toString(), object);
    }
    return map;
}

From source file:Main.java

public static <T> String join(Collection<T> col, String separator) {
    String ret = "";
    if (col != null && col.size() > 0) {
        for (Object x : col) {
            if (x instanceof java.lang.String) {
                ret += separator + (String) x;
            } else {
                ret += separator + x.toString();
            }//from w  ww . j  a v a 2 s . c om
        }
    }
    return ret.replaceFirst(separator, "");

}

From source file:Main.java

public static void serializeIfNotEqual(XmlSerializer serializer, String ns, String tag, Object value,
        Object forbiddenValue) throws Exception {
    if (value == null || value.equals(forbiddenValue))
        return;/*w w w  .  j ava2s . co m*/

    serializer.startTag(ns, tag);
    serializer.text(value.toString());
    serializer.endTag(ns, tag);
}

From source file:com.jsmartframework.web.manager.AuthEncrypter.java

static String encrypt(HttpServletRequest request, String key, Object value) {
    if (key != null && value != null) {
        try {//from   w w w .  j  ava  2s .co  m
            byte[] encode = getEncryptCipher(request, key).doFinal(value.toString().getBytes("UTF8"));
            return new String(Base64.encodeBase64(encode, true, true)).trim();
        } catch (Exception ex) {
            LOGGER.log(Level.INFO, "Failed to encrypt value [" + value + "]: " + ex.getMessage());
        }
        return value.toString();
    }
    return null;
}

From source file:com.twosigma.beaker.mimetype.MIMEContainer.java

protected static byte[] getBytes(Object data) throws IOException {
    byte[] bytes;
    if (isValidURL(data.toString())) {
        bytes = ByteStreams.toByteArray((new URL(data.toString()).openStream()));
    } else if (exists(data.toString())) {
        File imgFile = new File(data.toString());
        bytes = Files.toByteArray(imgFile);
    } else {/* w ww .j  a va2  s.c o  m*/
        throw new FileNotFoundException(data.toString() + " doesn't exist. ");
    }
    return bytes;
}

From source file:Main.java

public static final double objectToDouble(Object o) {
    if (o instanceof Number)
        return ((Number) o).doubleValue();
    try {/*  w w w.  jav  a 2s . c  o  m*/
        if (o == null)
            return -1D;
        else
            return Double.parseDouble(o.toString());
    } catch (NumberFormatException e) {
        e.printStackTrace();
        return -1D;
    }
}

From source file:Main.java

public static String getNonNull(Object o) {
    if (o == null) {
        return "";
    }/*ww  w .  j av a  2s. co m*/

    if (o instanceof Double && (((Double) o).isNaN() || ((Double) o).isNaN())) {
        return "";
    }

    return o.toString();
}

From source file:Main.java

/**
 * Adds attribute with <code>prefix</code> and <code>localName</code> to
 * <code>attributes</code> if value is not null. Follows the same rules as
 * {@link AttributesImpl#addAttribute(String, String, String, String, String)}
 * ./*from  ww  w.  j  a va  2 s.  c  o m*/
 * 
 * @param attributes
 *          to add to.
 * @param prefix
 *          of the attribute.
 * @param localName
 *          of attribute to add.
 * @param value
 *          to add to attribute.
 * @since 8.1
 */
static public void addAttribute(final AttributesImpl attributes, final String prefix, final String localName,
        final Object value) {
    if (null != value) {
        attributes.addAttribute(XMLConstants.NULL_NS_URI, localName, prefix + ":" + localName, "",
                value.toString());
    }
}

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

/**
 * long???/*from  w  ww.  j a  v  a 2  s. c  o m*/
 * 
 * @param key
 *            ???
 */
public static long getLong(String key) {
    Object value = get(key);
    return (value instanceof Number) ? ((Number) value).longValue()
            : Long.parseLong((value == null) ? null : value.toString());
}