768
|
1 |
/*
|
|
2 |
* Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
package com.sun.hotspot.igv.coordinator;
|
|
26 |
|
|
27 |
import com.sun.hotspot.igv.data.Group;
|
|
28 |
import com.sun.hotspot.igv.data.Pair;
|
|
29 |
import com.sun.hotspot.igv.data.services.GroupOrganizer;
|
|
30 |
import java.util.ArrayList;
|
|
31 |
import java.util.HashMap;
|
|
32 |
import java.util.List;
|
|
33 |
import java.util.Map;
|
|
34 |
import java.util.SortedSet;
|
|
35 |
import java.util.TreeSet;
|
|
36 |
|
|
37 |
/**
|
|
38 |
*
|
|
39 |
* @author Thomas Wuerthinger
|
|
40 |
*/
|
|
41 |
public class GraphCountGroupOrganizer implements GroupOrganizer {
|
|
42 |
|
|
43 |
public String getName() {
|
|
44 |
return "Graph count structure";
|
|
45 |
}
|
|
46 |
|
|
47 |
public List<Pair<String, List<Group>>> organize(List<String> subFolders, List<Group> groups) {
|
|
48 |
|
|
49 |
List<Pair<String, List<Group>>> result = new ArrayList<Pair<String, List<Group>>>();
|
|
50 |
|
|
51 |
if (subFolders.size() == 0) {
|
|
52 |
Map<Integer, List<Group>> map = new HashMap<Integer, List<Group>>();
|
|
53 |
for (Group g : groups) {
|
|
54 |
Integer cur = g.getGraphs().size();
|
|
55 |
if (!map.containsKey(cur)) {
|
|
56 |
map.put(cur, new ArrayList<Group>());
|
|
57 |
}
|
|
58 |
map.get(cur).add(g);
|
|
59 |
}
|
|
60 |
|
|
61 |
SortedSet<Integer> keys = new TreeSet<Integer>(map.keySet());
|
|
62 |
for (Integer i : keys) {
|
|
63 |
result.add(new Pair<String, List<Group>>("Graph count " + i, map.get(i)));
|
|
64 |
}
|
|
65 |
|
|
66 |
} else if (subFolders.size() == 1) {
|
|
67 |
for (Group g : groups) {
|
|
68 |
List<Group> children = new ArrayList<Group>();
|
|
69 |
children.add(g);
|
|
70 |
Pair<String, List<Group>> p = new Pair<String, List<Group>>();
|
|
71 |
p.setLeft(g.getName());
|
|
72 |
p.setRight(children);
|
|
73 |
result.add(p);
|
|
74 |
}
|
|
75 |
} else if (subFolders.size() == 2) {
|
|
76 |
result.add(new Pair<String, List<Group>>("", groups));
|
|
77 |
}
|
|
78 |
|
|
79 |
return result;
|
|
80 |
}
|
|
81 |
}
|