1 package org.postgresql.geometric;
5 import org.postgresql.util.*;
8 * This implements a path (a multiple segmented line, which may be closed)
10 public class PGpath extends PGobject implements Serializable, Cloneable
13 * True if the path is open, false if closed
18 * The points defining this path
20 public PGpoint points[];
23 * @param points the PGpoints that define the path
24 * @param open True if the path is open, false if closed
26 public PGpath(PGpoint[] points, boolean open)
34 * Required by the driver
42 * @param s definition of the circle in PostgreSQL's syntax.
43 * @exception SQLException on conversion failure
45 public PGpath(String s) throws SQLException
52 * @param s Definition of the path in PostgreSQL's syntax
53 * @exception SQLException on conversion failure
55 public void setValue(String s) throws SQLException
57 // First test to see if were open
58 if (s.startsWith("[") && s.endsWith("]"))
61 s = PGtokenizer.removeBox(s);
63 else if (s.startsWith("(") && s.endsWith(")"))
66 s = PGtokenizer.removePara(s);
69 throw new PSQLException("postgresql.geo.path");
71 PGtokenizer t = new PGtokenizer(s, ',');
72 int npoints = t.getSize();
73 points = new PGpoint[npoints];
74 for (int p = 0;p < npoints;p++)
75 points[p] = new PGpoint(t.getToken(p));
79 * @param obj Object to compare with
80 * @return true if the two boxes are identical
82 public boolean equals(Object obj)
84 if (obj instanceof PGpath)
86 PGpath p = (PGpath)obj;
88 if (p.points.length != points.length)
94 for (int i = 0;i < points.length;i++)
95 if (!points[i].equals(p.points[i]))
104 * This must be overidden to allow the object to be cloned
106 public Object clone()
108 PGpoint ary[] = new PGpoint[points.length];
109 for (int i = 0;i < points.length;i++)
110 ary[i] = (PGpoint)points[i].clone();
111 return new PGpath(ary, open);
115 * This returns the polygon in the syntax expected by org.postgresql
117 public String getValue()
119 StringBuffer b = new StringBuffer(open ? "[" : "(");
121 for (int p = 0;p < points.length;p++)
125 b.append(points[p].toString());
127 b.append(open ? "]" : ")");
132 public boolean isOpen()
137 public boolean isClosed()
142 public void closePath()
147 public void openPath()