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:org.fusesource.restygwt.client.codec.EncoderDecoderTestGwt.java

public void testTypeMapWithIntegerDecode() {
    Map<Integer, String> map = new HashMap<Integer, String>();
    map.put(123, "321");
    AbstractJsonEncoderDecoder<Integer> keyEncoder = AbstractJsonEncoderDecoder.INT;
    AbstractJsonEncoderDecoder<String> valueEncoder = AbstractJsonEncoderDecoder.STRING;
    assertEquals(map.toString(),
            AbstractJsonEncoderDecoder//ww  w .j  av  a 2s .  co  m
                    .toMap(AbstractJsonEncoderDecoder.toJSON(map, keyEncoder, valueEncoder, Json.Style.DEFAULT),
                            keyEncoder, valueEncoder, Json.Style.DEFAULT)
                    .toString());
    assertEquals(map.toString(),
            AbstractJsonEncoderDecoder
                    .toMap(AbstractJsonEncoderDecoder.toJSON(map, keyEncoder, valueEncoder,
                            Json.Style.JETTISON_NATURAL), keyEncoder, valueEncoder, Json.Style.JETTISON_NATURAL)
                    .toString());
}

From source file:org.fusesource.restygwt.client.codec.EncoderDecoderTestGwt.java

public void testTypeMapWithJsonStringDecode() {
    Map<String, String> map = new HashMap<String, String>();
    map.put("[1,2, 3]", "value");
    AbstractJsonEncoderDecoder<String> keyEncoder = AbstractJsonEncoderDecoder.STRING;
    AbstractJsonEncoderDecoder<String> valueEncoder = AbstractJsonEncoderDecoder.STRING;
    assertEquals(map.toString(),
            AbstractJsonEncoderDecoder/*from  ww  w. j av a 2  s.c  o  m*/
                    .toMap(AbstractJsonEncoderDecoder.toJSON(map, keyEncoder, valueEncoder, Json.Style.DEFAULT),
                            keyEncoder, valueEncoder, Json.Style.DEFAULT)
                    .toString());
    assertEquals(map.toString(),
            AbstractJsonEncoderDecoder
                    .toMap(AbstractJsonEncoderDecoder.toJSON(map, keyEncoder, valueEncoder,
                            Json.Style.JETTISON_NATURAL), keyEncoder, valueEncoder, Json.Style.JETTISON_NATURAL)
                    .toString());
}

From source file:jeeves.server.JeevesEngine.java

@SuppressWarnings("unchecked")
private void initAppHandler(Element handler, JeevesServlet servlet,
        JeevesApplicationContext jeevesApplicationContext) throws Exception {
    if (handler == null)
        info("Handler not found");
    else {/*w  ww. j a  v a2  s  . com*/
        String className = handler.getAttributeValue(ConfigFile.AppHandler.Attr.CLASS);

        if (className == null)
            throw new IllegalArgumentException("Missing '" + ConfigFile.AppHandler.Attr.CLASS
                    + "' attribute in '" + ConfigFile.Child.APP_HANDLER + "' element");

        info("Found handler : " + className);

        Class c = Class.forName(className);

        ApplicationHandler h = (ApplicationHandler) c.newInstance();

        ServiceContext srvContext = serviceMan.createServiceContext("AppHandler", jeevesApplicationContext);
        srvContext.setLanguage(defaultLang);
        srvContext.setLogger(appHandLogger);
        srvContext.setServlet(servlet);
        srvContext.setAsThreadLocal();

        try {
            info("--- Starting handler --------------------------------------");

            Object context = h.start(handler, srvContext);

            srvContext.getResourceManager().close();
            vAppHandlers.add(h);
            serviceMan.registerContext(h.getContextName(), context);
            scheduleMan.registerContext(h.getContextName(), context);
            monitorManager.initMonitorsForApp(srvContext);

            info("--- Handler started ---------------------------------------");
        } catch (Exception e) {
            Map<String, String> errors = new HashMap<String, String>();
            String eS = "Raised exception while starting appl handler. Skipped.";
            error(eS);
            errors.put("Error", eS);
            error("   Handler   : " + className);
            errors.put("Handler", className);
            error("   Exception : " + e);
            errors.put("Exception", e.toString());
            error("   Message   : " + e.getMessage());
            errors.put("Message", e.getMessage());
            error("   Stack     : " + Util.getStackTrace(e));
            errors.put("Stack", Util.getStackTrace(e));
            error(errors.toString());
            // only set the error if we don't already have one
            if (!serviceMan.isStartupError())
                serviceMan.setStartupErrors(errors);
            srvContext.getResourceManager().abort();
        }
    }
}

From source file:org.mobicents.restcomm.android.client.sdk.RCConnection.java

