下面列出了java.util.Stack#elementAt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* This method returns the latest node of the specified type,
* either on the stack, or on the 'popped' nodes.
*
* @param nodeType The node type
* @param onStack Whether from the stack
* @return The node, or null if not found
*/
public Node getLatestNode(String nodeType, boolean onStack) {
Node node = null;
synchronized (nodeStack) {
Stack<Node> stack = (onStack ? nodeStack : poppedNodes);
for (int i = 0; node == null && i < stack.size(); i++) {
Node n = stack.elementAt(i);
if (log.isLoggable(Level.FINEST)) {
log.finest("Get latest node: checking node type '" + nodeType
+ "' against '" + n.getClass().getSimpleName()
+ "' with node=" + n);
}
if (n.getClass().getSimpleName().equals(nodeType)) {
node = n;
}
}
}
return node;
}
public int firstOffendingParenthesis(String input) {
/*
Algorithm:
1. Iterate over all the characters of input String
2. If character is ')' and stack is not empty then remove element from stack
3. Else add the position into the stack
4. After iteration, if stack is empty then return -1 else get the first element and return its value.
*/
Stack<Integer> stack = new Stack<>();
for (int i = 0; i < input.length(); i++) {
if (input.charAt(i) == ')' && !stack.empty()) {
stack.pop();
} else {
stack.push(i);
}
}
return stack.empty() ? -1 : stack.elementAt(0);
}
private String getKey(Stack<String> nameStack) {
StringBuffer key = new StringBuffer();
for (int i = 0; i < nameStack.size(); i++) {
String name = nameStack.elementAt(i);
key.append(name).append(".");
}
key.deleteCharAt(key.lastIndexOf("."));
return key.toString();
}
private String getKey(Stack<String> nameStack) {
StringBuffer key = new StringBuffer();
for (int i = 0; i < nameStack.size(); i++) {
String name = nameStack.elementAt(i);
key.append(name).append(".");
}
key.deleteCharAt(key.lastIndexOf("."));
return key.toString();
}
private String getKey(Stack<String> nameStack) {
StringBuilder key = new StringBuilder();
for (int i = 0; i < nameStack.size(); i++) {
String name = nameStack.elementAt(i);
key.append(name).append('.');
}
key.deleteCharAt(key.lastIndexOf("."));
return key.toString();
}
private String getKey(Stack<String> nameStack) {
StringBuilder key = new StringBuilder();
for (int i = 0; i < nameStack.size(); i++) {
String name = nameStack.elementAt(i);
key.append(name).append(".");
}
key.deleteCharAt(key.lastIndexOf("."));
return key.toString();
}
private String getKey(Stack<String> nameStack) {
StringBuilder key = new StringBuilder();
for (int i = 0; i < nameStack.size(); i++) {
String name = nameStack.elementAt(i);
key.append(name).append(".");
}
key.deleteCharAt(key.lastIndexOf("."));
return key.toString();
}
private String getKey(Stack<String> nameStack) {
StringBuilder key = new StringBuilder();
for (int i = 0; i < nameStack.size(); i++) {
String name = nameStack.elementAt(i);
key.append(name).append(".");
}
key.deleteCharAt(key.lastIndexOf("."));
return key.toString();
}
/**
* Construct a QName from a string, resolving the prefix
* using the given namespace stack. The default namespace is
* not resolved.
*
* @param qname Qualified name to resolve
* @param namespaces Namespace stack to use to resolve namespace
* @param validate If true the new QName will be validated and an IllegalArgumentException will
* be thrown if it is invalid.
*/
public QName(String qname, Stack namespaces, boolean validate)
{
String namespace = null;
String prefix = null;
int indexOfNSSep = qname.indexOf(':');
if (indexOfNSSep > 0)
{
prefix = qname.substring(0, indexOfNSSep);
if (prefix.equals("xml"))
{
namespace = S_XMLNAMESPACEURI;
}
// Do we want this?
else if (prefix.equals("xmlns"))
{
return;
}
else
{
int depth = namespaces.size();
for (int i = depth - 1; i >= 0; i--)
{
NameSpace ns = (NameSpace) namespaces.elementAt(i);
while (null != ns)
{
if ((null != ns.m_prefix) && prefix.equals(ns.m_prefix))
{
namespace = ns.m_uri;
i = -1;
break;
}
ns = ns.m_next;
}
}
}
if (null == namespace)
{
throw new RuntimeException(
XMLMessages.createXMLMessage(
XMLErrorResources.ER_PREFIX_MUST_RESOLVE,
new Object[]{ prefix })); //"Prefix must resolve to a namespace: "+prefix);
}
}
_localName = (indexOfNSSep < 0)
? qname : qname.substring(indexOfNSSep + 1);
if (validate)
{
if ((_localName == null) || (!XML11Char.isXML11ValidNCName(_localName)))
{
throw new IllegalArgumentException(XMLMessages.createXMLMessage(
XMLErrorResources.ER_ARG_LOCALNAME_INVALID,null )); //"Argument 'localName' not a valid NCName");
}
}
_namespaceURI = namespace;
_prefix = prefix;
m_hashCode = toString().hashCode();
}
/**
* Construct a QName from a string, resolving the prefix
* using the given namespace stack. The default namespace is
* not resolved.
*
* @param qname Qualified name to resolve
* @param namespaces Namespace stack to use to resolve namespace
* @param validate If true the new QName will be validated and an IllegalArgumentException will
* be thrown if it is invalid.
*/
public QName(String qname, Stack namespaces, boolean validate)
{
String namespace = null;
String prefix = null;
int indexOfNSSep = qname.indexOf(':');
if (indexOfNSSep > 0)
{
prefix = qname.substring(0, indexOfNSSep);
if (prefix.equals("xml"))
{
namespace = S_XMLNAMESPACEURI;
}
// Do we want this?
else if (prefix.equals("xmlns"))
{
return;
}
else
{
int depth = namespaces.size();
for (int i = depth - 1; i >= 0; i--)
{
NameSpace ns = (NameSpace) namespaces.elementAt(i);
while (null != ns)
{
if ((null != ns.m_prefix) && prefix.equals(ns.m_prefix))
{
namespace = ns.m_uri;
i = -1;
break;
}
ns = ns.m_next;
}
}
}
if (null == namespace)
{
throw new RuntimeException(
XMLMessages.createXMLMessage(
XMLErrorResources.ER_PREFIX_MUST_RESOLVE,
new Object[]{ prefix })); //"Prefix must resolve to a namespace: "+prefix);
}
}
_localName = (indexOfNSSep < 0)
? qname : qname.substring(indexOfNSSep + 1);
if (validate)
{
if ((_localName == null) || (!XML11Char.isXML11ValidNCName(_localName)))
{
throw new IllegalArgumentException(XMLMessages.createXMLMessage(
XMLErrorResources.ER_ARG_LOCALNAME_INVALID,null )); //"Argument 'localName' not a valid NCName");
}
}
_namespaceURI = namespace;
_prefix = prefix;
m_hashCode = toString().hashCode();
}
/**
* Construct a QName from a string, resolving the prefix
* using the given namespace stack. The default namespace is
* not resolved.
*
* @param qname Qualified name to resolve
* @param namespaces Namespace stack to use to resolve namespace
* @param validate If true the new QName will be validated and an IllegalArgumentException will
* be thrown if it is invalid.
*/
public QName(String qname, Stack namespaces, boolean validate)
{
String namespace = null;
String prefix = null;
int indexOfNSSep = qname.indexOf(':');
if (indexOfNSSep > 0)
{
prefix = qname.substring(0, indexOfNSSep);
if (prefix.equals("xml"))
{
namespace = S_XMLNAMESPACEURI;
}
// Do we want this?
else if (prefix.equals("xmlns"))
{
return;
}
else
{
int depth = namespaces.size();
for (int i = depth - 1; i >= 0; i--)
{
NameSpace ns = (NameSpace) namespaces.elementAt(i);
while (null != ns)
{
if ((null != ns.m_prefix) && prefix.equals(ns.m_prefix))
{
namespace = ns.m_uri;
i = -1;
break;
}
ns = ns.m_next;
}
}
}
if (null == namespace)
{
throw new RuntimeException(
XMLMessages.createXMLMessage(
XMLErrorResources.ER_PREFIX_MUST_RESOLVE,
new Object[]{ prefix })); //"Prefix must resolve to a namespace: "+prefix);
}
}
_localName = (indexOfNSSep < 0)
? qname : qname.substring(indexOfNSSep + 1);
if (validate)
{
if ((_localName == null) || (!XML11Char.isXML11ValidNCName(_localName)))
{
throw new IllegalArgumentException(XMLMessages.createXMLMessage(
XMLErrorResources.ER_ARG_LOCALNAME_INVALID,null )); //"Argument 'localName' not a valid NCName");
}
}
_namespaceURI = namespace;
_prefix = prefix;
m_hashCode = toString().hashCode();
}
/**
* Construct a QName from a string, resolving the prefix
* using the given namespace stack. The default namespace is
* not resolved.
*
* @param qname Qualified name to resolve
* @param namespaces Namespace stack to use to resolve namespace
* @param validate If true the new QName will be validated and an IllegalArgumentException will
* be thrown if it is invalid.
*/
public QName(String qname, Stack namespaces, boolean validate)
{
String namespace = null;
String prefix = null;
int indexOfNSSep = qname.indexOf(':');
if (indexOfNSSep > 0)
{
prefix = qname.substring(0, indexOfNSSep);
if (prefix.equals("xml"))
{
namespace = S_XMLNAMESPACEURI;
}
// Do we want this?
else if (prefix.equals("xmlns"))
{
return;
}
else
{
int depth = namespaces.size();
for (int i = depth - 1; i >= 0; i--)
{
NameSpace ns = (NameSpace) namespaces.elementAt(i);
while (null != ns)
{
if ((null != ns.m_prefix) && prefix.equals(ns.m_prefix))
{
namespace = ns.m_uri;
i = -1;
break;
}
ns = ns.m_next;
}
}
}
if (null == namespace)
{
throw new RuntimeException(
XMLMessages.createXMLMessage(
XMLErrorResources.ER_PREFIX_MUST_RESOLVE,
new Object[]{ prefix })); //"Prefix must resolve to a namespace: "+prefix);
}
}
_localName = (indexOfNSSep < 0)
? qname : qname.substring(indexOfNSSep + 1);
if (validate)
{
if ((_localName == null) || (!XML11Char.isXML11ValidNCName(_localName)))
{
throw new IllegalArgumentException(XMLMessages.createXMLMessage(
XMLErrorResources.ER_ARG_LOCALNAME_INVALID,null )); //"Argument 'localName' not a valid NCName");
}
}
_namespaceURI = namespace;
_prefix = prefix;
m_hashCode = toString().hashCode();
}
/**
* Construct a QName from a string, resolving the prefix
* using the given namespace stack. The default namespace is
* not resolved.
*
* @param qname Qualified name to resolve
* @param namespaces Namespace stack to use to resolve namespace
* @param validate If true the new QName will be validated and an IllegalArgumentException will
* be thrown if it is invalid.
*/
public QName(String qname, Stack namespaces, boolean validate)
{
String namespace = null;
String prefix = null;
int indexOfNSSep = qname.indexOf(':');
if (indexOfNSSep > 0)
{
prefix = qname.substring(0, indexOfNSSep);
if (prefix.equals("xml"))
{
namespace = S_XMLNAMESPACEURI;
}
// Do we want this?
else if (prefix.equals("xmlns"))
{
return;
}
else
{
int depth = namespaces.size();
for (int i = depth - 1; i >= 0; i--)
{
NameSpace ns = (NameSpace) namespaces.elementAt(i);
while (null != ns)
{
if ((null != ns.m_prefix) && prefix.equals(ns.m_prefix))
{
namespace = ns.m_uri;
i = -1;
break;
}
ns = ns.m_next;
}
}
}
if (null == namespace)
{
throw new RuntimeException(
XMLMessages.createXMLMessage(
XMLErrorResources.ER_PREFIX_MUST_RESOLVE,
new Object[]{ prefix })); //"Prefix must resolve to a namespace: "+prefix);
}
}
_localName = (indexOfNSSep < 0)
? qname : qname.substring(indexOfNSSep + 1);
if (validate)
{
if ((_localName == null) || (!XML11Char.isXML11ValidNCName(_localName)))
{
throw new IllegalArgumentException(XMLMessages.createXMLMessage(
XMLErrorResources.ER_ARG_LOCALNAME_INVALID,null )); //"Argument 'localName' not a valid NCName");
}
}
_namespaceURI = namespace;
_prefix = prefix;
m_hashCode = toString().hashCode();
}
/**
* Construct a QName from a string, resolving the prefix
* using the given namespace stack. The default namespace is
* not resolved.
*
* @param qname Qualified name to resolve
* @param namespaces Namespace stack to use to resolve namespace
* @param validate If true the new QName will be validated and an IllegalArgumentException will
* be thrown if it is invalid.
*/
public QName(String qname, Stack namespaces, boolean validate)
{
String namespace = null;
String prefix = null;
int indexOfNSSep = qname.indexOf(':');
if (indexOfNSSep > 0)
{
prefix = qname.substring(0, indexOfNSSep);
if (prefix.equals("xml"))
{
namespace = S_XMLNAMESPACEURI;
}
// Do we want this?
else if (prefix.equals("xmlns"))
{
return;
}
else
{
int depth = namespaces.size();
for (int i = depth - 1; i >= 0; i--)
{
NameSpace ns = (NameSpace) namespaces.elementAt(i);
while (null != ns)
{
if ((null != ns.m_prefix) && prefix.equals(ns.m_prefix))
{
namespace = ns.m_uri;
i = -1;
break;
}
ns = ns.m_next;
}
}
}
if (null == namespace)
{
throw new RuntimeException(
XMLMessages.createXMLMessage(
XMLErrorResources.ER_PREFIX_MUST_RESOLVE,
new Object[]{ prefix })); //"Prefix must resolve to a namespace: "+prefix);
}
}
_localName = (indexOfNSSep < 0)
? qname : qname.substring(indexOfNSSep + 1);
if (validate)
{
if ((_localName == null) || (!XML11Char.isXML11ValidNCName(_localName)))
{
throw new IllegalArgumentException(XMLMessages.createXMLMessage(
XMLErrorResources.ER_ARG_LOCALNAME_INVALID,null )); //"Argument 'localName' not a valid NCName");
}
}
_namespaceURI = namespace;
_prefix = prefix;
m_hashCode = toString().hashCode();
}
/**
* Construct a QName from a string, resolving the prefix
* using the given namespace stack. The default namespace is
* not resolved.
*
* @param qname Qualified name to resolve
* @param namespaces Namespace stack to use to resolve namespace
* @param validate If true the new QName will be validated and an IllegalArgumentException will
* be thrown if it is invalid.
*/
public QName(String qname, Stack namespaces, boolean validate)
{
String namespace = null;
String prefix = null;
int indexOfNSSep = qname.indexOf(':');
if (indexOfNSSep > 0)
{
prefix = qname.substring(0, indexOfNSSep);
if (prefix.equals("xml"))
{
namespace = S_XMLNAMESPACEURI;
}
// Do we want this?
else if (prefix.equals("xmlns"))
{
return;
}
else
{
int depth = namespaces.size();
for (int i = depth - 1; i >= 0; i--)
{
NameSpace ns = (NameSpace) namespaces.elementAt(i);
while (null != ns)
{
if ((null != ns.m_prefix) && prefix.equals(ns.m_prefix))
{
namespace = ns.m_uri;
i = -1;
break;
}
ns = ns.m_next;
}
}
}
if (null == namespace)
{
throw new RuntimeException(
XMLMessages.createXMLMessage(
XMLErrorResources.ER_PREFIX_MUST_RESOLVE,
new Object[]{ prefix })); //"Prefix must resolve to a namespace: "+prefix);
}
}
_localName = (indexOfNSSep < 0)
? qname : qname.substring(indexOfNSSep + 1);
if (validate)
{
if ((_localName == null) || (!XML11Char.isXML11ValidNCName(_localName)))
{
throw new IllegalArgumentException(XMLMessages.createXMLMessage(
XMLErrorResources.ER_ARG_LOCALNAME_INVALID,null )); //"Argument 'localName' not a valid NCName");
}
}
_namespaceURI = namespace;
_prefix = prefix;
m_hashCode = toString().hashCode();
}
public static TypeCode getTypeCode(ORB orb,
QName type,
CorbaType obj,
CorbaTypeMap typeMap,
Stack<QName> seenTypes) {
if (type == null) {
throw new CorbaBindingException("corba:typemap type or elemtype information required"
+ (obj == null ? "" : " for " + obj)
+ (seenTypes.empty() ? "" : ", Enclosing type: " + seenTypes.elementAt(0)));
}
TypeCode tc = null;
// first see if it is a primitive
tc = getPrimitiveTypeCode(orb, type);
if (tc == null && type.equals(CorbaConstants.NT_CORBA_ANY)) {
// Anys are handled in a special way
tc = orb.get_primitive_tc(TCKind.from_int(TCKind._tk_any));
} else if (tc == null) {
if (typeMap == null) {
throw new CorbaBindingException("Unable to locate typemap for namespace \""
+ type.getNamespaceURI() + "\"");
}
tc = typeMap.getTypeCode(type);
if (tc == null) {
if (obj == null) {
obj = typeMap.getType(type.getLocalPart());
if (obj == null) {
throw new CorbaBindingException("Unable to locate object definition");
}
}
tc = getComplexTypeCode(orb, type, obj, typeMap, seenTypes);
if (tc != null) {
typeMap.addTypeCode(type, tc);
}
}
}
if (tc == null) {
throw new CorbaBindingException("Corba type node with qname " + type + " is not supported");
}
return tc;
}
private static Object[] handle(AbstractPool factory, Stack chain, int start,
Dictionary waiters, byte deadlockWake) {
// If start is zero then the space that started looking for the
// deadlock is activly involved in the deadlock.
Object checker = chain.elementAt(0);
int minLockCount = Integer.MAX_VALUE;
Object victim = null;
for (int i = start; i < chain.size(); i++) {
Object space = chain.elementAt(i);
if (space instanceof List) {
continue;
}
// See if the checker is in the deadlock and we
// already picked as a victim
if ((checker.equals(space)) && (deadlockWake == Constants.WAITING_LOCK_DEADLOCK)) {
victim = checker;
break;
}
LockSpace ls = (LockSpace) space;
int spaceCount = ls.deadlockCount(minLockCount);
if (spaceCount <= minLockCount) {
victim = space;
minLockCount = spaceCount;
}
}
// See if the vitim is the one doing the checking
if (checker.equals(victim)) {
Object[] data = new Object[2];
data[0] = chain;
data[1] = waiters;
return data;
}
ActiveLock victimLock = (ActiveLock) waiters.get(victim);
victimLock.wakeUp(Constants.WAITING_LOCK_DEADLOCK);
return null;
}
/**
* Construct a QName from a string, resolving the prefix
* using the given namespace stack. The default namespace is
* not resolved.
*
* @param qname Qualified name to resolve
* @param namespaces Namespace stack to use to resolve namespace
* @param validate If true the new QName will be validated and an IllegalArgumentException will
* be thrown if it is invalid.
*/
public QName(String qname, Stack namespaces, boolean validate)
{
String namespace = null;
String prefix = null;
int indexOfNSSep = qname.indexOf(':');
if (indexOfNSSep > 0)
{
prefix = qname.substring(0, indexOfNSSep);
if (prefix.equals("xml"))
{
namespace = S_XMLNAMESPACEURI;
}
// Do we want this?
else if (prefix.equals("xmlns"))
{
return;
}
else
{
int depth = namespaces.size();
for (int i = depth - 1; i >= 0; i--)
{
NameSpace ns = (NameSpace) namespaces.elementAt(i);
while (null != ns)
{
if ((null != ns.m_prefix) && prefix.equals(ns.m_prefix))
{
namespace = ns.m_uri;
i = -1;
break;
}
ns = ns.m_next;
}
}
}
if (null == namespace)
{
throw new RuntimeException(
XMLMessages.createXMLMessage(
XMLErrorResources.ER_PREFIX_MUST_RESOLVE,
new Object[]{ prefix })); //"Prefix must resolve to a namespace: "+prefix);
}
}
_localName = (indexOfNSSep < 0)
? qname : qname.substring(indexOfNSSep + 1);
if (validate)
{
if ((_localName == null) || (!XML11Char.isXML11ValidNCName(_localName)))
{
throw new IllegalArgumentException(XMLMessages.createXMLMessage(
XMLErrorResources.ER_ARG_LOCALNAME_INVALID,null )); //"Argument 'localName' not a valid NCName");
}
}
_namespaceURI = namespace;
_prefix = prefix;
m_hashCode = toString().hashCode();
}
private static Object[] handle(AbstractPool factory, Stack chain, int start,
Dictionary waiters, byte deadlockWake) {
// If start is zero then the space that started looking for the
// deadlock is activly involved in the deadlock.
Object checker = chain.elementAt(0);
int minLockCount = Integer.MAX_VALUE;
Object victim = null;
for (int i = start; i < chain.size(); i++) {
Object space = chain.elementAt(i);
if (space instanceof List) {
continue;
}
// See if the checker is in the deadlock and we
// already picked as a victim
if ((checker.equals(space)) && (deadlockWake == Constants.WAITING_LOCK_DEADLOCK)) {
victim = checker;
break;
}
LockSpace ls = (LockSpace) space;
int spaceCount = ls.deadlockCount(minLockCount);
if (spaceCount <= minLockCount) {
victim = space;
minLockCount = spaceCount;
}
}
// See if the vitim is the one doing the checking
if (checker.equals(victim)) {
Object[] data = new Object[2];
data[0] = chain;
data[1] = waiters;
return data;
}
ActiveLock victimLock = (ActiveLock) waiters.get(victim);
victimLock.wakeUp(Constants.WAITING_LOCK_DEADLOCK);
return null;
}
/**
* Handle a deadlock when it has been detected. Find out if the waiter
* that started looking for the deadlock is involved in it. If it isn't,
* pick a victim among the waiters that are involved.
*
* @return {@code null} if the waiter that started looking for the deadlock
* isn't involved in the deadlock (in which case another victim will have
* been picked and awoken), or an array describing the deadlock otherwise
*/
private static Object[] handle(AbstractPool factory, Stack chain, int start,
Dictionary waiters, byte deadlockWake) {
// If start is zero then the space that started looking for the
// deadlock is activly involved in the deadlock.
Object checker = chain.elementAt(0);
int minLockCount = Integer.MAX_VALUE;
Object victim = null;
for (int i = start; i < chain.size(); i++) {
Object space = chain.elementAt(i);
if (space instanceof List) {
continue;
}
// See if the checker is in the deadlock and we
// already picked as a victim
if ((checker.equals(space)) && (deadlockWake == Constants.WAITING_LOCK_DEADLOCK)) {
victim = checker;
break;
}
LockSpace ls = (LockSpace) space;
int spaceCount = ls.deadlockCount(minLockCount);
if (spaceCount <= minLockCount) {
victim = space;
minLockCount = spaceCount;
}
}
// See if the vitim is the one doing the checking
if (checker.equals(victim)) {
Object[] data = new Object[2];
data[0] = chain;
data[1] = waiters;
return data;
}
ActiveLock victimLock = (ActiveLock) waiters.get(victim);
victimLock.wakeUp(Constants.WAITING_LOCK_DEADLOCK);
return null;
}