Skip to content
Snippets Groups Projects
Commit 5e35c3c0 authored by Philipp Spohr's avatar Philipp Spohr
Browse files

changed many arrayLists to Hashmaps

parent b784a509
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
package de.hhu.ba.yoshikoWrapper.graphModel; package de.hhu.ba.yoshikoWrapper.graphModel;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import org.cytoscape.model.CyNetwork; import org.cytoscape.model.CyNetwork;
...@@ -36,21 +38,21 @@ public class YoshikoResult{ ...@@ -36,21 +38,21 @@ public class YoshikoResult{
private CyNetwork originalGraph; private CyNetwork originalGraph;
private ArrayList<YoshikoSolution> solutions; private HashMap<Long,YoshikoSolution> solutions;
private SolutionFlags flags; private SolutionFlags flags;
private int id; private int id;
public YoshikoResult(CyNetwork net, SolutionFlags flags) { public YoshikoResult(CyNetwork net, SolutionFlags flags) {
solutions = new ArrayList<YoshikoSolution>(); solutions = new HashMap<Long,YoshikoSolution>();
this.originalGraph = net; this.originalGraph = net;
this.flags = flags; this.flags = flags;
ResultList.add(this); ResultList.add(this);
} }
public void delete() { public void delete() {
for (YoshikoSolution s: solutions) { for (YoshikoSolution s: solutions.values()) {
s.delete(); s.delete();
} }
ResultList.remove(this.id); ResultList.remove(this.id);
...@@ -59,7 +61,7 @@ public class YoshikoResult{ ...@@ -59,7 +61,7 @@ public class YoshikoResult{
//___________SETTER GETTER_____________// //___________SETTER GETTER_____________//
/** /**
* @return the flags asspciated with this result * @return the flags associated with this result
*/ */
public SolutionFlags getFlags() { public SolutionFlags getFlags() {
return flags; return flags;
...@@ -67,15 +69,13 @@ public class YoshikoResult{ ...@@ -67,15 +69,13 @@ public class YoshikoResult{
public void addSolution(YoshikoSolution solution) { public void addSolution(YoshikoSolution solution) {
solutions.add(solution); solutions.put(solution.getId(),solution);
} }
public Collection<YoshikoSolution> getSolutions() {
public ArrayList<YoshikoSolution> getSolutions() { return solutions.values();
return solutions;
} }
public CyNetwork getOriginalGraph() { public CyNetwork getOriginalGraph() {
return originalGraph; return originalGraph;
} }
......
...@@ -21,11 +21,11 @@ ...@@ -21,11 +21,11 @@
******************************************************************************/ ******************************************************************************/
package de.hhu.ba.yoshikoWrapper.graphModel; package de.hhu.ba.yoshikoWrapper.graphModel;
import java.util.ArrayList; import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import javax.swing.JOptionPane;
import org.cytoscape.model.CyNetwork; import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode; import org.cytoscape.model.CyNode;
...@@ -43,7 +43,7 @@ public class YoshikoSolution { ...@@ -43,7 +43,7 @@ public class YoshikoSolution {
private HashMap<YoshikoCluster, CyNode> metaGraphMap; private HashMap<YoshikoCluster, CyNode> metaGraphMap;
public ArrayList<YoshikoCluster> clusters; private HashMap<Long,YoshikoCluster> clusters;
private final long id; private final long id;
...@@ -51,15 +51,39 @@ public class YoshikoSolution { ...@@ -51,15 +51,39 @@ public class YoshikoSolution {
public YoshikoSolution(YoshikoResult yoshikoResult, long id) { public YoshikoSolution(YoshikoResult yoshikoResult, long id) {
clusters = new ArrayList<YoshikoCluster>(); clusters = new HashMap<Long,YoshikoCluster>();
this.result = yoshikoResult; this.result = yoshikoResult;
this.id = id; this.id = id;
} }
public void delete() {
for (YoshikoCluster c: clusters.values()) {
c.delete();
}
if (this.metaGraph != null) {
CyCore.networkManager.destroyNetwork(metaGraph);
}
}
public void highlightInMetaGraph(YoshikoCluster yoshikoCluster) {
try {
List<CyRow> allRows = metaGraph.getDefaultNodeTable().getAllRows();
for (CyRow r: allRows) {
r.set("selected", false);
}
metaGraph.getRow(metaGraphMap.get(yoshikoCluster)).set("selected", true);
}
catch (Exception e) {
logger.warn("The graph doesn't exist anymore, can't highlight nodes!");
}
}
//_____________GETTER / SETTER ________________// //_____________GETTER / SETTER ________________//
public ArrayList<YoshikoCluster> getClusters() { public Collection<YoshikoCluster> getClusters() {
return clusters; return clusters.values();
} }
/** /**
...@@ -73,15 +97,6 @@ public class YoshikoSolution { ...@@ -73,15 +97,6 @@ public class YoshikoSolution {
return result.getOriginalGraph(); return result.getOriginalGraph();
} }
public void delete() {
for (YoshikoCluster c: clusters) {
c.delete();
}
if (this.metaGraph != null) {
CyCore.networkManager.destroyNetwork(metaGraph);
}
}
public void setMetaGraph(CyNetwork metaGraph, HashMap<YoshikoCluster, CyNode> map) { public void setMetaGraph(CyNetwork metaGraph, HashMap<YoshikoCluster, CyNode> map) {
this.metaGraph = metaGraph; this.metaGraph = metaGraph;
this.metaGraphMap = map; this.metaGraphMap = map;
...@@ -91,19 +106,9 @@ public class YoshikoSolution { ...@@ -91,19 +106,9 @@ public class YoshikoSolution {
return metaGraph; return metaGraph;
} }
public void highlightInMetaGraph(YoshikoCluster yoshikoCluster) { public void addCluster(YoshikoCluster cluster) {
try { clusters.put(cluster.getID(), cluster);
List<CyRow> allRows = metaGraph.getDefaultNodeTable().getAllRows();
for (CyRow r: allRows) {
r.set("selected", false);
}
metaGraph.getRow(metaGraphMap.get(yoshikoCluster)).set("selected", true);
}
catch (Exception e) {
logger.warn("The graph doesn't exist anymore, can't highlight nodes!");
} }
}
} }
...@@ -30,6 +30,7 @@ import java.awt.event.ActionListener; ...@@ -30,6 +30,7 @@ import java.awt.event.ActionListener;
import java.awt.event.ItemEvent; import java.awt.event.ItemEvent;
import java.awt.event.ItemListener; import java.awt.event.ItemListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import javax.swing.GroupLayout; import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment; import javax.swing.GroupLayout.Alignment;
...@@ -114,7 +115,9 @@ public class SolutionTab extends JPanel { ...@@ -114,7 +115,9 @@ public class SolutionTab extends JPanel {
clusterViewList = new ClusterViewList(); clusterViewList = new ClusterViewList();
//Build CV list //Build CV list
for (YoshikoCluster c: solution.clusters) { List<YoshikoCluster> list = new ArrayList<YoshikoCluster>(solution.getClusters());
list.sort(YoshikoCluster.lessThanComparator);
for (YoshikoCluster c: list) {
ClusterView clusterView = new ClusterView(c); ClusterView clusterView = new ClusterView(c);
clusterViewList.add(clusterView); clusterViewList.add(clusterView);
} }
...@@ -124,7 +127,7 @@ public class SolutionTab extends JPanel { ...@@ -124,7 +127,7 @@ public class SolutionTab extends JPanel {
scrollPane = new JScrollPane(clusterViewList); scrollPane = new JScrollPane(clusterViewList);
clusterCount = new JLabel(LocalizationManager.get("clusterFound")+" "+s.clusters.size()); clusterCount = new JLabel(LocalizationManager.get("clusterFound")+" "+s.getClusters().size());
createClusterView = new JButton(LocalizationManager.get("createClusterView")); createClusterView = new JButton(LocalizationManager.get("createClusterView"));
createMetaGraph = new JButton(LocalizationManager.get("createMetaGraph")); createMetaGraph = new JButton(LocalizationManager.get("createMetaGraph"));
......
...@@ -219,10 +219,10 @@ public class AlgorithmTask extends AbstractTask implements ObservableTask { ...@@ -219,10 +219,10 @@ public class AlgorithmTask extends AbstractTask implements ObservableTask {
net.getRow(node).set(columnName, ""+(k+1)); //Add Cluster ID in table (Remove in final version?) net.getRow(node).set(columnName, ""+(k+1)); //Add Cluster ID in table (Remove in final version?)
} }
//Register clusters with solution for further reference //Register clusters with solution for further reference
solution.clusters.add(cluster); solution.addCluster(cluster);
} }
//Sort clusters by size, descending as the biggest clusters are usually the most relevant //Sort clusters by size, descending as the biggest clusters are usually the most relevant
solution.clusters.sort(YoshikoCluster.lessThanComparator); //solution.sortClusters(YoshikoCluster.lessThanComparator);
//Register solution with c_result for further reference //Register solution with c_result for further reference
result.addSolution(solution); result.addSolution(solution);
} }
......
...@@ -2,6 +2,7 @@ package de.hhu.ba.yoshikoWrapper.tasks; ...@@ -2,6 +2,7 @@ package de.hhu.ba.yoshikoWrapper.tasks;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import org.cytoscape.model.CyEdge; import org.cytoscape.model.CyEdge;
import org.cytoscape.model.CyNetwork; import org.cytoscape.model.CyNetwork;
...@@ -103,10 +104,13 @@ public class CreateMetaGraphTask extends AbstractTask{ ...@@ -103,10 +104,13 @@ public class CreateMetaGraphTask extends AbstractTask{
taskMonitor.setStatusMessage(LocalizationManager.get("metaGraph_edges")); taskMonitor.setStatusMessage(LocalizationManager.get("metaGraph_edges"));
for (int x = 0; x <solution.getClusters().size(); x ++) { Iterator<YoshikoCluster> it1 = solution.getClusters().iterator();
YoshikoCluster c1 = solution.getClusters().get(x); Iterator<YoshikoCluster> it2 = solution.getClusters().iterator();
for (int y = x; y <solution.getClusters().size(); y ++) {
YoshikoCluster c2 = solution.getClusters().get(y); while (it1.hasNext()) {
YoshikoCluster c1 = it1.next();
while(it2.hasNext()) {
YoshikoCluster c2 = it2.next();
if(isTerminated) { if(isTerminated) {
throw new Exception("Terminated by user!"); throw new Exception("Terminated by user!");
......
package de.hhu.ba.yoshikoWrapper.tasks;
import java.util.ArrayList;
import org.cytoscape.work.ObservableTask;
import org.cytoscape.work.TaskMonitor;
import org.cytoscape.work.Tunable;
import de.hhu.ba.yoshikoWrapper.core.ResultList;
import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoCluster;
import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoResult;
import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoSolution;
public class GetClustersTask implements ObservableTask {
@Tunable(description="The result ID for which the solutions should be displayed", context="nogui")
public int resultID = -1;
@Tunable(description="The solution ID for which the solutions should be displayed", context="nogui")
public int solutionID = -1;
private ArrayList<YoshikoCluster> clusters;
@Override
public void run(TaskMonitor taskMonitor) throws Exception {
YoshikoResult result = ResultList.get(resultID);
if (result == null) {
throw new Exception("No result with ID: "+resultID+" was found!"); //TODO: Localization
}
}
@Override
public void cancel() {
// TODO Auto-generated method stub
}
@SuppressWarnings("unchecked")
@Override
public <R> R getResults(Class<? extends R> type) {
if (type.equals(String.class)) {
String ret = "";
return (R) ret;
}
return null;
}
}
package de.hhu.ba.yoshikoWrapper.tasks; package de.hhu.ba.yoshikoWrapper.tasks;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import org.cytoscape.work.ObservableTask; import org.cytoscape.work.ObservableTask;
import org.cytoscape.work.TaskMonitor; import org.cytoscape.work.TaskMonitor;
...@@ -15,7 +16,7 @@ public class GetSolutionsTask implements ObservableTask { ...@@ -15,7 +16,7 @@ public class GetSolutionsTask implements ObservableTask {
@Tunable(description="The result ID for which the solutions should be displayed", context="nogui") @Tunable(description="The result ID for which the solutions should be displayed", context="nogui")
public int resultID = -1; public int resultID = -1;
private ArrayList<YoshikoSolution> solutions; private Collection<YoshikoSolution> solutions;
@Override @Override
public void run(TaskMonitor taskMonitor) throws Exception { public void run(TaskMonitor taskMonitor) throws Exception {
...@@ -38,7 +39,7 @@ public class GetSolutionsTask implements ObservableTask { ...@@ -38,7 +39,7 @@ public class GetSolutionsTask implements ObservableTask {
if (type.equals(String.class)) { if (type.equals(String.class)) {
String ret = ""; String ret = "";
for (YoshikoSolution s: solutions) { for (YoshikoSolution s: solutions) {
ret+="Solution ["+s.getId()+"]: "+s.getClusters().size()+" clusters\n"; ret+="Solution[ID="+s.getId()+"]: "+s.getClusters().size()+" clusters\n";
} }
return (R) ret; return (R) ret;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment