1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/util/CharArray.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,158 @@ 1.4 +/* 1.5 + * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + * 1.28 + * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC. 1.29 + */ 1.30 + 1.31 +package com.sun.xml.internal.fastinfoset.util; 1.32 + 1.33 +public class CharArray implements CharSequence { 1.34 + public char[] ch; 1.35 + public int start; 1.36 + public int length; 1.37 + 1.38 + protected int _hash; 1.39 + 1.40 + protected CharArray() { 1.41 + } 1.42 + 1.43 + public CharArray(char[] _ch, int _start, int _length, boolean copy) { 1.44 + set(_ch, _start, _length, copy); 1.45 + } 1.46 + 1.47 + public final void set(char[] _ch, int _start, int _length, boolean copy) { 1.48 + if (copy) { 1.49 + ch = new char[_length]; 1.50 + start = 0; 1.51 + length = _length; 1.52 + System.arraycopy(_ch, _start, ch, 0, _length); 1.53 + } else { 1.54 + ch = _ch; 1.55 + start = _start; 1.56 + length = _length; 1.57 + } 1.58 + _hash = 0; 1.59 + } 1.60 + 1.61 + public final void cloneArray() { 1.62 + char[] _ch = new char[length]; 1.63 + System.arraycopy(ch, start, _ch, 0, length); 1.64 + ch = _ch; 1.65 + start = 0; 1.66 + } 1.67 + 1.68 + public String toString() { 1.69 + return new String(ch, start, length); 1.70 + } 1.71 + 1.72 + public int hashCode() { 1.73 + if (_hash == 0) { 1.74 + // Same hash code algorithm as used for String 1.75 + // s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] 1.76 + for (int i = start; i < start + length; i++) { 1.77 + _hash = 31*_hash + ch[i]; 1.78 + } 1.79 + } 1.80 + return _hash; 1.81 + } 1.82 + 1.83 + public static final int hashCode(char[] ch, int start, int length) { 1.84 + // Same hash code algorithm as used for String 1.85 + // s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] 1.86 + int hash = 0; 1.87 + for (int i = start; i < start + length; i++) { 1.88 + hash = 31*hash + ch[i]; 1.89 + } 1.90 + 1.91 + return hash; 1.92 + } 1.93 + 1.94 + public final boolean equalsCharArray(CharArray cha) { 1.95 + if (this == cha) { 1.96 + return true; 1.97 + } 1.98 + 1.99 + if (length == cha.length) { 1.100 + int n = length; 1.101 + int i = start; 1.102 + int j = cha.start; 1.103 + while (n-- != 0) { 1.104 + if (ch[i++] != cha.ch[j++]) 1.105 + return false; 1.106 + } 1.107 + return true; 1.108 + } 1.109 + 1.110 + return false; 1.111 + } 1.112 + 1.113 + public final boolean equalsCharArray(char[] ch, int start, int length) { 1.114 + if (this.length == length) { 1.115 + int n = this.length; 1.116 + int i = this.start; 1.117 + int j = start; 1.118 + while (n-- != 0) { 1.119 + if (this.ch[i++] != ch[j++]) 1.120 + return false; 1.121 + } 1.122 + return true; 1.123 + } 1.124 + 1.125 + return false; 1.126 + } 1.127 + 1.128 + public boolean equals(Object obj) { 1.129 + if (this == obj) { 1.130 + return true; 1.131 + } 1.132 + if (obj instanceof CharArray) { 1.133 + CharArray cha = (CharArray)obj; 1.134 + if (length == cha.length) { 1.135 + int n = length; 1.136 + int i = start; 1.137 + int j = cha.start; 1.138 + while (n-- != 0) { 1.139 + if (ch[i++] != cha.ch[j++]) 1.140 + return false; 1.141 + } 1.142 + return true; 1.143 + } 1.144 + } 1.145 + return false; 1.146 + } 1.147 + 1.148 + // CharSequence interface 1.149 + 1.150 + public final int length() { 1.151 + return length; 1.152 + } 1.153 + 1.154 + public final char charAt(int index) { 1.155 + return ch[start + index]; 1.156 + } 1.157 + 1.158 + public final CharSequence subSequence(int start, int end) { 1.159 + return new CharArray(ch, this.start + start, end - start, false); 1.160 + } 1.161 +}