1 /* 2 * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package jit.graph; 24 25 import nsk.share.TestFailure; 26 // This class define the tree node. 27 28 public class Node 29 { 30 public final static int Black = 0; // constants used to define the 31 public final static int Red = 1; // node color 32 public final static int Left_son = 2; // constants used to identify 33 public final static int Right_son = 3;// the node parent and sons. 34 public final static int Parent = 4; 35 36 37 private int color; 38 private int key; 39 private Node L,R,P; // L-left son,R-right son,P-parent 40 41 // constructor create a new node the default color is red 42 // the default appearance (bold) is regular. 43 // initialize the key field. 44 45 public Node(int k) 46 { 47 color = Red; 48 key = k; 49 L = null; 50 R = null; 51 P = null; 52 } 53 54 // constructor for constructing a tree null object, is color 55 // is black. 56 57 public Node() 58 { 59 color = Black; 60 key = -1; 61 L = null; 62 R = null; 63 P = null; 64 } 65 66 // This method set the node key. 67 68 public void setKey(int k) 69 { 70 key = k; 71 } 72 73 // This method return the node key. 74 75 public int getKey() 76 { 77 return (key); 78 } 79 80 // This method set the node color. 81 82 public void setColor(int c) 83 { 84 if (c == Black) 85 color = Black; 86 else 87 if (c == Red) 88 color = Red; 89 } 90 91 // This method return the node color. 92 93 public int getColor() 94 { 95 return (color); 96 } 97 98 // This method set the node parent or childs acording to the who 99 // parameter. 100 101 public void setNode(int who,Node n) 102 { 103 switch (who) 104 { 105 case Left_son: 106 L = n; 107 break; 108 case Right_son: 109 R = n; 110 break; 111 case Parent: 112 P = n; 113 break; 114 } 115 } 116 117 // This method return the node parent or childs acording to the who 118 // parameter. 119 120 public Node getNode(int who) 121 { 122 switch (who) 123 { 124 case Left_son: 125 return (L); 126 case Right_son: 127 return (R); 128 case Parent: 129 return (P); 130 } 131 return (null); 132 } 133 }