javaDSL简单实现示例分享
程序员文章站
2024-02-26 12:44:58
复制代码 代码如下:package com.vd.dsl;import static com.vd.dsl.graphbuilder.*;public class main...
复制代码 代码如下:
package com.vd.dsl;
import static com.vd.dsl.graphbuilder.*;
public class main {
public static void main(string[] args) {
graph().edge().from("a").to("b").weigth(20.0).edge().from("b").to("c").weigth(10.0).printgraph();
}
}
复制代码 代码如下:
package com.vd.dsl;
public class edge {
private vertex fromvertex;
private vertex tovertex;
public vertex getfromvertex() {
return fromvertex;
}
public void setfromvertex(vertex fromvertex) {
this.fromvertex = fromvertex;
}
public vertex gettovertex() {
return tovertex;
}
public void settovertex(vertex tovertex) {
this.tovertex = tovertex;
}
public double getweight() {
return weight;
}
public void setweight(double weight) {
this.weight = weight;
}
private double weight;
public edge() {
}
@override
public string tostring() {
return fromvertex.getlabel()+ " to "+
tovertex.getlabel() + "with weigth "+
this.weight;
}
}