1 package org.postgresql.geometric;
5 import org.postgresql.util.*;
8 * This implements the polygon datatype within PostgreSQL.
10 public class PGpolygon extends PGobject implements Serializable, Cloneable
13 * The points defining the polygon
15 public PGpoint points[];
18 * Creates a polygon using an array of PGpoints
20 * @param points the points defining the polygon
22 public PGpolygon(PGpoint[] points)
29 * @param s definition of the circle in PostgreSQL's syntax.
30 * @exception SQLException on conversion failure
32 public PGpolygon(String s) throws SQLException
39 * Required by the driver
47 * @param s Definition of the polygon in PostgreSQL's syntax
48 * @exception SQLException on conversion failure
50 public void setValue(String s) throws SQLException
52 PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(s), ',');
53 int npoints = t.getSize();
54 points = new PGpoint[npoints];
55 for (int p = 0;p < npoints;p++)
56 points[p] = new PGpoint(t.getToken(p));
60 * @param obj Object to compare with
61 * @return true if the two boxes are identical
63 public boolean equals(Object obj)
65 if (obj instanceof PGpolygon)
67 PGpolygon p = (PGpolygon)obj;
69 if (p.points.length != points.length)
72 for (int i = 0;i < points.length;i++)
73 if (!points[i].equals(p.points[i]))
82 * This must be overidden to allow the object to be cloned
86 PGpoint ary[] = new PGpoint[points.length];
87 for (int i = 0;i < points.length;i++)
88 ary[i] = (PGpoint)points[i].clone();
89 return new PGpolygon(ary);
93 * @return the PGpolygon in the syntax expected by org.postgresql
95 public String getValue()
97 StringBuffer b = new StringBuffer();
99 for (int p = 0;p < points.length;p++)
103 b.append(points[p].toString());