Home » activemq-parent-5.3.1-source-release » org.apache » activemq » kaha » impl » index » tree » [javadoc | source]

    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  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   package org.apache.activemq.kaha.impl.index.tree;
   18   
   19   import java.io.DataInput;
   20   import java.io.DataOutput;
   21   import java.io.IOException;
   22   import org.apache.activemq.kaha.Marshaller;
   23   
   24   /**
   25    * Key and index for a BTree
   26    * 
   27    * @version $Revision: 1.1.1.1 $
   28    */
   29   class TreeEntry implements Comparable {
   30   
   31       static final int NOT_SET = -1;
   32       private Comparable key;
   33       private long indexOffset;
   34       private long prevPageId = NOT_SET;
   35       private long nextPageId = NOT_SET;
   36   
   37       public int compareTo(Object o) {
   38           if (o instanceof TreeEntry) {
   39               TreeEntry other = (TreeEntry)o;
   40               return key.compareTo(other.key);
   41           } else {
   42               return key.compareTo(o);
   43           }
   44       }
   45   
   46       public boolean equals(Object o) {
   47           return compareTo(o) == 0;
   48       }
   49   
   50       public int hashCode() {
   51           return key.hashCode();
   52       }
   53   
   54       public String toString() {
   55           return "TreeEntry(" + key + "," + indexOffset + ")prev=" + prevPageId + ",next=" + nextPageId;
   56       }
   57   
   58       void reset() {
   59           prevPageId = NOT_SET;
   60           nextPageId = NOT_SET;
   61       }
   62   
   63       TreeEntry copy() {
   64           TreeEntry copy = new TreeEntry();
   65           copy.key = this.key;
   66           copy.indexOffset = this.indexOffset;
   67           copy.prevPageId = this.prevPageId;
   68           copy.nextPageId = this.nextPageId;
   69           return copy;
   70       }
   71   
   72       /**
   73        * @return the key
   74        */
   75       Comparable getKey() {
   76           return this.key;
   77       }
   78   
   79       /**
   80        * @param key the key to set
   81        */
   82       void setKey(Comparable key) {
   83           this.key = key;
   84       }
   85   
   86       /**
   87        * @return the nextPageId
   88        */
   89       long getNextPageId() {
   90           return this.nextPageId;
   91       }
   92   
   93       /**
   94        * @param nextPageId the nextPageId to set
   95        */
   96       void setNextPageId(long nextPageId) {
   97           this.nextPageId = nextPageId;
   98       }
   99   
  100       /**
  101        * @return the prevPageId
  102        */
  103       long getPrevPageId() {
  104           return this.prevPageId;
  105       }
  106   
  107       /**
  108        * @param prevPageId the prevPageId to set
  109        */
  110       void setPrevPageId(long prevPageId) {
  111           this.prevPageId = prevPageId;
  112       }
  113   
  114       /**
  115        * @return the indexOffset
  116        */
  117       long getIndexOffset() {
  118           return this.indexOffset;
  119       }
  120   
  121       /**
  122        * @param indexOffset the indexOffset to set
  123        */
  124       void setIndexOffset(long indexOffset) {
  125           this.indexOffset = indexOffset;
  126       }
  127   
  128       boolean hasChildPagesReferences() {
  129           return prevPageId != NOT_SET || nextPageId != NOT_SET;
  130       }
  131   
  132       void write(Marshaller keyMarshaller, DataOutput dataOut) throws IOException {
  133           keyMarshaller.writePayload(key, dataOut);
  134           dataOut.writeLong(indexOffset);
  135           dataOut.writeLong(nextPageId);
  136           dataOut.writeLong(prevPageId);
  137       }
  138   
  139       void read(Marshaller keyMarshaller, DataInput dataIn) throws IOException {
  140           key = (Comparable)keyMarshaller.readPayload(dataIn);
  141           indexOffset = dataIn.readLong();
  142           nextPageId = dataIn.readLong();
  143           prevPageId = dataIn.readLong();
  144       }
  145   
  146   }

Home » activemq-parent-5.3.1-source-release » org.apache » activemq » kaha » impl » index » tree » [javadoc | source]