Example usage for java.util Collection toString

List of usage examples for java.util Collection toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.gss_project.gss.web.client.TestClient.java

public static void main(String[] args) {
    String user = "ebstest@grnet-hq.admin.grnet.gr";
    String token = "PcxaZ/4oIqCqIvCYgsUcKr1hAFcsW40G3kcWJSRPJV5GjzoNuo8RsA==";
    String host = "pithos.grnet.gr";
    String restPath = "/pithos/rest";
    String path = "/" + user + "/files/";
    String now = DateUtil.formatDate(new Date());
    String signature = sign("GET", now, path, token);
    HttpClient client = new HttpClient();
    HostConfiguration hostconfig = new HostConfiguration();
    hostconfig.setHost(host);/*from w  w  w .j a  va  2  s  .c o  m*/
    HttpMethod method = new GetMethod(restPath + path);
    Collection<Header> headers = new ArrayList<Header>();
    Header auth = new Header("Authorization", user + " " + signature);
    headers.add(auth);
    Header date = new Header("X-GSS-Date", now);
    headers.add(date);
    System.out.println(headers.toString());
    hostconfig.getParams().setParameter("http.default-headers", headers);
    try {
        // Execute the method.
        int statusCode = client.executeMethod(hostconfig, method);

        if (statusCode != HttpStatus.SC_OK)
            System.err.println("Method failed: " + method.getStatusLine());

        // Read the response body.
        byte[] responseBody = method.getResponseBody();

        // Deal with the response.
        // Use caution: ensure correct character encoding and is not binary data
        System.out.println(new String(responseBody));
    } catch (HttpException e) {
        System.err.println("Fatal protocol violation: " + e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        System.err.println("Fatal transport error: " + e.getMessage());
        e.printStackTrace();
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
}

From source file:mase.jbot.JBotViewer.java

/**
 * @param args the command line arguments
 *//*from   w ww .java2  s.  co  m*/
public static void main(String args[]) throws Exception {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(JBotViewer.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(JBotViewer.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(JBotViewer.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(JBotViewer.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    }
    //</editor-fold>
    //</editor-fold>

    File jbotConfig;
    final File solution = new File(args[0]);
    if (args.length == 2) {
        jbotConfig = new File(args[1]);
    } else {
        // Search the individual's folder for the jbot config file
        File dir = solution.getParentFile();
        Collection<File> listFiles = FileUtils.listFiles(dir, new String[] { "conf" }, false);
        if (listFiles.size() != 1) {
            System.out.println("Zero or more than one config files found!:\n" + listFiles.toString());
        }
        jbotConfig = listFiles.iterator().next();
    }
    final File jbot = jbotConfig;

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                new JBotViewer(jbot, solution).setVisible(true);
            } catch (Exception ex) {
                Logger.getLogger(JBotViewer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
}

From source file:Main.java

public static <T> String collectionToString(Collection<T> collection) {
    if (collection == null)
        return null;
    return collection.toString();
}

From source file:org.mifos.platform.util.CollectionUtils.java

public static <T> String toString(Collection<T> collection) {
    String result = EMPTY;//from ww w. j ava  2s.  c o m
    if (isNotEmpty(collection)) {
        String collStr = collection.toString();
        result = collStr.substring(1, collStr.length() - 1);
    }
    return result;
}

From source file:Main.java

public static Object findOne(Collection coll) {
    if (coll.isEmpty()) {
        return null;
    } else if (coll.size() > 1) {
        throw new RuntimeException("Expected only one member in collection, found many: " + coll.toString());
    } else {/*from www  . j ava 2 s  . c o  m*/
        return coll.iterator().next();
    }
}

From source file:sturesy.util.web.WebCommands.java

public static String getLectureListInfo(Collection<String> lectures) {
    String string = lectures.toString();
    String stringWithoutFirstCharacter = string.substring(1, string.length() - 1);
    return "command=lectureinfo&lectures=" + removeWhitespace(stringWithoutFirstCharacter);
}

From source file:com.cloudera.oryx.common.OryxTest.java

private static <T> String abbreviatedToString(Collection<T> c) {
    return c.size() <= 16 ? c.toString() : c.stream().limit(16).collect(Collectors.toList()) + "...";
}

From source file:org.springframework.cloud.vault.VaultErrorMessage.java

/**
 * Obtain the error message from a JSON response.
 * //from w ww.  jav a2s . co  m
 * @param json
 * @return
 */
static String getError(String json) {

    if (json.contains("\"errors\":")) {

        try {
            Map<String, Object> map = OBJECT_MAPPER.readValue(json.getBytes(), Map.class);
            if (map.containsKey("errors")) {

                Collection<String> errors = (Collection<String>) map.get("errors");
                if (errors.size() == 1) {
                    return errors.iterator().next();
                }
                return errors.toString();
            }

        } catch (IOException o_O) {
            // ignore
        }
    }
    return json;
}

From source file:org.apache.tinkerpop.gremlin.structure.util.StringFactory.java

public static String removeEndBrackets(final Collection collection) {
    final String string = collection.toString();
    return string.substring(1, string.length() - 1);
}

From source file:eu.edisonproject.classification.main.BatchMain.java

private static void profile(String csvFile1, String csvFile2, String output) throws IOException, Exception {
    Map<String, Collection<Double>> cv = CSVFileReader.csvCompetanceToMap(csvFile1, ",", Boolean.TRUE);
    Map<String, Collection<Double>> jobVec = CSVFileReader.csvCompetanceToMap(csvFile2, ",", Boolean.TRUE);
    CosineSimilarityMatrix cosineFunction = new CosineSimilarityMatrix();

    String k1 = cv.keySet().iterator().next();
    Map<String, Double> winners = new HashMap<>();
    for (String k : jobVec.keySet()) {
        Collection<Double> j = jobVec.get(k);
        double d = cosineFunction.computeDistance(cv.get(k1), j);
        //      if (!Double.isNaN(d)) {
        winners.put(k, d);/*w w  w  .ja  v  a  2 s.  c o  m*/
        //      }
    }
    StringBuilder lines = new StringBuilder();
    ReaderFile rf = new ReaderFile(csvFile1);
    String fileHeader = rf.readFileWithN().split("\n")[0];
    String[] header = fileHeader.split(",");
    lines.append("rank").append(",");
    lines.append(fileHeader);
    lines.append("\n");

    int rank = 0;

    JSONObject cvJson = new JSONObject();
    Collection<Double> vector = cv.get(k1);
    String val = vector.toString().replaceAll("\\[", "").replaceAll("\\]", "");
    lines.append(rank).append(",").append(k1).append(",").append(val).append("\n");
    Iterator<Double> iter = vector.iterator();
    int i = 0;
    cvJson.put(header[i++], k1);
    while (iter.hasNext()) {
        String key = header[i++];
        Double value = iter.next();
        cvJson.put(key, value);
    }
    cvJson.put("rank", rank);
    JSONArray profileJson = new JSONArray();
    profileJson.add(cvJson);
    ValueComparator bvc = new ValueComparator(winners);
    Map<String, Double> sorted_map = new TreeMap(bvc);
    sorted_map.putAll(winners);

    for (String k : sorted_map.keySet()) {
        JSONObject jobJason = new JSONObject();
        rank++;
        vector = jobVec.get(k);
        val = vector.toString().replaceAll("\\[", "").replaceAll("\\]", "");
        lines.append(rank).append(",").append(k).append(",").append(val).append("\n");

        i = 0;
        jobJason.put(header[i++], k);
        iter = vector.iterator();
        while (iter.hasNext()) {
            String key = header[i++];
            Double value = iter.next();
            jobJason.put(key, value);
        }
        jobJason.put("rank", rank);
        profileJson.add(jobJason);
    }
    WriterFile wf = new WriterFile(output + File.separator + "result.csv");
    wf.writeFile(lines.toString());

    wf = new WriterFile(output + File.separator + "result.json");
    wf.writeFile(profileJson.toJSONString());
}