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.movies.jsf.JsfUtil.java

public static SelectItem[] getSelectItems(List<?> entities, boolean selectOne) {
    int size = selectOne ? entities.size() + 1 : entities.size();
    SelectItem[] items = new SelectItem[size];
    int i = 0;//from  w  w  w  .j av  a2  s . c  o m
    if (selectOne) {
        items[0] = new SelectItem("", "---");
        i++;
    }
    for (Object x : entities) {
        items[i++] = new SelectItem(x, x.toString());
    }
    return items;
}

From source file:org.eclipse.virgo.ide.beans.core.internal.locate.BlueprintConfigUtils.java

/**
 * Returns the {@value #BLUEPRINT_HEADER} if present from the given dictionary.
 *///from  w w w. j  a  va  2s  .  co m
public static String getBlueprintHeader(Dictionary<String, String> headers) {
    Object header = null;
    if (headers != null)
        header = headers.get(BLUEPRINT_HEADER);
    return (header != null ? header.toString().trim() : null);
}

From source file:com.healthmarketscience.jackcess.impl.CustomToStringStyle.java

private static String indent(Object obj) {
    return ((obj != null) ? obj.toString().replaceAll(SystemUtils.LINE_SEPARATOR, ML_FIELD_SEP) : null);
}

From source file:com.thoughtworks.go.domain.GoConfigRevision.java

public static String esc(Object content) {
    return content.toString().replaceAll(DELIMITER, DELIMITER_CHAR + DELIMITER_CHAR);
}

From source file:PrefsUtil.java

/**
 * Puts a list into the preferences.//from  ww w  . ja v a 2  s.  c  om
 */
public static void putMap(Preferences preferences, Map map) {
    if (preferences == null) {
        throw new IllegalArgumentException("Preferences not set.");
    }

    for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) {
        Map.Entry entry = (Map.Entry) iter.next();
        Object value = entry.getValue();
        preferences.put(entry.getKey().toString(), value == null ? null : value.toString());
    }
}

From source file:Main.java

public static final long objectToLong(Object o) {
    if (o instanceof Number)
        return ((Number) o).longValue();
    try {//from   w w w  . j ava 2s  .  c  om
        if (o == null)
            return -1L;
        else
            return Long.parseLong(o.toString());
    } catch (NumberFormatException e) {
        return -1L;
    }
}

From source file:shiver.me.timbers.spring.security.integration.CustomPrincipleAuthenticationConverter.java

private static String extractUsername(Authentication authentication) {
    final Object principal = authentication.getPrincipal();
    if (principal instanceof UserDetails) {
        return ((UserDetails) principal).getUsername();
    }/*from  w  w  w.  j  a  va2s. c o  m*/

    return principal.toString();
}

From source file:io.apiman.plugins.keycloak_oauth_policy.ClaimLookup.java

/**
 *
 * @param token token to retrieve claim from
 * @param claim the claim (field key)/*w ww  .j  av a  2s .c  o  m*/
 * @return string representaion of claim
 */
public static String getClaim(IDToken token, String claim) {
    if (claim == null || token == null)
        return null;
    // Get the standard claim field, if available
    if (STANDARD_CLAIMS_FIELD_MAP.containsKey(claim)) {
        return callClaimChain(token, STANDARD_CLAIMS_FIELD_MAP.get(claim));
    } else { // Otherwise look up 'other claims'
        Object otherClaim = getOtherClaimValue(token, claim);
        return otherClaim == null ? null : otherClaim.toString();
    }
}

From source file:StringUtil.java

/**
 * Truncate the supplied string to be no more than the specified length. This method returns an empty string if the supplied
 * object is null./*from   w  w w.j ava  2  s  .  c om*/
 * 
 * @param obj the object from which the string is to be obtained using {@link Object#toString()}.
 * @param maxLength the maximum length of the string being returned
 * @param suffix the suffix that should be added to the content if the string must be truncated, or null if the default suffix
 *        of "..." should be used
 * @return the supplied string if no longer than the maximum length, or the supplied string truncated to be no longer than the
 *         maximum length (including the suffix)
 * @throws IllegalArgumentException if the maximum length is negative
 */
public static String truncate(Object obj, int maxLength, String suffix) {
    if (obj == null || maxLength == 0) {
        return "";
    }
    String str = obj.toString();
    if (str.length() <= maxLength)
        return str;
    if (suffix == null)
        suffix = "...";
    int maxNumChars = maxLength - suffix.length();
    if (maxNumChars < 0) {
        // Then the max length is actually shorter than the suffix ...
        str = suffix.substring(0, maxLength);
    } else if (str.length() > maxNumChars) {
        str = str.substring(0, maxNumChars) + suffix;
    }
    return str;
}

From source file:com.base2.kagura.rest.helpers.ParameterUtils.java

public static void insertParameters(Parameters parameters, ReportConnector reportConnector,
        List<String> errors) {
    if (reportConnector.getParameterConfig() != null) {
        for (ParamConfig paramConfig : reportConnector.getParameterConfig()) {
            if (parameters.getParameters().containsKey(paramConfig.getId())) {
                Object o = parameters.getParameters().get(paramConfig.getId());
                try {
                    if (o != null && StringUtils.isNotBlank(o.toString()))
                        BeanUtils.setProperty(paramConfig, "value", o);
                    else
                        BeanUtils.setProperty(paramConfig, "value", null);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                } catch (ConversionException e) {
                    e.printStackTrace();
                    errors.add("Could not convert parameter: " + paramConfig.getId() + " value " + o);
                }/* w ww .  j a  va 2 s .com*/
            }
        }
    }
}