欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

javaDSL简单实现示例分享

程序员文章站 2024-02-23 16:52:22
复制代码 代码如下: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;
 }
}