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:com.nubits.nubot.trading.TradeUtils.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.  jav  a  2 s . c  om*/
    //LOG.info("Offset = " + Objects.toString(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.toString(System.currentTimeMillis() / 1000L));
            validNonce = getCCDKEvalidNonce(htmlString);
            offset = Integer.parseInt(validNonce) - (int) (System.currentTimeMillis() / 1000L);
            //LOG.info("Offset = " + Objects.toString(offset));
        } catch (IOException io) {
            //LOG.info(io.toString());
            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:at.ac.univie.isc.asio.engine.sql.WebRowSetWriter.java

private void tag(final String elementName, final Object content) throws XMLStreamException {
    xml.writeStartElement(WRS, elementName);
    final String text = Objects.toString(content);
    if ((content == null || text.isEmpty()) && useNullTag) {
        xml.writeEmptyElement(WRS, "null");
    } else if (!text.isEmpty()) {
        xml.writeCharacters(text);//from w  w w. j a v  a2 s.co  m
    } // else { ; }
    xml.writeEndElement();
}

From source file:com.github.technosf.posterer.models.impl.RequestBean.java

/**
 * Create a hashcode for the {@code Request}
 * /*from   w  ww .j a v  a2s.  co m*/
 * @param request
 * @return
 */
private static int hashCode(final @Nullable Request request) {
    if (request == null) {
        return 0;
    }

    return Objects.hash(Objects.toString(request.getEndpoint()), Objects.toString(request.getPayload()),
            Objects.toString(request.getMethod()), Objects.toString(request.getSecurity()),
            Objects.toString(request.getContentType()), Objects.toString(request.getBase64()));
}

From source file:org.dspace.app.rest.DiscoveryRestController.java

@RequestMapping(method = RequestMethod.GET, value = "/facets/{name}")
public ResourceSupport getFacetValues(@PathVariable("name") String facetName,
        @RequestParam(name = "prefix", required = false) String prefix,
        @RequestParam(name = "query", required = false) String query,
        @RequestParam(name = "dsoType", required = false) String dsoType,
        @RequestParam(name = "scope", required = false) String dsoScope, List<SearchFilter> searchFilters,
        Pageable page) throws Exception {
    if (log.isTraceEnabled()) {
        log.trace("Facetting on facet " + facetName + " with scope: " + StringUtils.trimToEmpty(dsoScope)
                + ", dsoType: " + StringUtils.trimToEmpty(dsoType) + ", prefix: "
                + StringUtils.trimToEmpty(prefix) + ", query: " + StringUtils.trimToEmpty(dsoType)
                + ", filters: " + Objects.toString(searchFilters) + ", page: " + Objects.toString(page));
    }//  ww w  .ja  v  a2s .co m

    FacetResultsRest facetResultsRest = discoveryRestRepository.getFacetObjects(facetName, prefix, query,
            dsoType, dsoScope, searchFilters, page);

    FacetResultsResource facetResultsResource = new FacetResultsResource(facetResultsRest);

    halLinkService.addLinks(facetResultsResource, page);
    return facetResultsResource;
}

From source file:com.joyent.manta.config.SettableConfigContext.java

/**
 * Utility method for setting a {@link SettableConfigContext} values via
 * String parameters. Note, this method will set null for values when the
 * inputs are invalid for integer or boolean types. For other types it
 * will just not set anything.//w  ww.  j a v  a 2 s.  com
 *
 * @param name string key to set via
 * @param value value to set to context
 * @param config config value to set
 */
static void setAttributeFromContext(final String name, final Object value,
        final SettableConfigContext<?> config) {
    switch (name) {
    case MapConfigContext.MANTA_URL_KEY:
    case EnvVarConfigContext.MANTA_URL_ENV_KEY:
        config.setMantaURL(Objects.toString(value));
        break;
    case MapConfigContext.MANTA_USER_KEY:
    case EnvVarConfigContext.MANTA_ACCOUNT_ENV_KEY:
        config.setMantaUser(Objects.toString(value));
        break;
    case MapConfigContext.MANTA_KEY_ID_KEY:
    case EnvVarConfigContext.MANTA_KEY_ID_ENV_KEY:
        config.setMantaKeyId(Objects.toString(value));
        break;
    case MapConfigContext.MANTA_KEY_PATH_KEY:
    case EnvVarConfigContext.MANTA_KEY_PATH_ENV_KEY:
        config.setMantaKeyPath(Objects.toString(value));
        break;
    case MapConfigContext.MANTA_TIMEOUT_KEY:
    case EnvVarConfigContext.MANTA_TIMEOUT_ENV_KEY:
        config.setTimeout(MantaUtils.parseIntegerOrNull(value));
        break;
    case MapConfigContext.MANTA_RETRIES_KEY:
    case EnvVarConfigContext.MANTA_RETRIES_ENV_KEY:
        config.setRetries(MantaUtils.parseIntegerOrNull(value));
        break;
    case MapConfigContext.MANTA_MAX_CONNS_KEY:
    case EnvVarConfigContext.MANTA_MAX_CONNS_ENV_KEY:
        config.setMaximumConnections(MantaUtils.parseIntegerOrNull(value));
        break;
    case MapConfigContext.MANTA_PRIVATE_KEY_CONTENT_KEY:
    case EnvVarConfigContext.MANTA_PRIVATE_KEY_CONTENT_ENV_KEY:
        config.setPrivateKeyContent(Objects.toString(value));
        break;
    case MapConfigContext.MANTA_PASSWORD_KEY:
    case EnvVarConfigContext.MANTA_PASSWORD_ENV_KEY:
        config.setPassword(Objects.toString(value));
        break;
    case MapConfigContext.MANTA_HTTP_BUFFER_SIZE_KEY:
    case EnvVarConfigContext.MANTA_HTTP_BUFFER_SIZE_ENV_KEY:
        config.setHttpBufferSize(MantaUtils.parseIntegerOrNull(value));
        break;
    case MapConfigContext.MANTA_HTTPS_PROTOCOLS_KEY:
    case EnvVarConfigContext.MANTA_HTTPS_PROTOCOLS_ENV_KEY:
        config.setHttpsProtocols(Objects.toString(value));
        break;
    case MapConfigContext.MANTA_HTTPS_CIPHERS_KEY:
    case EnvVarConfigContext.MANTA_HTTPS_CIPHERS_ENV_KEY:
        config.setHttpsCipherSuites(Objects.toString(value));
        break;
    case MapConfigContext.MANTA_NO_AUTH_KEY:
    case EnvVarConfigContext.MANTA_NO_AUTH_ENV_KEY:
        config.setNoAuth(MantaUtils.parseBooleanOrNull(value));
        break;
    case MapConfigContext.MANTA_NO_NATIVE_SIGS_KEY:
    case EnvVarConfigContext.MANTA_NO_NATIVE_SIGS_ENV_KEY:
        config.disableNativeSignatures();
        break;
    case MapConfigContext.MANTA_TCP_SOCKET_TIMEOUT_KEY:
    case EnvVarConfigContext.MANTA_TCP_SOCKET_TIMEOUT_ENV_KEY:
        config.setTcpSocketTimeout(MantaUtils.parseIntegerOrNull(value));
        break;
    case MapConfigContext.MANTA_UPLOAD_BUFFER_SIZE_KEY:
    case EnvVarConfigContext.MANTA_UPLOAD_BUFFER_SIZE_ENV_KEY:
        config.setUploadBufferSize(MantaUtils.parseIntegerOrNull(value));
        break;
    case MapConfigContext.MANTA_SKIP_DIRECTORY_DEPTH_KEY:
    case EnvVarConfigContext.MANTA_SKIP_DIRECTORY_DEPTH_ENV_KEY:
        config.setSkipDirectoryDepth(MantaUtils.parseIntegerOrNull(value));
        break;
    case MapConfigContext.MANTA_METRIC_REPORTER_MODE_KEY:
    case EnvVarConfigContext.MANTA_METRIC_REPORTER_MODE_ENV_KEY:
        final String metricReporterModeStr = Objects.toString(value);
        if (StringUtils.isBlank(metricReporterModeStr)) {
            return;
        }

        try {
            config.setEncryptionAuthenticationMode(EncryptionAuthenticationMode.valueOf(metricReporterModeStr));
        } catch (IllegalArgumentException e) {
            // error parsing enum value, so we just exit the function
            return;
        }

        break;
    case MapConfigContext.MANTA_METRIC_REPORTER_OUTPUT_INTERVAL_KEY:
    case EnvVarConfigContext.MANTA_METRIC_REPORTER_OUTPUT_INTERVAL_ENV_KEY:
        config.setMetricReporterOutputInterval(MantaUtils.parseIntegerOrNull(value));
        break;
    case MapConfigContext.MANTA_CLIENT_ENCRYPTION_ENABLED_KEY:
    case EnvVarConfigContext.MANTA_CLIENT_ENCRYPTION_ENABLED_ENV_KEY:
        config.setClientEncryptionEnabled(MantaUtils.parseBooleanOrNull(value));
        break;
    case MapConfigContext.MANTA_CONNECTION_REQUEST_TIMEOUT_KEY:
    case EnvVarConfigContext.MANTA_CONNECTION_REQUEST_TIMEOUT_ENV_KEY:
        config.setConnectionRequestTimeout(MantaUtils.parseIntegerOrNull(value));
        break;
    case MapConfigContext.MANTA_ENCRYPTION_KEY_ID_KEY:
    case EnvVarConfigContext.MANTA_ENCRYPTION_KEY_ID_ENV_KEY:
        config.setEncryptionKeyId(Objects.toString(value));
        break;
    case MapConfigContext.MANTA_PERMIT_UNENCRYPTED_DOWNLOADS_KEY:
    case EnvVarConfigContext.MANTA_PERMIT_UNENCRYPTED_DOWNLOADS_ENV_KEY:
        config.setPermitUnencryptedDownloads(MantaUtils.parseBooleanOrNull(value));
        break;
    case MapConfigContext.MANTA_ENCRYPTION_AUTHENTICATION_MODE_KEY:
    case EnvVarConfigContext.MANTA_ENCRYPTION_AUTHENTICATION_MODE_ENV_KEY:
        String stringVal = Objects.toString(value);
        if (StringUtils.isBlank(stringVal)) {
            return;
        }

        try {
            config.setEncryptionAuthenticationMode(EncryptionAuthenticationMode.valueOf(stringVal));
        } catch (IllegalArgumentException e) {
            // error parsing enum value, so we just exit the function
            return;
        }

        break;
    case MapConfigContext.MANTA_ENCRYPTION_PRIVATE_KEY_PATH_KEY:
    case EnvVarConfigContext.MANTA_ENCRYPTION_PRIVATE_KEY_PATH_ENV_KEY:
        config.setEncryptionPrivateKeyPath(Objects.toString(value));
        break;
    case MapConfigContext.MANTA_ENCRYPTION_PRIVATE_KEY_BYTES_KEY:
        if (value instanceof byte[]) {
            config.setEncryptionPrivateKeyBytes((byte[]) value);
        }
        break;
    case MapConfigContext.MANTA_ENCRYPTION_PRIVATE_KEY_BYTES_BASE64_KEY:
    case EnvVarConfigContext.MANTA_ENCRYPTION_PRIVATE_KEY_BYTES_BASE64_ENV_KEY:
        if (value instanceof String) {
            String base64 = (String) value;
            if (StringUtils.isEmpty(base64)) {
                return;
            }

            config.setEncryptionPrivateKeyBytes(Base64.decode(base64));
        }
        break;
    default:
        break;
    }
}

From source file:eu.itesla_project.modules.validation.OfflineValidationTool.java

private static void writeAttributesFiles(Set<RuleId> rulesIds,
        Map<String, Map<RuleId, Map<HistoDbAttributeId, Object>>> valuesPerRulePerCase, Path outputDir)
        throws IOException {
    for (RuleId ruleId : rulesIds) {
        Path attributesFile = outputDir.resolve("attributes_" + ruleId.toString() + ".csv");

        System.out.println("writing " + attributesFile + "...");

        try (BufferedWriter writer = Files.newBufferedWriter(attributesFile, StandardCharsets.UTF_8)) {
            writer.write("base case");

            Set<HistoDbAttributeId> allAttributeIds = new LinkedHashSet<>();
            for (Map<RuleId, Map<HistoDbAttributeId, Object>> valuesPerRule : valuesPerRulePerCase.values()) {
                Map<HistoDbAttributeId, Object> values = valuesPerRule.get(ruleId);
                if (values != null) {
                    allAttributeIds.addAll(values.keySet());
                }//from w  w  w .j  a va  2  s .com
            }

            for (HistoDbAttributeId attributeId : allAttributeIds) {
                writer.write(CSV_SEPARATOR);
                writer.write(attributeId.toString());
            }
            writer.newLine();

            for (Map.Entry<String, Map<RuleId, Map<HistoDbAttributeId, Object>>> e : valuesPerRulePerCase
                    .entrySet()) {
                String baseCaseName = e.getKey();
                Map<RuleId, Map<HistoDbAttributeId, Object>> valuesPerRule = e.getValue();
                writer.write(baseCaseName);

                Map<HistoDbAttributeId, Object> values = valuesPerRule.get(ruleId);
                for (HistoDbAttributeId attributeId : allAttributeIds) {
                    writer.write(CSV_SEPARATOR);
                    Object value = values.get(attributeId);
                    if (value != null && !(value instanceof Float && Float.isNaN((Float) value))) {
                        writer.write(Objects.toString(values.get(attributeId)));
                    }
                }

                writer.newLine();
            }
        }
    }
}

From source file:com.joyent.manta.client.MantaDirectoryListingIterator.java

@Override
public synchronized Map<String, Object> next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }//  w w  w  .  j a v a 2s  .c om

    try {
        String line = nextLine.getAndSet(br.readLine());
        lines.incrementAndGet();

        if (line == null) {
            selectReader();

            if (finished.get()) {
                throw new NoSuchElementException();
            }

            line = nextLine.getAndSet(br.readLine());
        }

        final Map<String, Object> lookup = mapper.readValue(line, new TypeReference<Map<String, Object>>() {
        });
        final String name = Objects.toString(lookup.get("name"));

        Validate.notNull(name, "Name must not be null in JSON input");

        /* Explicitly set the path of the object here so that we don't need
         * to create a new instance of MantaObjectConversionFunction per
         * object being read. */
        lookup.put("path", path);

        this.lastMarker = name;

        return lookup;

    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:com.tesobe.obp.transport.spi.MockResponder.java

public Response put(Decoder.Parameters ps, Map<String, ?> fields, Transport.Target t) {
    ps.type().map(type -> {//from  w ww .j av a  2 s.co  m
        assertThat(type, is("pain.001.001.03db"));
        return Void.TYPE;
    }).orElseGet(() -> {
        fail();
        return Void.TYPE;
    });

    assertThat(fields.get(Transaction.accountId), is("account-x"));
    assertThat(fields.get(Transaction.amount), is("10"));
    assertThat(fields.get(Transaction.bankId), is("bank-x"));
    assertThat(fields.get(Transaction.completedDate), is("1999-01-02T00:00:00.000Z"));
    assertThat(fields.get(Transaction.counterPartyId), is("counterPartyId-x"));
    assertThat(fields.get(Transaction.counterPartyName), is("counterPartyName-x"));
    assertThat(fields.get(Transaction.currency), is("currency-x"));
    assertThat(fields.get(Transaction.description), is("description-x"));
    assertThat(fields.get(Transaction.newBalanceAmount), is("123456.78"));
    assertThat(fields.get(Transaction.newBalanceCurrency), is("nbc-x"));
    assertThat(fields.get(Transaction.postedDate), is("1999-01-02T00:00:00.000Z"));
    assertThat(fields.get(Transaction.transactionId), is("transaction-x"));
    assertThat(fields.get(Transaction.type), is("type-x"));
    assertThat(fields.get(Transaction.userId), is("user-x"));

    return DefaultResponse.fromData(entity("transactionId", Objects.toString(fields.get("transactionId"))));
}

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

private ApiResponse enterOrder(String type, CurrencyPair pair, double amount, double rate) {
    ApiResponse apiResponse = new ApiResponse();
    String url = API_BASE_URL + "/" + API_ORDERS;
    HashMap<String, String> args = new HashMap<>();
    boolean isGet = false;

    args.put("amount", Objects.toString(amount));
    args.put("market", pair.toStringSepSpecial("/").toUpperCase());
    args.put("price", Objects.toString(rate));
    args.put("action", type);

    ApiResponse response = getQuery(url, args, true, isGet);
    if (response.isPositive()) {
        ApiResponse getOpenOrders = getActiveOrders(pair);
        if (getOpenOrders.isPositive()) {
            ArrayList<Order> orders = (ArrayList) getOpenOrders.getResponseObject();
            Date checkDate = null;
            String order_id = null;
            for (Iterator<Order> order = orders.iterator(); order.hasNext();) {
                Order thisOrder = order.next();
                if (checkDate == null || thisOrder.getInsertedDate().getTime() > checkDate.getTime()) {
                    checkDate = thisOrder.getInsertedDate();
                    order_id = thisOrder.getId();
                }//from w w  w.  j  a  v a 2  s. c o  m
            }
            apiResponse.setResponseObject(order_id);
        } else {
            apiResponse = getOpenOrders;
        }
    } else {
        apiResponse = response;
    }
    return apiResponse;
}