1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21/* 22 * 23 * ident "%Z%%M% %I% %E% SMI" 24 * 25 * Copyright (c) 1999 by Sun Microsystems, Inc. 26 * All rights reserved. 27 * 28 * BSTItem.java 29 * Simple binary search tree implementation for help articles 30 */ 31 32package com.sun.admin.pm.client; 33 34import java.lang.*; 35import com.sun.admin.pm.server.*; 36 37public class BSTItem extends Object { 38 public String key; 39 public Object data; 40 public int handle = UNINITIALIZED; 41 42 static int serial = 0; 43 static final int UNINITIALIZED = -1; 44 45 public BSTItem(String newKey) { 46 this(newKey, null); 47 } 48 49 public BSTItem(String newKey, Object obj) { 50 key = newKey.toLowerCase(); 51 data = obj; 52 handle = serial++; 53 } 54 55 public String toString() { 56 return new String("Item " + key + " (" + handle + ")"); 57 } 58 59 public int compare(BSTItem otherItem, boolean exact) { 60 61 return compare(otherItem.key, exact); 62 } 63 64 65 public int compare(BSTItem otherItem) { 66 return compare(otherItem, true); 67 } 68 69 public int compare(String otherKey) { 70 return compare(otherKey, true); 71 } 72 73 74 public int compare(String otherKey, boolean exact) { 75 76 /* 77 * System.out.println(this.toString() + " comparing " + 78 * (exact ? "exact" : "partial") + " to " + otherKey); 79 */ 80 81 int rv = 0; 82 83 if (otherKey != null && otherKey != "") 84 rv = exact ? 85 key.compareTo(otherKey) : 86 compareSub(otherKey.toLowerCase()); 87 88 /* 89 * System.out.println( 90 * "Compare: " + key + " to " + otherKey + " -> " + rv); 91 */ 92 93 return rv; 94 } 95 96 97 public int compareSub(String s) { 98 Debug.info("HELP: compareSub: " + key + " to " + s); 99 100 int rv = 0; 101 try { 102 rv = key.substring(0, s.length()).compareTo(s); 103 } catch (Exception x) { 104 Debug.info("HELP: compareSub caught: " + x); 105 rv = -1; 106 } 107 return rv; 108 } 109} 110