View Javadoc
1   /**
2    * @(#)Point.java
3    * Copyright (C) 2008-2011 delhezi.com
4    *
5    * This class is released under the:
6    * GNU Lesser General Public License (LGPL) version 3 or later.
7    * http://www.gnu.org/copyleft/lesser.html
8    */
9   package com.delhezi.ga.genes;
10  
11  /**
12   * Klasa <code>Point</code>: Klasa przechowująca informacje o punkcie;
13   * Klasa przykładowa, ale może należało użyć java.awt.geom.Point2D;
14   * UWAGA;
15   * W przypadku kiedy w trakcie działania programu może dojść do zmiany
16   * obiektu (np. mutacja pojedynczego genu), obiekt należy traktować jako
17   * ZMIENIALY co wymagana zapewnienie GLEBOKIEGO kopiowania w klasie
18   * com.delhezi.ga.Chromosome; Wówczas obiekt powinien implementować
19   * interfejs Cloneable + funkcję clone() + fubkcje set, w innym wypadku
20   * należy zrezygnowac z tych elementów.
21   * @version 1.0 2008-11-02
22   * @author <a href="mailto:wojciech.wolszczak@delhezi.com">
23   * Wojciech Wolszczak</a>
24   */
25  public class Point { //extends java.awt.geom.Point2D //implements Cloneable
26  
27      /** Wspłórzędna x. */
28      private int x;
29      /** Wspłórzędna y. */
30      private int y;
31  
32      /**
33       * Konstruktor.
34       * @param x Wspłórzędna x.
35       * @param y Wspłórzędna y.
36       * @since 1.0
37       */
38      public Point(final int x, final int y) {
39          this.x = x;
40          this.y = y;
41      }
42  
43      /**
44       * Zwraca wspłórzędną x.
45       * @return Wspłórzędna x.
46       * @since 1.0
47       */
48      public final int getx() {
49          return this.x;
50          }
51  
52      /**
53       * Ustawia wspłórzędną y.
54       * @return Wspłórzędna y.
55       * @since 1.0
56       */
57      public final int gety() {
58          return this.y;
59          }
60  
61      /**
62       * Ustawia wspłórzędną x.
63       * @param x Wspłórzędna x.
64       * @since 1.0
65       */
66      public final void setx(final int x) {
67          this.x = x;
68          }
69  
70      /**
71       * Ustawia wspłórzędną y.
72       * @param y Wspłórzędna y.
73       * @since 1.0
74       */
75      public final void sety(final int y) {
76          this.y = y;
77          }
78  
79     //
80     //  * Kopiuje chromosom.
81     //  * W przypadku kiedy w trakcie mutacji może dojść do zmiany
82     //  * wartości obiektu
83     //  * wymagane jest zapewnienie GLEBOKIEGO kopiowania w klasie
84     //  * com.delhezi.ga.Chromosome
85     //  * W tym celu zaimplementować w klasie genu interfejs Cloneable,
86     //  * klasę clone
87     //  * oraz DOPISAC OPCJE w funkcji com.delhezi.ga.Chromosome.clone()
88     //  * return Kopia chromosomu.
89     //  * since 1.0
90      //
91      //@Override
92      //public Point clone() {
93      //    try {
94      //        return (Point) super.clone();
95      //    } catch (CloneNotSupportedException ex) {
96      //        throw new AssertionError(); //Błąd JVM.
97      //                                    Nie powinien się zdarzyć.
98      //    }
99      //}
100 
101     /**
102      * @param object xxx
103      * @return boolean Porównanie objektów.
104      */
105     @Override
106     public final boolean equals(final Object object) {
107         if (object instanceof Point) {
108            Point other = (Point) object;
109            return (this.getx() == other.getx() && this.gety() == other.gety());
110         }
111         return super.equals(object);
112     }
113 
114   /**
115    * @return int.
116    */
117     @Override
118     public final int hashCode() {
119      long bits = java.lang.Double.doubleToLongBits(getx());
120      bits ^= java.lang.Double.doubleToLongBits(gety()) * 31;
121      return (((int) bits) ^ ((int) (bits >> 32)));
122     }
123 
124     /**
125      * String charakteryzujący gen.
126      * @return String charakteryzujący gen.
127      * @since 1.0
128      */
129     @Override
130     public final String toString() {
131         return "GENE type=point [x=" + this.getx() + ",y=" + this.gety() + "]";
132     }
133 }