List of usage examples for org.apache.commons.lang ObjectUtils toString
public static String toString(Object obj)
Gets the toString
of an Object
returning an empty string ("") if null
input.
ObjectUtils.toString(null) = "" ObjectUtils.toString("") = "" ObjectUtils.toString("bat") = "bat" ObjectUtils.toString(Boolean.TRUE) = "true"
From source file:MainClass.java
public static void main(String[] args) { //Create ObjectUtilsTrial instance MyClass one = new MyClass(); MyClass two = one; //Same Reference MyClass three = new MyClass(); //New Object MyClass four = null;// w ww .j a va2 s. c o m //Pass null get empty string System.out.print("6) Pass null and get back an Empty string >>>"); System.out.println("**" + ObjectUtils.toString(null) + "**"); }
From source file:ObjectUtilsTrial.java
public static void main(String[] args) { // Create ObjectUtilsTrial instance String one = new String(); String two = one; // Same Reference String three = new String(); // New Object String four = null;/*ww w.j a v a 2 s . c om*/ // four is null, returns DEFAULT System.out.print("1) If null return DEFAULT >>>"); System.out.println(ObjectUtils.defaultIfNull(four, "DEFAULT")); // one and two point to the same object System.out.print("2) References to the same object >>>"); System.out.println(ObjectUtils.equals(one, two)); // one and three are different objects System.out.print("3) Check object references and not values >>>"); System.out.println(ObjectUtils.equals(one, three)); // toString method gets called System.out.print("4) toSring gets invoked >>>"); System.out.println(one); // Object details displayed..toString is not called System.out.print("5) Display object details >>>"); System.out.println(ObjectUtils.identityToString(one)); // Pass null get empty string System.out.print("6) Pass null and get back an Empty string >>>"); System.out.println("**" + ObjectUtils.toString(null) + "**"); }
From source file:me.kafeitu.activiti.extra.utils.ActivitiExtraPropertiesUtil.java
public static String getAsString(String key) { return ObjectUtils.toString(PROPERTIES.get(key)); }
From source file:com.googlecode.markuputils.CssStyleUtils.java
public static String appendProperty(String name, Object value) { StringBuilder buffer = new StringBuilder(); String valueText = ObjectUtils.toString(value); if (StringUtils.isNotBlank(valueText)) { buffer.append(name).append(":").append(valueText).append(";"); }// w w w.j av a 2 s . c om return buffer.toString(); }
From source file:net.sf.zekr.common.util.ConfigUtils.java
@SuppressWarnings("unchecked") public static void write(Configuration configuration, Writer w) throws IOException { Iterator keys = configuration.getKeys(); while (keys.hasNext()) { String key = (String) keys.next(); Object value = configuration.getProperty(key); w.write(key);// w w w.ja v a 2 s . co m w.write(" = "); if (value instanceof Collection) { w.write(CollectionUtils.toString((List) value, ", ")); } else { w.write(ObjectUtils.toString(value)); } if (keys.hasNext()) { w.write(GlobalConfig.LINE_SEPARATOR); } } }
From source file:com.dattack.jtoolbox.commons.configuration.ConfigurationUtil.java
/** * Interpolates the specified value./* w ww . jav a2 s . c om*/ * * @param value * the value to be interpolated * @param configuration * the configuration object to use * @return the interpolated value */ public static String interpolate(final Object value, final AbstractConfiguration configuration) { return interpolate(ObjectUtils.toString(value), configuration); }
From source file:jef.common.Entry.java
public String toString() { return ObjectUtils.toString(key) + ":" + ObjectUtils.toString(value); }
From source file:com.yahoo.flowetl.core.util.EnumUtils.java
/** * Attempts to convert a string that represents an enumeration of a given * class into the actual enum object.// w w w. java 2s. c o m * * @param <T> * the generic type of the enum class to use * * @param enumKlass * the enum class that has the enumerations to select from * * @param enumStr * the enum string we will attempt to match * * @param caseSensitive * whether to compare case sensitive or not * * @return the enum object or null if not found/invalid... */ @SuppressWarnings("unchecked") public static <T extends Enum> T fromString(Class<T> enumKlass, String enumStr, boolean caseSensitive) { if (StringUtils.isEmpty(enumStr) || enumKlass == null) { // not valid return null; } Object[] types = enumKlass.getEnumConstants(); if (types == null) { // not an enum return null; } Object enumInstance = null; for (int i = 0; i < types.length; i++) { enumInstance = types[i]; if (caseSensitive == false) { if (StringUtils.equalsIgnoreCase(ObjectUtils.toString(enumInstance), enumStr)) { return (T) (enumInstance); } } else { if (StringUtils.equals(ObjectUtils.toString(enumInstance), enumStr)) { return (T) (enumInstance); } } } // not found throw new IllegalArgumentException( "Unknown enumeration [" + enumStr + "] for enum class [" + enumKlass + "]"); }
From source file:com.opengamma.core.LinkUtils.java
/** * Gets the best name for the object from the specified link. * <p>//from www .ja va 2 s . c o m * This will return a name extracted from the external bundle or object identifier. * * @param link the link, not null * @return the best representative name, not null */ public static String bestName(Link<?> link) { ArgumentChecker.notNull(link, "link"); ObjectId objectId = link.getObjectId(); ExternalIdBundle bundle = link.getExternalId(); if (bundle != null && bundle.size() > 0) { if (bundle.getValue(ExternalSchemes.BLOOMBERG_TICKER) != null) { return bundle.getValue(ExternalSchemes.BLOOMBERG_TICKER); } else if (bundle.getValue(ExternalSchemes.RIC) != null) { return bundle.getValue(ExternalSchemes.RIC); } else if (bundle.getValue(ExternalSchemes.ACTIVFEED_TICKER) != null) { return bundle.getValue(ExternalSchemes.ACTIVFEED_TICKER); } else { return bundle.getExternalIds().iterator().next().getValue(); } } return ObjectUtils.toString(objectId); }
From source file:com.intel.podm.ipxesupplier.RemoteTargetIpxeScript.java
@Override public String toIpxeScript() { return MessageFormat.format("#!ipxe\n" + "set initiator-iqn {0}\n" + "sanboot iscsi:{1}::{2}:{3}:{4}", ObjectUtils.toString(initiatorIqn), ObjectUtils.toString(serverName), ObjectUtils.toString(port), ObjectUtils.toString(lun), ObjectUtils.toString(targetName)); }