01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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: private final int x;
30: private final int y;
31:
32: public LayoutCoordinate(int x, int y) {
33: this .x = x;
34: this .y = y;
35: }
36:
37: /**
38: * @return the x axis (column) value of this coordinate.
39: */
40: public int getX() {
41: return x;
42: }
43:
44: /**
45: * @return the y axis (row) value of this coordinate.
46: */
47: public int getY() {
48: return y;
49: }
50:
51: /**
52: * Two LayoutCoordinates are equal if thier respective x and y values are equal.
53: */
54: public boolean equals(Object obj) {
55: if (obj instanceof LayoutCoordinate) {
56: LayoutCoordinate coordinate = (LayoutCoordinate) obj;
57: return x == coordinate.x && y == coordinate.y;
58: } else {
59: return false;
60: }
61: }
62:
63: public int hashCode() {
64: return toString().hashCode();
65: }
66:
67: public String toString() {
68: return x + "," + y;
69: }
70:
71: public int compareTo(Object obj) {
72: LayoutCoordinate coordinate = (LayoutCoordinate) obj;
73: if (!coordinate.equals(this )) {
74: if (y == coordinate.y) {
75: return x > coordinate.x ? 1 : -1;
76: } else {
77: return y > coordinate.y ? 1 : -1;
78: }
79:
80: } else {
81: return 0;
82: }
83: }
84:
85: }
|