如何在单个表中对具有相同ID键的数组进行分类

时间:2019-07-08 09:03:14

标签: java

通过以下代码恢复的表的列表:

package Stat;
public class Stats {

public static void main(String[] args) throws IOException, JSONException {

    private static final Pattern PATTERN = Pattern.compile("id=(\\w*)}");

    try {
        @SuppressWarnings("resource")
        MongoClient client = new MongoClient("localhost", 27017);
        MongoDatabase database = client.getDatabase("stats");
        MongoCollection<Document> collection = database.getCollection("stats");
        // System.out.println("DB Connexion");
        List<Document> stats = (List<Document>) collection.find().into(new ArrayList<Document>());
        // System.out.println("Collecion Récupéré"+ stats);
        for (Document result : stats) {
            @SuppressWarnings("unchecked")
            List<Document> results = (List<Document>) result.get("results");
            Document objDoc = null;
            for (Document doc : results) {
                if (doc.containsKey("googContentType")) {
                    objDoc = doc;
                    String objStr= objDoc.toString();
                    //System.out.println("" + objStr);
                ArrayList<String> myList = new ArrayList<String>(Arrays.asList(objStr.split(",")));                 
                    System.out.println(myList);                                                                                                                     

                    String getId(String element) {
                    Matcher matcher = PATTERN.matcher(element);
                    if (matcher.find()) {  
                        return;
                    }
                    return;
                    Map<String, List<String>> table = myList.stream().collect(Collectors.groupingBy(Stats::getId));
                    }               
                }       
                }               
            }}catch (UnknownException e) {
        e.printStackTrace();
    }   

**列表已恢复:     [Document {{googContentType = realtime,id = ssrc_1920071231_recv}}]

[Document{{googContentType=realtime, id=ssrc_3180255579_send}}]

[Document{{googContentType=realtime, id=ssrc_1920071231_recv}}]

[Document{{googContentType=realtime, id=ssrc_3180255579_send}}]

我正在尝试对同一表上具有相同键ID的表进行如下分类:     表1 =

[

[Document{{googContentType=realtime, id=ssrc_1920071231_recv}}]

[Document{{googContentType=realtime, id=ssrc_1920071231_recv}}]

]

table 2= 

[

[Document{{googContentType=realtime, id=ssrc_3180255579_send}}]

[Document{{googContentType=realtime, id=ssrc_3180255579_send}}]

]**

0 个答案:

没有答案