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.comcast.oscar.dictionary.DictionaryTLV.java

/**
 * /*from  w  w w.jav a2s .co  m*/
 * @param jaDictionary
        
 * @return Map<String,Integer>
 */
public static Map<String, Integer> getTopLevelTypeNameToTypeViaDictionary(JSONArray jaDictionary) {

    boolean localDebug = Boolean.FALSE;

    Map<String, Integer> msiTypeNameToType = new HashMap<String, Integer>();

    if (debug | localDebug)
        System.out.println(
                "DictionaryTLV.getAllTopLevelTypeNameToTypeViaDictionary(): JA-DICT: -> " + jaDictionary);

    for (int iJsonArrayIndex = 0; iJsonArrayIndex < jaDictionary.length(); iJsonArrayIndex++) {

        //Get Object
        JSONObject joTlvDictionary = new JSONObject();
        try {
            joTlvDictionary = jaDictionary.getJSONObject(iJsonArrayIndex);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        try {
            msiTypeNameToType.put(joTlvDictionary.getString(Dictionary.TLV_NAME),
                    joTlvDictionary.getInt(Dictionary.TYPE));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    if (debug | localDebug)
        System.out.println("DictionaryTLV.getAllTopLevelTypeNameToTypeViaDictionary(): Map ->  "
                + msiTypeNameToType.toString());

    return msiTypeNameToType;
}

From source file:nl.surfnet.coin.janus.JanusRestClient.java

@Override
public List<EntityMetadata> getSpList() {

    Map<String, String> parameters = new HashMap<String, String>();

    final Collection metadataAsStrings = CollectionUtils.collect(Arrays.asList(Metadata.values()),
            new Transformer() {
                @Override//from www  .  j a  v a 2  s. c  o  m
                public Object transform(Object input) {
                    return ((Metadata) input).val();
                }
            });

    parameters.put("keys", StringUtils.join(metadataAsStrings, ','));

    URI signedUri;
    try {
        signedUri = sign("getSpList", parameters);

        if (LOG.isTraceEnabled()) {
            LOG.trace("Signed Janus-request is: {}", signedUri);
        }

        @SuppressWarnings("unchecked")
        final Map<String, Map<String, Object>> restResponse = restTemplate.getForObject(signedUri, Map.class);

        if (LOG.isTraceEnabled()) {
            LOG.trace("Janus-request returned: {}", restResponse.toString());
        }

        List<EntityMetadata> entities = new ArrayList<EntityMetadata>();
        for (Map.Entry<String, Map<String, Object>> entry : restResponse.entrySet()) {
            String entityId = entry.getKey();
            final EntityMetadata e = EntityMetadata.fromMetadataMap(entry.getValue());
            e.setAppEntityId(entityId);
            entities.add(e);
        }

        return entities;

    } catch (IOException e) {
        LOG.error("While doing Janus-request", e);
    }
    return null;
}

From source file:nl.surfnet.coin.janus.JanusRestClient.java

@Override
public List<EntityMetadata> getIdpList() {

    Map<String, String> parameters = new HashMap<String, String>();

    final Collection metadataAsStrings = CollectionUtils.collect(Arrays.asList(Metadata.values()),
            new Transformer() {
                @Override//from w  w w .  j a va 2s  .  c o  m
                public Object transform(Object input) {
                    return ((Metadata) input).val();
                }
            });

    parameters.put("keys", StringUtils.join(metadataAsStrings, ','));

    URI signedUri;
    try {
        signedUri = sign("getIdpList", parameters);

        if (LOG.isTraceEnabled()) {
            LOG.trace("Signed Janus-request is: {}", signedUri);
        }

        @SuppressWarnings("unchecked")
        final Map<String, Map<String, Object>> restResponse = restTemplate.getForObject(signedUri, Map.class);

        if (LOG.isTraceEnabled()) {
            LOG.trace("Janus-request returned: {}", restResponse.toString());
        }

        List<EntityMetadata> entities = new ArrayList<EntityMetadata>();
        for (Map.Entry<String, Map<String, Object>> entry : restResponse.entrySet()) {
            String entityId = entry.getKey();
            final EntityMetadata e = EntityMetadata.fromMetadataMap(entry.getValue());
            e.setAppEntityId(entityId);
            entities.add(e);
        }

        return entities;

    } catch (IOException e) {
        LOG.error("While doing Janus-request", e);
    }
    return null;
}

From source file:edu.ucuenca.authorsdisambiguation.nwd.NWD.java

public synchronized String Http2(String s, Map<String, String> mp, String prefix)
        throws SQLException, IOException {
    String md = s + mp.toString();
    String get = Cache.getInstance().get(prefix + md);
    String resp = "";
    if (get != null) {
        resp = get;//from  w w  w .j a  v a2 s . c o m
    } else {
        HttpClient client = new HttpClient();
        PostMethod method = new PostMethod(s);
        method.getParams().setContentCharset("utf-8");

        //Add any parameter if u want to send it with Post req.
        for (Entry<String, String> mcc : mp.entrySet()) {
            method.addParameter(mcc.getKey(), mcc.getValue());
        }

        int statusCode = client.executeMethod(method);

        if (statusCode != -1) {
            InputStream in = method.getResponseBodyAsStream();
            final Scanner reader = new Scanner(in, "UTF-8");
            while (reader.hasNextLine()) {
                final String line = reader.nextLine();
                resp += line + "\n";
            }
            reader.close();
            Cache.getInstance().put(prefix + md, resp);

        }

    }

    return resp;
}

From source file:org.apache.ranger.audit.provider.kafka.KafkaAuditProvider.java

@Override
public void init(Properties props) {
    LOG.info("init() called");
    super.init(props);

    topic = MiscUtil.getStringProperty(props, AUDIT_KAFKA_TOPIC_NAME);
    if (topic == null || topic.isEmpty()) {
        topic = "ranger_audits";
    }/*w  w w .j a  v a  2  s  . co m*/

    try {
        if (!initDone) {
            String brokerList = MiscUtil.getStringProperty(props, AUDIT_KAFKA_BROKER_LIST);
            if (brokerList == null || brokerList.isEmpty()) {
                brokerList = "localhost:9092";
            }

            final Map<String, Object> kakfaProps = new HashMap<String, Object>();
            kakfaProps.put("metadata.broker.list", brokerList);
            kakfaProps.put("serializer.class", "kafka.serializer.StringEncoder");
            // kakfaProps.put("partitioner.class",
            // "example.producer.SimplePartitioner");
            kakfaProps.put("request.required.acks", "1");

            LOG.info("Connecting to Kafka producer using properties:" + kakfaProps.toString());

            producer = MiscUtil.executePrivilegedAction(new PrivilegedAction<Producer<String, String>>() {
                @Override
                public Producer<String, String> run() {
                    Producer<String, String> producer = new KafkaProducer<String, String>(kakfaProps);
                    return producer;
                };
            });

            initDone = true;
        }
    } catch (Throwable t) {
        LOG.fatal("Error initializing kafka:", t);
    }
}

From source file:com.emc.storageos.api.service.impl.resource.TaggedResource.java

/**
 * Get object specific search results by parameters other than name and tag.
 * Default is not implemented error//from  w  ww .  j  a v a2s.  c  om
 * 
 * @return SearchResults
 */
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
    throw APIException.badRequests.unknownParameter("search", parameters.toString());
}

From source file:com.linkedin.pinot.broker.routing.HelixExternalViewBasedRouting.java

@Override
public String dumpSnapshot(String tableName) throws Exception {
    JSONObject ret = new JSONObject();
    JSONArray routingTableSnapshot = new JSONArray();

    for (String currentTable : _routingTableBuilderMap.keySet()) {
        if (tableName == null || currentTable.startsWith(tableName)) {
            JSONObject tableEntry = new JSONObject();
            tableEntry.put("tableName", currentTable);

            JSONArray entries = new JSONArray();
            RoutingTableBuilder routingTableBuilder = _routingTableBuilderMap.get(currentTable);
            List<Map<String, List<String>>> routingTables = routingTableBuilder.getRoutingTables();
            for (Map<String, List<String>> routingTable : routingTables) {
                entries.put(new JSONObject(routingTable.toString()));
            }// www . j a va  2 s  .c o m
            tableEntry.put("routingTableEntries", entries);
            routingTableSnapshot.put(tableEntry);
        }
    }
    ret.put("routingTableSnapshot", routingTableSnapshot);
    ret.put("host", NetUtil.getHostnameOrAddress());

    return ret.toString(2);
}

From source file:esg.common.shell.ESGFEnv.java

License:asdf

@SuppressWarnings("unchecked")
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("Env... \n");
    Map<String, Object> contextSubMap = null;
    for (String contextKey : context.keySet()) {
        contextSubMap = null;//from   www.  j a va 2 s  .c  om
        if (null != (contextSubMap = (Map<String, Object>) context.get(contextKey))) {
            if (contextKey.equals(SYS))
                sb.append("SYS: ");
            if (contextKey.equals(USER))
                sb.append("USER: ");
            if (contextKey.equals(DEFAULT))
                sb.append("DEFAULT: ");
            sb.append(contextSubMap.toString() + "\n");
        }
    }
    return sb.toString();
}

From source file:org.apache.bigtop.itest.hive.TestHCatalog.java

@Test
public void hcatInputFormatOutputFormat()
        throws TException, IOException, ClassNotFoundException, InterruptedException, URISyntaxException {
    // Create a table to write to
    final String inputTable = "bigtop_hcat_input_table_" + rand.nextInt(Integer.MAX_VALUE);
    SerDeInfo serde = new SerDeInfo("default_serde", conf.getVar(HiveConf.ConfVars.HIVEDEFAULTSERDE),
            new HashMap<String, String>());
    FieldSchema schema = new FieldSchema("line", "string", "");
    inputSchema = new HCatSchema(Collections.singletonList(
            new HCatFieldSchema(schema.getName(), HCatFieldSchema.Type.STRING, schema.getComment())));
    StorageDescriptor sd = new StorageDescriptor(Collections.singletonList(schema), null,
            "org.apache.hadoop.mapred.TextInputFormat",
            "org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat", false, 0, serde, null, null,
            new HashMap<String, String>());
    Table table = new Table(inputTable, "default", "me", 0, 0, 0, sd, null, new HashMap<String, String>(), null,
            null, TableType.MANAGED_TABLE.toString());
    client.createTable(table);/*from  w  w w .  ja  va  2s  .c o  m*/

    final String outputTable = "bigtop_hcat_output_table_" + rand.nextInt(Integer.MAX_VALUE);
    sd = new StorageDescriptor(
            Arrays.asList(new FieldSchema("word", "string", ""), new FieldSchema("count", "int", "")), null,
            "org.apache.hadoop.mapred.TextInputFormat",
            "org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat", false, 0, serde, null, null,
            new HashMap<String, String>());
    table = new Table(outputTable, "default", "me", 0, 0, 0, sd, null, new HashMap<String, String>(), null,
            null, TableType.MANAGED_TABLE.toString());
    client.createTable(table);
    outputSchema = new HCatSchema(Arrays.asList(new HCatFieldSchema("word", HCatFieldSchema.Type.STRING, ""),
            new HCatFieldSchema("count", HCatFieldSchema.Type.INT, "")));

    // LATER Could I use HCatWriter here and the reader to read it?
    // Write some stuff into a file in the location of the table
    table = client.getTable("default", inputTable);
    String inputFile = table.getSd().getLocation() + "/input";
    Path inputPath = new Path(inputFile);
    FileSystem fs = FileSystem.get(conf);
    FSDataOutputStream out = fs.create(inputPath);
    out.writeChars("Mary had a little lamb\n");
    out.writeChars("its fleece was white as snow\n");
    out.writeChars("and everywhere that Mary went\n");
    out.writeChars("the lamb was sure to go\n");
    out.close();

    Map<String, String> env = new HashMap<>();
    env.put("HADOOP_CLASSPATH", System.getProperty(HCATCORE, ""));
    Map<String, String> results = HiveHelper.execCommand(new CommandLine("hive").addArgument("--service")
            .addArgument("jar").addArgument(System.getProperty(JOBJAR)).addArgument(HCatalogMR.class.getName())
            .addArgument("-it").addArgument(inputTable).addArgument("-ot").addArgument(outputTable)
            .addArgument("-is").addArgument(inputSchema.getSchemaAsTypeString()).addArgument("-os")
            .addArgument(outputSchema.getSchemaAsTypeString()), env);
    LOG.info(results.toString());
    Assert.assertEquals("HCat job failed", 0, Integer.parseInt(results.get("exitValue")));

    client.dropTable("default", inputTable);
    client.dropTable("default", outputTable);
}

From source file:com.google.transporttracker.TrackerService.java

private void logStatusToStorage(Map<String, Object> transportStatus) {
    try {/*  w ww. j  a  va2s.c  o  m*/
        File path = new File(Environment.getExternalStoragePublicDirectory(""), "transport-tracker-log.txt");
        if (!path.exists()) {
            path.createNewFile();
        }
        FileWriter logFile = new FileWriter(path.getAbsolutePath(), true);
        logFile.append(transportStatus.toString() + "\n");
        logFile.close();
    } catch (Exception e) {
        Log.e(TAG, "Log file error", e);
    }
}