1
package org.postgresql.geometric;
5
import org.postgresql.util.*;
8
* This implements a lseg (line segment) consisting of two points
10
public class PGlseg extends PGobject implements Serializable, Cloneable
13
* These are the two points.
15
public PGpoint point[] = new PGpoint[2];
18
* @param x1 coordinate for first point
19
* @param y1 coordinate for first point
20
* @param x2 coordinate for second point
21
* @param y2 coordinate for second point
23
public PGlseg(double x1, double y1, double x2, double y2)
25
this(new PGpoint(x1, y1), new PGpoint(x2, y2));
29
* @param p1 first point
30
* @param p2 second point
32
public PGlseg(PGpoint p1, PGpoint p2)
40
* @param s definition of the circle in PostgreSQL's syntax.
41
* @exception SQLException on conversion failure
43
public PGlseg(String s) throws SQLException
50
* reuired by the driver
58
* @param s Definition of the line segment in PostgreSQL's syntax
59
* @exception SQLException on conversion failure
61
public void setValue(String s) throws SQLException
63
PGtokenizer t = new PGtokenizer(PGtokenizer.removeBox(s), ',');
65
throw new PSQLException("postgresql.geo.lseg");
67
point[0] = new PGpoint(t.getToken(0));
68
point[1] = new PGpoint(t.getToken(1));
72
* @param obj Object to compare with
73
* @return true if the two boxes are identical
75
public boolean equals(Object obj)
77
if (obj instanceof PGlseg)
79
PGlseg p = (PGlseg)obj;
80
return (p.point[0].equals(point[0]) && p.point[1].equals(point[1])) ||
81
(p.point[0].equals(point[1]) && p.point[1].equals(point[0]));
87
* This must be overidden to allow the object to be cloned
91
return new PGlseg((PGpoint)point[0].clone(), (PGpoint)point[1].clone());
95
* @return the PGlseg in the syntax expected by org.postgresql
97
public String getValue()
99
return "[" + point[0] + "," + point[1] + "]";