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 26 package 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 */ 35 36 public class Pair 37 { 38 /** The pair name. */ 39 public String name; 40 41 /** The pair value. */ 42 public String value; 43 44 /** The pair numeric value. */ 45 public int num; 46 47 /** The characters of name. */ 48 public char[] chars; 49 50 /** The pair identifier. */ 51 public int id; 52 53 /** The list of associated pairs. */ 54 public Pair list; 55 56 /** The next pair in a chain. */ 57 public Pair next; 58 59 /** 60 * Creates a qualified name string from qualified name. 61 * 62 * @return The qualified name string. 63 */ 64 public String qname() 65 { 66 return new String(chars, 1, chars.length - 1); 67 } 68 69 /** 70 * Creates a local name string from qualified name. 71 * 72 * @return The local name string. 73 */ 74 public String local() 75 { 76 if (chars[0] != 0) { 77 return new String(chars, chars[0] + 1, chars.length - chars[0] - 1); 78 } 79 return new String(chars, 1, chars.length - 1); 80 } 81 82 /** 83 * Creates a prefix string from qualified name. 84 * 85 * @return The prefix string. 86 */ 87 public String pref() 88 { 89 if (chars[0] != 0) { 90 return new String(chars, 1, chars[0] - 1); 91 } 92 return ""; 93 } 94 95 /** 96 * Compares two qualified name prefixes. 97 * 98 * @param qname A qualified name. 99 * @return true if prefixes are equal. 100 */ 101 public boolean eqpref(char[] qname) 102 { 103 if (chars[0] == qname[0]) { 104 char len = chars[0]; 105 for (char i = 1; i < len; i += 1) { 106 if (chars[i] != qname[i]) 107 return false; 108 } 109 return true; 110 } 111 return false; 112 } 113 114 /** 115 * Compares two qualified names. 116 * 117 * @param qname A qualified name. 118 * @return true if qualified names are equal. 119 */ 120 public boolean eqname(char[] qname) 121 { 122 char len = (char)chars.length; 123 if (len == qname.length) { 124 for (char i = 0; i < len; i += 1) { 125 if (chars[i] != qname[i]) 126 return false; 127 } 128 return true; 129 } 130 return false; 131 } 132 }