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

public static byte doByte(Object obj, byte defValue) {
    return obj != null ? Byte.parseByte(obj.toString()) : defValue;
}

From source file:Main.java

private static int getMaxLength(Object[] msgs) {
    int max = 0;/*from w  ww . jav a  2s  .  c om*/
    int tmp;
    for (Object oo : msgs) {
        tmp = getBytesLength(oo.toString());
        if (tmp > max) {
            max = tmp;
        }
    }
    return max;
}

From source file:Main.java

public static int doInt(Object obj, int defValue) {
    return obj != null ? Integer.parseInt(obj.toString()) : defValue;
}

From source file:Main.java

public static String format(String src, Object... objects) {
    int k = 0;/*from   w  w  w.ja v a  2 s  .c  o m*/
    for (Object obj : objects) {
        src = src.replace("{" + k + "}", obj.toString());
        k++;
    }
    return src;
}

From source file:Main.java

private static String join(List<? extends Object> collection) {
    StringBuilder result = new StringBuilder();
    for (Object object : collection)
        result.append(object.toString());
    return result.toString();
}

From source file:Main.java

/**
 * Replace the pattern with the substitution
 *//* ww w. j a v a2s  .c o  m*/
public static String replace(Object src, Object pattern, Object substitution) {
    String result = src.toString().replaceAll(pattern.toString(), substitution.toString());
    return result;
}

From source file:Main.java

public static short doShort(Object obj, short defValue) {
    return obj != null ? Short.parseShort(obj.toString()) : defValue;
}

From source file:Main.java

public static float doFloat(Object obj, float defValue) {
    return obj != null ? Float.parseFloat(obj.toString()) : defValue;
}

From source file:Main.java

/**
 * Same Source String escape(Object text) in com.sec.fs.common.spring.EscapeXmlReference
 * @param text//from   w ww.j  a  v  a  2 s  .c  om
 * @return
 */
public static String escape(Object text) {
    return text == null ? null
            : text.toString().replaceAll("&", "&amp;")
                    //             .replaceAll("\"","&quot;")
                    //             .replaceAll("\"","&apos;")
                    .replaceAll("<", "&lt;").replaceAll(">", "&gt;");
}

From source file:Main.java

/**
 * Takes the characters until the pattern is matched
 *///w  w  w .  ja  v  a 2  s .co  m
public static String takeUntil(Object src, Object pattern) {
    String src2 = src.toString();
    Matcher matcher = Pattern.compile(pattern.toString()).matcher(src2);

    if (!matcher.find())
        return src2;

    int index = matcher.start();

    if (index == -1) {
        return src2;
    }
    return src2.substring(0, index);
}