Commit 5e35c3c0 authored by Philipp Spohr's avatar Philipp Spohr
Browse files

changed many arrayLists to Hashmaps

parent b784a509
......@@ -22,6 +22,8 @@
package de.hhu.ba.yoshikoWrapper.graphModel;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import org.cytoscape.model.CyNetwork;
......@@ -36,21 +38,21 @@ public class YoshikoResult{
private CyNetwork originalGraph;
private ArrayList<YoshikoSolution> solutions;
private HashMap<Long,YoshikoSolution> solutions;
private SolutionFlags flags;
private int id;
public YoshikoResult(CyNetwork net, SolutionFlags flags) {
solutions = new ArrayList<YoshikoSolution>();
solutions = new HashMap<Long,YoshikoSolution>();
this.originalGraph = net;
this.flags = flags;
ResultList.add(this);
}
public void delete() {
for (YoshikoSolution s: solutions) {
for (YoshikoSolution s: solutions.values()) {
s.delete();
}
ResultList.remove(this.id);
......@@ -59,7 +61,7 @@ public class YoshikoResult{
//___________SETTER GETTER_____________//
/**
* @return the flags asspciated with this result
* @return the flags associated with this result
*/
public SolutionFlags getFlags() {
return flags;
......@@ -67,15 +69,13 @@ public class YoshikoResult{
public void addSolution(YoshikoSolution solution) {
solutions.add(solution);
solutions.put(solution.getId(),solution);
}
public ArrayList<YoshikoSolution> getSolutions() {
return solutions;
public Collection<YoshikoSolution> getSolutions() {
return solutions.values();
}
public CyNetwork getOriginalGraph() {
return originalGraph;
}
......
......@@ -21,11 +21,11 @@
******************************************************************************/
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.List;
import javax.swing.JOptionPane;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode;
......@@ -43,7 +43,7 @@ public class YoshikoSolution {
private HashMap<YoshikoCluster, CyNode> metaGraphMap;
public ArrayList<YoshikoCluster> clusters;
private HashMap<Long,YoshikoCluster> clusters;
private final long id;
......@@ -51,15 +51,39 @@ public class YoshikoSolution {
public YoshikoSolution(YoshikoResult yoshikoResult, long id) {
clusters = new ArrayList<YoshikoCluster>();
clusters = new HashMap<Long,YoshikoCluster>();
this.result = yoshikoResult;
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 ________________//
public ArrayList<YoshikoCluster> getClusters() {
return clusters;
public Collection<YoshikoCluster> getClusters() {
return clusters.values();
}
/**
......@@ -73,15 +97,6 @@ public class YoshikoSolution {
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) {
this.metaGraph = metaGraph;
this.metaGraphMap = map;
......@@ -91,19 +106,9 @@ public class YoshikoSolution {
return 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!");
}
public void addCluster(YoshikoCluster cluster) {
clusters.put(cluster.getID(), cluster);
}
}
......@@ -30,6 +30,7 @@ import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
......@@ -114,7 +115,9 @@ public class SolutionTab extends JPanel {
clusterViewList = new ClusterViewList();
//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);
clusterViewList.add(clusterView);
}
......@@ -124,7 +127,7 @@ public class SolutionTab extends JPanel {
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"));
createMetaGraph = new JButton(LocalizationManager.get("createMetaGraph"));
......
......@@ -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?)
}
//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
solution.clusters.sort(YoshikoCluster.lessThanComparator);
//solution.sortClusters(YoshikoCluster.lessThanComparator);
//Register solution with c_result for further reference
result.addSolution(solution);
}
......
......@@ -2,6 +2,7 @@ package de.hhu.ba.yoshikoWrapper.tasks;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import org.cytoscape.model.CyEdge;
import org.cytoscape.model.CyNetwork;
......@@ -103,10 +104,13 @@ public class CreateMetaGraphTask extends AbstractTask{
taskMonitor.setStatusMessage(LocalizationManager.get("metaGraph_edges"));
for (int x = 0; x <solution.getClusters().size(); x ++) {
YoshikoCluster c1 = solution.getClusters().get(x);
for (int y = x; y <solution.getClusters().size(); y ++) {
YoshikoCluster c2 = solution.getClusters().get(y);
Iterator<YoshikoCluster> it1 = solution.getClusters().iterator();
Iterator<YoshikoCluster> it2 = solution.getClusters().iterator();
while (it1.hasNext()) {
YoshikoCluster c1 = it1.next();
while(it2.hasNext()) {
YoshikoCluster c2 = it2.next();
if(isTerminated) {
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;
import java.util.ArrayList;
import java.util.Collection;
import org.cytoscape.work.ObservableTask;
import org.cytoscape.work.TaskMonitor;
......@@ -15,7 +16,7 @@ public class GetSolutionsTask implements ObservableTask {
@Tunable(description="The result ID for which the solutions should be displayed", context="nogui")
public int resultID = -1;
private ArrayList<YoshikoSolution> solutions;
private Collection<YoshikoSolution> solutions;
@Override
public void run(TaskMonitor taskMonitor) throws Exception {
......@@ -38,7 +39,7 @@ public class GetSolutionsTask implements ObservableTask {
if (type.equals(String.class)) {
String ret = "";
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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment