Compare commits
2 commits
7ffd5c2d20
...
b635c13d57
Author | SHA1 | Date | |
---|---|---|---|
b635c13d57 | |||
02c1adbcbf |
4 changed files with 19 additions and 20 deletions
|
@ -1,8 +1,8 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
<classpathentry kind="src" path="test"/>
|
<classpathentry kind="src" path="test"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class GraphGenerator {
|
||||||
|
|
||||||
public static class Graph{
|
public static class Graph{
|
||||||
|
|
||||||
private static Pattern PATTERN = Pattern.compile("^(\\d+)\\s+->\s+(.*)$");
|
private static Pattern PATTERN = Pattern.compile("^(\\d+)\\s+->\\s+(.*)$");
|
||||||
|
|
||||||
private List<Node> nodes;
|
private List<Node> nodes;
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,7 @@ public class Operator{
|
||||||
VisitorBag vbag = visitor.visit(element);
|
VisitorBag vbag = visitor.visit(element);
|
||||||
if(!vbag.isValidated()) return new VisitorBag();
|
if(!vbag.isValidated()) return new VisitorBag();
|
||||||
bag.merge(vbag);
|
bag.merge(vbag);
|
||||||
for(Object computed : vbag.computeList()){
|
set.add(vbag.computed());
|
||||||
set.add(computed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for(Object obj : set) bag.compute(obj);
|
for(Object obj : set) bag.compute(obj);
|
||||||
return bag;
|
return bag;
|
||||||
|
@ -53,9 +51,7 @@ public class Operator{
|
||||||
VisitorBag vbag = visitor.visit(element);
|
VisitorBag vbag = visitor.visit(element);
|
||||||
if(!vbag.isValidated()) return new VisitorBag();
|
if(!vbag.isValidated()) return new VisitorBag();
|
||||||
bag.merge(vbag);
|
bag.merge(vbag);
|
||||||
for(Object computed : vbag.computeList()){
|
bag.compute(vbag.computed());
|
||||||
bag.compute(computed);
|
|
||||||
}
|
|
||||||
return bag;
|
return bag;
|
||||||
}
|
}
|
||||||
return bag;
|
return bag;
|
||||||
|
@ -94,7 +90,7 @@ public class Operator{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPropagate(){
|
public boolean canPropagate(){
|
||||||
return true;
|
return visitor.canPropagate();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -108,7 +104,6 @@ public class Operator{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canVisit(Class<?> type){
|
public boolean canVisit(Class<?> type){
|
||||||
// System.out.println("collect can visit ? "+type);
|
|
||||||
return visitor.canVisit(type);
|
return visitor.canVisit(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,35 +9,39 @@ import java.util.Map;
|
||||||
//only one pass in parameter or visit ?
|
//only one pass in parameter or visit ?
|
||||||
public class VisitorBag{
|
public class VisitorBag{
|
||||||
|
|
||||||
private static final Object VALIDATE_BAG = new Object();
|
private static final Object VALIDATED_BAG = new Object();
|
||||||
|
|
||||||
private List<Object> collect;
|
private List<Object> collect;
|
||||||
private Object computed;
|
private Object computed;
|
||||||
|
|
||||||
public VisitorBag(){
|
public VisitorBag(){
|
||||||
this.collect = new ArrayList<>();
|
this.collect = new ArrayList<>(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void compute(Object element){
|
public void compute(Object element){
|
||||||
this.computed = element;
|
this.computed = element;
|
||||||
}
|
}
|
||||||
|
|
||||||
VisitorBag pair(Object key){
|
|
||||||
this.collect = Arrays.asList(new Pair<>(key, collect));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void merge(VisitorBag bag){
|
public void merge(VisitorBag bag){
|
||||||
this.collect.addAll(bag.collect);
|
this.collect.addAll(bag.collect);
|
||||||
if(!this.collect.isEmpty()) this.computed = VALIDATE_BAG;
|
if((!this.collect.isEmpty()) && this.computed == null) this.computed = VALIDATED_BAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object computed(){
|
||||||
|
return this.computed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValidated(){
|
public boolean isValidated(){
|
||||||
return this.VALIDATE_BAG != null;
|
return this.computed != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
VisitorBag pair(Object key){
|
||||||
|
this.collect = Arrays.asList(new Pair<>(key, this.collect));
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
VisitorBag collect(){
|
VisitorBag collect(){
|
||||||
this.collect.addAll(this.list);
|
if(this.computed != null) this.collect.add(this.computed);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue