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 Map<String, String> convert(Properties props) {
    Map<String, String> _result = new HashMap<String, String>();
    Set<Entry<Object, Object>> propsSet = props.entrySet();
    for (Entry<Object, Object> p : propsSet) {
        Object value = p.getValue();
        if (value == null) {
            _result.put(p.getKey().toString(), null);
        } else {/*from   ww  w .java2  s  .co  m*/
            _result.put(p.getKey().toString(), value.toString());
        }
    }
    return _result;
}

From source file:Main.java

@SuppressWarnings("rawtypes")
public static void notEmpty(Object obj, String message) {
    if (obj == null) {
        throw new IllegalArgumentException(message + " must be specified");
    }//w  ww  .  ja  va  2s  .com
    if (obj instanceof String && obj.toString().trim().length() == 0) {
        throw new IllegalArgumentException(message + " must be specified");
    }
    if (obj.getClass().isArray() && Array.getLength(obj) == 0) {
        throw new IllegalArgumentException(message + " must be specified");
    }
    if (obj instanceof Collection && ((Collection) obj).isEmpty()) {
        throw new IllegalArgumentException(message + " must be specified");
    }
    if (obj instanceof Map && ((Map) obj).isEmpty()) {
        throw new IllegalArgumentException(message + " must be specified");
    }
}

From source file:Main.java

public static Document documentify(ResultSet rs) throws ParserConfigurationException, SQLException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.newDocument();
    Element results = doc.createElement("Results");
    doc.appendChild(results);/*from w  w w  .  j  a va2s  .  c om*/
    ResultSetMetaData rsmd = rs.getMetaData();
    int colCount = rsmd.getColumnCount();

    while (rs.next()) {
        Element row = doc.createElement("Row");
        results.appendChild(row);
        for (int i = 1; i <= colCount; i++) {
            String columnName = rsmd.getColumnName(i);
            Object value = rs.getObject(i);
            Element node = doc.createElement(columnName);
            node.appendChild(doc.createTextNode(value.toString()));
            row.appendChild(node);
        }
    }
    return doc;
}

From source file:lichen.orm.LichenOrmModule.java

public static DataSource buildDataSource(@Symbol(LichenOrmSymbols.DATABASE_CFG_FILE) String dbCfgFile,
        RegistryShutdownHub shutdownHub) throws IOException, ProxoolException {
    ResourceLoader resourceLoader = new DefaultResourceLoader();
    Resource resource = resourceLoader.getResource(dbCfgFile);
    Properties info = new Properties();
    info.load(resource.getInputStream());
    PropertyConfigurator.configure(info);

    String poolNameKey = F.flow(info.keySet()).filter(new Predicate<Object>() {
        public boolean accept(Object element) {
            return element.toString().contains("alias");
        }/* ww  w .j  av  a2  s.  c om*/
    }).first().toString();

    if (poolNameKey == null) {
        throw new RuntimeException("?poolName");
    }
    final String poolName = info.getProperty(poolNameKey);

    //new datasource
    ProxoolDataSource ds = new ProxoolDataSource(poolName);
    //register to shutdown
    shutdownHub.addRegistryShutdownListener(new RegistryShutdownListener() {
        public void registryDidShutdown() {
            Flow<?> flow = F.flow(ProxoolFacade.getAliases()).filter(new Predicate<String>() {
                public boolean accept(String element) {
                    return element.equals(poolName);
                }
            });
            if (flow.count() == 1) {
                try {
                    ProxoolFacade.removeConnectionPool(poolName);
                } catch (ProxoolException e) {
                    //do nothing
                }
            }
        }
    });
    return ds;
}

From source file:com.htmlhifive.pitalium.core.selenium.PtlCapabilities.java

/**
 * ????????//from w  w w. java 2  s .com
 * 
 * @param object ?
 * @return ????
 */
private static String toString(Object object) {
    return object == null ? null : object.toString();
}

From source file:de.codesourcery.eve.skills.market.impl.EveMarketLogParser.java

protected static final String formatLeft(Object s) {
    return StringUtils.leftPad(s.toString(), 20) + " | ";
}

From source file:Main.java

/**
 * Reverse Engineers an XPath Expression of a given Node in the DOM.
 * /*from   ww  w  .j  ava 2s  . c o  m*/
 * @param node
 *            the given node.
 * @return string xpath expression (e.g., "/html[1]/body[1]/div[3]").
 */
public static String getXPathExpression(Node node) {
    Object xpathCache = node.getUserData(FULL_XPATH_CACHE);
    if (xpathCache != null) {
        return xpathCache.toString();
    }
    Node parent = node.getParentNode();

    if ((parent == null) || parent.getNodeName().contains("#document")) {
        String xPath = "/" + node.getNodeName() + "[1]";
        node.setUserData(FULL_XPATH_CACHE, xPath, null);
        return xPath;
    }

    StringBuffer buffer = new StringBuffer();

    if (parent != node) {
        buffer.append(getXPathExpression(parent));
        buffer.append("/");
    }

    buffer.append(node.getNodeName());

    List<Node> mySiblings = getSiblings(parent, node);

    for (int i = 0; i < mySiblings.size(); i++) {
        Node el = mySiblings.get(i);

        if (el.equals(node)) {
            buffer.append('[').append(Integer.toString(i + 1)).append(']');
            // Found so break;
            break;
        }
    }
    String xPath = buffer.toString();
    node.setUserData(FULL_XPATH_CACHE, xPath, null);
    return xPath;
}

From source file:org.tsm.concharto.web.util.ValidationHelper.java

public static void rejectIfTooLong(Errors errors, String field, int maxLength, String errorCode) {
    Object value = errors.getFieldValue(field);
    if (value != null) {
        rejectIfTooLong(errors, field, maxLength, errorCode,
                new Object[] { maxLength, value.toString().length() }, null);
    }/*from w w w. ja va 2  s  .co  m*/
}

From source file:de.codesourcery.eve.skills.market.impl.EveMarketLogParser.java

protected static final String formatRight(Object s) {
    return StringUtils.rightPad(s.toString(), 20) + " | ";
}

From source file:com.deploymentio.cfnstacker.template.VelocityUtil.java

public static String valueOrDefault(Object val, String defaultVal) {
    if (val == null || ((val instanceof String) && StringUtils.isEmpty((String) val))) {
        return defaultVal;
    }//ww  w. jav a  2 s. co m
    return val.toString();
}