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:net.modelbased.proasense.storage.writer.RandomEventGenerator.java

public RecommendationEvent generateRecommendationEvent(String collectionId) {
    // Define complex value
    ComplexValue value = new ComplexValue();
    value.setValue(Objects.toString(randomNumber.nextLong()));
    value.setType(VariableType.LONG);//from w  w w . j a  v a  2 s.  co m

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

    // Define recommendation event
    RecommendationEvent event = new RecommendationEvent();
    event.setRecommendationId(Objects.toString(System.currentTimeMillis()));
    event.setAction(randomData.nextHexString(100));
    event.setTimestamp(System.currentTimeMillis());
    event.setActor(randomData.nextHexString(10));
    event.setEventProperties(properties);
    event.setEventName(randomData.nextHexString(10));

    return event;
}

From source file:com.worldsmostinterestinginfographic.servlet.CallbackServlet.java

/**
 * Servlet to handle initial callback in response to an authorization request.
 *
 * Will check for the presence of an authorization code.  If present, will attempt to make an access token request
 * using the authorization code.  This is all done in accordance with the authorization code grant workflow in the
 * OAuth 2 specification [RFC 6749]. If no authorization code is detected, the authorization code is expired, or any
 * other errors occur, the user will be sent to an error page.
 *
 * @param request  The HTTP request sent by the client
 * @param response The HTTP response that the server will send back to the client
 *
 * @see <a href="https://tools.ietf.org/html/rfc6749">RFC 6749 - The OAuth 2.0 Authorization Framework</a>
 *///  w w w.  j a v  a2s. c o m
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    // Check for the presence of an authorization code
    String authorizationCode = request.getParameter("code");
    if (!StringUtils.isEmpty(authorizationCode)) {

        // Get access token
        log.info("[" + request.getSession().getId()
                + "] Starting session.  Requesting access token with authorization code "
                + LoggingUtils.anonymize(authorizationCode));

        String tokenEndpoint = Model.TOKEN_ENDPOINT + "?grant_type=authorization_code&code=" + authorizationCode
                + "&redirect_uri="
                + URLEncoder.encode(
                        (request.getScheme() + "://" + request.getServerName() + Model.REDIRECTION_ENDPOINT),
                        StandardCharsets.UTF_8.name())
                + "&client_id=" + Model.CLIENT_ID + "&client_secret=" + Model.CLIENT_SECRET;
        String accessToken = OAuth2Utils.requestAccessToken(tokenEndpoint);
        if (StringUtils.isEmpty(accessToken)) {
            response.sendRedirect("/uh-oh");
            return;
        }

        // Get profile data
        log.info("[" + request.getSession().getId() + "] Access token " + LoggingUtils.anonymize(accessToken)
                + " received.  Requesting profile data.");

        User user = facebookService.getProfile(accessToken);
        if (user == null) {
            response.sendRedirect("/uh-oh");
            return;
        }

        // Here we go
        log.info("[" + request.getSession().getId() + "] Hello, "
                + LoggingUtils.anonymize(Objects.toString(user.getId())) + "!");

        Model.cache.put(request.getSession().getId() + ".profile", user);
        Model.cache.put(request.getSession().getId() + ".token", accessToken);

        response.sendRedirect("/you-rock");

    } else if (request.getParameter("error") != null) {

        // An error happened during authorization code request
        String error = request.getParameter("error");
        String errorDescription = request.getParameter("error_description");

        request.getSession().setAttribute("error", error);
        request.getSession().setAttribute("errorDescription", errorDescription);

        log.severe("[" + request.getSession().getId()
                + "] Error encountered during authorization code request: " + error + " - " + errorDescription);
        response.sendRedirect("/uh-oh");

    } else {
        log.warning("[" + request.getSession().getId()
                + "] No authorization code or error message detected at redirection endpoint");
        response.sendRedirect("/uh-oh");
    }
}

From source file:org.squashtest.tm.domain.event.RequirementModificationEventPublisherAspect.java

private boolean requirementWasModified(Object oldValue, Object newValue) {
    return !Objects.equals(Objects.toString(oldValue), Objects.toString(newValue));
}

From source file:io.tsdb.opentsdb.realtime.RollupPublisher.java

private void storeRollups() {
    if (this.dataPointsMap.size() == 0) {
        LOG.debug("No DataPoints to consider for rollup");
        return;/*from  www  .j a  va  2 s  .  co m*/
    }
    LOG.debug("Considering " + this.dataPointsMap.size() + " DataPoints for rollup");
    long maximumTS = floorTimestamp(new Date(), this.minutes).getTime();
    for (Map.Entry<String, DataPoints> entry : this.dataPointsMap.entrySet()) {
        DataPoints dps = entry.getValue();
        if (dps.getTimestamp() < (maximumTS)) {
            IncomingDataPoint avgDP = dps.getAvgValue();
            LOG.debug("Key: " + entry.getKey() + " Metric: " + dps.getMetric() + " Timestamp: "
                    + Objects.toString(dps.getTimestamp()) + " Tags: " + getTagString(dps.getTags()) + " Avg: "
                    + avgDP.getValue());
            LOG.trace("removing " + entry.getKey() + " from dataPointsMap");
            this.dataPointsMap.remove(entry.getKey());
        }
    }
}

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

