~ubuntu-branches/ubuntu/maverick/libpgjava/maverick

« back to all changes in this revision

Viewing changes to src/interfaces/jdbc/org/postgresql/geometric/PGpolygon.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2006-04-25 00:07:07 UTC
  • mfrom: (1.3.1 upstream) (3.1.1 dapper)
  • Revision ID: james.westby@ubuntu.com-20060425000707-6lr2s0awuz4z48hm
* Drop support for the old jdbc2 driver (can be reverted if wanted)
  (closes: #358345).
* New upstream (thanks to Wolfgang Baer).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*-------------------------------------------------------------------------
2
 
 *
3
 
 * PGline.java
4
 
 *     This implements the polygon datatype within PostgreSQL.
5
 
 *
6
 
 * Copyright (c) 2003, PostgreSQL Global Development Group
7
 
 *
8
 
 * IDENTIFICATION
9
 
 *        $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/geometric/Attic/PGpolygon.java,v 1.5 2003/05/29 04:39:48 barry Exp $
10
 
 *
11
 
 *-------------------------------------------------------------------------
12
 
 */
13
 
package org.postgresql.geometric;
14
 
 
15
 
import org.postgresql.util.PGobject;
16
 
import org.postgresql.util.PGtokenizer;
17
 
import java.io.Serializable;
18
 
import java.sql.SQLException;
19
 
 
20
 
public class PGpolygon extends PGobject implements Serializable, Cloneable
21
 
{
22
 
        /*
23
 
         * The points defining the polygon
24
 
         */
25
 
        public PGpoint points[];
26
 
 
27
 
        /*
28
 
         * Creates a polygon using an array of PGpoints
29
 
         *
30
 
         * @param points the points defining the polygon
31
 
         */
32
 
        public PGpolygon(PGpoint[] points)
33
 
        {
34
 
                this();
35
 
                this.points = points;
36
 
        }
37
 
 
38
 
        /*
39
 
         * @param s definition of the circle in PostgreSQL's syntax.
40
 
         * @exception SQLException on conversion failure
41
 
         */
42
 
        public PGpolygon(String s) throws SQLException
43
 
        {
44
 
                this();
45
 
                setValue(s);
46
 
        }
47
 
 
48
 
        /*
49
 
         * Required by the driver
50
 
         */
51
 
        public PGpolygon()
52
 
        {
53
 
                setType("polygon");
54
 
        }
55
 
 
56
 
        /*
57
 
         * @param s Definition of the polygon in PostgreSQL's syntax
58
 
         * @exception SQLException on conversion failure
59
 
         */
60
 
        public void setValue(String s) throws SQLException
61
 
        {
62
 
                PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(s), ',');
63
 
                int npoints = t.getSize();
64
 
                points = new PGpoint[npoints];
65
 
                for (int p = 0;p < npoints;p++)
66
 
                        points[p] = new PGpoint(t.getToken(p));
67
 
        }
68
 
 
69
 
        /*
70
 
         * @param obj Object to compare with
71
 
         * @return true if the two boxes are identical
72
 
         */
73
 
        public boolean equals(Object obj)
74
 
        {
75
 
                if (obj instanceof PGpolygon)
76
 
                {
77
 
                        PGpolygon p = (PGpolygon)obj;
78
 
 
79
 
                        if (p.points.length != points.length)
80
 
                                return false;
81
 
 
82
 
                        for (int i = 0;i < points.length;i++)
83
 
                                if (!points[i].equals(p.points[i]))
84
 
                                        return false;
85
 
 
86
 
                        return true;
87
 
                }
88
 
                return false;
89
 
        }
90
 
 
91
 
        /*
92
 
         * This must be overidden to allow the object to be cloned
93
 
         */
94
 
        public Object clone()
95
 
        {
96
 
                PGpoint ary[] = new PGpoint[points.length];
97
 
                for (int i = 0;i < points.length;i++)
98
 
                        ary[i] = (PGpoint)points[i].clone();
99
 
                return new PGpolygon(ary);
100
 
        }
101
 
 
102
 
        /*
103
 
         * @return the PGpolygon in the syntax expected by org.postgresql
104
 
         */
105
 
        public String getValue()
106
 
        {
107
 
                StringBuffer b = new StringBuffer();
108
 
                b.append("(");
109
 
                for (int p = 0;p < points.length;p++)
110
 
                {
111
 
                        if (p > 0)
112
 
                                b.append(",");
113
 
                        b.append(points[p].toString());
114
 
                }
115
 
                b.append(")");
116
 
                return b.toString();
117
 
        }
118
 
}