001: /*
002: * $Id: LongValue.java 457783 2005-10-02 10:06:33Z jcompagner $ $Revision:
003: * 1.4 $ $Date: 2005-10-02 12:06:33 +0200 (Sun, 02 Oct 2005) $
004: *
005: * ==============================================================================
006: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
007: * use this file except in compliance with the License. You may obtain a copy of
008: * the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
014: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015: * License for the specific language governing permissions and limitations under
016: * the License.
017: */
018: package wicket.util.value;
019:
020: import java.io.Serializable;
021:
022: import wicket.util.lang.Primitives;
023:
024: /**
025: * A base class for value classes based on a Java long primitive which want to
026: * implement standard operations on that value without the pain of aggregating a
027: * Long object.
028: *
029: * @author Jonathan Locke
030: */
031: public class LongValue implements Comparable, Serializable {
032: private static final long serialVersionUID = 1L;
033:
034: /** The long value */
035: protected final long value;
036:
037: /**
038: * Constructor
039: *
040: * @param value
041: * The long value
042: */
043: public LongValue(final long value) {
044: this .value = value;
045: }
046:
047: /**
048: * @param object
049: * The object to compare with
050: * @return 0 if equal, -1 if less than or 1 if greater than
051: */
052: public final int compareTo(final Object object) {
053: final LongValue that = (LongValue) object;
054:
055: if (this .value < that.value) {
056: return -1;
057: }
058:
059: if (this .value > that.value) {
060: return 1;
061: }
062:
063: return 0;
064: }
065:
066: /**
067: * @param that
068: * The value to compare against
069: * @return True if this value is equal to that value
070: */
071: public final boolean equals(final Object that) {
072: if (that instanceof LongValue) {
073: return this .value == ((LongValue) that).value;
074: }
075:
076: return false;
077: }
078:
079: /**
080: * @param value
081: * The value to compare against
082: * @return True if this value is greater than the given value
083: */
084: public final boolean greaterThan(final long value) {
085: return this .value > value;
086: }
087:
088: /**
089: * @param that
090: * The value to compare against
091: * @return True if this value is greater than that value
092: */
093: public final boolean greaterThan(final LongValue that) {
094: return this .value > that.value;
095: }
096:
097: /**
098: * @return Hashcode for this object
099: */
100: public final int hashCode() {
101: return Primitives.hashCode(value);
102: }
103:
104: /**
105: * @param that
106: * The value to compare against
107: * @return True if this value is less than that value
108: */
109: public final boolean lessThan(final long that) {
110: return this .value < that;
111: }
112:
113: /**
114: * @param that
115: * The value to compare against
116: * @return True if this value is less than that value
117: */
118: public final boolean lessThan(final LongValue that) {
119: return this .value < that.value;
120: }
121:
122: /**
123: * Converts this value to a string
124: *
125: * @return The string for this value
126: */
127: public String toString() {
128: return String.valueOf(value);
129: }
130: }
|