Example usage for java.util Map toString

List of usage examples for java.util Map toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.github.itoshige.testrail.client.TestRailClient.java

private static Object post(String command, final Map<String, ?> map) {
    try {/* www.j a va  2 s  .co  m*/
        Object obj = client.sendPost(command, map);
        return obj;
    } catch (Exception e) {
        throw new TestInitializerException(
                String.format("command:%s cannot post. map:%s", command, map.toString()), e);
    }
}

From source file:Main.java

/**
 * Make the log more meanings/* w w w . jav a 2s  .co m*/
 * 
 * @param <K>
 * @param <V>
 * @param map
 * @return
 */
public static <K, V> String toLog(Map<K, V> map) {
    // using StringBuffer instead of String because expect there are many append operation
    StringBuffer sb = new StringBuffer();

    if (map == null) {
        return null;
    }
    if (map.isEmpty()) {
        return map.toString();
    }

    sb.append("{");

    for (Iterator<K> iterator = map.keySet().iterator(); iterator.hasNext();) {
        K key = iterator.next();
        Object value = map.get(key);
        sb.append(key).append("=");
        sb.append(toString4Log(value));
        if (iterator.hasNext()) {
            sb.append(", ");
        }
    }

    sb.append("}");

    return sb.toString();
}

From source file:org.jwebsocket.ldap.Main.java

/**
 *
 * @param aAD/*from   w ww.ja  v a2s.c o  m*/
 */
public static void demo(ADTools aAD) {

    aAD.login(USERNAME, PASSWORD);

    if (aAD.getDirContext() != null) {
        String lDNDL0 = aAD.getDNfromDL(mTestDL0);
        mLog.info("DN User " + mTestDL0 + ": " + lDNDL0);

        String lDN_User0 = aAD.getDNfromLoginname(mTestUserNames[0]);
        mLog.info("DN User '" + mTestUserNames[0] + "': " + lDN_User0);
        String lDN_User1 = aAD.getDNfromLoginname(mTestUserNames[1]);
        mLog.info("DN User '" + mTestUserNames[1] + "': " + lDN_User1);
        String lDN_User2 = aAD.getDNfromLoginname(mTestUserNames[2]);
        mLog.info("DN User '" + mTestUserNames[2] + "': " + lDN_User2);
        String lDN_User3 = aAD.getDNfromLoginname(mTestUserNames[3]);
        mLog.info("DN User '" + mTestUserNames[3] + "': " + lDN_User3);

        String lDNDL1 = aAD.getDNfromDL(mTestDL1);
        mLog.info("DN DL '" + mTestDL1 + "': " + lDNDL1);

        Map<String, String> lDNs;

        String[] lAttrs = { "distinguishedName", "displayName", "mail", "mailNickname" };

        String lTestUserId = mTestUserNames[0];

        Map<String, List<String>> lTmpRes = aAD.getUserAttrs(lTestUserId, lAttrs);
        mLog.info("Attributes: " + (lTmpRes == null ? "none" : lTmpRes.toString()));

        Map<String, String> lDLs = aAD.getUserDLs(lTestUserId);
        mLog.info("DLs for '" + lDN_User2 + "':");
        mLog.info("Group-Names: " + lDLs.keySet().toString());

        boolean lUser0InTestTL1 = aAD.isUserInDL(lTestUserId, mTestDL1, lDLs);
        boolean lUser0InOtherDL = aAD.isUserInDL(lTestUserId, "ArbitraryDLNameForTest", lDLs);
        mLog.info("In '" + mTestDL1 + "'?: " + lUser0InTestTL1);
        mLog.info("In other DL?: " + lUser0InOtherDL);

        lDNs = aAD.getUserDLs(mTestUserNames[0]);
        mLog.info("DLs for " + mTestUserNames[0] + ":");
        mLog.info("Group-Names: " + lDNs.keySet().toString());

        lDNs = aAD.getUserDLs(mTestUserNames[1]);
        mLog.info("DLs for " + mTestUserNames[1] + ":");
        mLog.info("Group-Names: " + lDNs.keySet().toString());

        lDNs = aAD.getUserDLs(mTestUserNames[2]);
        mLog.info("DLs for " + mTestUserNames[2] + ":");
        mLog.info(lDNs.keySet().toString());

        lDNs = aAD.getUserDLs(mTestUserNames[3]);
        mLog.info("DLs for " + mTestUserNames[3] + ":");
        mLog.info(lDNs.keySet().toString());

        mLog.info("List DNs from " + mTestDL0 + ":");
        List<String> dns = aAD.getDLMemberDNs(mTestDL0);
        if (dns != null) {
            for (String dn : dns) {
                mLog.info(dn);
            }
        }

        // mLog.info("Deleting all users from " + mTestDL + ":");
        // clearDL(mTestDL);
        mLog.info("List DNs from " + mTestDL0 + ":");
        dns = aAD.getDLMemberDNs(mTestDL0);
        if (dns != null) {
            for (String dn : dns) {
                mLog.info(dn);
            }
        }

        mLog.info(
                "Adding '" + mTestUserNames[0] + "' and '" + mTestUserNames[1] + "' to '" + mTestDL0 + "'...");
        aAD.addDNToDL(lDNDL0, lDN_User0);
        aAD.addDNToDL(lDNDL1, lDN_User1);

        mLog.info("List DNs from " + mTestDL0 + ":");
        dns = aAD.getDLMemberDNs(mTestDL0);
        if (dns != null) {
            for (String dn : dns) {
                mLog.info(dn);
            }
        }
    } else {
        mLog.error("Authenticaton failed");
    }
}

