Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.jts / src / main / java / org / gvsig / fmap / geom / jts / transform / EqualUtils.java @ 42775

History | View | Annotate | Download (2.08 KB)

1
/**
2
 * 
3
 */
4
package org.gvsig.fmap.geom.jts.transform;
5

    
6

    
7
/**
8
 * Collected methods which allow easy implementation of <code>equals</code>.
9
 * Rewritten from http://www.javapractices.com/topic/TopicAction.do?Id=17.
10
 *
11
 * Example use case in a class called Car:
12
 * <pre>
13
public boolean equals(Object aThat){
14
  if ( this == aThat ) return true;
15
  if ( !(aThat instanceof Car) ) return false;
16
  Car that = (Car)aThat;
17
  return
18
    EqualsUtil.areEqual(this.name, that.name) &&
19
    EqualsUtil.areEqual(this.numDoors, that.numDoors) &&
20
    EqualsUtil.areEqual(this.gasMileage, that.gasMileage) &&
21
    EqualsUtil.areEqual(this.color, that.color) &&
22
    Arrays.equals(this.maintenanceChecks, that.maintenanceChecks); //array!
23
}
24
 * </pre>
25
 *
26
 * <em>Arrays are not handled by this class</em>.
27
 * This is because the <code>Arrays.equals</code> methods should be used for
28
 * array fields.
29
 */
30
public final class EqualUtils {
31

    
32
        static public boolean areEqual(boolean aThis, boolean aThat){
33
                //System.out.println("boolean");
34
                return aThis == aThat;
35
        }
36

    
37
        static public boolean areEqual(char aThis, char aThat){
38
                //System.out.println("char");
39
                return aThis == aThat;
40
        }
41

    
42
        static public boolean areEqual(long aThis, long aThat){
43
                /*
44
                 * Implementation Note
45
                 * Note that byte, short, and int are handled by this method, through
46
                 * implicit conversion.
47
                 */
48
                //System.out.println("long");
49
                return aThis == aThat;
50
        }
51

    
52
        static public boolean areEqual(float aThis, float aThat){
53
                //System.out.println("float");
54
                return Float.floatToIntBits(aThis) == Float.floatToIntBits(aThat);
55
        }
56

    
57
        static public boolean areEqual(double aThis, double aThat){
58
                //System.out.println("double");
59
                return Double.doubleToLongBits(aThis) == Double.doubleToLongBits(aThat);
60
        }
61

    
62
        /**
63
         * Possibly-null object field.
64
         *
65
         * Includes type-safe enumerations and collections, but does not include
66
         * arrays. See class comment.
67
         */
68
        static public boolean areEqual(Object aThis, Object aThat){
69
                //System.out.println("Object");
70
                return aThis == null ? aThat == null : aThis.equals(aThat);
71
        }
72
}