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

« back to all changes in this revision

Viewing changes to src/interfaces/jdbc/org/postgresql/geometric/PGlseg.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
 
 * PGlseg.java
4
 
 *     This implements a lseg (line segment) consisting of two points
5
 
 *
6
 
 * Copyright (c) 2003, PostgreSQL Global Development Group
7
 
 *
8
 
 * IDENTIFICATION
9
 
 *        $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/geometric/Attic/PGlseg.java,v 1.5 2003/09/13 04:02:15 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 org.postgresql.util.PSQLException;
18
 
import org.postgresql.util.PSQLState;
19
 
 
20
 
import java.io.Serializable;
21
 
import java.sql.SQLException;
22
 
 
23
 
public class PGlseg extends PGobject implements Serializable, Cloneable
24
 
{
25
 
        /*
26
 
         * These are the two points.
27
 
         */
28
 
        public PGpoint point[] = new PGpoint[2];
29
 
 
30
 
        /*
31
 
         * @param x1 coordinate for first point
32
 
         * @param y1 coordinate for first point
33
 
         * @param x2 coordinate for second point
34
 
         * @param y2 coordinate for second point
35
 
         */
36
 
        public PGlseg(double x1, double y1, double x2, double y2)
37
 
        {
38
 
                this(new PGpoint(x1, y1), new PGpoint(x2, y2));
39
 
        }
40
 
 
41
 
        /*
42
 
         * @param p1 first point
43
 
         * @param p2 second point
44
 
         */
45
 
        public PGlseg(PGpoint p1, PGpoint p2)
46
 
        {
47
 
                this();
48
 
                this.point[0] = p1;
49
 
                this.point[1] = p2;
50
 
        }
51
 
 
52
 
        /*
53
 
         * @param s definition of the circle in PostgreSQL's syntax.
54
 
         * @exception SQLException on conversion failure
55
 
         */
56
 
        public PGlseg(String s) throws SQLException
57
 
        {
58
 
                this();
59
 
                setValue(s);
60
 
        }
61
 
 
62
 
        /*
63
 
         * reuired by the driver
64
 
         */
65
 
        public PGlseg()
66
 
        {
67
 
                setType("lseg");
68
 
        }
69
 
 
70
 
        /*
71
 
         * @param s Definition of the line segment in PostgreSQL's syntax
72
 
         * @exception SQLException on conversion failure
73
 
         */
74
 
        public void setValue(String s) throws SQLException
75
 
        {
76
 
                PGtokenizer t = new PGtokenizer(PGtokenizer.removeBox(s), ',');
77
 
                if (t.getSize() != 2)
78
 
                        throw new PSQLException("postgresql.geo.lseg", PSQLState.DATA_TYPE_MISMATCH);
79
 
 
80
 
                point[0] = new PGpoint(t.getToken(0));
81
 
                point[1] = new PGpoint(t.getToken(1));
82
 
        }
83
 
 
84
 
        /*
85
 
         * @param obj Object to compare with
86
 
         * @return true if the two boxes are identical
87
 
         */
88
 
        public boolean equals(Object obj)
89
 
        {
90
 
                if (obj instanceof PGlseg)
91
 
                {
92
 
                        PGlseg p = (PGlseg)obj;
93
 
                        return (p.point[0].equals(point[0]) && p.point[1].equals(point[1])) ||
94
 
                                   (p.point[0].equals(point[1]) && p.point[1].equals(point[0]));
95
 
                }
96
 
                return false;
97
 
        }
98
 
 
99
 
        /*
100
 
         * This must be overidden to allow the object to be cloned
101
 
         */
102
 
        public Object clone()
103
 
        {
104
 
                return new PGlseg((PGpoint)point[0].clone(), (PGpoint)point[1].clone());
105
 
        }
106
 
 
107
 
        /*
108
 
         * @return the PGlseg in the syntax expected by org.postgresql
109
 
         */
110
 
        public String getValue()
111
 
        {
112
 
                return "[" + point[0] + "," + point[1] + "]";
113
 
        }
114
 
}