summaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/postgresql/PGcircle.java
blob: 543a0a71c9111cfbd9da109c940589abe1c637d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
 *
 * This implements a circle consisting of a point and a radius
 *
 */

package postgresql;

import java.io.*;
import java.sql.*;

public class PGcircle implements Serializable
{
  /**
   * This is the centre point
   */
  public PGpoint center;
  
  /**
   * This is the radius
   */
  double radius;
  
  public PGcircle(double x,double y,double r)
  {
    this.center = new PGpoint(x,y);
    this.radius = r;
  }
  
  public PGcircle(PGpoint c,double r)
  {
    this.center = c;
    this.radius = r;
  }
  
  public PGcircle(PGcircle c)
  {
    this.center = new PGpoint(c.center);
    this.radius = c.radius;
  }
  
  /**
   * This constructor is used by the driver.
   */
  public PGcircle(String s) throws SQLException
  {
    PGtokenizer t = new PGtokenizer(PGtokenizer.removeAngle(s),',');
    if(t.getSize() != 2)
      throw new SQLException("conversion of circle failed - "+s);
    
    try {
      center = new PGpoint(t.getToken(0));
      radius = Double.valueOf(t.getToken(1)).doubleValue();
    } catch(NumberFormatException e) {
      throw new SQLException("conversion of circle failed - "+s+" - +"+e.toString());
    }
  }
  
  public boolean equals(Object obj)
  {
    PGcircle p = (PGcircle)obj;
    return p.center.equals(center) && p.radius==radius;
  }
  
  /**
   * This returns the circle in the syntax expected by postgresql
   */
  public String toString()
  {
    return "<"+center+","+radius+">";
  }
}