Package com.example.renderer.visitor
Class JSONExportVisitor
java.lang.Object
com.example.renderer.visitor.JSONExportVisitor
- All Implemented Interfaces:
ExportVisitor
JSON导出访问者实现类
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
将圆形对象转换为JSON格式输出 格式: {"type":"circle", "x":x, "y":y, "r":radius}void
将椭圆对象转换为JSON格式输出 格式: {"type":"ellipse", "x":x, "y":y, "rx":xRadius, "ry":yRadius}void
将矩形对象转换为JSON格式输出 格式: {"type":"rectangle", "x":x, "y":y, "w":width, "h":height}void
将三角形对象转换为JSON格式输出 格式: {"type":"triangle", "x1":x1, "y1":y1, ..., "y3":y3}
-
Constructor Details
-
JSONExportVisitor
public JSONExportVisitor()
-
-
Method Details
-
visitCircle
将圆形对象转换为JSON格式输出 格式: {"type":"circle", "x":x, "y":y, "r":radius}- Specified by:
visitCircle
in interfaceExportVisitor
- Parameters:
c
- 要导出的圆形对象,不能为null- Throws:
NullPointerException
- 如果参数c为nullIllegalArgumentException
- 如果半径值为负数
-
visitRectangle
将矩形对象转换为JSON格式输出 格式: {"type":"rectangle", "x":x, "y":y, "w":width, "h":height}- Specified by:
visitRectangle
in interfaceExportVisitor
- Parameters:
r
- 要导出的矩形对象,不能为null- Throws:
NullPointerException
- 如果参数r为nullIllegalArgumentException
- 如果宽度或高度为负数
-
visitEllipse
将椭圆对象转换为JSON格式输出 格式: {"type":"ellipse", "x":x, "y":y, "rx":xRadius, "ry":yRadius}- Specified by:
visitEllipse
in interfaceExportVisitor
- Parameters:
e
- 要导出的椭圆对象,不能为null- Throws:
NullPointerException
- 如果参数e为nullIllegalArgumentException
- 如果宽度或高度为负数
-
visitTriangle
将三角形对象转换为JSON格式输出 格式: {"type":"triangle", "x1":x1, "y1":y1, ..., "y3":y3}- Specified by:
visitTriangle
in interfaceExportVisitor
- Parameters:
t
- 要导出的三角形对象,不能为null- Throws:
NullPointerException
- 如果参数t为null
-