1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.directory.server.core.splay; 21 22 23 /** 24 * A linked binary tree node. 25 * 26 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 27 * @version $Rev$, $Date$ 28 */ 29 public class LinkedBinaryNode<T> 30 { 31 T key; // The data in the node 32 LinkedBinaryNode<T> left; // Left child 33 LinkedBinaryNode<T> right; // Right child 34 LinkedBinaryNode<T> next; 35 LinkedBinaryNode<T> previous; 36 37 transient int depth; 38 39 LinkedBinaryNode( T theKey ) 40 { 41 key = theKey; 42 left = right = null; 43 } 44 45 46 public LinkedBinaryNode<T> getLeft() { 47 return left; 48 } 49 50 51 public LinkedBinaryNode<T> getRight() { 52 return right; 53 } 54 55 public T getKey() { 56 return key; 57 } 58 59 public boolean isLeaf() 60 { 61 return ( right == null && left == null ); 62 } 63 64 /** 65 * This method is used for internal purpose only while pretty printing the tree.<br> 66 * @return the depth at the this node 67 */ 68 public int getDepth() { 69 return depth; 70 } 71 72 /** 73 * This method is used for internal purpose only while pretty printing the tree.<br> 74 * @param depth value representing the depth of the this node 75 */ 76 public void setDepth( int depth ) { 77 this.depth = depth; 78 } 79 80 @Override 81 public String toString() { 82 return "[" + key + "]"; 83 } 84 85 86 }