1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.portlets.layout;
18
19 import java.io.Serializable;
20
21 /***
22 *
23 * Simple class that holds an x,y (column,row) coordinate.
24 *
25 * @author <href a="mailto:weaver@apache.org">Scott T. Weaver</a>
26 *
27 */
28 public final class LayoutCoordinate implements Comparable, Serializable
29 {
30 private final int x;
31 private final int y;
32
33 public LayoutCoordinate(int x, int y)
34 {
35 this.x = x;
36 this.y = y;
37 }
38
39 /***
40 * @return the x axis (column) value of this coordinate.
41 */
42 public int getX()
43 {
44 return x;
45 }
46
47 /***
48 * @return the y axis (row) value of this coordinate.
49 */
50 public int getY()
51 {
52 return y;
53 }
54
55 /***
56 * Two LayoutCoordinates are equal if thier respective x and y values are equal.
57 */
58 public boolean equals(Object obj)
59 {
60 if(obj instanceof LayoutCoordinate)
61 {
62 LayoutCoordinate coordinate = (LayoutCoordinate) obj;
63 return x == coordinate.x && y == coordinate.y;
64 }
65 else
66 {
67 return false;
68 }
69 }
70
71 public int hashCode()
72 {
73 return toString().hashCode();
74 }
75
76 public String toString()
77 {
78 return x+","+y;
79 }
80
81 public int compareTo(Object obj)
82 {
83 LayoutCoordinate coordinate = (LayoutCoordinate) obj;
84 if(!coordinate.equals(this))
85 {
86 if(y == coordinate.y)
87 {
88 return x > coordinate.x ? 1 : -1;
89 }
90 else
91 {
92 return y > coordinate.y ? 1 : -1;
93 }
94
95 }
96 else
97 {
98 return 0;
99 }
100 }
101
102
103 }