aboutsummaryrefslogtreecommitdiff
path: root/src/com/sun/org/apache/xerces/internal/impl/xpath/regex/Token.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/sun/org/apache/xerces/internal/impl/xpath/regex/Token.java')
-rw-r--r--src/com/sun/org/apache/xerces/internal/impl/xpath/regex/Token.java113
1 files changed, 77 insertions, 36 deletions
diff --git a/src/com/sun/org/apache/xerces/internal/impl/xpath/regex/Token.java b/src/com/sun/org/apache/xerces/internal/impl/xpath/regex/Token.java
index a395e47..e364995 100644
--- a/src/com/sun/org/apache/xerces/internal/impl/xpath/regex/Token.java
+++ b/src/com/sun/org/apache/xerces/internal/impl/xpath/regex/Token.java
@@ -1,13 +1,13 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * Copyright 1999-2002,2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@@ -20,8 +20,18 @@
package com.sun.org.apache.xerces.internal.impl.xpath.regex;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.Vector;
-import java.util.Hashtable;
/**
* This class represents a node in parse tree.
@@ -583,8 +593,8 @@ class Token implements java.io.Serializable {
}
// ------------------------------------------------------
- private final static Hashtable categories = new Hashtable();
- private final static Hashtable categories2 = new Hashtable();
+ private final static Map<String, Token> categories = new HashMap<>();
+ private final static Map<String, Token> categories2 = new HashMap<>();
private static final String[] categoryNames = {
"Cn", "Lu", "Ll", "Lt", "Lm", "Lo", "Mn", "Me", "Mc", "Nd",
"Nl", "No", "Zs", "Zl", "Zp", "Cc", "Cf", null, "Co", "Cs",
@@ -820,7 +830,7 @@ class Token implements java.io.Serializable {
//REVISIT: do we really need to support block names as in Unicode 3.1
// or we can just create all the names in IsBLOCKNAME format (XML Schema REC)?
//
- StringBuffer buffer = new StringBuffer(50);
+ StringBuilder buffer = new StringBuilder(50);
for (int i = 0; i < Token.blockNames.length; i ++) {
Token r1 = Token.createRange();
int location;
@@ -972,22 +982,17 @@ class Token implements java.io.Serializable {
return range;
}
- static Hashtable nonxs = null;
+ static final Set<String> nonxs = Collections.synchronizedSet(new HashSet<>());
/**
* This method is called by only getRange().
* So this method need not MT-safe.
*/
static protected void registerNonXS(String name) {
- if (Token.nonxs == null)
- Token.nonxs = new Hashtable();
- Token.nonxs.put(name, name);
+ Token.nonxs.add(name);
}
+
static protected boolean isRegisterNonXS(String name) {
- if (Token.nonxs == null)
- return false;
- //DEBUG
- //System.err.println("isRegisterNonXS: "+name);
- return Token.nonxs.containsKey(name);
+ return Token.nonxs.contains(name);
}
private static void setAlias(String newName, String name, boolean positive) {
@@ -1423,17 +1428,26 @@ class Token implements java.io.Serializable {
private static final long serialVersionUID = -2568843945989489861L;
- Vector children;
+ List<Token> children;
+
+ /**
+ * @serialField children Vector children
+ */
+ private static final ObjectStreamField[] serialPersistentFields =
+ new ObjectStreamField[] {
+ new ObjectStreamField("children", Vector.class),
+ };
UnionToken(int type) {
super(type);
}
+ @Override
void addChild(Token tok) {
if (tok == null) return;
- if (this.children == null) this.children = new Vector();
+ if (this.children == null) this.children = new ArrayList<>();
if (this.type == UNION) {
- this.children.addElement(tok);
+ this.children.add(tok);
return;
}
// This is CONCAT, and new child is CONCAT.
@@ -1444,31 +1458,31 @@ class Token implements java.io.Serializable {
}
int size = this.children.size();
if (size == 0) {
- this.children.addElement(tok);
+ this.children.add(tok);
return;
}
- Token previous = (Token)this.children.elementAt(size-1);
+ Token previous = this.children.get(size - 1);
if (!((previous.type == CHAR || previous.type == STRING)
&& (tok.type == CHAR || tok.type == STRING))) {
- this.children.addElement(tok);
+ this.children.add(tok);
return;
}
//System.err.println("Merge '"+previous+"' and '"+tok+"'.");
- StringBuffer buffer;
+ StringBuilder buffer;
int nextMaxLength = (tok.type == CHAR ? 2 : tok.getString().length());
if (previous.type == CHAR) { // Replace previous token by STRING
- buffer = new StringBuffer(2 + nextMaxLength);
+ buffer = new StringBuilder(2 + nextMaxLength);
int ch = previous.getChar();
if (ch >= 0x10000)
buffer.append(REUtil.decomposeToSurrogates(ch));
else
buffer.append((char)ch);
previous = Token.createString(null);
- this.children.setElementAt(previous, size-1);
+ this.children.set(size - 1, previous);
} else { // STRING
- buffer = new StringBuffer(previous.getString().length() + nextMaxLength);
+ buffer = new StringBuilder(previous.getString().length() + nextMaxLength);
buffer.append(previous.getString());
}
@@ -1485,13 +1499,16 @@ class Token implements java.io.Serializable {
((StringToken)previous).string = new String(buffer);
}
+ @Override
int size() {
return this.children == null ? 0 : this.children.size();
}
+ @Override
Token getChild(int index) {
- return (Token)this.children.elementAt(index);
+ return this.children.get(index);
}
+ @Override
public String toString(int options) {
String ret;
if (this.type == CONCAT) {
@@ -1505,9 +1522,9 @@ class Token implements java.io.Serializable {
} else
ret = ch.toString(options)+ch2.toString(options);
} else {
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
for (int i = 0; i < this.children.size(); i ++) {
- sb.append(((Token)this.children.elementAt(i)).toString(options));
+ sb.append(((Token)this.children.get(i)).toString(options));
}
ret = new String(sb);
}
@@ -1519,15 +1536,39 @@ class Token implements java.io.Serializable {
&& this.getChild(0).type == EMPTY) {
ret = this.getChild(1).toString(options)+"??";
} else {
- StringBuffer sb = new StringBuffer();
- sb.append(((Token)this.children.elementAt(0)).toString(options));
+ StringBuilder sb = new StringBuilder();
+ sb.append((this.children.get(0)).toString(options));
for (int i = 1; i < this.children.size(); i ++) {
sb.append((char)'|');
- sb.append(((Token)this.children.elementAt(i)).toString(options));
+ sb.append((this.children.get(i)).toString(options));
}
ret = new String(sb);
}
return ret;
}
+
+ /**
+ * @serialData Serialized fields. Convert the List to Vector for backward compatibility.
+ */
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ // Convert List to Vector
+ Vector<Token> vChildren = (children == null)? null : new Vector<>(children);
+
+ // Write serialized fields
+ ObjectOutputStream.PutField pf = out.putFields();
+ pf.put("children", vChildren);
+ out.writeFields();
+ }
+
+ @SuppressWarnings("unchecked")
+ private void readObject(ObjectInputStream in)
+ throws IOException, ClassNotFoundException {
+ // We have to read serialized fields first.
+ ObjectInputStream.GetField gf = in.readFields();
+ Vector<Token> vChildren = (Vector<Token>)gf.get("children", null);
+
+ //convert Vector back to List
+ if (vChildren != null) children = new ArrayList<>(vChildren);
+ }
}
}