01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.validator.internal;
16:
17: import java.io.Serializable;
18:
19: import org.strecks.util.Assert;
20:
21: /*
22: * Copyright 2005-2006 the original author or authors.
23: *
24: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
25: * in compliance with the License. You may obtain a copy of the License at
26: *
27: * http://www.apache.org/licenses/LICENSE-2.0
28: *
29: * Unless required by applicable law or agreed to in writing, software distributed under the License
30: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
31: * or implied. See the License for the specific language governing permissions and limitations under
32: * the License.
33: */
34:
35: /**
36: * Implements the equality semantics of the property name and the ordering semantics of the order
37: * field. Used to maintain an ordering of <code>Validators</code> so that they can be executed in
38: * the correct order. Suitable for use as a key in a <code>TreeMap</code>
39: *
40: * @author Phil Zoio
41: */
42: public class OrderedProperty implements Comparable<OrderedProperty>,
43: Serializable {
44:
45: private static final long serialVersionUID = 7326461095275238567L;
46:
47: private String propertyName;
48:
49: private Integer order;
50:
51: public OrderedProperty(String propertyName, Integer order) {
52: super ();
53: Assert.notNull(propertyName);
54: Assert.notNull(order);
55: this .propertyName = propertyName;
56: this .order = order;
57: }
58:
59: public int compareTo(OrderedProperty o) {
60: int compareTo = order.compareTo(o.getOrder());
61: if (compareTo == 0) {
62: return propertyName.compareTo(o.getPropertyName());
63: }
64: return compareTo;
65: }
66:
67: public Integer getOrder() {
68: return order;
69: }
70:
71: public String getPropertyName() {
72: return propertyName;
73: }
74:
75: @Override
76: public boolean equals(Object obj) {
77: if (!(obj instanceof OrderedProperty)) {
78: return false;
79: } else {
80: OrderedProperty other = (OrderedProperty) obj;
81: return propertyName.equals(other.getPropertyName());
82: }
83: }
84:
85: @Override
86: public int hashCode() {
87: return propertyName.hashCode();
88: }
89:
90: @Override
91: public String toString() {
92: return propertyName + " (" + order + ")";
93: }
94:
95: }
|