Skip to content
Snippets Groups Projects
Commit b04668f6 authored by Peter Wagenhuber's avatar Peter Wagenhuber
Browse files

path.java weggeschmissen und stattdessen eine list<channel> genommen

parent 3ed02429
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
......@@ -46,34 +46,35 @@ public class Nloc {
chan9.addChild(chan10);
chan10.addChild(s0);
List<Path> pathlist = getAllPaths(p0, new Path());
//printAllPaths(p0,new Path(), pl);
List<List<Channel>> pathlist = getAllPaths(p0, new ArrayList<Channel>());
printPaths(pathlist);
}
public static void printPaths(List<Path> pathlist) {
public static void printPaths(List<List<Channel>> pathlist) {
System.out.println("Number of paths found: " + pathlist.size());
for (Path p : pathlist) {
for (Channel ch : p.getChanlist()) {
for (List<Channel> p : pathlist) {
for (Channel ch : p) {
System.out.print("ID: " + ch.getID() + " ");
}
System.out.println("");
}
}
public static List<Path> getAllPaths(Channel chan, Path path) {
List<Path> pl = new ArrayList<Path>();
public static List<List<Channel>> getAllPaths(Channel chan, List<Channel> path) {
List<List<Channel>> pl = new ArrayList<List<Channel>>();
getAllPathsRecursive(chan, path, pl);
return pl;
}
public static void getAllPathsRecursive(Channel chan, Path path, List<Path> pathlist) {
public static void getAllPathsRecursive(Channel chan, List<Channel> path, List<List<Channel>> pathlist) {
path.add(chan);
if (chan.getChildren().size() == 0) {
pathlist.add(path);
} else {
for (Channel ch : chan.getChildren()) {
getAllPathsRecursive(ch, new Path(path), pathlist);
getAllPathsRecursive(ch, new ArrayList<Channel>(path), pathlist);
}
}
}
......
package nloc;
import java.util.List;
import java.util.LinkedList;
public class Path {
private List<Channel> path;
public Path (List<Channel> path) {
this.path = path;
}
public Path (Path p) {
this.path = new LinkedList<Channel>(p.getChanlist());
}
public Path () {
this.path = new LinkedList<Channel>();
}
public void add(Channel chan) {
path.add(chan);
}
public List<Channel> getChanlist() {
return path;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment