LongRecordLocation xref

View Javadoc

    1   /***
    2    *
    3    * Copyright 2004 Hiram Chirino
    4    *
    5    * Licensed under the Apache License, Version 2.0 (the "License");
    6    * you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    * 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   **/
    18  package org.activeio.journal.howl;
    19
    20  import org.activeio.journal.RecordLocation;
    21
    22  /***
    23   * Provides a RecordLocation implementation for the long based
    24   * location pointers that HOWL uses.
    25   *
    26   * @version $Revision: 1.1 $
    27   */
    28  public class LongRecordLocation implements RecordLocation {
    29
    30  	final private long location;
    31
    32  	public LongRecordLocation(long l) {
    33  		this.location = l;
    34  	}
    35
    36  	/***
    37  	 * @see java.lang.Comparable#compareTo(java.lang.Object)
    38  	 */
    39  	public int compareTo(Object o) {
    40  		return (int) (location - ((LongRecordLocation) o).location);
    41  	}
    42
    43  	/***
    44  	 * @return the original long location provided by HOWL
    45  	 */
    46  	public long getLongLocation() {
    47  		return location;
    48  	}
    49
    50  	/***
    51  	 * @see java.lang.Object#hashCode()
    52  	 */
    53  	public int hashCode() {
    54  		int lowPart = (int) (0xFFFFFFFF & location);
    55  		int highPart = (int) (0xFFFFFFFF & (location >> 4));
    56  		return lowPart ^ highPart;
    57  	}
    58
    59  	/***
    60  	 * @see java.lang.Object#equals(java.lang.Object)
    61  	 */
    62  	public boolean equals(Object o) {
    63  		if (o == null || o.getClass() != LongRecordLocation.class)
    64  			return false;
    65  		return ((LongRecordLocation) o).location == location;
    66  	}
    67
    68  	/***
    69  	 * @see java.lang.Object#toString()
    70  	 */
    71  	public String toString() {
    72  		return "0x" + Long.toHexString(location);
    73  	}
    74  }