Source Code Cross Referenced for PGbox.java in  » Database-JDBC-Connection-Pool » postgresql » org » postgresql » geometric » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database JDBC Connection Pool » postgresql » org.postgresql.geometric 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*-------------------------------------------------------------------------
002:         *
003:         * Copyright (c) 2003-2005, PostgreSQL Global Development Group
004:         *
005:         * IDENTIFICATION
006:         *   $PostgreSQL: pgjdbc/org/postgresql/geometric/PGbox.java,v 1.14 2007/07/16 15:02:53 jurka Exp $
007:         *
008:         *-------------------------------------------------------------------------
009:         */
010:        package org.postgresql.geometric;
011:
012:        import org.postgresql.util.GT;
013:        import org.postgresql.util.PGobject;
014:        import org.postgresql.util.PGtokenizer;
015:        import org.postgresql.util.PSQLException;
016:        import org.postgresql.util.PSQLState;
017:
018:        import java.io.Serializable;
019:        import java.sql.SQLException;
020:
021:        /**
022:         *     This represents the box datatype within org.postgresql.
023:         */
024:        public class PGbox extends PGobject implements  Serializable, Cloneable {
025:            /**
026:             * These are the two points.
027:             */
028:            public PGpoint point[] = new PGpoint[2];
029:
030:            /**
031:             * @param x1 first x coordinate
032:             * @param y1 first y coordinate
033:             * @param x2 second x coordinate
034:             * @param y2 second y coordinate
035:             */
036:            public PGbox(double x1, double y1, double x2, double y2) {
037:                this ();
038:                this .point[0] = new PGpoint(x1, y1);
039:                this .point[1] = new PGpoint(x2, y2);
040:            }
041:
042:            /**
043:             * @param p1 first point
044:             * @param p2 second point
045:             */
046:            public PGbox(PGpoint p1, PGpoint p2) {
047:                this ();
048:                this .point[0] = p1;
049:                this .point[1] = p2;
050:            }
051:
052:            /**
053:             * @param s Box definition in PostgreSQL syntax
054:             * @exception SQLException if definition is invalid
055:             */
056:            public PGbox(String s) throws SQLException {
057:                this ();
058:                setValue(s);
059:            }
060:
061:            /**
062:             * Required constructor
063:             */
064:            public PGbox() {
065:                setType("box");
066:            }
067:
068:            /**
069:             * This method sets the value of this object. It should be overidden,
070:             * but still called by subclasses.
071:             *
072:             * @param value a string representation of the value of the object
073:             * @exception SQLException thrown if value is invalid for this type
074:             */
075:            public void setValue(String value) throws SQLException {
076:                PGtokenizer t = new PGtokenizer(value, ',');
077:                if (t.getSize() != 2)
078:                    throw new PSQLException(GT.tr(
079:                            "Conversion to type {0} failed: {1}.",
080:                            new Object[] { type, value }),
081:                            PSQLState.DATA_TYPE_MISMATCH);
082:
083:                point[0] = new PGpoint(t.getToken(0));
084:                point[1] = new PGpoint(t.getToken(1));
085:            }
086:
087:            /**
088:             * @param obj Object to compare with
089:             * @return true if the two boxes are identical
090:             */
091:            public boolean equals(Object obj) {
092:                if (obj instanceof  PGbox) {
093:                    PGbox p = (PGbox) obj;
094:
095:                    // Same points.
096:                    if (p.point[0].equals(point[0])
097:                            && p.point[1].equals(point[1]))
098:                        return true;
099:
100:                    // Points swapped.
101:                    if (p.point[0].equals(point[1])
102:                            && p.point[1].equals(point[0]))
103:                        return true;
104:
105:                    // Using the opposite two points of the box:
106:                    //  (x1,y1),(x2,y2)  ->   (x1,y2),(x2,y1)
107:                    if (p.point[0].x == point[0].x
108:                            && p.point[0].y == point[1].y
109:                            && p.point[1].x == point[1].x
110:                            && p.point[1].y == point[0].y)
111:                        return true;
112:
113:                    // Using the opposite two points of the box, and the points are swapped
114:                    //  (x1,y1),(x2,y2)  ->   (x2,y1),(x1,y2)
115:                    if (p.point[0].x == point[1].x
116:                            && p.point[0].y == point[0].y
117:                            && p.point[1].x == point[0].x
118:                            && p.point[1].y == point[1].y)
119:                        return true;
120:                }
121:
122:                return false;
123:            }
124:
125:            public int hashCode() {
126:                // This relies on the behaviour of point's hashcode being an exclusive-OR of
127:                // its X and Y components; we end up with an exclusive-OR of the two X and
128:                // two Y components, which is equal whenever equals() would return true
129:                // since xor is commutative.
130:                return point[0].hashCode() ^ point[1].hashCode();
131:            }
132:
133:            public Object clone() throws CloneNotSupportedException {
134:                PGbox newPGbox = (PGbox) super .clone();
135:                if (newPGbox.point != null) {
136:                    newPGbox.point = (PGpoint[]) newPGbox.point.clone();
137:                    for (int i = 0; i < newPGbox.point.length; ++i)
138:                        if (newPGbox.point[i] != null)
139:                            newPGbox.point[i] = (PGpoint) newPGbox.point[i]
140:                                    .clone();
141:                }
142:                return newPGbox;
143:            }
144:
145:            /**
146:             * @return the PGbox in the syntax expected by org.postgresql
147:             */
148:            public String getValue() {
149:                return point[0].toString() + "," + point[1].toString();
150:            }
151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.