@RequestMapping(method = RequestMethod.GET, value = "/search/facets")
public FacetsResource getFacets(@RequestParam(name = "query", required = false) String query,
        @RequestParam(name = "dsoType", required = false) String dsoType,
        @RequestParam(name = "scope", required = false) String dsoScope,
        @RequestParam(name = "configuration", required = false) String configurationName,
        List<SearchFilter> searchFilters, Pageable page) throws Exception {

    if (log.isTraceEnabled()) {
        log.trace("Searching with scope: " + StringUtils.trimToEmpty(dsoScope) + ", configuration name: "
                + StringUtils.trimToEmpty(configurationName) + ", dsoType: " + StringUtils.trimToEmpty(dsoType)
                + ", query: " + StringUtils.trimToEmpty(dsoType) + ", filters: "
                + Objects.toString(searchFilters));
    }/*w  w  w.j a va  2 s.com*/

    SearchResultsRest searchResultsRest = discoveryRestRepository.getAllFacets(query, dsoType, dsoScope,
            configurationName, searchFilters);

    FacetsResource facetsResource = new FacetsResource(searchResultsRest, page);
    halLinkService.addLinks(facetsResource, page);

    return facetsResource;

}

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

private void appendContext(StringBuilder sb) {
    for (Map.Entry<String, Object> entry : context.entrySet()) {
        if (sb.length() > 0) {
            sb.append(CONTEXT_SEPARATOR);
        }/*from   w w  w.ja  va  2s .c o m*/
        sb.append(entry.getKey()).append("=").append(Objects.toString(entry.getValue()));
    }
}

From source file:com.javaeeeee.dropbookmarks.core.Bookmark.java

@Override
public String toString() {
    return "Bookmark{" + "id=" + id + ", url=" + url + ", description=" + description + ", user="
            + Objects.toString(user) + '}';
}

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

public FeedbackEvent generateFeedbackEvent(String collectionId) {
    // Define complex value
    ComplexValue value = new ComplexValue();
    value.setValue(Objects.toString(randomNumber.nextLong()));
    value.setType(VariableType.LONG);//from w ww  . ja v a 2  s  .c om

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

    // Define feedback event
    FeedbackEvent event = new FeedbackEvent();
    event.setActor(randomData.nextHexString(10));
    event.setTimestamp(System.currentTimeMillis());
    event.setStatus(Status.SUGGESTED);
    event.setComments(randomData.nextHexString(100));
    event.setRecommendationId(Objects.toString(System.currentTimeMillis()));

    return event;
}

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

public String createNonce(String requester) {
    //This is a  workaround waiting for clarifications from CCEDK team
    int lastdigit;
    String validNonce;//from w ww .j a v a2  s  .com
    int numericalNonce;
    String startvalid = " till";
    int indexStart;
    int upperEdge;
    String nonceError;
    if (offset == -1000000000) {
        JSONParser parser = new JSONParser();
        try {
            String htmlString = Utils.getHTML("https://www.ccedk.com/api/v1/currency/list?nonce=1234567891",
                    false);
            //{"errors":{"nonce":"incorrect range `nonce`=`1234567891`, must be from `1411036100` till `1411036141`"}
            JSONObject httpAnswerJson = (JSONObject) (parser.parse(htmlString));
            JSONObject errors = (JSONObject) httpAnswerJson.get("errors");
            nonceError = (String) errors.get("nonce");
            indexStart = nonceError.lastIndexOf(startvalid) + startvalid.length() + 2;
            upperEdge = Integer.parseInt(nonceError.substring(indexStart, indexStart + 10));
            offset = upperEdge - (int) (System.currentTimeMillis() / 1000L);
        } catch (ParseException ex) {
            LOG.error(ex.toString());
        } catch (IOException io) {
            LOG.error(io.toString());
        }
    }
    if (offset != -1000000000) {
        numericalNonce = (int) (System.currentTimeMillis() / 1000L) + offset;

        validNonce = Objects.toString(numericalNonce);
        //LOG.warn("validNonce = " + validNonce);
    } else {
        LOG.error("Error calculating nonce");
        validNonce = "1234567891";
    }
    return validNonce;
}

From source file:com.splicemachine.db.impl.sql.compile.ResultSetNode.java

@Override
public String toHTMLString() {
    return "resultSetNumber: " + resultSetNumber + "<br/>" + "referencedTableMap: "
            + Objects.toString(referencedTableMap) + "<br/>" + "statementResultSet: " + statementResultSet
            + "<br/>";
}