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.zxy.commons.lang.utils.ObjectsUtils.java

/**
 * ?//from w  ww  .  ja va  2s.  com
 * 
 * @param obj 
 * @return ?
 */
public static boolean isEmpty(Object obj) {
    if (obj == null) {
        return true;
    }
    if (obj.toString().length() == 0) {
        return true;
    }
    return StringUtils.isEmpty(obj.toString());
}

From source file:Main.java

public static void appendNewCDATAElement(Document doc, Element targetElement, String elementName,
        Object value) {

    if (value != null) {
        appendNewCDATAElement(doc, targetElement, elementName, value.toString());
    }/*from   w ww.  j  a v a2s  .  c om*/
}

From source file:Main.java

/**
 * Applies an XSLT.// w w  w . j a v  a  2s . co  m
 *
 * @param xml          The soucrce to translate.
 * @param xsltFilename The filename of the xsl file to use.
 * @param params       A map of parameters to pass to the transformation.
 *                     if null is passed none are used.
 *
 * @return The string representing of the result of the transformation.
 */
public static String applyXSLT(Source xml, String xsltFilename, Map params) {
    try {
        String fullPath = xsltFilename;
        File xslt = new File(fullPath);
        TransformerFactory f = TransformerFactory.newInstance();
        StreamSource xsltSrc = new StreamSource(xslt);
        StringWriter out = new StringWriter();
        StreamResult res = new StreamResult(out);
        Transformer t = f.newTransformer(xsltSrc);

        if (params != null) {
            Iterator i = params.keySet().iterator();
            while (i.hasNext()) {
                Object obj = i.next();
                t.setParameter(obj.toString(), params.get(obj));
            }
        }
        t.transform(xml, res);

        return out.toString();
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

/**
 * convert a string to integer./*from   ww w. j  a va2s  .c  om*/
 * <p>
 * null => defaultValue<br/> "abc" => defaultValue<br/> "123" => 123<br/> "
 * 123 " => 123<br/> "1,234,567" => 1234567<br/>
 * </p>
 * 
 * @param str
 * @param defaultValue
 * @return a int value or <code>defaultValue</code> if cant convert.
 */
public static Integer convertStrToInteger(Object str, Integer defaultValue) {
    if (null == str) {
        return defaultValue;
    }
    try {
        String s = str.toString().replace(",", "");
        return Integer.valueOf(s.trim());
    } catch (Exception e) {
        return defaultValue;
    }
}

From source file:apm.common.utils.DateUtils.java

/**
 *  ?/* w ww.  jav a  2 s . c o m*/
 * { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", 
 *   "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm" }
 */
public static Date parseDate(Object str) {
    if (str == null) {
        return null;
    }
    try {
        return parseDate(str.toString(), parsePatterns);
    } catch (ParseException e) {
        return null;
    }
}

From source file:com.github.blindpirate.gogradle.util.MapUtils.java

public static String getString(Map<String, Object> map, String key, String defaultValue) {
    if (map != null) {
        Object answer = map.get(key);
        if (answer != null) {
            return answer.toString();
        }/*  w  w w. j  a  v a2 s.c o  m*/
    }
    return defaultValue;
}

From source file:io.covert.dns.geo.IpGeo.java

private static void put(Map<String, Object> rec, String name, Object val) {
    if (val != null)
        rec.put(name, val.toString().toUpperCase());
}

From source file:Main.java

public static boolean isInt(Object srcStr) {
    // return null == srcStr || srcStr.equals("null");
    if (srcStr == null) {
        return false;
    }/*from www .ja  v a  2s.c  om*/
    String s = srcStr.toString().replaceAll("(\\s)", "");
    Pattern p = Pattern.compile("([-]?[\\d]+)");
    Matcher m = p.matcher(s);
    return m.matches();
    // return nvl(srcStr, "").trim().length() == 0 || nvl(srcStr,
    // "").equals("null");
}

From source file:CollectionUtils.java

/**
 * Converts specified map to {@link java.util.Properties}. The keys and String values
 * are migrated unchnaged, other types of values are {@link Object#toString() converted to String}.
 * @param map map to convert./*from  w  w w .  ja  v  a  2  s.  com*/
 * @return converted map as Properties.
 */
public static Properties asProperties(Map<String, ?> map) {
    Properties props = new Properties();
    for (Map.Entry<String, ?> entry : map.entrySet()) {
        Object v = entry.getValue();
        if (v != null) {
            props.put(entry.getKey(), v.toString());
        }
    }
    return props;
}

From source file:com.thoughtworks.go.util.StringUtil.java

public static String escapeAndJoinStrings(Object... items) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < items.length; i++) {
        Object item = items[i];
        if (item != null) {
            builder.append(item.toString().replaceAll(DELIMITER_MATCHER, DELIMITER_ESCAPE_SEQ));
        }// w  w w.  jav  a2s .c o m
        if (i + 1 < items.length) {
            builder.append(DELIMITER);
        }
    }
    return builder.toString();
}