From source file:com.zxy.commons.lang.utils.ObjectsUtils.java

/**
 * ??//from w w  w .jav a2  s .  c  o m
 * 
 * @param obj 
 * @param toStringStyle ?
 *                      {@code ToStringStyle.SIMPLE_STYLE }
 *                      {@code ToStringStyle.SHORT_PREFIX_STYLE }
 *                      {@code ToStringStyle.MULTI_LINE_STYLE }
 * @return ??
 * @see ToStringStyle
 */
public static String toString(Object obj, ToStringStyle toStringStyle) {
    if (obj == null) {
        return null;
    }
    if ((obj instanceof Collection)) {
        Collection<?> cs = (Collection<?>) obj;
        List<String> returnCs = new ArrayList<>();
        for (Object c : cs) {
            returnCs.add(ReflectionToStringBuilder.toString(c, toStringStyle));
        }
        return returnCs.toString();
    }
    if ((obj instanceof Map)) {
        Map<?, ?> maps = (Map<?, ?>) obj;
        Map<String, String> returnMaps = new HashMap<>();
        for (Map.Entry<?, ?> entry : maps.entrySet()) {
            String key = entry.getKey().toString();
            String value = ReflectionToStringBuilder.toString(entry.getValue(), toStringStyle);
            returnMaps.put(key, value);
        }
        return returnMaps.toString();
    }
    //        return ReflectionToStringBuilder.toString(obj, ToStringStyle.SHORT_PREFIX_STYLE);
    return ReflectionToStringBuilder.toString(obj, toStringStyle);
}

From source file:com.example.shitij.railway.log.Logging.java

/**
 * Method to com.example.shitij.railway.log Errors from application
 *
 * @param LOG_TAG is the tag for message
 * @param error is the error message to be logged
 * @param priority is the priority of the logging defined by {@link CommonLibs.Priority class}
 * @param dict is the extra params to be passed with exception
 *
 */// ww  w . j  av  a 2  s .  c o m
public static void logError(String LOG_TAG, String error, @CommonLibs.Priority.PriorityConstants int priority,
        Map<String, String> dict) {
    switch (priority) {
    case CommonLibs.Priority.VERY_HIGH:
        if (error != null && error.trim().length() > 0) {
            if (BuildConfig.DEBUG)
                Log.e(LOG_TAG, error + "\nDATA :\n" + dict.toString());

            else {
                //                        Crashlytics.getInstance().core.com.example.shitij.railway.log(Log.ERROR, LOG_TAG, error);
                //                        Sentry.SentryEventBuilder builder = new Sentry.SentryEventBuilder();
                //                        builder.setLevel(Sentry.SentryEventBuilder.SentryEventLevel.FATAL);
                //                        builder.setMessage(error);
                //                        builder.setExtra(dict);
                //                        Sentry.captureEvent(builder);
            }
        }
        break;

    case CommonLibs.Priority.HIGH:
        if (error != null && error.trim().length() > 0) {
            if (BuildConfig.DEBUG)
                Log.e(LOG_TAG, error + "\nDATA :\n" + dict.toString());

            else {
                //                        Crashlytics.getInstance().core.com.example.shitij.railway.log(Log.ERROR, LOG_TAG, error);
                //                        Sentry.SentryEventBuilder builder = new Sentry.SentryEventBuilder();
                //                        builder.setLevel(Sentry.SentryEventBuilder.SentryEventLevel.FATAL);
                //                        builder.setMessage(error);
                //                        builder.setExtra(dict);
                //                        Sentry.captureEvent(builder);
            }
        }
        break;

    case CommonLibs.Priority.MEDIUM:

    case CommonLibs.Priority.LOW:

    case CommonLibs.Priority.VERY_LOW:
        if (BuildConfig.DEBUG)
            Log.e(LOG_TAG, error + "\nDATA :\n" + dict.toString());
        break;

    default:
        if (BuildConfig.DEBUG)
            Log.e(LOG_TAG, error + "\nDATA :\n" + dict.toString());
    }
}