/**
 * Accept the incoming connection. Important: if you work with Android API 23 or above you will need to handle dynamic Android permissions in your Activity
 * as described at https://developer.android.com/training/permissions/requesting.html. More specifically the Restcomm Client SDK needs RECORD_AUDIO, CAMERA (only if the local user
 * has enabled local video via RCConnection.ParameterKeys.CONNECTION_VIDEO_ENABLED; if not then this permission isn't needed), and USE_SIP permission
 * to be able to accept() a connection. For an example of such permission handling you can check MainActivity of restcomm-hello world sample App. Notice that if any of these permissions
 * are missing, the call will fail with a ERROR_CONNECTION_PERMISSION_DENIED error.
 *
 * @param parameters Parameters such as whether we want video enabled, etc. Possible keys: <br>
 *   <b>RCConnection.ParameterKeys.CONNECTION_VIDEO_ENABLED</b>: Whether we want WebRTC video enabled or not <br>
 *   <b>RCConnection.ParameterKeys.CONNECTION_LOCAL_VIDEO</b>: View where we want the local video to be rendered <br>
 *   <b>RCConnection.ParameterKeys.CONNECTION_REMOTE_VIDEO</b>: View where we want the remote video to be rendered  <br>
 *   <b>RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_CODEC</b>: Preferred video codec to use. Default is VP8. Possible values: <i>'VP8', 'VP9'</i> <br>
 * means that RCDevice.state not ready to make a call (this usually means no WiFi available)
 *///from  w  w  w  .j  ava2 s  . co m
public void accept(Map<String, Object> parameters) {
    RCLogger.i(TAG, "accept(): " + parameters.toString());
    if (!checkPermissions((Boolean) parameters.get(ParameterKeys.CONNECTION_VIDEO_ENABLED))) {
        return;
    }

    if (state == ConnectionState.CONNECTING) {
        this.callParams = (HashMap<String, Object>) parameters;
        initializeWebrtc((Boolean) this.callParams.get(ParameterKeys.CONNECTION_VIDEO_ENABLED),
                (PercentFrameLayout) parameters.get(ParameterKeys.CONNECTION_LOCAL_VIDEO),
                (PercentFrameLayout) parameters.get(ParameterKeys.CONNECTION_REMOTE_VIDEO),
                (String) parameters.get(ParameterKeys.CONNECTION_PREFERRED_VIDEO_CODEC));

        startTurn();
    } else {
        // let's delay a millisecond to avoid calling code in the App getting intertwined with App listener code
        new Handler(RCClient.getContext().getMainLooper()).postDelayed(new Runnable() {
            @Override
            public void run() {
                listener.onError(RCConnection.this,
                        RCClient.ErrorCodes.ERROR_CONNECTION_ACCEPT_WRONG_STATE.ordinal(),
                        RCClient.errorText(RCClient.ErrorCodes.ERROR_CONNECTION_ACCEPT_WRONG_STATE));
            }
        }, 1);
    }
}

From source file:org.fusesource.restygwt.client.codec.EncoderDecoderTestGwt.java

public void testTypeMapWithLargeDigitStringDecode() {
    Map<String, String> map = new HashMap<String, String>();
    map.put("1234567890123456789", "321");
    AbstractJsonEncoderDecoder<String> keyEncoder = AbstractJsonEncoderDecoder.STRING;
    AbstractJsonEncoderDecoder<String> valueEncoder = AbstractJsonEncoderDecoder.STRING;
    assertEquals(map.toString(),
            AbstractJsonEncoderDecoder//from w w w  .  ja va  2s . c  om
                    .toMap(AbstractJsonEncoderDecoder.toJSON(map, keyEncoder, valueEncoder, Json.Style.DEFAULT),
                            keyEncoder, valueEncoder, Json.Style.DEFAULT)
                    .toString());
    assertEquals(map.toString(),
            AbstractJsonEncoderDecoder
                    .toMap(AbstractJsonEncoderDecoder.toJSON(map, keyEncoder, valueEncoder,
                            Json.Style.JETTISON_NATURAL), keyEncoder, valueEncoder, Json.Style.JETTISON_NATURAL)
                    .toString());
}

From source file:io.logspace.hq.solr.SolrEventService.java

@Override
public NativeQueryResult executeNativeQuery(Map<String, String[]> parameters) {
    SolrParams params = this.createSolrParams(parameters);

    try {//from w  w  w  . jav a 2  s  .  c  om
        QueryRequest request = new QueryRequest(params, METHOD.POST);
        request.setResponseParser(new InputStreamResponseParser("json"));
        QueryResponse response = request.process(this.solrClient);

        InputStream inputStream = (InputStream) response.getResponse().get("stream");
        if (inputStream != null) {
            return new SolrNativeQueryResult(inputStream);
        }

        return new SolrNativeQueryResult(this.serializeResponse(params, response));
    } catch (SolrException | SolrServerException | IOException e) {
        throw new DataRetrievalException(
                "Could not execute direct query with parameters " + parameters.toString() + ".", e);
    }
}

From source file:org.craftercms.cstudio.alfresco.objectstate.ObjectStateDAOServiceImpl.java

