author | shade |
Fri, 20 Feb 2015 18:32:10 +0300 | |
changeset 29094 | a4fd2b5e49f8 |
parent 6314 | 8ab691ddb904 |
permissions | -rw-r--r-- |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1 |
/* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
10 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
15 |
* accompanied this code). |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
16 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
20 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
23 |
* questions. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
24 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
25 |
package xmlkit; // -*- mode: java; indent-tabs-mode: nil -*- |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
26 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
27 |
// XML Implementation packages: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
28 |
import java.util.*; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
29 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
30 |
import java.io.Reader; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
31 |
import java.io.Writer; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
32 |
import java.io.OutputStream; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
33 |
import java.io.InputStreamReader; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
34 |
import java.io.OutputStreamWriter; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
35 |
import java.io.BufferedReader; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
36 |
import java.io.PrintWriter; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
37 |
import java.io.StringWriter; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
38 |
import java.io.StringReader; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
39 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
40 |
import java.io.IOException; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
41 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
42 |
import org.xml.sax.XMLReader; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
43 |
import org.xml.sax.InputSource; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
44 |
import org.xml.sax.ContentHandler; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
45 |
import org.xml.sax.SAXException; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
46 |
import org.xml.sax.SAXParseException; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
47 |
import org.xml.sax.Attributes; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
48 |
import org.xml.sax.ext.LexicalHandler; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
49 |
import org.xml.sax.helpers.AttributesImpl; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
50 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
51 |
/** |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
52 |
* A kit of methods and classes useful for manipulating XML trees in |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
53 |
* memory. They are very compact and easy to use. An XML element |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
54 |
* occupies six pointers of overhead (like two arrays) plus a pointer |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
55 |
* for its name, each attribute name and value, and each sub-element. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
56 |
* Many useful XML operations (or Lisp-like calls) can be accomplished |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
57 |
* with a single method call on an element itself. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
58 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
59 |
* There is strong integration with the Java collection classes. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
60 |
* There are viewing and conversion operators to and from various |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
61 |
* collection types. Elements directly support list iterators. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
62 |
* Most <tt>List</tt> methods work analogously on elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
63 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
64 |
* Because of implementation compromises, these XML trees are less |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
65 |
* functional than many standard XML classes. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
66 |
* <ul> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
67 |
* <li>There are no parent or sibling pointers in the tree.</li> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
68 |
* <li>Attribute names are simple strings, with no namespaces.</li> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
69 |
* <li>There is no internal support for schemas or validation.</li> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
70 |
* </ul> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
71 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
72 |
* Here is a summary of functionality in <tt>XMLKit</tt>. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
73 |
* (Overloaded groups of methods are summarized by marking some |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
74 |
* arguments optional with their default values. Some overloaded |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
75 |
* arguments are marked with their alternative types separated by |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
76 |
* a bar "|". Arguments or return values for which a null is |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
77 |
* specially significant are marked by an alternative "|null". |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
78 |
* Accessors which have corresponding setters are marked |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
79 |
* by "/set". Removers which have corresponding retainers are marked |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
80 |
* by "/retain".) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
81 |
* <pre> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
82 |
* --- element construction |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
83 |
* new Element(int elemCapacity=4), String name="" |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
84 |
* new Element(String name, String[] attrs={}, Element[] elems={}, int elemCapacity=4) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
85 |
* new Element(String name, String[] attrs, Object[] elems, int elemCapacity=4) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
86 |
* new Element(Element original) // shallow copy |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
87 |
* new Element(String name="", Collection elems) // coercion |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
88 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
89 |
* Element shallowCopy() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
90 |
* Element shallowFreeze() // side-effecting |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
91 |
* Element deepCopy() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
92 |
* Element deepFreeze() // not side-effecting |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
93 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
94 |
* EMPTY // frozen empty anonymous element |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
95 |
* void ensureExtraCapacity(int) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
96 |
* void trimToSize() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
97 |
* void sortAttrs() // sort by key |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
98 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
99 |
* --- field accessors |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
100 |
* String getName()/set |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
101 |
* int size() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
102 |
* boolean isEmpty() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
103 |
* boolean isFrozen() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
104 |
* boolean isAnonymous() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
105 |
* int getExtraCapacity()/set |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
106 |
* int attrSize() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
107 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
108 |
* --- attribute accessors |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
109 |
* String getAttr(int i)/set |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
110 |
* String getAttrName(int i) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
111 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
112 |
* String getAttr(String key)/set |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
113 |
* List getAttrList(String key)/set |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
114 |
* Number getAttrNumber(String key)/set |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
115 |
* long getAttrLong(String key)/set |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
116 |
* double getAttrDouble(String key)/set |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
117 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
118 |
* String getAttr(String key, String dflt=null) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
119 |
* long getAttrLong(String key, long dflt=0) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
120 |
* double getAttrDouble(String key, double dflt=0) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
121 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
122 |
* Element copyAttrsOnly() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
123 |
* Element getAttrs()/set => <em><><key>value</key>...</></em> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
124 |
* void addAttrs(Element attrs) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
125 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
126 |
* void removeAttr(int i) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
127 |
* void clearAttrs() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
128 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
129 |
* --- element accessors |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
130 |
* Object get(int i)/set |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
131 |
* Object getLast() | null |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
132 |
* Object[] toArray() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
133 |
* Element copyContentOnly() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
134 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
135 |
* void add(int i=0, Object subElem) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
136 |
* int addAll(int i=0, Collection | Element elems) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
137 |
* int addContent(int i=0, TokenList|Element|Object|null) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
138 |
* void XMLKit.addContent(TokenList|Element|Object|null, Collection sink|null) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
139 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
140 |
* void clear(int beg=0, int end=size) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
141 |
* void sort(Comparator=contentOrder()) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
142 |
* void reverse() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
143 |
* void shuffle(Random rnd=(anonymous)) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
144 |
* void rotate(int distance) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
145 |
* Object min/max(Comparator=contentOrder()) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
146 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
147 |
* --- text accessors |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
148 |
* CharSequence getText()/set |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
149 |
* CharSequence getUnmarkedText() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
150 |
* int addText(int i=size, CharSequence) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
151 |
* void trimText(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
152 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
153 |
* --- views |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
154 |
* List asList() // element view |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
155 |
* ListIterator iterator() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
156 |
* PrintWriter asWriter() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
157 |
* Map asAttrMap() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
158 |
* Iterable<CharSequence> texts() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
159 |
* Iterable<Element> elements() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
160 |
* Iterable<T> partsOnly(Class<T>) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
161 |
* String[] toStrings() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
162 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
163 |
* --- queries |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
164 |
* boolean equals(Element | Object) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
165 |
* int compareTo(Element | Object) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
166 |
* boolean equalAttrs(Element) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
167 |
* int hashCode() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
168 |
* boolean isText() // every sub-elem is CharSequence |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
169 |
* boolean hasText() // some sub-elem is CharSequence |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
170 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
171 |
* boolean contains(Object) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
172 |
* boolean containsAttr(String) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
173 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
174 |
* int indexOf(Object) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
175 |
* int indexOf(Filter, int fromIndex=0) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
176 |
* int lastIndexOf(Object) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
177 |
* int lastIndexOf(Filter, int fromIndex=size-1) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
178 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
179 |
* int indexOfAttr(String) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
180 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
181 |
* // finders, removers, and replacers do addContent of each filtered value |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
182 |
* // (i.e., TokenLists and anonymous Elements are broken out into their parts) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
183 |
* boolean matches(Filter) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
184 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
185 |
* Object find(Filter, int fromIndex=0) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
186 |
* Object findLast(Filter, int fromIndex=size-1) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
187 |
* Element findAll(Filter, int fromIndex=0 & int toIndex=size) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
188 |
* int findAll(Filter, Collection sink | null, int fromIndex=0 & int toIndex=size) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
189 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
190 |
* Element removeAllInTree(Filter)/retain |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
191 |
* int findAllInTree(Filter, Collection sink | null) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
192 |
* int countAllInTree(Filter) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
193 |
* Element removeAllInTree(Filter)/retain |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
194 |
* int removeAllInTree(Filter, Collection sink | null)/retain |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
195 |
* void replaceAllInTree(Filter) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
196 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
197 |
* Element findElement(String name=any) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
198 |
* Element findAllElements(String name=any) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
199 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
200 |
* Element findWithAttr(String key, String value=any) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
201 |
* Element findAllWithAttr(String key, String value=any) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
202 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
203 |
* Element removeElement(String name=any) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
204 |
* Element removeAllElements(String name=any)/retain |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
205 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
206 |
* Element removeWithAttr(String key, String value=any) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
207 |
* Element removeAllWithAttr(String key, String value=any)/retain |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
208 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
209 |
* //countAll is the same as findAll but with null sink |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
210 |
* int countAll(Filter) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
211 |
* int countAllElements(String name=any) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
212 |
* int countAllWithAttr(String key, String value=any) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
213 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
214 |
* void replaceAll(Filter, int fromIndex=0 & int toIndex=size) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
215 |
* void replaceAllInTree(Filter) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
216 |
* void XMLKit.replaceAll(Filter, List target) //if(fx){remove x;addContent fx} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
217 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
218 |
* --- element mutators |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
219 |
* boolean remove(Object) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
220 |
* Object remove(int) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
221 |
* Object removeLast() | null |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
222 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
223 |
* Object remove(Filter, int fromIndex=0) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
224 |
* Object removeLast(Filter, int fromIndex=size-1) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
225 |
* Element sink = removeAll(Filter, int fromIndex=0 & int toIndex=size)/retain |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
226 |
* int count = removeAll(Filter, int fromIndex=0 & int toIndex=size, Collection sink | null)/retain |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
227 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
228 |
* Element removeAllElements(String name=any) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
229 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
230 |
* --- attribute mutators |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
231 |
* ??int addAllAttrsFrom(Element attrSource) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
232 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
233 |
* --- parsing and printing |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
234 |
* void tokenize(String delims=whitespace, returnDelims=false) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
235 |
* void writeTo(Writer) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
236 |
* void writePrettyTo(Writer) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
237 |
* String prettyString() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
238 |
* String toString() |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
239 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
240 |
* ContentHandler XMLKit.makeBuilder(Collection sink, tokenizing=false, makeFrozen=false) // for standard XML parser |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
241 |
* Element XMLKit.readFrom(Reader, tokenizing=false, makeFrozen=false) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
242 |
* void XMLKit.prettyPrintTo(Writer | OutputStream, Element) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
243 |
* class XMLKit.Printer(Writer) { void print/Recursive(Element) } |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
244 |
* void XMLKit.output(Object elem, ContentHandler, LexicalHandler=null) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
245 |
* void XMLKit.writeToken(String, char quote, Writer) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
246 |
* void XMLKit.writeCData(String, Writer) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
247 |
* Number XMLKit.convertToNumber(String, Number dflt=null) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
248 |
* long XMLKit.convertToLong(String, long dflt=0) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
249 |
* double XMLKit.convertToDouble(String, double dflt=0) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
250 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
251 |
* --- filters |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
252 |
* XMLKit.ElementFilter { Element filter(Element) } |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
253 |
* XMLKit.elementFilter(String name=any | Collection nameSet) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
254 |
* XMLKit.AttrFilter(String key) { boolean test(String value) } |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
255 |
* XMLKit.attrFilter(String key, String value=any) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
256 |
* XMLKit.attrFilter(Element matchThis, String key) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
257 |
* XMLKit.classFilter(Class) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
258 |
* XMLKit.textFilter() // matches any CharSequence |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
259 |
* XMLKit.specialFilter() // matches any Special element |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
260 |
* XMLKit.methodFilter(Method m, Object[] args=null, falseResult=null) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
261 |
* XMLKit.testMethodFilter(Method m, Object[] args=null) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
262 |
* XMLKit.not(Filter) // inverts sense of Filter |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
263 |
* XMLKit.and(Filter&Filter | Filter[]) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
264 |
* XMLKit.or(Filter&Filter | Filter[]) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
265 |
* XMLKit.stack(Filter&Filter | Filter[]) // result is (fx && g(fx)) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
266 |
* XMLKit.content(Filter, Collection sink) // copies content to sink |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
267 |
* XMLKit.replaceInTree(Filter pre, Filter post=null) // pre-replace else recur |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
268 |
* XMLKit.findInTree(Filter pre, Collection sink=null) // pre-find else recur |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
269 |
* XMLKit.nullFilter() // ignores input, always returns null (i.e., false) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
270 |
* XMLKit.selfFilter( ) // always returns input (i.e., true) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
271 |
* XMLKit.emptyFilter() // ignores input, always returns EMPTY |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
272 |
* XMLKit.constantFilter(Object) // ignores input, always returns constant |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
273 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
274 |
* --- misc |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
275 |
* Comparator XMLKit.contentOrder() // for comparing/sorting mixed content |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
276 |
* Method XMLKit.Element.method(String name) // returns Element method |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
277 |
* </pre> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
278 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
279 |
* @author jrose |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
280 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
281 |
public abstract class XMLKit { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
282 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
283 |
private XMLKit() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
284 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
285 |
// We need at least this much slop if the element is to stay unfrozen. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
286 |
static final int NEED_SLOP = 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
287 |
static final Object[] noPartsFrozen = {}; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
288 |
static final Object[] noPartsNotFrozen = new Object[NEED_SLOP]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
289 |
static final String WHITESPACE_CHARS = " \t\n\r\f"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
290 |
static final String ANON_NAME = new String("*"); // unique copy of "*" |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
291 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
292 |
public static final class Element implements Comparable<Element>, Iterable<Object> { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
293 |
// Note: Does not implement List, because it has more |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
294 |
// significant parts besides its sub-elements. Therefore, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
295 |
// hashCode and equals must be more distinctive than Lists. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
296 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
297 |
// <name> of element |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
298 |
String name; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
299 |
// number of child elements, in parts[0..size-1] |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
300 |
int size; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
301 |
// The parts start with child elements:: {e0, e1, e2, ...}. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
302 |
// Following that are optional filler elements, all null. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
303 |
// Following that are attributes as key/value pairs. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
304 |
// They are in reverse: {...key2, val2, key1, val1, key0, val0}. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
305 |
// Child elements and attr keys and values are never null. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
306 |
Object[] parts; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
307 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
308 |
// Build a partially-constructed node. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
309 |
// Caller is responsible for initializing promised attributes. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
310 |
Element(String name, int size, int capacity) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
311 |
this.name = name.toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
312 |
this.size = size; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
313 |
assert (size <= capacity); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
314 |
this.parts = capacity > 0 ? new Object[capacity] : noPartsFrozen; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
315 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
316 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
317 |
/** An anonymous, empty element. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
318 |
* Optional elemCapacity argument is expected number of sub-elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
319 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
320 |
public Element() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
321 |
this(ANON_NAME, 0, NEED_SLOP + 4); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
322 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
323 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
324 |
public Element(int extraCapacity) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
325 |
this(ANON_NAME, 0, NEED_SLOP + Math.max(0, extraCapacity)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
326 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
327 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
328 |
/** An empty element with the given name. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
329 |
* Optional extraCapacity argument is expected number of sub-elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
330 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
331 |
public Element(String name) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
332 |
this(name, 0, NEED_SLOP + 4); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
333 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
334 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
335 |
public Element(String name, int extraCapacity) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
336 |
this(name, 0, NEED_SLOP + Math.max(0, extraCapacity)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
337 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
338 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
339 |
/** An empty element with the given name and attributes. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
340 |
* Optional extraCapacity argument is expected number of sub-elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
341 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
342 |
public Element(String name, String... attrs) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
343 |
this(name, attrs, (Element[]) null, 0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
344 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
345 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
346 |
public Element(String name, String[] attrs, int extraCapacity) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
347 |
this(name, attrs, (Element[]) null, extraCapacity); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
348 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
349 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
350 |
/** An empty element with the given name and sub-elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
351 |
* Optional extraCapacity argument is expected extra sub-elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
352 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
353 |
public Element(String name, Element... elems) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
354 |
this(name, (String[]) null, elems, 0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
355 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
356 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
357 |
public Element(String name, Element[] elems, int extraCapacity) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
358 |
this(name, (String[]) null, elems, extraCapacity); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
359 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
360 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
361 |
/** An empty element with the given name, attributes, and sub-elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
362 |
* Optional extraCapacity argument is expected extra sub-elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
363 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
364 |
public Element(String name, String[] attrs, Object... elems) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
365 |
this(name, attrs, elems, 0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
366 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
367 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
368 |
public Element(String name, String[] attrs, Object[] elems, int extraCapacity) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
369 |
this(name, 0, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
370 |
((elems == null) ? 0 : elems.length) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
371 |
+ Math.max(0, extraCapacity) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
372 |
+ NEED_SLOP |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
373 |
+ ((attrs == null) ? 0 : attrs.length)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
374 |
int ne = ((elems == null) ? 0 : elems.length); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
375 |
int na = ((attrs == null) ? 0 : attrs.length); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
376 |
int fillp = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
377 |
for (int i = 0; i < ne; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
378 |
if (elems[i] != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
379 |
parts[fillp++] = elems[i]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
380 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
381 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
382 |
size = fillp; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
383 |
for (int i = 0; i < na; i += 2) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
384 |
setAttr(attrs[i + 0], attrs[i + 1]); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
385 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
386 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
387 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
388 |
public Element(Collection c) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
389 |
this(c.size()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
390 |
addAll(c); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
391 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
392 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
393 |
public Element(String name, Collection c) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
394 |
this(name, c.size()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
395 |
addAll(c); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
396 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
397 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
398 |
/** Shallow copy. Same as old.shallowCopy(). |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
399 |
* Optional extraCapacity argument is expected extra sub-elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
400 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
401 |
public Element(Element old) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
402 |
this(old, 0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
403 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
404 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
405 |
public Element(Element old, int extraCapacity) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
406 |
this(old.name, old.size, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
407 |
old.size |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
408 |
+ Math.max(0, extraCapacity) + NEED_SLOP |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
409 |
+ old.attrLength()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
410 |
// copy sub-elements |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
411 |
System.arraycopy(old.parts, 0, parts, 0, size); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
412 |
int alen = parts.length |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
413 |
- (size + Math.max(0, extraCapacity) + NEED_SLOP); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
414 |
// copy attributes |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
415 |
System.arraycopy(old.parts, old.parts.length - alen, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
416 |
parts, parts.length - alen, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
417 |
alen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
418 |
assert (!isFrozen()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
419 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
420 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
421 |
/** Shallow copy. Same as new Element(this). */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
422 |
public Element shallowCopy() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
423 |
return new Element(this); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
424 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
425 |
static public final Element EMPTY = new Element(ANON_NAME, 0, 0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
426 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
427 |
Element deepFreezeOrCopy(boolean makeFrozen) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
428 |
if (makeFrozen && isFrozen()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
429 |
return this; // no need to copy it |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
430 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
431 |
int alen = attrLength(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
432 |
int plen = size + (makeFrozen ? 0 : NEED_SLOP) + alen; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
433 |
Element copy = new Element(name, size, plen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
434 |
// copy attributes |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
435 |
System.arraycopy(parts, parts.length - alen, copy.parts, plen - alen, alen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
436 |
// copy sub-elements |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
437 |
for (int i = 0; i < size; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
438 |
Object e = parts[i]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
439 |
String str; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
440 |
if (e instanceof Element) { // recursion is common case |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
441 |
e = ((Element) e).deepFreezeOrCopy(makeFrozen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
442 |
} else if (makeFrozen) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
443 |
// Freeze StringBuffers, etc. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
444 |
e = fixupString(e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
445 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
446 |
copy.setRaw(i, e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
447 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
448 |
return copy; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
449 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
450 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
451 |
/** Returns new Element(this), and also recursively copies sub-elements. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
452 |
public Element deepCopy() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
453 |
return deepFreezeOrCopy(false); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
454 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
455 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
456 |
/** Returns frozen version of deepCopy. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
457 |
public Element deepFreeze() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
458 |
return deepFreezeOrCopy(true); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
459 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
460 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
461 |
/** Freeze this element. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
462 |
* Throw an IllegalArgumentException if any sub-element is not already frozen. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
463 |
* (Use deepFreeze() to make a frozen copy of an entire element tree.) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
464 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
465 |
public void shallowFreeze() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
466 |
if (isFrozen()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
467 |
return; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
468 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
469 |
int alen = attrLength(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
470 |
Object[] nparts = new Object[size + alen]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
471 |
// copy attributes |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
472 |
System.arraycopy(parts, parts.length - alen, nparts, size, alen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
473 |
// copy sub-elements |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
474 |
for (int i = 0; i < size; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
475 |
Object e = parts[i]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
476 |
String str; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
477 |
if (e instanceof Element) { // recursion is common case |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
478 |
if (!((Element) e).isFrozen()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
479 |
throw new IllegalArgumentException("Sub-element must be frozen."); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
480 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
481 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
482 |
// Freeze StringBuffers, etc. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
483 |
e = fixupString(e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
484 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
485 |
nparts[i] = e; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
486 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
487 |
parts = nparts; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
488 |
assert (isFrozen()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
489 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
490 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
491 |
/** Return the name of this element. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
492 |
public String getName() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
493 |
return name; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
494 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
495 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
496 |
/** Change the name of this element. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
497 |
public void setName(String name) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
498 |
checkNotFrozen(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
499 |
this.name = name.toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
500 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
501 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
502 |
/** Reports if the element's name is a particular string (spelled "*"). |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
503 |
* Such elements are created by the nullary Element constructor, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
504 |
* and by query functions which return multiple values, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
505 |
* such as <tt>findAll</tt>. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
506 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
507 |
public boolean isAnonymous() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
508 |
return name == ANON_NAME; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
509 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
510 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
511 |
/** Return number of elements. (Does not include attributes.) */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
512 |
public int size() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
513 |
return size; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
514 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
515 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
516 |
/** True if no elements. (Does not consider attributes.) */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
517 |
public boolean isEmpty() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
518 |
return size == 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
519 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
520 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
521 |
/** True if this element does not allow modification. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
522 |
public boolean isFrozen() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
523 |
// It is frozen iff there is no slop space. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
524 |
return !hasNulls(NEED_SLOP); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
525 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
526 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
527 |
void checkNotFrozen() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
528 |
if (isFrozen()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
529 |
throw new UnsupportedOperationException("cannot modify frozen element"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
530 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
531 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
532 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
533 |
/** Remove specified elements. (Does not affect attributes.) */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
534 |
public void clear() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
535 |
clear(0, size); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
536 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
537 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
538 |
public void clear(int beg) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
539 |
clear(beg, size); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
540 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
541 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
542 |
public void clear(int beg, int end) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
543 |
if (end > size) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
544 |
badIndex(end); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
545 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
546 |
if (beg < 0 || beg > end) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
547 |
badIndex(beg); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
548 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
549 |
if (beg == end) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
550 |
return; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
551 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
552 |
checkNotFrozen(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
553 |
if (end == size) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
554 |
if (beg == 0 |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
555 |
&& parts.length > 0 && parts[parts.length - 1] == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
556 |
// If no attributes, free the parts array. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
557 |
parts = noPartsNotFrozen; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
558 |
size = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
559 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
560 |
clearParts(beg, size); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
561 |
size = beg; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
562 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
563 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
564 |
close(beg, end - beg); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
565 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
566 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
567 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
568 |
void clearParts(int beg, int end) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
569 |
for (int i = beg; i < end; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
570 |
parts[i] = null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
571 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
572 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
573 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
574 |
/** True if name, attributes, and elements are the same. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
575 |
public boolean equals(Element that) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
576 |
if (!this.name.equals(that.name)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
577 |
return false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
578 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
579 |
if (this.size != that.size) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
580 |
return false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
581 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
582 |
// elements must be equal and ordered |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
583 |
Object[] thisParts = this.parts; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
584 |
Object[] thatParts = that.parts; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
585 |
for (int i = 0; i < size; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
586 |
Object thisPart = thisParts[i]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
587 |
Object thatPart = thatParts[i]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
588 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
589 |
if (thisPart instanceof Element) { // recursion is common case |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
590 |
if (!thisPart.equals(thatPart)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
591 |
return false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
592 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
593 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
594 |
// If either is a non-string char sequence, normalize it. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
595 |
thisPart = fixupString(thisPart); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
596 |
thatPart = fixupString(thatPart); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
597 |
if (!thisPart.equals(thatPart)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
598 |
return false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
599 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
600 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
601 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
602 |
// finally, attributes must be equal (unordered) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
603 |
return this.equalAttrs(that); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
604 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
605 |
// bridge method |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
606 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
607 |
public boolean equals(Object o) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
608 |
if (!(o instanceof Element)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
609 |
return false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
610 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
611 |
return equals((Element) o); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
612 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
613 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
614 |
public int hashCode() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
615 |
int hc = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
616 |
int alen = attrLength(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
617 |
for (int i = parts.length - alen; i < parts.length; i += 2) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
618 |
hc += (parts[i + 0].hashCode() ^ parts[i + 1].hashCode()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
619 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
620 |
hc ^= hc << 11; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
621 |
hc += name.hashCode(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
622 |
for (int i = 0; i < size; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
623 |
hc ^= hc << 7; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
624 |
Object p = parts[i]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
625 |
if (p instanceof Element) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
626 |
hc += p.hashCode(); // recursion is common case |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
627 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
628 |
hc += fixupString(p).hashCode(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
629 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
630 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
631 |
hc ^= hc >>> 19; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
632 |
return hc; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
633 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
634 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
635 |
/** Compare lexicographically. Earlier-spelled attrs are more sigificant. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
636 |
public int compareTo(Element that) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
637 |
int r; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
638 |
// Primary key is element name. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
639 |
r = this.name.compareTo(that.name); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
640 |
if (r != 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
641 |
return r; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
642 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
643 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
644 |
// Secondary key is attributes, as if in normal key order. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
645 |
// The key/value pairs are sorted as a token sequence. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
646 |
int thisAlen = this.attrLength(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
647 |
int thatAlen = that.attrLength(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
648 |
if (thisAlen != 0 || thatAlen != 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
649 |
r = compareAttrs(thisAlen, that, thatAlen, true); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
650 |
assert (assertAttrCompareOK(r, that)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
651 |
if (r != 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
652 |
return r; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
653 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
654 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
655 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
656 |
// Finally, elements should be equal and ordered, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
657 |
// and the first difference rules. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
658 |
Object[] thisParts = this.parts; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
659 |
Object[] thatParts = that.parts; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
660 |
int minSize = this.size; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
661 |
if (minSize > that.size) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
662 |
minSize = that.size; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
663 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
664 |
Comparator<Object> cc = contentOrder(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
665 |
for (int i = 0; i < minSize; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
666 |
r = cc.compare(thisParts[i], thatParts[i]); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
667 |
if (r != 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
668 |
return r; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
669 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
670 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
671 |
//if (this.size < that.size) return -1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
672 |
return this.size - that.size; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
673 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
674 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
675 |
private boolean assertAttrCompareOK(int r, Element that) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
676 |
Element e0 = this.copyAttrsOnly(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
677 |
Element e1 = that.copyAttrsOnly(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
678 |
e0.sortAttrs(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
679 |
e1.sortAttrs(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
680 |
int r2; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
681 |
for (int k = 0;; k++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
682 |
boolean con0 = e0.containsAttr(k); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
683 |
boolean con1 = e1.containsAttr(k); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
684 |
if (con0 != con1) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
685 |
if (!con0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
686 |
r2 = 0 - 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
687 |
break; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
688 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
689 |
if (!con1) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
690 |
r2 = 1 - 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
691 |
break; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
692 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
693 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
694 |
if (!con0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
695 |
r2 = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
696 |
break; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
697 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
698 |
String k0 = e0.getAttrName(k); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
699 |
String k1 = e1.getAttrName(k); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
700 |
r2 = k0.compareTo(k1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
701 |
if (r2 != 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
702 |
break; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
703 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
704 |
String v0 = e0.getAttr(k); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
705 |
String v1 = e1.getAttr(k); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
706 |
r2 = v0.compareTo(v1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
707 |
if (r2 != 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
708 |
break; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
709 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
710 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
711 |
if (r != 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
712 |
r = (r > 0) ? 1 : -1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
713 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
714 |
if (r2 != 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
715 |
r2 = (r2 > 0) ? 1 : -1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
716 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
717 |
if (r != r2) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
718 |
System.out.println("*** wrong attr compare, " + r + " != " + r2); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
719 |
System.out.println(" this = " + this); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
720 |
System.out.println(" attr->" + e0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
721 |
System.out.println(" that = " + that); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
722 |
System.out.println(" attr->" + e1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
723 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
724 |
return r == r2; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
725 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
726 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
727 |
private void badIndex(int i) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
728 |
Object badRef = (new Object[0])[i]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
729 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
730 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
731 |
public Object get(int i) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
732 |
if (i >= size) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
733 |
badIndex(i); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
734 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
735 |
return parts[i]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
736 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
737 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
738 |
public Object set(int i, Object e) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
739 |
if (i >= size) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
740 |
badIndex(i); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
741 |
} |
29094
a4fd2b5e49f8
8073479: Replace obj.getClass hacks with Objects.requireNonNull
shade
parents:
6314
diff
changeset
|
742 |
Objects.requireNonNull(e); |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
743 |
checkNotFrozen(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
744 |
Object old = parts[i]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
745 |
setRaw(i, e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
746 |
return old; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
747 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
748 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
749 |
void setRaw(int i, Object e) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
750 |
parts[i] = e; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
751 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
752 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
753 |
public boolean remove(Object e) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
754 |
int i = indexOf(e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
755 |
if (i < 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
756 |
return false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
757 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
758 |
close(i, 1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
759 |
return true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
760 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
761 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
762 |
public Object remove(int i) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
763 |
if (i >= size) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
764 |
badIndex(i); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
765 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
766 |
Object e = parts[i]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
767 |
close(i, 1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
768 |
return e; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
769 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
770 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
771 |
public Object removeLast() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
772 |
if (size == 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
773 |
return null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
774 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
775 |
return remove(size - 1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
776 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
777 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
778 |
/** Remove the first element matching the given filter. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
779 |
* Return the filtered value. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
780 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
781 |
public Object remove(Filter f) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
782 |
return findOrRemove(f, 0, true); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
783 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
784 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
785 |
public Object remove(Filter f, int fromIndex) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
786 |
if (fromIndex < 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
787 |
fromIndex = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
788 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
789 |
return findOrRemove(f, fromIndex, true); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
790 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
791 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
792 |
/** Remove the last element matching the given filter. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
793 |
* Return the filtered value. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
794 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
795 |
public Object removeLast(Filter f) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
796 |
return findOrRemoveLast(f, size - 1, true); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
797 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
798 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
799 |
public Object removeLast(Filter f, int fromIndex) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
800 |
if (fromIndex >= size) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
801 |
fromIndex = size - 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
802 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
803 |
return findOrRemoveLast(f, fromIndex, true); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
804 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
805 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
806 |
/** Remove all elements matching the given filter. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
807 |
* If there is a non-null collection given as a sink, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
808 |
* transfer removed elements to the given collection. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
809 |
* The int result is the number of removed elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
810 |
* If there is a null sink given, the removed elements |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
811 |
* are discarded. If there is no sink given, the removed |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
812 |
* elements are returned in an anonymous container element. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
813 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
814 |
public Element removeAll(Filter f) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
815 |
Element result = new Element(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
816 |
findOrRemoveAll(f, false, 0, size, result.asList(), true); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
817 |
return result; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
818 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
819 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
820 |
public Element removeAll(Filter f, int fromIndex, int toIndex) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
821 |
Element result = new Element(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
822 |
findOrRemoveAll(f, true, fromIndex, toIndex, result.asList(), true); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
823 |
return result; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
824 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
825 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
826 |
public int removeAll(Filter f, Collection<Object> sink) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
827 |
return findOrRemoveAll(f, false, 0, size, sink, true); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
828 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
829 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
830 |
public int removeAll(Filter f, int fromIndex, int toIndex, Collection<Object> sink) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
831 |
return findOrRemoveAll(f, false, fromIndex, toIndex, sink, true); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
832 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
833 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
834 |
/** Remove all elements not matching the given filter. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
835 |
* If there is a non-null collection given as a sink, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
836 |
* transfer removed elements to the given collection. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
837 |
* The int result is the number of removed elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
838 |
* If there is a null sink given, the removed elements |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
839 |
* are discarded. If there is no sink given, the removed |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
840 |
* elements are returned in an anonymous container element. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
841 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
842 |
public Element retainAll(Filter f) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
843 |
Element result = new Element(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
844 |
findOrRemoveAll(f, true, 0, size, result.asList(), true); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
845 |
return result; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
846 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
847 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
848 |
public Element retainAll(Filter f, int fromIndex, int toIndex) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
849 |
Element result = new Element(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
850 |
findOrRemoveAll(f, true, fromIndex, toIndex, result.asList(), true); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
851 |
return result; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
852 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
853 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
854 |
public int retainAll(Filter f, Collection<Object> sink) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
855 |
return findOrRemoveAll(f, true, 0, size, sink, true); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
856 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
857 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
858 |
public int retainAll(Filter f, int fromIndex, int toIndex, Collection<Object> sink) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
859 |
return findOrRemoveAll(f, true, fromIndex, toIndex, sink, true); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
860 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
861 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
862 |
public void add(int i, Object e) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
863 |
// (The shape of this method is tweaked for common cases.) |
29094
a4fd2b5e49f8
8073479: Replace obj.getClass hacks with Objects.requireNonNull
shade
parents:
6314
diff
changeset
|
864 |
Objects.requireNonNull(e); |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
865 |
if (hasNulls(1 + NEED_SLOP)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
866 |
// Common case: Have some slop space. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
867 |
if (i == size) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
868 |
// Most common case: Append. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
869 |
setRaw(i, e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
870 |
size++; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
871 |
return; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
872 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
873 |
if (i > size) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
874 |
badIndex(i); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
875 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
876 |
// Second most common case: Shift right by one. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
877 |
open(i, 1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
878 |
setRaw(i, e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
879 |
return; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
880 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
881 |
// Ran out of space. Do something complicated. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
882 |
size = expand(i, 1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
883 |
setRaw(i, e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
884 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
885 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
886 |
public boolean add(Object e) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
887 |
add(size, e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
888 |
return true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
889 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
890 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
891 |
public Object getLast() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
892 |
return size == 0 ? null : parts[size - 1]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
893 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
894 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
895 |
/** Returns the text of this Element. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
896 |
* All sub-elements of this Element must be of type CharSequence. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
897 |
* A ClassCastException is raised if there are non-character sub-elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
898 |
* If there is one sub-element, return it. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
899 |
* Otherwise, returns a TokenList of all sub-elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
900 |
* This results in a space being placed between each adjacent pair of sub-elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
901 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
902 |
public CharSequence getText() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
903 |
checkTextOnly(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
904 |
if (size == 1) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
905 |
return parts[0].toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
906 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
907 |
return new TokenList(parts, 0, size); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
908 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
909 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
910 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
911 |
/** Provides an iterable view of this object as a series of texts. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
912 |
* All sub-elements of this Element must be of type CharSequence. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
913 |
* A ClassCastException is raised if there are non-character sub-elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
914 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
915 |
public Iterable<CharSequence> texts() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
916 |
checkTextOnly(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
917 |
return (Iterable<CharSequence>) (Iterable) this; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
918 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
919 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
920 |
/** Returns an array of strings derived from the sub-elements of this object. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
921 |
* All sub-elements of this Element must be of type CharSequence. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
922 |
* A ClassCastException is raised if there are non-character sub-elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
923 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
924 |
public String[] toStrings() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
925 |
//checkTextOnly(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
926 |
String[] result = new String[size]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
927 |
for (int i = 0; i < size; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
928 |
result[i] = ((CharSequence) parts[i]).toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
929 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
930 |
return result; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
931 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
932 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
933 |
/** Like getText, except that it disregards non-text elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
934 |
* Non-text elements are replaced by their textual contents, if any. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
935 |
* Text elements which were separated only by non-text element |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
936 |
* boundaries are merged into single tokens. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
937 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
938 |
* There is no corresponding setter, since this accessor does |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
939 |
* not report the full state of the element. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
940 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
941 |
public CharSequence getFlatText() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
942 |
if (size == 1) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
943 |
// Simple cases. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
944 |
if (parts[0] instanceof CharSequence) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
945 |
return parts[0].toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
946 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
947 |
return new TokenList(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
948 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
949 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
950 |
if (isText()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
951 |
return getText(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
952 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
953 |
// Filter and merge. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
954 |
Element result = new Element(size); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
955 |
boolean merge = false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
956 |
for (int i = 0; i < size; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
957 |
Object text = parts[i]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
958 |
if (!(text instanceof CharSequence)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
959 |
// Skip, but erase this boundary. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
960 |
if (text instanceof Element) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
961 |
Element te = (Element) text; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
962 |
if (!te.isEmpty()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
963 |
result.addText(te.getFlatText()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
964 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
965 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
966 |
merge = true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
967 |
continue; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
968 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
969 |
if (merge) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
970 |
// Merge w/ previous token. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
971 |
result.addText((CharSequence) text); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
972 |
merge = false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
973 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
974 |
result.add(text); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
975 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
976 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
977 |
if (result.size() == 1) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
978 |
return (CharSequence) result.parts[0]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
979 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
980 |
return result.getText(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
981 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
982 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
983 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
984 |
/** Return true if all sub-elements are of type CharSequence. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
985 |
public boolean isText() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
986 |
for (int i = 0; i < size; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
987 |
if (!(parts[i] instanceof CharSequence)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
988 |
return false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
989 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
990 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
991 |
return true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
992 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
993 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
994 |
/** Return true if at least one sub-element is of type CharSequence. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
995 |
public boolean hasText() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
996 |
for (int i = 0; i < size; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
997 |
if (parts[i] instanceof CharSequence) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
998 |
return true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
999 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1000 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1001 |
return false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1002 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1003 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1004 |
/** Raise a ClassCastException if !isText. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1005 |
public void checkTextOnly() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1006 |
for (int i = 0; i < size; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1007 |
((CharSequence) parts[i]).getClass(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1008 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1009 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1010 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1011 |
/** Clears out all sub-elements, and replaces them by the given text. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1012 |
* A ClassCastException is raised if there are non-character sub-elements, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1013 |
* either before or after the change. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1014 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1015 |
public void setText(CharSequence text) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1016 |
checkTextOnly(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1017 |
clear(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1018 |
if (text instanceof TokenList) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1019 |
// TL's contain only strings |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1020 |
addAll(0, (TokenList) text); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1021 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1022 |
add(text); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1023 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1024 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1025 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1026 |
/** Add text at the given position, merging with any previous |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1027 |
* text element, but preserving token boundaries where possible. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1028 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1029 |
* In all cases, the new value of getText() is the string |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1030 |
* concatenation of the old value of getText() plus the new text. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1031 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1032 |
* The total effect is to concatenate the given text to any |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1033 |
* pre-existing text, and to do so efficiently even if there |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1034 |
* are many such concatenations. Also, getText calls which |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1035 |
* return multiple tokens (in a TokenList) are respected. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1036 |
* For example, if x is empty, x.addText(y.getText()) puts |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1037 |
* an exact structural copy of y's text into x. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1038 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1039 |
* Internal token boundaries in the original text, and in the new |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1040 |
* text (i.e., if it is a TokenList), are preserved. However, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1041 |
* at the point where new text joins old text, a StringBuffer |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1042 |
* or new String may be created to join the last old and first |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1043 |
* new token. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1044 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1045 |
* If the given text is a TokenList, add the tokens as |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1046 |
* separate sub-elements, possibly merging the first token to |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1047 |
* a previous text item (to avoid making a new token boundary). |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1048 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1049 |
* If the element preceding position i is a StringBuffer, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1050 |
* append the first new token to it. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1051 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1052 |
* If the preceding element is a CharSequence, replace it by a |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1053 |
* StringBuffer containing both its and the first new token. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1054 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1055 |
* If tokens are added after a StringBuffer, freeze it into a String. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1056 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1057 |
* Every token not merged into a previous CharSequence is added |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1058 |
* as a new sub-element, starting at position i. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1059 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1060 |
* Returns the number of elements added, which is useful |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1061 |
* for further calls to addText. This number is zero |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1062 |
* if the input string was null, or was successfully |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1063 |
* merged into a StringBuffer at position i-1. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1064 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1065 |
* By contrast, calling add(text) always adds a new sub-element. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1066 |
* In that case, if there is a previous string, a separating |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1067 |
* space is virtually present also, and will be observed if |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1068 |
* getText() is used to return all the text together. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1069 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1070 |
public int addText(int i, CharSequence text) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1071 |
if (text instanceof String) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1072 |
return addText(i, (String) text); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1073 |
} else if (text instanceof TokenList) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1074 |
// Text is a list of tokens. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1075 |
TokenList tl = (TokenList) text; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1076 |
int tlsize = tl.size(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1077 |
if (tlsize == 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1078 |
return 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1079 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1080 |
String token0 = tl.get(0).toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1081 |
if (tlsize == 1) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1082 |
return addText(i, token0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1083 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1084 |
if (mergeWithPrev(i, token0, false)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1085 |
// Add the n-1 remaining tokens. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1086 |
addAll(i, tl.subList(1, tlsize)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1087 |
return tlsize - 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1088 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1089 |
addAll(i, (Collection) tl); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1090 |
return tlsize; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1091 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1092 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1093 |
return addText(i, text.toString()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1094 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1095 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1096 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1097 |
public int addText(CharSequence text) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1098 |
return addText(size, text); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1099 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1100 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1101 |
private // no reason to make this helper public |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1102 |
int addText(int i, String text) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1103 |
if (text.length() == 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1104 |
return 0; // Trivial success. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1105 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1106 |
if (mergeWithPrev(i, text, true)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1107 |
return 0; // Merged with previous token. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1108 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1109 |
// No previous token. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1110 |
add(i, text); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1111 |
return 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1112 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1113 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1114 |
// Tries to merge token with previous contents. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1115 |
// Returns true if token is successfully disposed of. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1116 |
// If keepSB is false, any previous StringBuffer is frozen. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1117 |
// If keepSB is true, a StringBuffer may be created to hold |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1118 |
// the merged token. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1119 |
private boolean mergeWithPrev(int i, String token, boolean keepSB) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1120 |
if (i == 0) // Trivial success if the token is length zero. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1121 |
{ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1122 |
return (token.length() == 0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1123 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1124 |
Object prev = parts[i - 1]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1125 |
if (prev instanceof StringBuffer) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1126 |
StringBuffer psb = (StringBuffer) prev; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1127 |
psb.append(token); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1128 |
if (!keepSB) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1129 |
parts[i - 1] = psb.toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1130 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1131 |
return true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1132 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1133 |
if (token.length() == 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1134 |
return true; // Trivial success. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1135 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1136 |
if (prev instanceof CharSequence) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1137 |
// Must concatenate. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1138 |
StringBuffer psb = new StringBuffer(prev.toString()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1139 |
psb.append(token); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1140 |
if (keepSB) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1141 |
parts[i - 1] = psb; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1142 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1143 |
parts[i - 1] = psb.toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1144 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1145 |
return true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1146 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1147 |
return false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1148 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1149 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1150 |
/** Trim all strings, using String.trim(). |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1151 |
* Remove empty strings. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1152 |
* Normalize CharSequences to Strings. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1153 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1154 |
public void trimText() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1155 |
checkNotFrozen(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1156 |
int fillp = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1157 |
int size = this.size; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1158 |
Object[] parts = this.parts; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1159 |
for (int i = 0; i < size; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1160 |
Object e = parts[i]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1161 |
if (e instanceof CharSequence) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1162 |
String tt = e.toString().trim(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1163 |
if (tt.length() == 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1164 |
continue; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1165 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1166 |
e = tt; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1167 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1168 |
parts[fillp++] = e; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1169 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1170 |
while (size > fillp) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1171 |
parts[--size] = null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1172 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1173 |
this.size = fillp; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1174 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1175 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1176 |
/** Add one or more subelements at the given position. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1177 |
* If the object reference is null, nothing happens. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1178 |
* If the object is an anonymous Element, addAll is called. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1179 |
* If the object is a TokenList, addAll is called (to add the tokens). |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1180 |
* Otherwise, add is called, adding a single subelement or string. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1181 |
* The net effect is to add zero or more tokens. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1182 |
* The returned value is the number of added elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1183 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1184 |
* Note that getText() can return a TokenList which preserves |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1185 |
* token boundaries in the text source. Such a text will be |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1186 |
* added as multiple text sub-elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1187 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1188 |
* If a text string is added adjacent to an immediately |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1189 |
* preceding string, there will be a token boundary between |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1190 |
* the strings, which will print as an extra space. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1191 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1192 |
public int addContent(int i, Object e) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1193 |
if (e == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1194 |
return 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1195 |
} else if (e instanceof TokenList) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1196 |
return addAll(i, (Collection) e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1197 |
} else if (e instanceof Element |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1198 |
&& ((Element) e).isAnonymous()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1199 |
return addAll(i, (Element) e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1200 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1201 |
add(i, e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1202 |
return 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1203 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1204 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1205 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1206 |
public int addContent(Object e) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1207 |
return addContent(size, e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1208 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1209 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1210 |
public Object[] toArray() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1211 |
Object[] result = new Object[size]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1212 |
System.arraycopy(parts, 0, result, 0, size); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1213 |
return result; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1214 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1215 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1216 |
public Element copyContentOnly() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1217 |
Element content = new Element(size); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1218 |
System.arraycopy(parts, 0, content.parts, 0, size); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1219 |
content.size = size; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1220 |
return content; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1221 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1222 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1223 |
public void sort(Comparator<Object> c) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1224 |
Arrays.sort(parts, 0, size, c); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1225 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1226 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1227 |
public void sort() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1228 |
sort(CONTENT_ORDER); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1229 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1230 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1231 |
/** Equivalent to Collections.reverse(this.asList()). */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1232 |
public void reverse() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1233 |
for (int i = 0, mid = size >> 1, j = size - 1; i < mid; i++, j--) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1234 |
Object p = parts[i]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1235 |
parts[i] = parts[j]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1236 |
parts[j] = p; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1237 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1238 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1239 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1240 |
/** Equivalent to Collections.shuffle(this.asList() [, rnd]). */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1241 |
public void shuffle() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1242 |
Collections.shuffle(this.asList()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1243 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1244 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1245 |
public void shuffle(Random rnd) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1246 |
Collections.shuffle(this.asList(), rnd); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1247 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1248 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1249 |
/** Equivalent to Collections.rotate(this.asList(), dist). */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1250 |
public void rotate(int dist) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1251 |
Collections.rotate(this.asList(), dist); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1252 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1253 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1254 |
/** Equivalent to Collections.min(this.asList(), c). */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1255 |
public Object min(Comparator<Object> c) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1256 |
return Collections.min(this.asList(), c); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1257 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1258 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1259 |
public Object min() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1260 |
return min(CONTENT_ORDER); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1261 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1262 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1263 |
/** Equivalent to Collections.max(this.asList(), c). */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1264 |
public Object max(Comparator<Object> c) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1265 |
return Collections.max(this.asList(), c); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1266 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1267 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1268 |
public Object max() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1269 |
return max(CONTENT_ORDER); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1270 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1271 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1272 |
public int addAll(int i, Collection c) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1273 |
if (c instanceof LView) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1274 |
return addAll(i, ((LView) c).asElement()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1275 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1276 |
int csize = c.size(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1277 |
if (csize == 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1278 |
return 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1279 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1280 |
openOrExpand(i, csize); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1281 |
int fill = i; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1282 |
for (Object part : c) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1283 |
parts[fill++] = part; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1284 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1285 |
return csize; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1286 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1287 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1288 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1289 |
public int addAll(int i, Element e) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1290 |
int esize = e.size; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1291 |
if (esize == 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1292 |
return 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1293 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1294 |
openOrExpand(i, esize); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1295 |
System.arraycopy(e.parts, 0, parts, i, esize); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1296 |
return esize; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1297 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1298 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1299 |
public int addAll(Collection c) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1300 |
return addAll(size, c); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1301 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1302 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1303 |
public int addAll(Element e) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1304 |
return addAll(size, e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1305 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1306 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1307 |
public int addAllAttrsFrom(Element e) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1308 |
int added = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1309 |
for (int k = 0; e.containsAttr(k); k++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1310 |
String old = setAttr(e.getAttrName(k), e.getAttr(k)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1311 |
if (old == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1312 |
added += 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1313 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1314 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1315 |
// Return number of added (not merely changed) attrs. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1316 |
return added; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1317 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1318 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1319 |
// Search. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1320 |
public boolean matches(Filter f) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1321 |
return f.filter(this) != null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1322 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1323 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1324 |
public Object find(Filter f) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1325 |
return findOrRemove(f, 0, false); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1326 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1327 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1328 |
public Object find(Filter f, int fromIndex) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1329 |
if (fromIndex < 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1330 |
fromIndex = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1331 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1332 |
return findOrRemove(f, fromIndex, false); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1333 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1334 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1335 |
/** Find the last element matching the given filter. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1336 |
* Return the filtered value. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1337 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1338 |
public Object findLast(Filter f) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1339 |
return findOrRemoveLast(f, size - 1, false); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1340 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1341 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1342 |
public Object findLast(Filter f, int fromIndex) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1343 |
if (fromIndex >= size) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1344 |
fromIndex = size - 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1345 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1346 |
return findOrRemoveLast(f, fromIndex, false); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1347 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1348 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1349 |
/** Find all elements matching the given filter. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1350 |
* If there is a non-null collection given as a sink, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1351 |
* transfer matching elements to the given collection. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1352 |
* The int result is the number of matching elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1353 |
* If there is a null sink given, the matching elements are |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1354 |
* not collected. If there is no sink given, the matching |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1355 |
* elements are returned in an anonymous container element. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1356 |
* In no case is the receiver element changed. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1357 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1358 |
* Note that a simple count of matching elements can be |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1359 |
* obtained by passing a null collection argument. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1360 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1361 |
public Element findAll(Filter f) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1362 |
Element result = new Element(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1363 |
findOrRemoveAll(f, false, 0, size, result.asList(), false); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1364 |
return result; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1365 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1366 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1367 |
public Element findAll(Filter f, int fromIndex, int toIndex) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1368 |
Element result = new Element(name); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1369 |
findOrRemoveAll(f, false, fromIndex, toIndex, result.asList(), false); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1370 |
return result; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1371 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1372 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1373 |
public int findAll(Filter f, Collection<Object> sink) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1374 |
return findOrRemoveAll(f, false, 0, size, sink, false); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1375 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1376 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1377 |
public int findAll(Filter f, int fromIndex, int toIndex, Collection<Object> sink) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1378 |
return findOrRemoveAll(f, false, fromIndex, toIndex, sink, false); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1379 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1380 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1381 |
/// Driver routines. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1382 |
private Object findOrRemove(Filter f, int fromIndex, boolean remove) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1383 |
for (int i = fromIndex; i < size; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1384 |
Object x = f.filter(parts[i]); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1385 |
if (x != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1386 |
if (remove) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1387 |
close(i, 1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1388 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1389 |
return x; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1390 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1391 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1392 |
return null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1393 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1394 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1395 |
private Object findOrRemoveLast(Filter f, int fromIndex, boolean remove) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1396 |
for (int i = fromIndex; i >= 0; i--) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1397 |
Object x = f.filter(parts[i]); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1398 |
if (x != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1399 |
if (remove) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1400 |
close(i, 1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1401 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1402 |
return x; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1403 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1404 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1405 |
return null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1406 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1407 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1408 |
private int findOrRemoveAll(Filter f, boolean fInvert, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1409 |
int fromIndex, int toIndex, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1410 |
Collection<Object> sink, boolean remove) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1411 |
if (fromIndex < 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1412 |
badIndex(fromIndex); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1413 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1414 |
if (toIndex > size) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1415 |
badIndex(toIndex); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1416 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1417 |
int found = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1418 |
for (int i = fromIndex; i < toIndex; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1419 |
Object p = parts[i]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1420 |
Object x = f.filter(p); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1421 |
if (fInvert ? (x == null) : (x != null)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1422 |
if (remove) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1423 |
close(i--, 1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1424 |
toIndex--; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1425 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1426 |
found += XMLKit.addContent(fInvert ? p : x, sink); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1427 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1428 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1429 |
return found; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1430 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1431 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1432 |
public void replaceAll(Filter f) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1433 |
XMLKit.replaceAll(f, this.asList()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1434 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1435 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1436 |
public void replaceAll(Filter f, int fromIndex, int toIndex) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1437 |
XMLKit.replaceAll(f, this.asList().subList(fromIndex, toIndex)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1438 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1439 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1440 |
/// Recursive walks. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1441 |
// findAllInTree(f) == findAll(findInTree(f,S)), S.toElement |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1442 |
// findAllInTree(f,S) == findAll(findInTree(content(f,S))) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1443 |
// removeAllInTree(f) == replaceAll(replaceInTree(and(f,emptyF))) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1444 |
// removeAllInTree(f,S) == replaceAll(replaceInTree(and(content(f,S),emptyF))) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1445 |
// retainAllInTree(f) == removeAllInTree(not(f)) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1446 |
// replaceAllInTree(f) == replaceAll(replaceInTree(f)) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1447 |
public Element findAllInTree(Filter f) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1448 |
Element result = new Element(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1449 |
findAllInTree(f, result.asList()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1450 |
return result; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1451 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1452 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1453 |
public int findAllInTree(Filter f, Collection<Object> sink) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1454 |
int found = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1455 |
int size = this.size; // cache copy |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1456 |
for (int i = 0; i < size; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1457 |
Object p = parts[i]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1458 |
Object x = f.filter(p); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1459 |
if (x != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1460 |
found += XMLKit.addContent(x, sink); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1461 |
} else if (p instanceof Element) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1462 |
found += ((Element) p).findAllInTree(f, sink); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1463 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1464 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1465 |
return found; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1466 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1467 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1468 |
public int countAllInTree(Filter f) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1469 |
return findAllInTree(f, null); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1470 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1471 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1472 |
public int removeAllInTree(Filter f, Collection<Object> sink) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1473 |
if (sink == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1474 |
sink = newCounterColl(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1475 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1476 |
replaceAll(replaceInTree(and(content(f, sink), emptyFilter()))); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1477 |
return sink.size(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1478 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1479 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1480 |
public Element removeAllInTree(Filter f) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1481 |
Element result = new Element(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1482 |
removeAllInTree(f, result.asList()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1483 |
return result; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1484 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1485 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1486 |
public int retainAllInTree(Filter f, Collection<Object> sink) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1487 |
return removeAllInTree(not(f), sink); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1488 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1489 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1490 |
public Element retainAllInTree(Filter f) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1491 |
Element result = new Element(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1492 |
retainAllInTree(f, result.asList()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1493 |
return result; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1494 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1495 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1496 |
public void replaceAllInTree(Filter f) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1497 |
replaceAll(replaceInTree(f)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1498 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1499 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1500 |
/** Raise a ClassCastException if any subelements are the wrong type. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1501 |
public void checkPartsOnly(Class<?> elementClass) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1502 |
for (int i = 0; i < size; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1503 |
elementClass.cast(parts[i]).getClass(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1504 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1505 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1506 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1507 |
/** Return true if all sub-elements are of the given type. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1508 |
public boolean isPartsOnly(Class<?> elementClass) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1509 |
for (int i = 0; i < size; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1510 |
if (!elementClass.isInstance(parts[i])) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1511 |
return false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1512 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1513 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1514 |
return true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1515 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1516 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1517 |
/** Provides an iterable view of this object as a series of elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1518 |
* All sub-elements of this Element must be of type Element. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1519 |
* A ClassCastException is raised if there are non-Element sub-elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1520 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1521 |
public <T> Iterable<T> partsOnly(Class<T> elementClass) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1522 |
checkPartsOnly(elementClass); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1523 |
return (Iterable<T>) (Iterable) this; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1524 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1525 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1526 |
public Iterable<Element> elements() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1527 |
return partsOnly(Element.class); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1528 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1529 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1530 |
/// Useful shorthands. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1531 |
// Finding or removing elements w/o regard to their type or content. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1532 |
public Element findElement() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1533 |
return (Element) find(elementFilter()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1534 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1535 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1536 |
public Element findAllElements() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1537 |
return findAll(elementFilter()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1538 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1539 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1540 |
public Element removeElement() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1541 |
return (Element) remove(elementFilter()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1542 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1543 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1544 |
public Element removeAllElements() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1545 |
return (Element) removeAll(elementFilter()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1546 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1547 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1548 |
// Finding or removing by element tag or selected attribute, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1549 |
// as if by elementFilter(name) or attrFilter(name, value). |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1550 |
// Roughly akin to Common Lisp ASSOC. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1551 |
public Element findElement(String name) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1552 |
return (Element) find(elementFilter(name)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1553 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1554 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1555 |
public Element removeElement(String name) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1556 |
return (Element) remove(elementFilter(name)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1557 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1558 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1559 |
public Element findWithAttr(String key) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1560 |
return (Element) find(attrFilter(name)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1561 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1562 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1563 |
public Element findWithAttr(String key, String value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1564 |
return (Element) find(attrFilter(name, value)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1565 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1566 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1567 |
public Element removeWithAttr(String key) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1568 |
return (Element) remove(attrFilter(name)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1569 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1570 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1571 |
public Element removeWithAttr(String key, String value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1572 |
return (Element) remove(attrFilter(name, value)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1573 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1574 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1575 |
public Element findAllElements(String name) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1576 |
return findAll(elementFilter(name)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1577 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1578 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1579 |
public Element removeAllElements(String name) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1580 |
return removeAll(elementFilter(name)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1581 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1582 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1583 |
public Element retainAllElements(String name) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1584 |
return retainAll(elementFilter(name)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1585 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1586 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1587 |
public Element findAllWithAttr(String key) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1588 |
return findAll(attrFilter(key)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1589 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1590 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1591 |
public Element removeAllWithAttr(String key) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1592 |
return removeAll(attrFilter(key)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1593 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1594 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1595 |
public Element retainAllWithAttr(String key) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1596 |
return retainAll(attrFilter(key)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1597 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1598 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1599 |
public Element findAllWithAttr(String key, String value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1600 |
return findAll(attrFilter(key, value)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1601 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1602 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1603 |
public Element removeAllWithAttr(String key, String value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1604 |
return removeAll(attrFilter(key, value)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1605 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1606 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1607 |
public Element retainAllWithAttr(String key, String value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1608 |
return retainAll(attrFilter(key, value)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1609 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1610 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1611 |
public int countAll(Filter f) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1612 |
return findAll(f, null); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1613 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1614 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1615 |
public int countAllElements() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1616 |
return countAll(elementFilter()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1617 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1618 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1619 |
public int countAllElements(String name) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1620 |
return countAll(elementFilter(name)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1621 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1622 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1623 |
public int countAllWithAttr(String key) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1624 |
return countAll(attrFilter(name)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1625 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1626 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1627 |
public int countAllWithAttr(String key, String value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1628 |
return countAll(attrFilter(key, value)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1629 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1630 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1631 |
public int indexOf(Object e) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1632 |
for (int i = 0; i < size; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1633 |
if (e.equals(parts[i])) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1634 |
return i; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1635 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1636 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1637 |
return -1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1638 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1639 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1640 |
public int lastIndexOf(Object e) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1641 |
for (int i = size - 1; i >= 0; i--) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1642 |
if (e.equals(parts[i])) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1643 |
return i; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1644 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1645 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1646 |
return -1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1647 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1648 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1649 |
/** Remove the first element matching the given filter. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1650 |
* Return the filtered value. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1651 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1652 |
public int indexOf(Filter f) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1653 |
return indexOf(f, 0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1654 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1655 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1656 |
public int indexOf(Filter f, int fromIndex) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1657 |
if (fromIndex < 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1658 |
fromIndex = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1659 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1660 |
for (int i = fromIndex; i < size; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1661 |
Object x = f.filter(parts[i]); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1662 |
if (x != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1663 |
return i; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1664 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1665 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1666 |
return -1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1667 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1668 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1669 |
/** Remove the last element matching the given filter. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1670 |
* Return the filtered value. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1671 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1672 |
public int lastIndexOf(Filter f) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1673 |
return lastIndexOf(f, size - 1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1674 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1675 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1676 |
public int lastIndexOf(Filter f, int fromIndex) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1677 |
if (fromIndex >= size) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1678 |
fromIndex = size - 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1679 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1680 |
for (int i = fromIndex; i >= 0; i--) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1681 |
Object x = f.filter(parts[i]); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1682 |
if (x != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1683 |
return i; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1684 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1685 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1686 |
return -1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1687 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1688 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1689 |
public boolean contains(Object e) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1690 |
return indexOf(e) >= 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1691 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1692 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1693 |
// attributes |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1694 |
private int findOrCreateAttr(String key, boolean create) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1695 |
key.toString(); // null check |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1696 |
int attrBase = parts.length; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1697 |
for (int i = parts.length - 2; i >= size; i -= 2) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1698 |
String akey = (String) parts[i + 0]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1699 |
if (akey == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1700 |
if (!create) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1701 |
return -1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1702 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1703 |
if (i == size) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1704 |
break; // NEED_SLOP |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1705 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1706 |
parts[i + 0] = key; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1707 |
//parts[i+1] = ""; //caller responsibility |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1708 |
return i; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1709 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1710 |
attrBase = i; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1711 |
if (akey.equals(key)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1712 |
return i; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1713 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1714 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1715 |
// If we fell through, we ran into an element part. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1716 |
// Therefore we have run out of empty slots. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1717 |
if (!create) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1718 |
return -1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1719 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1720 |
assert (!isFrozen()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1721 |
int alen = parts.length - attrBase; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1722 |
expand(size, 2); // generally expands by more than 2 |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1723 |
// since there was a reallocation, the garbage slots are really null |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1724 |
assert (parts[size + 0] == null && parts[size + 1] == null); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1725 |
alen += 2; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1726 |
int i = parts.length - alen; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1727 |
parts[i + 0] = key; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1728 |
//parts[i+1] = ""; //caller responsibility |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1729 |
return i; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1730 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1731 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1732 |
public int attrSize() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1733 |
return attrLength() >>> 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1734 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1735 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1736 |
public int indexOfAttr(String key) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1737 |
return findOrCreateAttr(key, false); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1738 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1739 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1740 |
public boolean containsAttr(String key) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1741 |
return indexOfAttr(key) >= 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1742 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1743 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1744 |
public String getAttr(String key) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1745 |
return getAttr(key, null); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1746 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1747 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1748 |
public String getAttr(String key, String dflt) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1749 |
int i = findOrCreateAttr(key, false); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1750 |
return (i < 0) ? dflt : (String) parts[i + 1]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1751 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1752 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1753 |
public TokenList getAttrList(String key) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1754 |
return convertToList(getAttr(key)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1755 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1756 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1757 |
public Number getAttrNumber(String key) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1758 |
return convertToNumber(getAttr(key)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1759 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1760 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1761 |
public long getAttrLong(String key) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1762 |
return getAttrLong(key, 0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1763 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1764 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1765 |
public double getAttrDouble(String key) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1766 |
return getAttrDouble(key, 0.0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1767 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1768 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1769 |
public long getAttrLong(String key, long dflt) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1770 |
return convertToLong(getAttr(key), dflt); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1771 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1772 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1773 |
public double getAttrDouble(String key, double dflt) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1774 |
return convertToDouble(getAttr(key), dflt); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1775 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1776 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1777 |
int indexAttr(int k) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1778 |
int i = parts.length - (k * 2) - 2; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1779 |
if (i < size || parts[i] == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1780 |
return -2; // always oob |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1781 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1782 |
return i; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1783 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1784 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1785 |
public boolean containsAttr(int k) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1786 |
return indexAttr(k) >= 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1787 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1788 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1789 |
public String getAttr(int k) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1790 |
return (String) parts[indexAttr(k) + 1]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1791 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1792 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1793 |
public String getAttrName(int k) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1794 |
return (String) parts[indexAttr(k) + 0]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1795 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1796 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1797 |
public Iterable<String> attrNames() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1798 |
//return asAttrMap().keySet(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1799 |
return new Iterable<String>() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1800 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1801 |
public Iterator<String> iterator() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1802 |
return new ANItr(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1803 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1804 |
}; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1805 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1806 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1807 |
// Hand-inlined replacement for asAttrMap().keySet().iterator(): |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1808 |
class ANItr implements Iterator<String> { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1809 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1810 |
boolean lastRet; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1811 |
int cursor = -2; // pointer from end of parts |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1812 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1813 |
public boolean hasNext() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1814 |
int i = cursor + parts.length; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1815 |
return i >= size && parts[i] == null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1816 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1817 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1818 |
public String next() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1819 |
int i = cursor + parts.length; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1820 |
Object x; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1821 |
if (i < size || (x = parts[i]) == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1822 |
nsee(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1823 |
return null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1824 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1825 |
cursor -= 2; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1826 |
lastRet = true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1827 |
return (String) x; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1828 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1829 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1830 |
public void remove() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1831 |
if (!lastRet) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1832 |
throw new IllegalStateException(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1833 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1834 |
Element.this.removeAttr((-4 - cursor) / 2); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1835 |
cursor += 2; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1836 |
lastRet = false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1837 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1838 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1839 |
Exception nsee() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1840 |
throw new NoSuchElementException("attribute " + (-2 - cursor) / 2); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1841 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1842 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1843 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1844 |
/** Return an anonymous copy of self, but only with attributes. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1845 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1846 |
public Element copyAttrsOnly() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1847 |
int alen = attrLength(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1848 |
Element attrs = new Element(alen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1849 |
Object[] attrParts = attrs.parts; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1850 |
assert (attrParts.length == NEED_SLOP + alen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1851 |
System.arraycopy(parts, parts.length - alen, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1852 |
attrParts, NEED_SLOP, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1853 |
alen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1854 |
return attrs; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1855 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1856 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1857 |
/** Get all attributes, represented as an element with sub-elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1858 |
* The name of each sub-element is the attribute key, and the text |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1859 |
* This is a fresh copy, and can be updated with affecting the original. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1860 |
* of each sub-element is the corresponding attribute value. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1861 |
* See also asAttrMap() for a "live" view of all the attributes as a Map. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1862 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1863 |
public Element getAttrs() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1864 |
int asize = attrSize(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1865 |
Element attrs = new Element(ANON_NAME, asize, NEED_SLOP + asize); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1866 |
for (int i = 0; i < asize; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1867 |
Element attr = new Element(getAttrName(i), 1, NEED_SLOP + 1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1868 |
// %%% normalize attrs to token lists? |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1869 |
attr.setRaw(0, getAttr(i)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1870 |
attrs.setRaw(i, attr); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1871 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1872 |
return attrs; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1873 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1874 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1875 |
public void setAttrs(Element attrs) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1876 |
int alen = attrLength(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1877 |
clearParts(parts.length - alen, alen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1878 |
if (!hasNulls(NEED_SLOP + attrs.size * 2)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1879 |
expand(size, attrs.size * 2); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1880 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1881 |
addAttrs(attrs); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1882 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1883 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1884 |
public void addAttrs(Element attrs) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1885 |
for (int i = 0; i < attrs.size; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1886 |
Element attr = (Element) attrs.get(i); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1887 |
setAttr(attr.name, attr.getText().toString()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1888 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1889 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1890 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1891 |
public void removeAttr(int i) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1892 |
checkNotFrozen(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1893 |
while ((i -= 2) >= size) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1894 |
Object k = parts[i + 0]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1895 |
Object v = parts[i + 1]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1896 |
if (k == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1897 |
break; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1898 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1899 |
parts[i + 2] = k; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1900 |
parts[i + 3] = v; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1901 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1902 |
parts[i + 2] = null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1903 |
parts[i + 3] = null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1904 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1905 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1906 |
public void clearAttrs() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1907 |
if (parts.length == 0 || parts[parts.length - 1] == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1908 |
return; // no attrs to clear |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1909 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1910 |
checkNotFrozen(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1911 |
if (size == 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1912 |
// If no elements, free the parts array. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1913 |
parts = noPartsNotFrozen; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1914 |
return; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1915 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1916 |
for (int i = parts.length - 1; parts[i] != null; i--) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1917 |
assert (i >= size); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1918 |
parts[i] = null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1919 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1920 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1921 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1922 |
public String setAttr(String key, String value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1923 |
String old; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1924 |
if (value == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1925 |
int i = findOrCreateAttr(key, false); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1926 |
if (i >= 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1927 |
old = (String) parts[i + 1]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1928 |
removeAttr(i); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1929 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1930 |
old = null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1931 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1932 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1933 |
checkNotFrozen(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1934 |
int i = findOrCreateAttr(key, true); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1935 |
old = (String) parts[i + 1]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1936 |
parts[i + 1] = value; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1937 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1938 |
return old; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1939 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1940 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1941 |
public String setAttrList(String key, List<String> l) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1942 |
if (l == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1943 |
return setAttr(key, null); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1944 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1945 |
if (!(l instanceof TokenList)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1946 |
l = new TokenList(l); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1947 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1948 |
return setAttr(key, l.toString()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1949 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1950 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1951 |
public String setAttrNumber(String key, Number n) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1952 |
return setAttr(key, (n == null) ? null : n.toString()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1953 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1954 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1955 |
public String setAttrLong(String key, long n) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1956 |
return setAttr(key, (n == 0) ? null : String.valueOf(n)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1957 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1958 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1959 |
public String setAttrDouble(String key, double n) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1960 |
return setAttr(key, (n == 0) ? null : String.valueOf(n)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1961 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1962 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1963 |
public String setAttr(int k, String value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1964 |
int i = indexAttr(k); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1965 |
String old = (String) parts[i + 1]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1966 |
if (value == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1967 |
removeAttr(i); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1968 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1969 |
checkNotFrozen(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1970 |
parts[i + 1] = value; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1971 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1972 |
return old; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1973 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1974 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1975 |
int attrLength() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1976 |
return parts.length - attrBase(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1977 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1978 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1979 |
/** Are the attributes of the two two elements equal? |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1980 |
* Disregards name, sub-elements, and ordering of attributes. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1981 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1982 |
public boolean equalAttrs(Element that) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1983 |
int alen = this.attrLength(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1984 |
if (alen != that.attrLength()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1985 |
return false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1986 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1987 |
if (alen == 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1988 |
return true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1989 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1990 |
return compareAttrs(alen, that, alen, false) == 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1991 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1992 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1993 |
private int compareAttrs(int thisAlen, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1994 |
Element that, int thatAlen, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1995 |
boolean fullCompare) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1996 |
Object[] thisParts = this.parts; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1997 |
Object[] thatParts = that.parts; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1998 |
int thisBase = thisParts.length - thisAlen; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1999 |
int thatBase = thatParts.length - thatAlen; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2000 |
// search indexes into unmatched parts of this.attrs: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2001 |
int firstI = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2002 |
// search indexes into unmatched parts of that.attrs: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2003 |
int firstJ = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2004 |
int lastJ = thatAlen - 2; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2005 |
// try to find the mismatch with the first key: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2006 |
String firstKey = null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2007 |
int firstKeyValCmp = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2008 |
int foundKeys = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2009 |
for (int i = 0; i < thisAlen; i += 2) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2010 |
String key = (String) thisParts[thisBase + i + 0]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2011 |
String val = (String) thisParts[thisBase + i + 1]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2012 |
String otherVal = null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2013 |
for (int j = firstJ; j <= lastJ; j += 2) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2014 |
if (key.equals(thatParts[thatBase + j + 0])) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2015 |
foundKeys += 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2016 |
otherVal = (String) thatParts[thatBase + j + 1]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2017 |
// Optimization: Narrow subsequent searches when easy. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2018 |
if (j == lastJ) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2019 |
lastJ -= 2; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2020 |
} else if (j == firstJ) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2021 |
firstJ += 2; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2022 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2023 |
if (i == firstI) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2024 |
firstI += 2; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2025 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2026 |
break; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2027 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2028 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2029 |
int valCmp; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2030 |
if (otherVal != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2031 |
// The key was found. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2032 |
if (!fullCompare) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2033 |
if (!val.equals(otherVal)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2034 |
return 1 - 0; //arb. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2035 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2036 |
continue; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2037 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2038 |
valCmp = val.compareTo(otherVal); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2039 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2040 |
// Found the key in this but not that. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2041 |
// Such a mismatch puts the guy missing the key last. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2042 |
valCmp = 0 - 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2043 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2044 |
if (valCmp != 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2045 |
// found a mismatch, key present in both elems |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2046 |
if (firstKey == null |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2047 |
|| firstKey.compareTo(key) > 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2048 |
// found a better key |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2049 |
firstKey = key; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2050 |
firstKeyValCmp = valCmp; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2051 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2052 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2053 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2054 |
// We have located the first mismatch of all keys in this.attrs. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2055 |
// In general we must also look for keys in that.attrs but missing |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2056 |
// from this.attrs; such missing keys, if earlier than firstKey, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2057 |
// rule the comparison. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2058 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2059 |
// We can sometimes prove quickly there is no missing key. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2060 |
if (foundKeys == thatAlen / 2) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2061 |
// Exhausted all keys in that.attrs. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2062 |
return firstKeyValCmp; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2063 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2064 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2065 |
// Search for a missing key in that.attrs earlier than firstKey. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2066 |
findMissingKey: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2067 |
for (int j = firstJ; j <= lastJ; j += 2) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2068 |
String otherKey = (String) thatParts[thatBase + j + 0]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2069 |
if (firstKey == null |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2070 |
|| firstKey.compareTo(otherKey) > 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2071 |
// Found a better key; is it missing? |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2072 |
for (int i = firstI; i < thisAlen; i += 2) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2073 |
if (otherKey.equals(thisParts[thisBase + i + 0])) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2074 |
continue findMissingKey; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2075 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2076 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2077 |
// If we get here, there was no match in this.attrs. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2078 |
return 1 - 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2079 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2080 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2081 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2082 |
// No missing key. Previous comparison value rules. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2083 |
return firstKeyValCmp; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2084 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2085 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2086 |
// Binary search looking for first non-null after size. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2087 |
int attrBase() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2088 |
// Smallest & largest possible attribute indexes: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2089 |
int kmin = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2090 |
int kmax = (parts.length - size) >>> 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2091 |
// earlist possible attribute position: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2092 |
int abase = parts.length - (kmax * 2); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2093 |
// binary search using scaled indexes: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2094 |
while (kmin != kmax) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2095 |
int kmid = kmin + ((kmax - kmin) >>> 1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2096 |
if (parts[abase + (kmid * 2)] == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2097 |
kmin = kmid + 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2098 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2099 |
kmax = kmid; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2100 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2101 |
assert (kmin <= kmax); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2102 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2103 |
return abase + (kmax * 2); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2104 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2105 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2106 |
/** Sort attributes by name. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2107 |
public void sortAttrs() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2108 |
checkNotFrozen(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2109 |
int abase = attrBase(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2110 |
int alen = parts.length - abase; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2111 |
String[] buf = new String[alen]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2112 |
// collect keys |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2113 |
for (int k = 0; k < alen / 2; k++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2114 |
String akey = (String) parts[abase + (k * 2) + 0]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2115 |
buf[k] = akey; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2116 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2117 |
Arrays.sort(buf, 0, alen / 2); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2118 |
// collect values |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2119 |
for (int k = 0; k < alen / 2; k++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2120 |
String akey = buf[k]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2121 |
buf[k + alen / 2] = getAttr(akey); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2122 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2123 |
// reorder keys and values |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2124 |
int fillp = parts.length; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2125 |
for (int k = 0; k < alen / 2; k++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2126 |
String akey = buf[k]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2127 |
String aval = buf[k + alen / 2]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2128 |
fillp -= 2; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2129 |
parts[fillp + 0] = akey; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2130 |
parts[fillp + 1] = aval; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2131 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2132 |
assert (fillp == abase); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2133 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2134 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2135 |
/* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2136 |
Notes on whitespace and tokenization. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2137 |
On input, never split CDATA blocks. They remain single tokens. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2138 |
?Try to treat encoded characters as CDATA-quoted, also? |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2139 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2140 |
Internally, each String sub-element is logically a token. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2141 |
However, if there was no token-splitting on input, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2142 |
consecutive strings are merged by the parser. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2143 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2144 |
Internally, we need addToken (intervening blank) and addText |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2145 |
(hard concatenation). |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2146 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2147 |
Optionally on input, tokenize unquoted text into words. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2148 |
Between each adjacent word pair, elide either one space |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2149 |
or all space. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2150 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2151 |
On output, we always add spaces between tokens. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2152 |
The Element("a", {"b", "c", Element("d"), "e f"}) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2153 |
outputs as "<a>b c<d/>e f</a>" |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2154 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2155 |
/** Split strings into tokens, using a StringTokenizer. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2156 |
public void tokenize(String delims, boolean returnDelims) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2157 |
checkNotFrozen(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2158 |
if (delims == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2159 |
delims = WHITESPACE_CHARS; // StringTokenizer default |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2160 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2161 |
for (int i = 0; i < size; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2162 |
if (!(parts[i] instanceof CharSequence)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2163 |
continue; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2164 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2165 |
int osize = size; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2166 |
String str = parts[i].toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2167 |
StringTokenizer st = new StringTokenizer(str, delims, returnDelims); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2168 |
int nstrs = st.countTokens(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2169 |
switch (nstrs) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2170 |
case 0: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2171 |
close(i--, 1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2172 |
break; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2173 |
case 1: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2174 |
parts[i] = st.nextToken(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2175 |
break; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2176 |
default: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2177 |
openOrExpand(i + 1, nstrs - 1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2178 |
for (int j = 0; j < nstrs; j++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2179 |
parts[i + j] = st.nextToken(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2180 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2181 |
i += nstrs - 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2182 |
break; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2183 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2184 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2185 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2186 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2187 |
public void tokenize(String delims) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2188 |
tokenize(delims, false); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2189 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2190 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2191 |
public void tokenize() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2192 |
tokenize(null, false); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2193 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2194 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2195 |
// views |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2196 |
class LView extends AbstractList<Object> { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2197 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2198 |
Element asElement() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2199 |
return Element.this; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2200 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2201 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2202 |
public int size() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2203 |
return Element.this.size(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2204 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2205 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2206 |
public Object get(int i) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2207 |
return Element.this.get(i); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2208 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2209 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2210 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2211 |
public boolean contains(Object e) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2212 |
return Element.this.contains(e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2213 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2214 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2215 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2216 |
public Object[] toArray() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2217 |
return Element.this.toArray(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2218 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2219 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2220 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2221 |
public int indexOf(Object e) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2222 |
return Element.this.indexOf(e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2223 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2224 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2225 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2226 |
public int lastIndexOf(Object e) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2227 |
return Element.this.lastIndexOf(e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2228 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2229 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2230 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2231 |
public void add(int i, Object e) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2232 |
++modCount; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2233 |
Element.this.add(i, e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2234 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2235 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2236 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2237 |
public boolean addAll(int i, Collection<? extends Object> c) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2238 |
++modCount; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2239 |
return Element.this.addAll(i, c) > 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2240 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2241 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2242 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2243 |
public boolean addAll(Collection<? extends Object> c) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2244 |
++modCount; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2245 |
return Element.this.addAll(c) > 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2246 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2247 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2248 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2249 |
public Object remove(int i) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2250 |
++modCount; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2251 |
return Element.this.remove(i); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2252 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2253 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2254 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2255 |
public Object set(int i, Object e) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2256 |
++modCount; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2257 |
return Element.this.set(i, e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2258 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2259 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2260 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2261 |
public void clear() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2262 |
++modCount; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2263 |
Element.this.clear(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2264 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2265 |
// Others: toArray(Object[]), containsAll, removeAll, retainAll |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2266 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2267 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2268 |
/** Produce a list view of sub-elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2269 |
* (The list view does not provide access to the element's |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2270 |
* name or attributes.) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2271 |
* Changes to this view are immediately reflected in the |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2272 |
* element itself. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2273 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2274 |
public List<Object> asList() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2275 |
return new LView(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2276 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2277 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2278 |
/** Produce a list iterator on all sub-elements. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2279 |
public ListIterator<Object> iterator() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2280 |
//return asList().listIterator(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2281 |
return new Itr(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2282 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2283 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2284 |
// Hand-inlined replacement for LView.listIterator(): |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2285 |
class Itr implements ListIterator<Object> { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2286 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2287 |
int lastRet = -1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2288 |
int cursor = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2289 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2290 |
public boolean hasNext() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2291 |
return cursor < size; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2292 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2293 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2294 |
public boolean hasPrevious() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2295 |
return cursor > 0 && cursor <= size; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2296 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2297 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2298 |
public Object next() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2299 |
if (!hasNext()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2300 |
nsee(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2301 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2302 |
return parts[lastRet = cursor++]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2303 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2304 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2305 |
public Object previous() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2306 |
if (!hasPrevious()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2307 |
nsee(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2308 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2309 |
return parts[--cursor]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2310 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2311 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2312 |
public int nextIndex() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2313 |
return cursor; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2314 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2315 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2316 |
public int previousIndex() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2317 |
return cursor - 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2318 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2319 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2320 |
public void set(Object x) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2321 |
parts[lastRet] = x; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2322 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2323 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2324 |
public void add(Object x) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2325 |
lastRet = -1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2326 |
Element.this.add(cursor++, x); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2327 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2328 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2329 |
public void remove() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2330 |
if (lastRet < 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2331 |
throw new IllegalStateException(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2332 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2333 |
Element.this.remove(lastRet); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2334 |
if (lastRet < cursor) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2335 |
--cursor; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2336 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2337 |
lastRet = -1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2338 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2339 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2340 |
void nsee() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2341 |
throw new NoSuchElementException("element " + cursor); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2342 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2343 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2344 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2345 |
/** A PrintWriter which always appends as if by addText. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2346 |
* Use of this stream may insert a StringBuffer at the end |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2347 |
* of the Element. The user must not directly modify this |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2348 |
* StringBuffer, or use it in other data structures. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2349 |
* From time to time, the StringBuffer may be replaced by a |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2350 |
* constant string as a result of using the PrintWriter. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2351 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2352 |
public PrintWriter asWriter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2353 |
return new ElemW(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2354 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2355 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2356 |
class ElemW extends PrintWriter { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2357 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2358 |
ElemW() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2359 |
super(new StringWriter()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2360 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2361 |
final StringBuffer buf = ((StringWriter) out).getBuffer(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2362 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2363 |
{ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2364 |
lock = buf; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2365 |
} // synchronize on this buffer |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2366 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2367 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2368 |
public void println() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2369 |
synchronized (buf) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2370 |
ensureCursor(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2371 |
super.println(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2372 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2373 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2374 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2375 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2376 |
public void write(int ch) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2377 |
synchronized (buf) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2378 |
ensureCursor(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2379 |
//buf.append(ch); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2380 |
super.write(ch); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2381 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2382 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2383 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2384 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2385 |
public void write(char buf[], int off, int len) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2386 |
synchronized (buf) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2387 |
ensureCursor(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2388 |
super.write(buf, off, len); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2389 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2390 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2391 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2392 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2393 |
public void write(String s, int off, int len) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2394 |
synchronized (buf) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2395 |
ensureCursor(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2396 |
//buf.append(s.substring(off, off+len)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2397 |
super.write(s, off, len); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2398 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2399 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2400 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2401 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2402 |
public void write(String s) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2403 |
synchronized (buf) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2404 |
ensureCursor(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2405 |
//buf.append(s); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2406 |
super.write(s); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2407 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2408 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2409 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2410 |
private void ensureCursor() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2411 |
checkNotFrozen(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2412 |
if (getLast() != buf) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2413 |
int pos = indexOf(buf); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2414 |
if (pos >= 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2415 |
// Freeze the pre-existing use of buf. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2416 |
setRaw(pos, buf.toString()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2417 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2418 |
add(buf); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2419 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2420 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2421 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2422 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2423 |
/** Produce a map view of attributes, in which the attribute |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2424 |
* name strings are the keys. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2425 |
* (The map view does not provide access to the element's |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2426 |
* name or sub-elements.) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2427 |
* Changes to this view are immediately reflected in the |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2428 |
* element itself. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2429 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2430 |
public Map<String, String> asAttrMap() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2431 |
class Entry implements Map.Entry<String, String> { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2432 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2433 |
final int k; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2434 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2435 |
Entry(int k) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2436 |
this.k = k; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2437 |
assert (((String) getKey()).toString() != null); // check, fail-fast |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2438 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2439 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2440 |
public String getKey() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2441 |
return Element.this.getAttrName(k); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2442 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2443 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2444 |
public String getValue() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2445 |
return Element.this.getAttr(k); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2446 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2447 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2448 |
public String setValue(String v) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2449 |
return Element.this.setAttr(k, v.toString()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2450 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2451 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2452 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2453 |
public boolean equals(Object o) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2454 |
if (!(o instanceof Map.Entry)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2455 |
return false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2456 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2457 |
Map.Entry that = (Map.Entry) o; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2458 |
return (this.getKey().equals(that.getKey()) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2459 |
&& this.getValue().equals(that.getValue())); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2460 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2461 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2462 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2463 |
public int hashCode() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2464 |
return getKey().hashCode() ^ getValue().hashCode(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2465 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2466 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2467 |
class EIter implements Iterator<Map.Entry<String, String>> { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2468 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2469 |
int k = 0; // index of pending next() attribute |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2470 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2471 |
public boolean hasNext() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2472 |
return Element.this.containsAttr(k); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2473 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2474 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2475 |
public Map.Entry<String, String> next() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2476 |
return new Entry(k++); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2477 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2478 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2479 |
public void remove() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2480 |
Element.this.removeAttr(--k); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2481 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2482 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2483 |
class ESet extends AbstractSet<Map.Entry<String, String>> { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2484 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2485 |
public int size() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2486 |
return Element.this.attrSize(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2487 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2488 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2489 |
public Iterator<Map.Entry<String, String>> iterator() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2490 |
return new EIter(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2491 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2492 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2493 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2494 |
public void clear() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2495 |
Element.this.clearAttrs(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2496 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2497 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2498 |
class AView extends AbstractMap<String, String> { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2499 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2500 |
private transient Set<Map.Entry<String, String>> eSet; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2501 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2502 |
public Set<Map.Entry<String, String>> entrySet() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2503 |
if (eSet == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2504 |
eSet = new ESet(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2505 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2506 |
return eSet; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2507 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2508 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2509 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2510 |
public int size() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2511 |
return Element.this.attrSize(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2512 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2513 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2514 |
public boolean containsKey(String k) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2515 |
return Element.this.containsAttr(k); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2516 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2517 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2518 |
public String get(String k) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2519 |
return Element.this.getAttr(k); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2520 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2521 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2522 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2523 |
public String put(String k, String v) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2524 |
return Element.this.setAttr(k, v.toString()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2525 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2526 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2527 |
public String remove(String k) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2528 |
return Element.this.setAttr(k, null); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2529 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2530 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2531 |
return new AView(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2532 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2533 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2534 |
/** Reports number of additional elements this object can accommodate |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2535 |
* without reallocation. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2536 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2537 |
public int getExtraCapacity() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2538 |
int abase = attrBase(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2539 |
return Math.max(0, abase - size - NEED_SLOP); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2540 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2541 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2542 |
/** Ensures that at least the given number of additional elements |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2543 |
* can be added to this object without reallocation. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2544 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2545 |
public void ensureExtraCapacity(int cap) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2546 |
if (cap == 0 || hasNulls(cap + NEED_SLOP)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2547 |
return; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2548 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2549 |
setExtraCapacity(cap); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2550 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2551 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2552 |
/** |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2553 |
* Trim excess capacity to zero, or do nothing if frozen. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2554 |
* This minimizes the space occupied by this Element, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2555 |
* at the expense of a reallocation if sub-elements or attributes |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2556 |
* are added later. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2557 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2558 |
public void trimToSize() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2559 |
if (isFrozen()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2560 |
return; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2561 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2562 |
setExtraCapacity(0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2563 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2564 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2565 |
/** Changes the number of additional elements this object can accommodate |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2566 |
* without reallocation. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2567 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2568 |
public void setExtraCapacity(int cap) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2569 |
checkNotFrozen(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2570 |
int abase = attrBase(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2571 |
int alen = parts.length - abase; // slots allocated for attrs |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2572 |
int nlen = size + cap + NEED_SLOP + alen; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2573 |
if (nlen != parts.length) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2574 |
Object[] nparts = new Object[nlen]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2575 |
// copy attributes |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2576 |
System.arraycopy(parts, abase, nparts, nlen - alen, alen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2577 |
// copy sub-elements |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2578 |
System.arraycopy(parts, 0, nparts, 0, size); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2579 |
parts = nparts; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2580 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2581 |
assert (cap == getExtraCapacity()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2582 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2583 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2584 |
// Return true if there are at least len nulls of slop available. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2585 |
boolean hasNulls(int len) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2586 |
if (len == 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2587 |
return true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2588 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2589 |
int lastNull = size + len - 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2590 |
if (lastNull >= parts.length) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2591 |
return false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2592 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2593 |
return (parts[lastNull] == null); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2594 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2595 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2596 |
// Opens up parts array at pos by len spaces. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2597 |
void open(int pos, int len) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2598 |
assert (pos < size); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2599 |
assert (hasNulls(len + NEED_SLOP)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2600 |
checkNotFrozen(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2601 |
int nsize = size + len; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2602 |
int tlen = size - pos; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2603 |
System.arraycopy(parts, pos, parts, pos + len, tlen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2604 |
size = nsize; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2605 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2606 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2607 |
// Reallocate and open up at parts[pos] to at least len empty places. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2608 |
// Shift anything after pos right by len. Reallocate if necessary. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2609 |
// If pos < size, caller must fill it in with non-null values. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2610 |
// Returns incremented size; caller is responsible for storing it |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2611 |
// down, if desired. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2612 |
int expand(int pos, int len) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2613 |
assert (pos <= size); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2614 |
// There must be at least len nulls between elems and attrs. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2615 |
assert (!hasNulls(NEED_SLOP + len)); // caller responsibility |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2616 |
checkNotFrozen(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2617 |
int nsize = size + len; // length of all elements |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2618 |
int tlen = size - pos; // length of elements in post-pos tail |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2619 |
int abase = attrBase(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2620 |
int alen = parts.length - abase; // slots allocated for attrs |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2621 |
int nlen = nsize + alen + NEED_SLOP; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2622 |
nlen += (nlen >>> 1); // add new slop! |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2623 |
Object[] nparts = new Object[nlen]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2624 |
// copy head of sub-elements |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2625 |
System.arraycopy(parts, 0, nparts, 0, pos); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2626 |
// copy tail of sub-elements |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2627 |
System.arraycopy(parts, pos, nparts, pos + len, tlen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2628 |
// copy attributes |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2629 |
System.arraycopy(parts, abase, nparts, nlen - alen, alen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2630 |
// update self |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2631 |
parts = nparts; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2632 |
//assert(hasNulls(len)); <- not yet true, since size != nsize |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2633 |
return nsize; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2634 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2635 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2636 |
// Open or expand at the given position, as appropriate. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2637 |
boolean openOrExpand(int pos, int len) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2638 |
if (pos < 0 || pos > size) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2639 |
badIndex(pos); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2640 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2641 |
if (hasNulls(len + NEED_SLOP)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2642 |
if (pos == size) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2643 |
size += len; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2644 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2645 |
open(pos, len); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2646 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2647 |
return false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2648 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2649 |
size = expand(pos, len); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2650 |
return true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2651 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2652 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2653 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2654 |
// Close up at parts[pos] len old places. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2655 |
// Shift anything after pos left by len. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2656 |
// Fill unused end of parts with null. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2657 |
void close(int pos, int len) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2658 |
assert (len > 0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2659 |
assert ((size - pos) >= len); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2660 |
checkNotFrozen(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2661 |
int tlen = (size - pos) - len; // length of elements in post-pos tail |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2662 |
int nsize = size - len; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2663 |
System.arraycopy(parts, pos + len, parts, pos, tlen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2664 |
// reinitialize the unoccupied slots to null |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2665 |
clearParts(nsize, nsize + len); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2666 |
// update self |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2667 |
size = nsize; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2668 |
assert (hasNulls(len)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2669 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2670 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2671 |
public void writeTo(Writer w) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2672 |
new Printer(w).print(this); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2673 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2674 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2675 |
public void writePrettyTo(Writer w) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2676 |
prettyPrintTo(w, this); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2677 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2678 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2679 |
public String prettyString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2680 |
StringWriter sw = new StringWriter(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2681 |
try { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2682 |
writePrettyTo(sw); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2683 |
} catch (IOException ee) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2684 |
throw new Error(ee); // should not happen |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2685 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2686 |
return sw.toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2687 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2688 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2689 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2690 |
public String toString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2691 |
StringWriter sw = new StringWriter(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2692 |
try { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2693 |
writeTo(sw); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2694 |
} catch (IOException ee) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2695 |
throw new Error(ee); // should not happen |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2696 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2697 |
return sw.toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2698 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2699 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2700 |
public String dump() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2701 |
// For debugging only. Reveals internal layout. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2702 |
StringBuilder buf = new StringBuilder(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2703 |
buf.append("<").append(name).append("[").append(size).append("]"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2704 |
for (int i = 0; i < parts.length; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2705 |
Object p = parts[i]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2706 |
if (p == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2707 |
buf.append(" null"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2708 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2709 |
buf.append(" {"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2710 |
String cname = p.getClass().getName(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2711 |
cname = cname.substring(1 + cname.indexOf('/')); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2712 |
cname = cname.substring(1 + cname.indexOf('$')); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2713 |
cname = cname.substring(1 + cname.indexOf('#')); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2714 |
if (!cname.equals("String")) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2715 |
buf.append(cname).append(":"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2716 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2717 |
buf.append(p); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2718 |
buf.append("}"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2719 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2720 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2721 |
return buf.append(">").toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2722 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2723 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2724 |
public static java.lang.reflect.Method method(String name) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2725 |
HashMap allM = allMethods; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2726 |
if (allM == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2727 |
allM = makeAllMethods(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2728 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2729 |
java.lang.reflect.Method res = (java.lang.reflect.Method) allMethods.get(name); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2730 |
if (res == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2731 |
throw new IllegalArgumentException(name); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2732 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2733 |
return res; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2734 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2735 |
private static HashMap allMethods; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2736 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2737 |
private static synchronized HashMap makeAllMethods() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2738 |
if (allMethods != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2739 |
return allMethods; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2740 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2741 |
java.lang.reflect.Method[] methods = Element.class.getMethods(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2742 |
HashMap<String, java.lang.reflect.Method> allM = new HashMap<String, java.lang.reflect.Method>(), |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2743 |
ambig = new HashMap<String, java.lang.reflect.Method>(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2744 |
for (int i = 0; i < methods.length; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2745 |
java.lang.reflect.Method m = methods[i]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2746 |
Class[] args = m.getParameterTypes(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2747 |
String name = m.getName(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2748 |
assert (java.lang.reflect.Modifier.isPublic(m.getModifiers())); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2749 |
if (name.startsWith("notify")) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2750 |
continue; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2751 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2752 |
if (name.endsWith("Attr") |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2753 |
&& args.length > 0 && args[0] == int.class) // ignore getAttr(int), etc. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2754 |
{ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2755 |
continue; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2756 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2757 |
if (name.endsWith("All") |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2758 |
&& args.length > 1 && args[0] == Filter.class) // ignore findAll(Filter, int...), etc. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2759 |
{ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2760 |
continue; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2761 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2762 |
java.lang.reflect.Method pm = allM.put(name, m); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2763 |
if (pm != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2764 |
Class[] pargs = pm.getParameterTypes(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2765 |
if (pargs.length > args.length) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2766 |
allM.put(name, pm); // put it back |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2767 |
} else if (pargs.length == args.length) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2768 |
ambig.put(name, pm); // make a note of it |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2769 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2770 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2771 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2772 |
// Delete ambiguous methods. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2773 |
for (Map.Entry<String, java.lang.reflect.Method> e : ambig.entrySet()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2774 |
String name = e.getKey(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2775 |
java.lang.reflect.Method pm = e.getValue(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2776 |
java.lang.reflect.Method m = allM.get(name); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2777 |
Class[] args = m.getParameterTypes(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2778 |
Class[] pargs = pm.getParameterTypes(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2779 |
if (pargs.length == args.length) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2780 |
//System.out.println("ambig: "+pm); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2781 |
//System.out.println(" with: "+m); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2782 |
//ambig: int addAll(int,Element) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2783 |
// with: int addAll(int,Collection) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2784 |
allM.put(name, null); // get rid of |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2785 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2786 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2787 |
//System.out.println("allM: "+allM); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2788 |
return allMethods = allM; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2789 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2790 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2791 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2792 |
static Object fixupString(Object part) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2793 |
if (part instanceof CharSequence && !(part instanceof String)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2794 |
return part.toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2795 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2796 |
return part; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2797 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2798 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2799 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2800 |
public static final class Special implements Comparable<Special> { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2801 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2802 |
String kind; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2803 |
Object value; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2804 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2805 |
public Special(String kind, Object value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2806 |
this.kind = kind; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2807 |
this.value = value; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2808 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2809 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2810 |
public String getKind() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2811 |
return kind; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2812 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2813 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2814 |
public Object getValue() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2815 |
return value; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2816 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2817 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2818 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2819 |
public boolean equals(Object o) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2820 |
if (!(o instanceof Special)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2821 |
return false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2822 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2823 |
Special that = (Special) o; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2824 |
return this.kind.equals(that.kind) && this.value.equals(that.value); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2825 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2826 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2827 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2828 |
public int hashCode() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2829 |
return kind.hashCode() * 65 + value.hashCode(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2830 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2831 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2832 |
public int compareTo(Special that) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2833 |
int r = this.kind.compareTo(that.kind); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2834 |
if (r != 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2835 |
return r; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2836 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2837 |
return ((Comparable) this.value).compareTo(that.value); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2838 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2839 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2840 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2841 |
public String toString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2842 |
int split = kind.indexOf(' '); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2843 |
String pref = kind.substring(0, split < 0 ? 0 : split); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2844 |
String post = kind.substring(split + 1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2845 |
return pref + value + post; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2846 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2847 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2848 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2849 |
/** Supports sorting of mixed content. Sorts strings first, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2850 |
* then Elements, then everything else (as Comparable). |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2851 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2852 |
public static Comparator<Object> contentOrder() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2853 |
return CONTENT_ORDER; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2854 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2855 |
private static Comparator<Object> CONTENT_ORDER = new ContentComparator(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2856 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2857 |
private static class ContentComparator implements Comparator<Object> { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2858 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2859 |
public int compare(Object o1, Object o2) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2860 |
boolean cs1 = (o1 instanceof CharSequence); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2861 |
boolean cs2 = (o2 instanceof CharSequence); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2862 |
if (cs1 && cs2) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2863 |
String s1 = (String) fixupString(o1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2864 |
String s2 = (String) fixupString(o2); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2865 |
return s1.compareTo(s2); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2866 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2867 |
if (cs1) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2868 |
return 0 - 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2869 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2870 |
if (cs2) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2871 |
return 1 - 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2872 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2873 |
boolean el1 = (o1 instanceof Element); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2874 |
boolean el2 = (o2 instanceof Element); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2875 |
if (el1 && el2) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2876 |
return ((Element) o1).compareTo((Element) o2); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2877 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2878 |
if (el1) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2879 |
return 0 - 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2880 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2881 |
if (el2) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2882 |
return 1 - 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2883 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2884 |
return ((Comparable) o1).compareTo(o2); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2885 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2886 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2887 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2888 |
/** Used to find, filter, or transform sub-elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2889 |
* When used as a predicate, the filter returns a null |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2890 |
* value for false, and the original object value for true. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2891 |
* When used as a transformer, the filter may return |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2892 |
* null, for no values, the original object, a new object, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2893 |
* or an anonymous Element (meaning multiple results). |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2894 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2895 |
public interface Filter { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2896 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2897 |
Object filter(Object value); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2898 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2899 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2900 |
/** Use this to find an element, perhaps with a given name. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2901 |
public static class ElementFilter implements Filter { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2902 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2903 |
/** Subclasses may override this to implement better value tests. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2904 |
* By default, it returns the element itself, thus recognizing |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2905 |
* all elements, regardless of name. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2906 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2907 |
public Element filter(Element elem) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2908 |
return elem; // override this |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2909 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2910 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2911 |
public final Object filter(Object value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2912 |
if (!(value instanceof Element)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2913 |
return null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2914 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2915 |
return filter((Element) value); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2916 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2917 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2918 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2919 |
public String toString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2920 |
return "<ElementFilter name='*'/>"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2921 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2922 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2923 |
private static Filter elementFilter; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2924 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2925 |
public static Filter elementFilter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2926 |
return (elementFilter != null) ? elementFilter : (elementFilter = new ElementFilter()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2927 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2928 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2929 |
public static Filter elementFilter(final String name) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2930 |
name.toString(); // null check |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2931 |
return new ElementFilter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2932 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2933 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2934 |
public Element filter(Element elem) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2935 |
return name.equals(elem.name) ? elem : null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2936 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2937 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2938 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2939 |
public String toString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2940 |
return "<ElementFilter name='" + name + "'/>"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2941 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2942 |
}; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2943 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2944 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2945 |
public static Filter elementFilter(final Collection nameSet) { |
29094
a4fd2b5e49f8
8073479: Replace obj.getClass hacks with Objects.requireNonNull
shade
parents:
6314
diff
changeset
|
2946 |
Objects.requireNonNull(nameSet); |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2947 |
return new ElementFilter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2948 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2949 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2950 |
public Element filter(Element elem) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2951 |
return nameSet.contains(elem.name) ? elem : null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2952 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2953 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2954 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2955 |
public String toString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2956 |
return "<ElementFilter name='" + nameSet + "'/>"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2957 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2958 |
}; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2959 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2960 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2961 |
public static Filter elementFilter(String... nameSet) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2962 |
Collection<String> ncoll = Arrays.asList(nameSet); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2963 |
if (nameSet.length > 10) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2964 |
ncoll = new HashSet<String>(ncoll); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2965 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2966 |
return elementFilter(ncoll); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2967 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2968 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2969 |
/** Use this to find an element with a named attribute, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2970 |
* possibly with a particular value. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2971 |
* (Note that an attribute is missing if and only if its value is null.) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2972 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2973 |
public static class AttrFilter extends ElementFilter { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2974 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2975 |
protected final String attrName; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2976 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2977 |
public AttrFilter(String attrName) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2978 |
this.attrName = attrName.toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2979 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2980 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2981 |
/** Subclasses may override this to implement better value tests. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2982 |
* By default, it returns true for any non-null value, thus |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2983 |
* recognizing any attribute of the given name, regardless of value. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2984 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2985 |
public boolean test(String attrVal) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2986 |
return attrVal != null; // override this |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2987 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2988 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2989 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2990 |
public final Element filter(Element elem) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2991 |
return test(elem.getAttr(attrName)) ? elem : null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2992 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2993 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2994 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2995 |
public String toString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2996 |
return "<AttrFilter name='" + attrName + "' value='*'/>"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2997 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2998 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
2999 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3000 |
public static Filter attrFilter(String attrName) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3001 |
return new AttrFilter(attrName); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3002 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3003 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3004 |
public static Filter attrFilter(String attrName, final String attrVal) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3005 |
if (attrVal == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3006 |
return not(attrFilter(attrName)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3007 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3008 |
return new AttrFilter(attrName) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3009 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3010 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3011 |
public boolean test(String attrVal2) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3012 |
return attrVal.equals(attrVal2); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3013 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3014 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3015 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3016 |
public String toString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3017 |
return "<AttrFilter name='" + attrName + "' value='" + attrVal + "'/>"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3018 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3019 |
}; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3020 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3021 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3022 |
public static Filter attrFilter(Element matchThis, String attrName) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3023 |
return attrFilter(attrName, matchThis.getAttr(attrName)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3024 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3025 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3026 |
/** Use this to find a sub-element of a given class. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3027 |
public static Filter classFilter(final Class clazz) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3028 |
return new Filter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3029 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3030 |
public Object filter(Object value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3031 |
return clazz.isInstance(value) ? value : null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3032 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3033 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3034 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3035 |
public String toString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3036 |
return "<ClassFilter class='" + clazz.getName() + "'/>"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3037 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3038 |
}; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3039 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3040 |
private static Filter textFilter; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3041 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3042 |
public static Filter textFilter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3043 |
return (textFilter != null) ? textFilter : (textFilter = classFilter(CharSequence.class)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3044 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3045 |
private static Filter specialFilter; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3046 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3047 |
public static Filter specialFilter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3048 |
return (specialFilter != null) ? specialFilter : (specialFilter = classFilter(Special.class)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3049 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3050 |
private static Filter selfFilter; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3051 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3052 |
/** This filter always returns its own argument. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3053 |
public static Filter selfFilter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3054 |
if (selfFilter != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3055 |
return selfFilter; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3056 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3057 |
return selfFilter = new Filter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3058 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3059 |
public Object filter(Object value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3060 |
return value; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3061 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3062 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3063 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3064 |
public String toString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3065 |
return "<Self/>"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3066 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3067 |
}; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3068 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3069 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3070 |
/** This filter always returns a fixed value, regardless of argument. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3071 |
public static Filter constantFilter(final Object value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3072 |
return new Filter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3073 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3074 |
public Object filter(Object ignore) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3075 |
return value; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3076 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3077 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3078 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3079 |
public String toString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3080 |
return "<Constant>" + value + "</Constant>"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3081 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3082 |
}; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3083 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3084 |
private static Filter nullFilter; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3085 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3086 |
public static Filter nullFilter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3087 |
return (nullFilter != null) ? nullFilter : (nullFilter = constantFilter(null)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3088 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3089 |
private static Filter emptyFilter; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3090 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3091 |
public static Filter emptyFilter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3092 |
return (emptyFilter != null) ? emptyFilter : (emptyFilter = constantFilter(Element.EMPTY)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3093 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3094 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3095 |
/** Use this to invert the logical sense of the given filter. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3096 |
public static Filter not(final Filter f) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3097 |
return new Filter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3098 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3099 |
public Object filter(Object value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3100 |
return f.filter(value) == null ? value : null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3101 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3102 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3103 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3104 |
public String toString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3105 |
return "<Not>" + f + "</Not>"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3106 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3107 |
}; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3108 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3109 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3110 |
/** Use this to combine several filters with logical AND. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3111 |
* Returns either the first null or the last non-null value. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3112 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3113 |
public static Filter and(final Filter f0, final Filter f1) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3114 |
return and(new Filter[]{f0, f1}); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3115 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3116 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3117 |
public static Filter and(final Filter... fs) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3118 |
switch (fs.length) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3119 |
case 0: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3120 |
return selfFilter(); // always true (on non-null inputs) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3121 |
case 1: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3122 |
return fs[0]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3123 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3124 |
return new Filter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3125 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3126 |
public Object filter(Object value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3127 |
Object res = fs[0].filter(value); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3128 |
if (res != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3129 |
res = fs[1].filter(value); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3130 |
for (int i = 2; res != null && i < fs.length; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3131 |
res = fs[i].filter(value); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3132 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3133 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3134 |
return res; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3135 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3136 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3137 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3138 |
public String toString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3139 |
return opToString("<And>", fs, "</And>"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3140 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3141 |
}; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3142 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3143 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3144 |
/** Use this to combine several filters with logical OR. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3145 |
* Returns either the first non-null or the last null value. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3146 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3147 |
public static Filter or(final Filter f0, final Filter f1) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3148 |
return or(new Filter[]{f0, f1}); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3149 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3150 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3151 |
public static Filter or(final Filter... fs) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3152 |
switch (fs.length) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3153 |
case 0: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3154 |
return nullFilter(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3155 |
case 1: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3156 |
return fs[0]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3157 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3158 |
return new Filter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3159 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3160 |
public Object filter(Object value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3161 |
Object res = fs[0].filter(value); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3162 |
if (res == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3163 |
res = fs[1].filter(value); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3164 |
for (int i = 2; res == null && i < fs.length; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3165 |
res = fs[i].filter(value); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3166 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3167 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3168 |
return res; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3169 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3170 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3171 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3172 |
public String toString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3173 |
return opToString("<Or>", fs, "</Or>"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3174 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3175 |
}; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3176 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3177 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3178 |
/** Use this to combine several filters with logical AND, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3179 |
* and where each non-null result is passed as the argument |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3180 |
* to the next filter. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3181 |
* Returns either the first null or the last non-null value. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3182 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3183 |
public static Filter stack(final Filter f0, final Filter f1) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3184 |
return stack(new Filter[]{f0, f1}); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3185 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3186 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3187 |
public static Filter stack(final Filter... fs) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3188 |
switch (fs.length) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3189 |
case 0: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3190 |
return nullFilter(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3191 |
case 1: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3192 |
return fs[0]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3193 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3194 |
return new Filter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3195 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3196 |
public Object filter(Object value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3197 |
Object res = fs[0].filter(value); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3198 |
if (res != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3199 |
res = fs[1].filter(res); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3200 |
for (int i = 2; res != null && i < fs.length; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3201 |
res = fs[i].filter(res); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3202 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3203 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3204 |
return res; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3205 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3206 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3207 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3208 |
public String toString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3209 |
return opToString("<Stack>", fs, "</Stack>"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3210 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3211 |
}; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3212 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3213 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3214 |
/** Copy everything produced by f to sink, using addContent. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3215 |
public static Filter content(final Filter f, final Collection<Object> sink) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3216 |
return new Filter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3217 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3218 |
public Object filter(Object value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3219 |
Object res = f.filter(value); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3220 |
addContent(res, sink); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3221 |
return res; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3222 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3223 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3224 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3225 |
public String toString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3226 |
return opToString("<addContent>", new Object[]{f, sink}, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3227 |
"</addContent>"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3228 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3229 |
}; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3230 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3231 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3232 |
/** Look down the tree using f, collecting fx, else recursing into x. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3233 |
* Identities: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3234 |
* <code> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3235 |
* findInTree(f, s) == findInTree(content(f, s)) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3236 |
* findInTree(f) == replaceInTree(and(f, selfFilter())). |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3237 |
* </code> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3238 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3239 |
public static Filter findInTree(Filter f, Collection<Object> sink) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3240 |
if (sink != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3241 |
f = content(f, sink); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3242 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3243 |
return findInTree(f); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3244 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3245 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3246 |
/** Look down the tree using f, recursing into x unless fx. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3247 |
public static Filter findInTree(final Filter f) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3248 |
return new Filter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3249 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3250 |
public Object filter(Object value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3251 |
Object res = f.filter(value); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3252 |
if (res != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3253 |
return res; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3254 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3255 |
if (value instanceof Element) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3256 |
// recurse |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3257 |
return ((Element) value).find(this); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3258 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3259 |
return null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3260 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3261 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3262 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3263 |
public String toString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3264 |
return opToString("<FindInTree>", new Object[]{f}, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3265 |
"</FindInTree>"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3266 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3267 |
}; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3268 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3269 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3270 |
/** Look down the tree using f. Replace each x with fx, else recurse. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3271 |
* If post filter g is given, optionally replace with gx after recursion. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3272 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3273 |
public static Filter replaceInTree(final Filter f, final Filter g) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3274 |
return new Filter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3275 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3276 |
public Object filter(Object value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3277 |
Object res = (f == null) ? null : f.filter(value); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3278 |
if (res != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3279 |
return res; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3280 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3281 |
if (value instanceof Element) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3282 |
// recurse |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3283 |
((Element) value).replaceAll(this); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3284 |
// Optional postorder traversal: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3285 |
if (g != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3286 |
res = g.filter(value); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3287 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3288 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3289 |
return res; // usually null, meaning no replacement |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3290 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3291 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3292 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3293 |
public String toString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3294 |
return opToString("<ReplaceInTree>", |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3295 |
new Object[]{f, g}, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3296 |
"</ReplaceInTree>"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3297 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3298 |
}; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3299 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3300 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3301 |
public static Filter replaceInTree(Filter f) { |
29094
a4fd2b5e49f8
8073479: Replace obj.getClass hacks with Objects.requireNonNull
shade
parents:
6314
diff
changeset
|
3302 |
Objects.requireNonNull(f); |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3303 |
return replaceInTree(f, null); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3304 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3305 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3306 |
/** Make a filter which calls this method on the given element. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3307 |
* If the method is static, the first argument is passed the |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3308 |
* the subtree value being filtered. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3309 |
* If the method is non-static, the receiver is the subtree value itself. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3310 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3311 |
* Optionally, additional arguments may be specified. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3312 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3313 |
* If the filtered value does not match the receiver class |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3314 |
* (or else the first argument type, if the method is static), |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3315 |
* the filter returns null without invoking the method. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3316 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3317 |
* The returned filter value is the result returned from the method. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3318 |
* Optionally, a non-null special false result value may be specified. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3319 |
* If the result returned from the method is equal to that false value, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3320 |
* the filter will return null. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3321 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3322 |
public static Filter methodFilter(java.lang.reflect.Method m, Object[] extraArgs, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3323 |
Object falseResult) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3324 |
return methodFilter(m, false, extraArgs, falseResult); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3325 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3326 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3327 |
public static Filter methodFilter(java.lang.reflect.Method m, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3328 |
Object[] args) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3329 |
return methodFilter(m, args, null); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3330 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3331 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3332 |
public static Filter methodFilter(java.lang.reflect.Method m) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3333 |
return methodFilter(m, null, null); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3334 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3335 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3336 |
public static Filter testMethodFilter(java.lang.reflect.Method m, Object[] extraArgs, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3337 |
Object falseResult) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3338 |
return methodFilter(m, true, extraArgs, falseResult); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3339 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3340 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3341 |
public static Filter testMethodFilter(java.lang.reflect.Method m, Object[] extraArgs) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3342 |
return methodFilter(m, true, extraArgs, zeroArgs.get(m.getReturnType())); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3343 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3344 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3345 |
public static Filter testMethodFilter(java.lang.reflect.Method m) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3346 |
return methodFilter(m, true, null, zeroArgs.get(m.getReturnType())); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3347 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3348 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3349 |
private static Filter methodFilter(final java.lang.reflect.Method m, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3350 |
final boolean isTest, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3351 |
Object[] extraArgs, final Object falseResult) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3352 |
Class[] params = m.getParameterTypes(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3353 |
final boolean isStatic = java.lang.reflect.Modifier.isStatic(m.getModifiers()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3354 |
int insertLen = (isStatic ? 1 : 0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3355 |
if (insertLen + (extraArgs == null ? 0 : extraArgs.length) > params.length) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3356 |
throw new IllegalArgumentException("too many arguments"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3357 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3358 |
final Object[] args = (params.length == insertLen) ? null |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3359 |
: new Object[params.length]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3360 |
final Class valueType = !isStatic ? m.getDeclaringClass() : params[0]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3361 |
if (valueType.isPrimitive()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3362 |
throw new IllegalArgumentException("filtered value must be reference type"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3363 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3364 |
int fillp = insertLen; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3365 |
if (extraArgs != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3366 |
for (int i = 0; i < extraArgs.length; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3367 |
args[fillp++] = extraArgs[i]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3368 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3369 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3370 |
if (args != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3371 |
while (fillp < args.length) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3372 |
Class param = params[fillp]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3373 |
args[fillp++] = param.isPrimitive() ? zeroArgs.get(param) : null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3374 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3375 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3376 |
final Thread curt = Thread.currentThread(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3377 |
class MFilt implements Filter { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3378 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3379 |
public Object filter(Object value) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3380 |
if (!valueType.isInstance(value)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3381 |
return null; // filter fails quickly |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3382 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3383 |
Object[] args1 = args; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3384 |
if (isStatic) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3385 |
if (args1 == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3386 |
args1 = new Object[1]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3387 |
} else if (curt != Thread.currentThread()) // Dirty hack to curtail array copying in common case. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3388 |
{ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3389 |
args1 = (Object[]) args1.clone(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3390 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3391 |
args1[0] = value; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3392 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3393 |
Object res; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3394 |
try { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3395 |
res = m.invoke(value, args1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3396 |
} catch (java.lang.reflect.InvocationTargetException te) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3397 |
Throwable ee = te.getCause(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3398 |
if (ee instanceof RuntimeException) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3399 |
throw (RuntimeException) ee; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3400 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3401 |
if (ee instanceof Error) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3402 |
throw (Error) ee; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3403 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3404 |
throw new RuntimeException("throw in filter", ee); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3405 |
} catch (IllegalAccessException ee) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3406 |
throw new RuntimeException("access error in filter", ee); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3407 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3408 |
if (res == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3409 |
if (!isTest && m.getReturnType() == Void.TYPE) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3410 |
// Void methods return self by convention. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3411 |
// (But void "tests" always return false.) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3412 |
res = value; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3413 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3414 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3415 |
if (falseResult != null && falseResult.equals(res)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3416 |
res = null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3417 |
} else if (isTest) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3418 |
// Tests return self by convention. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3419 |
res = value; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3420 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3421 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3422 |
return res; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3423 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3424 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3425 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3426 |
public String toString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3427 |
return "<Method>" + m + "</Method>"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3428 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3429 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3430 |
return new MFilt(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3431 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3432 |
private static HashMap<Class, Object> zeroArgs = new HashMap<Class, Object>(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3433 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3434 |
static { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3435 |
zeroArgs.put(Boolean.TYPE, Boolean.FALSE); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3436 |
zeroArgs.put(Character.TYPE, new Character((char) 0)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3437 |
zeroArgs.put(Byte.TYPE, new Byte((byte) 0)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3438 |
zeroArgs.put(Short.TYPE, new Short((short) 0)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3439 |
zeroArgs.put(Integer.TYPE, new Integer(0)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3440 |
zeroArgs.put(Float.TYPE, new Float(0)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3441 |
zeroArgs.put(Long.TYPE, new Long(0)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3442 |
zeroArgs.put(Double.TYPE, new Double(0)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3443 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3444 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3445 |
private static String opToString(String s1, Object[] s2, String s3) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3446 |
StringBuilder buf = new StringBuilder(s1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3447 |
for (int i = 0; i < s2.length; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3448 |
if (s2[i] != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3449 |
buf.append(s2[i]); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3450 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3451 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3452 |
buf.append(s3); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3453 |
return buf.toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3454 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3455 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3456 |
/** Call the filter on each list element x, and replace x with the |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3457 |
* resulting filter value e, or its parts. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3458 |
* If e is null, keep x. (This eases use of partial-domain filters.) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3459 |
* If e is a TokenList or an anonymous Element, add e's parts |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3460 |
* to the list instead of x. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3461 |
* Otherwise, replace x by e. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3462 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3463 |
* The effect at each list position <code>n</code> may be expressed |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3464 |
* in terms of XMLKit.addContent as follows: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3465 |
* <pre> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3466 |
* Object e = f.filter(target.get(n)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3467 |
* if (e != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3468 |
* target.remove(n); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3469 |
* addContent(e, target.subList(n,n)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3470 |
* } |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3471 |
* </pre> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3472 |
* <p> |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3473 |
* Note: To force deletion of x, simply have the filter return |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3474 |
* Element.EMPTY or TokenList.EMPTY. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3475 |
* To force null filter values to have this effect, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3476 |
* use the expression: <code>or(f, emptyFilter())</code>. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3477 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3478 |
public static void replaceAll(Filter f, List<Object> target) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3479 |
for (ListIterator<Object> i = target.listIterator(); i.hasNext();) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3480 |
Object x = i.next(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3481 |
Object fx = f.filter(x); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3482 |
if (fx == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3483 |
// Unliked addContent, a null is a no-op here. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3484 |
// i.remove(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3485 |
} else if (fx instanceof TokenList) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3486 |
TokenList tl = (TokenList) fx; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3487 |
if (tl.size() == 1) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3488 |
i.set(tl); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3489 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3490 |
i.remove(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3491 |
for (String part : tl) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3492 |
i.add(part); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3493 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3494 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3495 |
} else if (fx instanceof Element |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3496 |
&& ((Element) fx).isAnonymous()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3497 |
Element anon = (Element) fx; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3498 |
if (anon.size() == 1) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3499 |
i.set(anon); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3500 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3501 |
i.remove(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3502 |
for (Object part : anon) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3503 |
i.add(part); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3504 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3505 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3506 |
} else if (x != fx) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3507 |
i.set(fx); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3508 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3509 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3510 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3511 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3512 |
/** If e is null, return zero. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3513 |
* If e is a TokenList or an anonymous Element, add e's parts |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3514 |
* to the collection, and return the number of parts. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3515 |
* Otherwise, add e to the collection, and return one. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3516 |
* If the collection reference is null, the result is as if |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3517 |
* a throwaway collection were used. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3518 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3519 |
public static int addContent(Object e, Collection<Object> sink) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3520 |
if (e == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3521 |
return 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3522 |
} else if (e instanceof TokenList) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3523 |
TokenList tl = (TokenList) e; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3524 |
if (sink != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3525 |
sink.addAll(tl); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3526 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3527 |
return tl.size(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3528 |
} else if (e instanceof Element |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3529 |
&& ((Element) e).isAnonymous()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3530 |
Element anon = (Element) e; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3531 |
if (sink != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3532 |
sink.addAll(anon.asList()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3533 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3534 |
return anon.size(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3535 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3536 |
if (sink != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3537 |
sink.add(e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3538 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3539 |
return 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3540 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3541 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3542 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3543 |
static Collection<Object> newCounterColl() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3544 |
return new AbstractCollection<Object>() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3545 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3546 |
int size; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3547 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3548 |
public int size() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3549 |
return size; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3550 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3551 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3552 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3553 |
public boolean add(Object o) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3554 |
++size; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3555 |
return true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3556 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3557 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3558 |
public Iterator<Object> iterator() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3559 |
throw new UnsupportedOperationException(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3560 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3561 |
}; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3562 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3563 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3564 |
/** SAX2 document handler for building Element trees. */ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3565 |
private static class Builder implements ContentHandler, LexicalHandler { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3566 |
/*, EntityResolver, DTDHandler, ErrorHandler*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3567 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3568 |
Collection<Object> sink; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3569 |
boolean makeFrozen; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3570 |
boolean tokenizing; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3571 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3572 |
Builder(Collection<Object> sink, boolean tokenizing, boolean makeFrozen) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3573 |
this.sink = sink; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3574 |
this.tokenizing = tokenizing; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3575 |
this.makeFrozen = makeFrozen; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3576 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3577 |
Object[] parts = new Object[30]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3578 |
int nparts = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3579 |
int[] attrBases = new int[10]; // index into parts |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3580 |
int[] elemBases = new int[10]; // index into parts |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3581 |
int depth = -1; // index into attrBases, elemBases |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3582 |
// Parts is organized this way: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3583 |
// | name0 | akey aval ... | subelem ... | name1 | ... | |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3584 |
// The position of the first "akey" after name0 is attrBases[0]. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3585 |
// The position of the first "subelem" after name0 is elemBases[0]. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3586 |
// The position after the last part is always nparts. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3587 |
int mergeableToken = -1; // index into parts of recent CharSequence |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3588 |
boolean inCData = false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3589 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3590 |
void addPart(Object x) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3591 |
//System.out.println("addPart "+x); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3592 |
if (nparts == parts.length) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3593 |
Object[] newParts = new Object[parts.length * 2]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3594 |
System.arraycopy(parts, 0, newParts, 0, parts.length); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3595 |
parts = newParts; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3596 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3597 |
parts[nparts++] = x; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3598 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3599 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3600 |
Object getMergeableToken() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3601 |
if (mergeableToken == nparts - 1) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3602 |
assert (parts[mergeableToken] instanceof CharSequence); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3603 |
return parts[nparts - 1]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3604 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3605 |
return null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3606 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3607 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3608 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3609 |
void clearMergeableToken() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3610 |
if (mergeableToken >= 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3611 |
// Freeze temporary StringBuffers into strings. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3612 |
assert (parts[mergeableToken] instanceof CharSequence); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3613 |
parts[mergeableToken] = parts[mergeableToken].toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3614 |
mergeableToken = -1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3615 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3616 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3617 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3618 |
void setMergeableToken() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3619 |
if (mergeableToken != nparts - 1) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3620 |
clearMergeableToken(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3621 |
mergeableToken = nparts - 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3622 |
assert (parts[mergeableToken] instanceof CharSequence); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3623 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3624 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3625 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3626 |
// ContentHandler callbacks |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3627 |
public void startElement(String ns, String localName, String name, Attributes atts) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3628 |
clearMergeableToken(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3629 |
addPart(name.intern()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3630 |
++depth; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3631 |
if (depth == attrBases.length) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3632 |
int oldlen = depth; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3633 |
int newlen = depth * 2; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3634 |
int[] newAB = new int[newlen]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3635 |
int[] newEB = new int[newlen]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3636 |
System.arraycopy(attrBases, 0, newAB, 0, oldlen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3637 |
System.arraycopy(elemBases, 0, newEB, 0, oldlen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3638 |
attrBases = newAB; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3639 |
elemBases = newEB; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3640 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3641 |
attrBases[depth] = nparts; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3642 |
// Collect attributes. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3643 |
int na = atts.getLength(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3644 |
for (int k = 0; k < na; k++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3645 |
addPart(atts.getQName(k).intern()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3646 |
addPart(atts.getValue(k)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3647 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3648 |
// Get ready to collect elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3649 |
elemBases[depth] = nparts; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3650 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3651 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3652 |
public void endElement(String ns, String localName, String name) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3653 |
assert (depth >= 0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3654 |
clearMergeableToken(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3655 |
int ebase = elemBases[depth]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3656 |
int elen = nparts - ebase; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3657 |
int abase = attrBases[depth]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3658 |
int alen = ebase - abase; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3659 |
int nbase = abase - 1; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3660 |
int cap = alen + (makeFrozen ? 0 : NEED_SLOP) + elen; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3661 |
Element e = new Element((String) parts[nbase], elen, cap); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3662 |
// Set up attributes. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3663 |
for (int k = 0; k < alen; k += 2) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3664 |
e.parts[cap - k - 2] = parts[abase + k + 0]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3665 |
e.parts[cap - k - 1] = parts[abase + k + 1]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3666 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3667 |
// Set up sub-elements. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3668 |
System.arraycopy(parts, ebase, e.parts, 0, elen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3669 |
// Back out of this level. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3670 |
--depth; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3671 |
nparts = nbase; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3672 |
assert (e.isFrozen() == makeFrozen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3673 |
assert (e.size() == elen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3674 |
assert (e.attrSize() * 2 == alen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3675 |
if (depth >= 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3676 |
addPart(e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3677 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3678 |
sink.add(e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3679 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3680 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3681 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3682 |
public void startCDATA() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3683 |
inCData = true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3684 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3685 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3686 |
public void endCDATA() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3687 |
inCData = false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3688 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3689 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3690 |
public void characters(char[] buf, int off, int len) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3691 |
boolean headSpace = false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3692 |
boolean tailSpace = false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3693 |
int firstLen; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3694 |
if (tokenizing && !inCData) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3695 |
// Strip unquoted blanks. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3696 |
while (len > 0 && isWhitespace(buf[off])) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3697 |
headSpace = true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3698 |
++off; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3699 |
--len; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3700 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3701 |
if (len == 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3702 |
tailSpace = true; // it is all space |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3703 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3704 |
while (len > 0 && isWhitespace(buf[off + len - 1])) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3705 |
tailSpace = true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3706 |
--len; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3707 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3708 |
firstLen = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3709 |
while (firstLen < len && !isWhitespace(buf[off + firstLen])) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3710 |
++firstLen; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3711 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3712 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3713 |
firstLen = len; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3714 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3715 |
if (headSpace) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3716 |
clearMergeableToken(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3717 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3718 |
boolean mergeAtEnd = !tailSpace; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3719 |
// If buffer was empty, or had only ignorable blanks, do nothing. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3720 |
if (len == 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3721 |
return; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3722 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3723 |
// Decide whether to merge some of these chars into a previous token. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3724 |
Object prev = getMergeableToken(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3725 |
if (prev instanceof StringBuffer) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3726 |
((StringBuffer) prev).append(buf, off, firstLen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3727 |
} else if (prev == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3728 |
addPart(new String(buf, off, firstLen)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3729 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3730 |
// Merge two strings. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3731 |
String prevStr = prev.toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3732 |
StringBuffer prevBuf = new StringBuffer(prevStr.length() + firstLen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3733 |
prevBuf.append(prevStr); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3734 |
prevBuf.append(buf, off, firstLen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3735 |
if (mergeAtEnd && len == firstLen) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3736 |
// Replace previous string with new StringBuffer. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3737 |
parts[nparts - 1] = prevBuf; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3738 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3739 |
// Freeze it now. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3740 |
parts[nparts - 1] = prevBuf.toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3741 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3742 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3743 |
off += firstLen; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3744 |
len -= firstLen; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3745 |
if (len > 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3746 |
// Appended only the first token. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3747 |
clearMergeableToken(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3748 |
// Add the rest as separate parts. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3749 |
while (len > 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3750 |
while (len > 0 && isWhitespace(buf[off])) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3751 |
++off; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3752 |
--len; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3753 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3754 |
int nextLen = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3755 |
while (nextLen < len && !isWhitespace(buf[off + nextLen])) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3756 |
++nextLen; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3757 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3758 |
assert (nextLen > 0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3759 |
addPart(new String(buf, off, nextLen)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3760 |
off += nextLen; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3761 |
len -= nextLen; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3762 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3763 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3764 |
if (mergeAtEnd) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3765 |
setMergeableToken(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3766 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3767 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3768 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3769 |
public void ignorableWhitespace(char[] buf, int off, int len) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3770 |
clearMergeableToken(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3771 |
if (false) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3772 |
characters(buf, off, len); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3773 |
clearMergeableToken(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3774 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3775 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3776 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3777 |
public void comment(char[] buf, int off, int len) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3778 |
addPart(new Special("<!-- -->", new String(buf, off, len))); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3779 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3780 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3781 |
public void processingInstruction(String name, String instruction) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3782 |
Element pi = new Element(name); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3783 |
pi.add(instruction); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3784 |
addPart(new Special("<? ?>", pi)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3785 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3786 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3787 |
public void skippedEntity(String name) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3788 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3789 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3790 |
public void startDTD(String name, String publicId, String systemId) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3791 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3792 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3793 |
public void endDTD() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3794 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3795 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3796 |
public void startEntity(String name) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3797 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3798 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3799 |
public void endEntity(String name) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3800 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3801 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3802 |
public void setDocumentLocator(org.xml.sax.Locator locator) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3803 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3804 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3805 |
public void startDocument() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3806 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3807 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3808 |
public void endDocument() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3809 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3810 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3811 |
public void startPrefixMapping(String prefix, String uri) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3812 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3813 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3814 |
public void endPrefixMapping(String prefix) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3815 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3816 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3817 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3818 |
/** Produce a ContentHandler for use with an XML parser. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3819 |
* The object is <em>also</em> a LexicalHandler. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3820 |
* Every top-level Element produced will get added to sink. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3821 |
* All elements will be frozen iff makeFrozen is true. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3822 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3823 |
public static ContentHandler makeBuilder(Collection<Object> sink, boolean tokenizing, boolean makeFrozen) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3824 |
return new Builder(sink, tokenizing, makeFrozen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3825 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3826 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3827 |
public static ContentHandler makeBuilder(Collection<Object> sink, boolean tokenizing) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3828 |
return new Builder(sink, tokenizing, false); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3829 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3830 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3831 |
public static ContentHandler makeBuilder(Collection<Object> sink) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3832 |
return makeBuilder(sink, false, false); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3833 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3834 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3835 |
public static Element readFrom(Reader in, boolean tokenizing, boolean makeFrozen) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3836 |
Element sink = new Element(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3837 |
ContentHandler b = makeBuilder(sink.asList(), tokenizing, makeFrozen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3838 |
XMLReader parser; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3839 |
try { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3840 |
parser = org.xml.sax.helpers.XMLReaderFactory.createXMLReader(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3841 |
} catch (SAXException ee) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3842 |
throw new Error(ee); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3843 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3844 |
//parser.setFastStandalone(true); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3845 |
parser.setContentHandler(b); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3846 |
try { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3847 |
parser.setProperty("http://xml.org/sax/properties/lexical-handler", |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3848 |
(LexicalHandler) b); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3849 |
} catch (SAXException ee) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3850 |
// Ignore. We will miss the comments and whitespace. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3851 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3852 |
try { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3853 |
parser.parse(new InputSource(in)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3854 |
} catch (SAXParseException ee) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3855 |
throw new RuntimeException("line " + ee.getLineNumber() + " col " + ee.getColumnNumber() + ": ", ee); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3856 |
} catch (SAXException ee) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3857 |
throw new RuntimeException(ee); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3858 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3859 |
switch (sink.size()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3860 |
case 0: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3861 |
return null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3862 |
case 1: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3863 |
if (sink.get(0) instanceof Element) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3864 |
return (Element) sink.get(0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3865 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3866 |
// fall through |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3867 |
default: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3868 |
if (makeFrozen) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3869 |
sink.shallowFreeze(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3870 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3871 |
return sink; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3872 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3873 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3874 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3875 |
public static Element readFrom(Reader in, boolean tokenizing) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3876 |
return readFrom(in, tokenizing, false); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3877 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3878 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3879 |
public static Element readFrom(Reader in) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3880 |
return readFrom(in, false, false); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3881 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3882 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3883 |
public static void prettyPrintTo(OutputStream out, Element e) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3884 |
prettyPrintTo(new OutputStreamWriter(out), e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3885 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3886 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3887 |
public static void prettyPrintTo(Writer out, Element e) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3888 |
Printer pr = new Printer(out); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3889 |
pr.pretty = true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3890 |
pr.print(e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3891 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3892 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3893 |
static class Outputter { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3894 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3895 |
ContentHandler ch; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3896 |
LexicalHandler lh; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3897 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3898 |
Outputter(ContentHandler ch, LexicalHandler lh) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3899 |
this.ch = ch; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3900 |
this.lh = lh; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3901 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3902 |
AttributesImpl atts = new AttributesImpl(); // handy |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3903 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3904 |
void output(Object x) throws SAXException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3905 |
// Cf. jdom.org/jdom-b8/src/java/org/jdom/output/SAXOutputter.java |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3906 |
if (x instanceof Element) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3907 |
Element e = (Element) x; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3908 |
atts.clear(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3909 |
for (int asize = e.attrSize(), k = 0; k < asize; k++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3910 |
String key = e.getAttrName(k); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3911 |
String val = e.getAttr(k); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3912 |
atts.addAttribute("", "", key, "CDATA", val); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3913 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3914 |
ch.startElement("", "", e.getName(), atts); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3915 |
for (int i = 0; i < e.size(); i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3916 |
output(e.get(i)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3917 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3918 |
ch.endElement("", "", e.getName()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3919 |
} else if (x instanceof Special) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3920 |
Special sp = (Special) x; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3921 |
if (sp.kind.startsWith("<!--")) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3922 |
char[] chars = sp.value.toString().toCharArray(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3923 |
lh.comment(chars, 0, chars.length); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3924 |
} else if (sp.kind.startsWith("<?")) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3925 |
Element nameInstr = (Element) sp.value; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3926 |
ch.processingInstruction(nameInstr.name, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3927 |
nameInstr.get(0).toString()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3928 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3929 |
// drop silently |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3930 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3931 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3932 |
char[] chars = x.toString().toCharArray(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3933 |
ch.characters(chars, 0, chars.length); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3934 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3935 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3936 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3937 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3938 |
public static class Printer { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3939 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3940 |
public Writer w; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3941 |
public boolean tokenizing; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3942 |
public boolean pretty; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3943 |
public boolean abbreviated; // nonstandard format cuts down on noise |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3944 |
int depth = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3945 |
boolean prevStr; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3946 |
int tabStop = 2; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3947 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3948 |
public Printer(Writer w) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3949 |
this.w = w; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3950 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3951 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3952 |
public Printer() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3953 |
StringWriter sw = new StringWriter(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3954 |
this.w = sw; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3955 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3956 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3957 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3958 |
public String nextString() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3959 |
StringBuffer sb = ((StringWriter) w).getBuffer(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3960 |
String next = sb.toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3961 |
sb.setLength(0); // reset |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3962 |
return next; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3963 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3964 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3965 |
void indent(int depth) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3966 |
if (depth > 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3967 |
w.write("\n"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3968 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3969 |
int nsp = tabStop * depth; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3970 |
while (nsp > 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3971 |
String s = " "; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3972 |
String t = s.substring(0, nsp < s.length() ? nsp : s.length()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3973 |
w.write(t); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3974 |
nsp -= t.length(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3975 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3976 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3977 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3978 |
public void print(Element e) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3979 |
if (e.isAnonymous()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3980 |
printParts(e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3981 |
return; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3982 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3983 |
printRecursive(e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3984 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3985 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3986 |
public void println(Element e) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3987 |
print(e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3988 |
w.write("\n"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3989 |
w.flush(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3990 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3991 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3992 |
public void printRecursive(Element e) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3993 |
boolean indented = false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3994 |
if (pretty && !prevStr && e.size() + e.attrSize() > 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3995 |
indent(depth); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3996 |
indented = true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3997 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3998 |
w.write("<"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3999 |
w.write(e.name); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4000 |
for (int asize = e.attrSize(), k = 0; k < asize; k++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4001 |
String key = e.getAttrName(k); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4002 |
String val = e.getAttr(k); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4003 |
w.write(" "); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4004 |
w.write(key); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4005 |
w.write("="); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4006 |
if (val == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4007 |
w.write("null"); // Should not happen.... |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4008 |
} else if (val.indexOf("\"") < 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4009 |
w.write("\""); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4010 |
writeToken(val, '"', w); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4011 |
w.write("\""); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4012 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4013 |
w.write("'"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4014 |
writeToken(val, '\'', w); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4015 |
w.write("'"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4016 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4017 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4018 |
if (e.size() == 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4019 |
w.write("/>"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4020 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4021 |
++depth; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4022 |
if (abbreviated) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4023 |
w.write("/"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4024 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4025 |
w.write(">"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4026 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4027 |
prevStr = false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4028 |
printParts(e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4029 |
if (abbreviated) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4030 |
w.write(">"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4031 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4032 |
if (indented && !prevStr) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4033 |
indent(depth - 1); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4034 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4035 |
w.write("</"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4036 |
w.write(e.name); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4037 |
w.write(">"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4038 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4039 |
prevStr = false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4040 |
--depth; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4041 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4042 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4043 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4044 |
private void printParts(Element e) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4045 |
for (int i = 0; i < e.size(); i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4046 |
Object x = e.get(i); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4047 |
if (x instanceof Element) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4048 |
printRecursive((Element) x); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4049 |
prevStr = false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4050 |
} else if (x instanceof Special) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4051 |
w.write(((Special) x).toString()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4052 |
prevStr = false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4053 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4054 |
String s = String.valueOf(x); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4055 |
if (pretty) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4056 |
s = s.trim(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4057 |
if (s.length() == 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4058 |
continue; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4059 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4060 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4061 |
if (prevStr) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4062 |
w.write(' '); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4063 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4064 |
writeToken(s, tokenizing ? ' ' : (char) -1, w); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4065 |
prevStr = true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4066 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4067 |
if (pretty && depth == 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4068 |
w.write("\n"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4069 |
prevStr = false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4070 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4071 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4072 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4073 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4074 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4075 |
public static void output(Object e, ContentHandler ch, LexicalHandler lh) throws SAXException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4076 |
new Outputter(ch, lh).output(e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4077 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4078 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4079 |
public static void output(Object e, ContentHandler ch) throws SAXException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4080 |
if (ch instanceof LexicalHandler) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4081 |
output(e, ch, (LexicalHandler) ch); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4082 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4083 |
output(e, ch, null); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4084 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4085 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4086 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4087 |
public static void writeToken(String val, char quote, Writer w) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4088 |
int len = val.length(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4089 |
boolean canUseCData = (quote != '"' && quote != '\''); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4090 |
int vpos = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4091 |
for (int i = 0; i < len; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4092 |
char ch = val.charAt(i); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4093 |
if ((ch == '<' || ch == '&' || ch == '>' || ch == quote) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4094 |
|| (quote == ' ' && isWhitespace(ch))) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4095 |
if (canUseCData) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4096 |
assert (vpos == 0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4097 |
writeCData(val, w); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4098 |
return; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4099 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4100 |
if (vpos < i) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4101 |
w.write(val, vpos, i - vpos); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4102 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4103 |
String esc; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4104 |
switch (ch) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4105 |
case '&': |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4106 |
esc = "&"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4107 |
break; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4108 |
case '<': |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4109 |
esc = "<"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4110 |
break; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4111 |
case '\'': |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4112 |
esc = "'"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4113 |
break; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4114 |
case '"': |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4115 |
esc = """; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4116 |
break; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4117 |
case '>': |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4118 |
esc = ">"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4119 |
break; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4120 |
default: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4121 |
esc = "&#" + (int) ch + ";"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4122 |
break; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4123 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4124 |
w.write(esc); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4125 |
vpos = i + 1; // skip escaped char |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4126 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4127 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4128 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4129 |
// write the unquoted tail |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4130 |
w.write(val, vpos, val.length() - vpos); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4131 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4132 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4133 |
public static void writeCData(String val, Writer w) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4134 |
String begCData = "<![CDATA["; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4135 |
String endCData = "]]>"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4136 |
w.write(begCData); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4137 |
for (int vpos = 0, split;; vpos = split) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4138 |
split = val.indexOf(endCData, vpos); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4139 |
if (split < 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4140 |
w.write(val, vpos, val.length() - vpos); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4141 |
w.write(endCData); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4142 |
return; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4143 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4144 |
split += 2; // bisect the "]]>" goo |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4145 |
w.write(val, vpos, split - vpos); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4146 |
w.write(endCData); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4147 |
w.write(begCData); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4148 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4149 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4150 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4151 |
public static TokenList convertToList(String str) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4152 |
if (str == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4153 |
return null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4154 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4155 |
return new TokenList(str); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4156 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4157 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4158 |
/** If str is null, empty, or blank, returns null. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4159 |
* Otherwise, return a Double if str spells a double value and contains '.' or 'e'. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4160 |
* Otherwise, return an Integer if str spells an int value. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4161 |
* Otherwise, return a Long if str spells a long value. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4162 |
* Otherwise, return a BigInteger for the string. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4163 |
* Otherwise, throw NumberFormatException. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4164 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4165 |
public static Number convertToNumber(String str) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4166 |
if (str == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4167 |
return null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4168 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4169 |
str = str.trim(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4170 |
if (str.length() == 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4171 |
return null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4172 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4173 |
if (str.indexOf('.') >= 0 |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4174 |
|| str.indexOf('e') >= 0 |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4175 |
|| str.indexOf('E') >= 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4176 |
return Double.valueOf(str); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4177 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4178 |
try { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4179 |
long lval = Long.parseLong(str); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4180 |
if (lval == (int) lval) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4181 |
// Narrow to Integer, if possible. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4182 |
return new Integer((int) lval); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4183 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4184 |
return new Long(lval); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4185 |
} catch (NumberFormatException ee) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4186 |
// Could not represent it as a long. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4187 |
return new java.math.BigInteger(str, 10); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4188 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4189 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4190 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4191 |
public static Number convertToNumber(String str, Number dflt) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4192 |
Number n = convertToNumber(str); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4193 |
return (n == null) ? dflt : n; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4194 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4195 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4196 |
public static long convertToLong(String str) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4197 |
return convertToLong(str, 0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4198 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4199 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4200 |
public static long convertToLong(String str, long dflt) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4201 |
Number n = convertToNumber(str); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4202 |
return (n == null) ? dflt : n.longValue(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4203 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4204 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4205 |
public static double convertToDouble(String str) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4206 |
return convertToDouble(str, 0); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4207 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4208 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4209 |
public static double convertToDouble(String str, double dflt) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4210 |
Number n = convertToNumber(str); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4211 |
return (n == null) ? dflt : n.doubleValue(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4212 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4213 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4214 |
// Testing: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4215 |
public static void main(String... av) throws Exception { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4216 |
Element.method("getAttr"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4217 |
//new org.jdom.input.SAXBuilder().build(file).getRootElement(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4218 |
//jdom.org/jdom-b8/src/java/org/jdom/input/SAXBuilder.java |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4219 |
//Document build(InputSource in) throws JDOMException |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4220 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4221 |
int reps = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4222 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4223 |
boolean tokenizing = false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4224 |
boolean makeFrozen = false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4225 |
if (av.length > 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4226 |
tokenizing = true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4227 |
try { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4228 |
reps = Integer.parseInt(av[0]); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4229 |
} catch (NumberFormatException ee) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4230 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4231 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4232 |
Reader inR = new BufferedReader(new InputStreamReader(System.in)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4233 |
String inS = null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4234 |
if (reps > 1) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4235 |
StringWriter inBufR = new StringWriter(1 << 14); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4236 |
char[] cbuf = new char[1024]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4237 |
for (int nr; (nr = inR.read(cbuf)) >= 0;) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4238 |
inBufR.write(cbuf, 0, nr); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4239 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4240 |
inS = inBufR.toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4241 |
inR = new StringReader(inS); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4242 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4243 |
Element e = XMLKit.readFrom(inR, tokenizing, makeFrozen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4244 |
System.out.println("transform = " + e.findAll(methodFilter(Element.method("prettyString")))); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4245 |
System.out.println("transform = " + e.findAll(testMethodFilter(Element.method("hasText")))); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4246 |
long tm0 = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4247 |
int warmup = 10; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4248 |
for (int i = 1; i < reps; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4249 |
inR = new StringReader(inS); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4250 |
readFrom(inR, tokenizing, makeFrozen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4251 |
if (i == warmup) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4252 |
System.out.println("Start timing..."); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4253 |
tm0 = System.currentTimeMillis(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4254 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4255 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4256 |
if (tm0 != 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4257 |
long tm1 = System.currentTimeMillis(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4258 |
System.out.println((reps - warmup) + " in " + (tm1 - tm0) + " ms"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4259 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4260 |
System.out.println("hashCode = " + e.hashCode()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4261 |
String eStr = e.toString(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4262 |
System.out.println(eStr); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4263 |
Element e2 = readFrom(new StringReader(eStr), tokenizing, !makeFrozen); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4264 |
System.out.println("hashCode = " + e2.hashCode()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4265 |
if (!e.equals(e2)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4266 |
System.out.println("**** NOT EQUAL 1\n" + e2); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4267 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4268 |
e = e.deepCopy(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4269 |
System.out.println("hashCode = " + e.hashCode()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4270 |
if (!e.equals(e2)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4271 |
System.out.println("**** NOT EQUAL 2"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4272 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4273 |
e2.shallowFreeze(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4274 |
System.out.println("hashCode = " + e2.hashCode()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4275 |
if (!e.equals(e2)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4276 |
System.out.println("**** NOT EQUAL 3"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4277 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4278 |
if (false) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4279 |
System.out.println(e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4280 |
} else { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4281 |
prettyPrintTo(new OutputStreamWriter(System.out), e); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4282 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4283 |
System.out.println("Flat text:|" + e.getFlatText() + "|"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4284 |
{ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4285 |
System.out.println("<!--- Sorted: --->"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4286 |
Element ce = e.copyContentOnly(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4287 |
ce.sort(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4288 |
prettyPrintTo(new OutputStreamWriter(System.out), ce); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4289 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4290 |
{ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4291 |
System.out.println("<!--- Trimmed: --->"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4292 |
Element tr = e.deepCopy(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4293 |
findInTree(testMethodFilter(Element.method("trimText"))).filter(tr); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4294 |
System.out.println(tr); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4295 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4296 |
{ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4297 |
System.out.println("<!--- Unstrung: --->"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4298 |
Element us = e.deepCopy(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4299 |
int nr = us.retainAllInTree(elementFilter(), null); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4300 |
System.out.println("nr=" + nr); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4301 |
System.out.println(us); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4302 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4303 |
{ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4304 |
System.out.println("<!--- Rollup: --->"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4305 |
Element ru = e.deepCopy(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4306 |
Filter makeAnonF = |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4307 |
methodFilter(Element.method("setName"), |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4308 |
new Object[]{ANON_NAME}); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4309 |
Filter testSizeF = |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4310 |
testMethodFilter(Element.method("size")); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4311 |
Filter walk = |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4312 |
replaceInTree(and(not(elementFilter()), emptyFilter()), |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4313 |
and(testSizeF, makeAnonF)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4314 |
ru = (Element) walk.filter(ru); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4315 |
//System.out.println(ru); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4316 |
prettyPrintTo(new OutputStreamWriter(System.out), ru); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4317 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4318 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4319 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4320 |
static boolean isWhitespace(char c) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4321 |
switch (c) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4322 |
case 0x20: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4323 |
case 0x09: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4324 |
case 0x0D: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4325 |
case 0x0A: |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4326 |
return true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4327 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4328 |
return false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4329 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4330 |
} |