From source file:ai.susi.tools.JsonSignature.java

public static void addSignature(Map<String, byte[]> obj, PrivateKey key)
        throws InvalidKeyException, SignatureException {

    removeSignature(obj);// w  w  w  .j  a v  a2  s  .c  om

    Signature signature;
    try {
        signature = Signature.getInstance("SHA256withRSA");
    } catch (NoSuchAlgorithmException e) {
        return; //does not happen
    }

    signature.initSign(key);
    signature.update(obj.toString().getBytes(StandardCharsets.UTF_8));

    byte[] sigBytes = signature.sign();

    obj.put(signatureString, Base64.getEncoder().encode(sigBytes));
}

From source file:com.wealdtech.gcm.GCMClient.java

/**
 * Encode a message as JSON, capturing errors
 * @param message the message//from   www  . j  av  a2  s  .com
 * @return a JSON string
 */
private static String encodeMessageAsJson(final Map<String, Object> message) {
    try {
        return WealdMapper.getMapper().writeValueAsString(message);
    } catch (JsonProcessingException e) {
        throw new ServerError(
                "Failed to create JSON message from \"" + message.toString() + "\": " + e.getMessage());
    }
}

From source file:org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1.java

public static AtlasVertex getVertexByUniqueAttributes(AtlasEntityType entityType,
        Map<String, Object> attrValues) throws AtlasBaseException {
    AtlasVertex vertex = findByUniqueAttributes(entityType, attrValues);

    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND,
                entityType.getTypeName(), attrValues.toString());
    }/* www  .j av  a 2 s.c o  m*/

    return vertex;
}

From source file:org.jxstar.control.action.ActionHelper.java

/**
 * RequestContext?HttpServletRequest?/*from  www .jav a2 s  .c  o m*/
 * ?[sys.realpath]IP?[sys.realpath]
 * @param request
 * @return
 */
public static RequestContext getRequestContext(HttpServletRequest request) throws ActionException {
    Map<String, Object> requestMap;
    boolean isMultipart = DiskFileUpload.isMultipartContent(request);
    _log.showDebug("request is have file upload: " + isMultipart);
    if (isMultipart) {
        requestMap = parseMultiRequest(request);
    } else {
        requestMap = parseRequestParam(request);
    }
    _log.showDebug("------------request param=" + requestMap.toString());
    //?
    requestMap.put(JsParam.REALPATH, SystemVar.REALPATH);

    //?
    RequestContext requestContext = new RequestContext(requestMap);
    //?Map<String,String>???client_ip?session_id
    requestContext.setClientInfo(getClientInfo(request));

    //?ID?Context
    String funid = requestContext.getRequestValue(JsParam.FUNID);
    requestContext.setFunID(funid);

    //??
    String pageType = requestContext.getRequestValue(JsParam.PAGETYPE);
    requestContext.setPageType(pageType);

    //?eventCode????eventCode
    String eventCode = requestContext.getRequestValue(JsParam.EVENTCODE);
    requestContext.setEventCode(eventCode);

    return requestContext;
}

From source file:nl.paston.bonita.importfile.Main.java

protected static void pushRecordToBonita(ProcessAPI processAPI, ProcessDeploymentInfo info,
        Map<String, Serializable> map) {
    if (map == null) {
        log.warn("map is null.");
        return;//from  w  ww .j  ava  2s . com
    }
    log.info("Pushing record to Bonita server.");
    log.debug(map.toString());
    try {
        processAPI.startProcessWithInputs(info.getProcessId(), map);
        log.debug("Succesfully pushed record.");
    } catch (ProcessDefinitionNotFoundException | ProcessActivationException | ProcessExecutionException
            | ContractViolationException ex) {
        log.error("Cannot push data to bonita. Reason: " + ex.getMessage());
        System.exit(1);
    }
}