Example usage for java.util Objects toString

List of usage examples for java.util Objects toString

Introduction

In this page you can find the example usage for java.util Objects toString.

Prototype

public static String toString(Object o) 

Source Link

Document

Returns the result of calling toString for a non- null argument and "null" for a null argument.

Usage

From source file:org.sonar.api.utils.log.ConsoleFormatter.java

static String format(String pattern, Object... args) {
    String result = pattern;/*from ww w. j  av a 2  s.  co m*/
    for (Object arg : args) {
        result = StringUtils.replaceOnce(result, "{}", Objects.toString(arg));
    }
    return result;
}

From source file:Main.java

/**
 * Adapts a Object-value <code>List</code> to a String-value one. If the list to adapt is <code>null</code>, then an
 * empty list is returned./*  w  w  w.  j a  v a2 s .co  m*/
 *
 * @param list
 *            the List to adapt, may be null
 * @return the adapted List
 */
public static List<String> listAsString(final List<Object> list) {

    final List<String> result = new ArrayList<>();
    if (list != null) {
        for (final Object obj : list) {
            result.add(Objects.toString(obj));
        }
    }
    return result;
}

From source file:com.bits.protocolanalyzer.mvc.formatter.LinkFormatter.java

public String print(LinkAnalyzerEntity object, Locale locale) {
    return Objects.toString(object.getId());
}

From source file:io.neba.core.util.JsonUtil.java

private static String toJson(Object value) {
    if (value == null) {
        return "\"\"";
    }//  w  w w  .ja v  a2  s  . c  o m

    if (!value.getClass().isArray()
            && (value.getClass().isPrimitive() || wrapperToPrimitive(value.getClass()) != null)) {
        return Objects.toString(value);
    }
    if (value instanceof String) {
        return '"' + ((String) value).replaceAll("\"", "\\\\\"") + '"';
    }
    if (value instanceof Collection) {
        return toJson((Collection) value);
    }
    if (value instanceof Map) {
        return toJson((Map<?, ?>) value);
    }
    throw new IllegalArgumentException("Cannot convert value " + value + " to JSON.");
}

From source file:org.mingle.pear.persistence.domain.BaseDomain.java

@Override
public String toString() {
    return Objects.toString(this);
}

From source file:net.modelbased.proasense.storage.writer.RandomEventGenerator.java

public SimpleEvent generateSimpleEvent(String sensorId) {
    // Define complex value
    ComplexValue value = new ComplexValue();
    value.setValue(Objects.toString(randomNumber.nextLong()));
    value.setType(VariableType.LONG);/* w  w w .jav a2s  .  c  o m*/

    // Define properties
    Map<String, ComplexValue> properties = new HashMap<String, ComplexValue>();
    properties.put("value", value);

    // Define simple event
    SimpleEvent event = new SimpleEvent();
    event.setTimestamp(System.currentTimeMillis());
    event.setSensorId(sensorId);
    event.setEventProperties(properties);

    return event;
}

From source file:at.ac.univie.isc.asio.insight.VndError.java

/**
 * Create an error descriptor from a java exception. Ensures that either the exception message or
 * if not available the exception class name are included as human readable message.
 *
 * @param exception    the exception that occurred
 * @param correlation  an identifier of the failed activity
 * @param timestamp    time when the error occurred
 * @param includeTrace whether the full stack trace of the exception is included
 * @return initialized error/*from www  . j a  v a  2s  .co m*/
 */
@Nonnull
public static VndError from(final Throwable exception, final Correlation correlation, final long timestamp,
        final boolean includeTrace) {
    final Throwable root = findRoot(exception);
    final String message = labelFor(exception);
    final List<ErrorChainElement> errorChain = includeTrace ? collectCausalChain(exception)
            : ImmutableList.<ErrorChainElement>of();
    return create(message, Objects.toString(root), correlation, timestamp, errorChain);
}

From source file:com.github.rutledgepaulv.testsupport.CriteriaSerializer.java

private List<?> applyList(Collection<?> items) {
    return items.stream().map(item -> {
        if (item instanceof Enum<?>) {
            return Objects.toString(item);
        } else {//from www  . j  av a2s  .  co  m
            return item;
        }
    }).collect(Collectors.toList());
}

From source file:com.nubits.nubot.trading.wrappers.TradeUtilsCCEDK.java

public static String getCCDKEvalidNonce() {
    //It tries to send a wrong nonce, get the allowed window, and use it for the actual call
    String wrongNonce = "1234567891";
    String lastdigits;/*from   ww w .ja v a2  s .  c  o  m*/
    //LOG.info("Offset = " + Objects.toStringSep(offset));
    String validNonce;
    if (offset == 0) {
        try {
            String htmlString = Utils.getHTML("https://www.ccedk.com/api/v1/currency/list?nonce=" + wrongNonce,
                    false);
            //LOG.info(htmlString);
            //LOG.info(Objects.toStringSep(System.currentTimeMillis() / 1000L));
            validNonce = getCCDKEvalidNonce(htmlString);
            offset = Integer.parseInt(validNonce) - (int) (System.currentTimeMillis() / 1000L);
            //LOG.info("Offset = " + Objects.toStringSep(offset));
        } catch (IOException io) {
            //LOG.info(io.toStringSep());
            validNonce = "";
        }
    } else {
        validNonce = Objects.toString(((int) (System.currentTimeMillis() / 1000L) + offset) - 1);
    }
    if (!validNonce.equals("")) {
        lastdigits = validNonce.substring(validNonce.length() - 2);
        if (lastdigits.equals("98") || lastdigits.equals("99")) {
            offset = 0;
            validNonce = getCCDKEvalidNonce();
        }
    } else {
        offset = 0;
        validNonce = getCCDKEvalidNonce();
    }
    //LOG.info("Last digits = " + lastdigits + "\nvalidNonce = " + validNonce);
    return validNonce;
}

From source file:com.opentable.exception.OTApiException.java

protected OTApiException(Map<String, ? extends Object> fields) {
    super(null, Objects.toString(fields.get(DETAIL)));
    checkNotBlank(fields, ERROR_TYPE);/*from   ww  w.  j  a va 2 s  .  c  o m*/
    checkNotBlank(fields, ERROR_SUBTYPE);
    this.fields = ImmutableMap.copyOf(fields);
}