1/* 2 * Copyright (c) 2012, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26package jdk.internal.util.xml.impl; 27 28 29/** 30 * A name with value pair. 31 * 32 * This class keeps name with value pair with additional information and 33 * supports pair chaining. 34 */ 35public class Pair { 36 37 /** The pair name. */ 38 public String name; 39 /** The pair value. */ 40 public String value; 41 /** The pair numeric value. */ 42 public int num; 43 /** The characters of name. */ 44 public char[] chars; 45 /** The pair identifier. */ 46 public int id; 47 /** The list of associated pairs. */ 48 public Pair list; 49 /** The next pair in a chain. */ 50 public Pair next; 51 52 /** 53 * Creates a qualified name string from qualified name. 54 * 55 * @return The qualified name string. 56 */ 57 public String qname() { 58 return new String(chars, 1, chars.length - 1); 59 } 60 61 /** 62 * Creates a local name string from qualified name. 63 * 64 * @return The local name string. 65 */ 66 public String local() { 67 if (chars[0] != 0) { 68 return new String(chars, chars[0] + 1, chars.length - chars[0] - 1); 69 } 70 return new String(chars, 1, chars.length - 1); 71 } 72 73 /** 74 * Creates a prefix string from qualified name. 75 * 76 * @return The prefix string. 77 */ 78 public String pref() { 79 if (chars[0] != 0) { 80 return new String(chars, 1, chars[0] - 1); 81 } 82 return ""; 83 } 84 85 /** 86 * Compares two qualified name prefixes. 87 * 88 * @param qname A qualified name. 89 * @return true if prefixes are equal. 90 */ 91 public boolean eqpref(char[] qname) { 92 if (chars[0] == qname[0]) { 93 char len = chars[0]; 94 for (char i = 1; i < len; i += 1) { 95 if (chars[i] != qname[i]) { 96 return false; 97 } 98 } 99 return true; 100 } 101 return false; 102 } 103 104 /** 105 * Compares two qualified names. 106 * 107 * @param qname A qualified name. 108 * @return true if qualified names are equal. 109 */ 110 public boolean eqname(char[] qname) { 111 char len = (char) chars.length; 112 if (len == qname.length) { 113 for (char i = 0; i < len; i += 1) { 114 if (chars[i] != qname[i]) { 115 return false; 116 } 117 } 118 return true; 119 } 120 return false; 121 } 122} 123