@Override
public List<ObjectStateTO> getObjectStateByStates(String site, List<ObjectStateService.State> states) {
    if (states != null && !states.isEmpty()) {
        Map<String, Object> params = new HashMap<String, Object>();
        List<String> statesValues = new ArrayList<String>();
        for (ObjectStateService.State state : states) {
            statesValues.add(state.name());
        }//from  w ww.j ava  2  s  .c  om
        params.put("states", statesValues);
        params.put("site", site);
        List<ObjectStateTO> result = new ArrayList<ObjectStateTO>();
        try {
            List<ObjectStateDAO> tmp = _sqlMapClient.queryForList(STATEMENT_GET_OBJECT_STATE_BY_STATUS, params);
            for (ObjectStateDAO objectStateDAO : tmp) {
                result.add(toObjectStateTo(objectStateDAO));
            }
        } catch (SQLException e) {
            if (LOGGER.isErrorEnabled()) {
                // TODO CodeRev: How does the caller know this operation failed, what they get is an empty list and
                // TODO CodeRev: the false notion that an empty list is correct
                LOGGER.error("Error getting ObjectState Status for " + params.toString(), e);
            }
        }
        return result;
    } else {
        return new FastList<ObjectStateTO>(0);
    }
}

From source file:org.mitre.opensextant.extraction.PlacenameMatcher.java

/**
 * Debugging/*  w  ww . jav  a2  s  . c o m*/
 */
private void summarizeExtraction(List<PlaceCandidate> candidates, String docid) {
    if (candidates == null) {
        log.error("Something is very wrong.");
        return;
    }
    log.debug("DOC=" + docid + " PLACE CANDIDATES SIZE = " + candidates.size());
    Map<String, Integer> countries = new HashMap<>();

    // This loops through findings and reports out just Country names for now.
    for (PlaceCandidate candidate : candidates) {
        boolean _break = false;
        String namekey = TextUtils.normalize_text_entity(candidate.getText()); // .toLowerCase();
        namekey = namekey.toLowerCase();

        for (Place p : candidate.getPlaces()) {
            if (p.isAbbreviation()) {
                log.debug("Ignore all abbreviations for now " + candidate.getText());
                _break = true;
                break;
            }
            if (p.isCountry()) {
                Integer count = countries.get(namekey);
                if (count == null) {
                    count = new Integer(1);
                    countries.put(namekey, count);
                }
                ++count;
                countries.put(namekey, count);
                _break = true;
                break;
            }
        }
        if (_break) {
            continue;
        }
    }
    log.debug("Countries found:" + countries.toString());
}

From source file:org.fusesource.restygwt.client.codec.EncoderDecoderTestGwt.java

public void testTypeMapWithBigDecimalDecode() {
    Map<BigDecimal, String> map = new HashMap<BigDecimal, String>();
    map.put(BigDecimal.valueOf(123), "321");
    AbstractJsonEncoderDecoder<BigDecimal> keyEncoder = AbstractJsonEncoderDecoder.BIG_DECIMAL;
    AbstractJsonEncoderDecoder<String> valueEncoder = AbstractJsonEncoderDecoder.STRING;
    assertEquals(map.toString(),
            AbstractJsonEncoderDecoder/*w w  w.j a v a2s.c o m*/
                    .toMap(AbstractJsonEncoderDecoder.toJSON(map, keyEncoder, valueEncoder, Json.Style.DEFAULT),
                            keyEncoder, valueEncoder, Json.Style.DEFAULT)
                    .toString());
    assertEquals(map.toString(),
            AbstractJsonEncoderDecoder
                    .toMap(AbstractJsonEncoderDecoder.toJSON(map, keyEncoder, valueEncoder,
                            Json.Style.JETTISON_NATURAL), keyEncoder, valueEncoder, Json.Style.JETTISON_NATURAL)
                    .toString());
}

From source file:data.AbstractRepository.java

@Override
public List<T> findBy(Map<String, Object> params) throws DataException {
    StringBuilder query = new StringBuilder();
    query.append("SELECT * FROM ").append(DB_TABLE).append(" WHERE ");

    Iterator it = params.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry) it.next();
        query.append(getColumnAttr((String) pair.getKey())).append("=")
                .append(attributeToQuery(pair.getValue()));

        String nextLine = it.hasNext() ? " AND " : ";";
        query.append(nextLine);//from w w  w  .j av  a  2s.  c o  m
    }

    List<T> objects = new ArrayList<T>();

    try {
        Connection connection = DriverManager.getConnection(url, username, password);
        PreparedStatement statement = connection.prepareStatement(query.toString());
        ResultSet result = statement.executeQuery();

        try {
            while (result.next()) {
                objects.add(setObject(result));
            }
        } finally {
            result.close();
            statement.close();
            connection.close();
        }

        return objects;
    } catch (SQLException e) {
        throw new DataException("Error finding object with params: " + params.toString());
    }
}