下面列出了java.util.Stack#clone ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public Pair<Integer, Stack<Pair<Integer, S>>> getNextState(
Pair<Integer, Stack<Pair<Integer, S>>> state,
TaggedSymbol<S> input, BooleanAlgebra<U, S> ba) throws TimeoutException {
if (input.tag == SymbolTag.Internal) {
Integer currState = state.first;
if (currState == from) {
Stack<Pair<Integer, S>> currStack = state.second;
if (ba.HasModel(guard, input.input)) {
@SuppressWarnings("unchecked")
Stack<Pair<Integer, S>> newStack = (Stack<Pair<Integer, S>>) currStack
.clone();
return new Pair<Integer, Stack<Pair<Integer, S>>>(to,
newStack);
}
}
}
return null;
}
public Pair<Integer, Stack<Pair<Integer, S>>> getNextState(
Pair<Integer, Stack<Pair<Integer, S>>> state,
TaggedSymbol<S> input, BooleanAlgebra<U, S> ba) throws TimeoutException {
if (input.tag == SymbolTag.Return) {
Integer currState = state.first;
if (currState == from) {
Stack<Pair<Integer, S>> currStack = state.second;
if (currStack.size() == 0
&& ba.HasModel(guard, input.input)) {
@SuppressWarnings("unchecked")
Stack<Pair<Integer, S>> newStack = (Stack<Pair<Integer, S>>) currStack
.clone();
return new Pair<Integer, Stack<Pair<Integer, S>>>(to,
newStack);
}
}
}
return null;
}
public Pair<Integer, Stack<Pair<Integer, S>>> getNextState(
Pair<Integer, Stack<Pair<Integer, S>>> state,
TaggedSymbol<S> input, BooleanAlgebra<U, S> ba) throws TimeoutException {
if (input.tag == SymbolTag.Return) {
Integer currState = state.first;
if (currState == from) {
Stack<Pair<Integer, S>> currStack = state.second;
if (currStack.size() > 0) {
Pair<Integer, S> stackTop = currStack.peek();
if (stackTop.first == stackState
&& ba.HasModel(guard, stackTop.second, input.input)) {
@SuppressWarnings("unchecked")
Stack<Pair<Integer, S>> newStack = (Stack<Pair<Integer, S>>) currStack
.clone();
newStack.pop();
return new Pair<Integer, Stack<Pair<Integer, S>>>(to,
newStack);
}
}
}
}
return null;
}
/**
* Clone the diagnostic context for the current thread.
* <p/>
* <p>Internally a diagnostic context is represented as a stack. A given thread can supply the stack (i.e.
* diagnostic context) to a child thread so that the child can inherit the parent thread's diagnostic context.
* <p/>
* <p>The child thread uses the {@link #inherit inherit} method to inherit the parent's diagnostic context.
*
* @return Stack A clone of the current thread's diagnostic context.
*/
public
static Stack cloneStack() {
final Stack stack = getCurrentStack();
if (stack == null) {
return null;
} else {
return (Stack) stack.clone();
}
}
@SuppressWarnings("unchecked")
private String printSurroundingElements(PrintWriter pw,
Object userObject,
String indent,
Stack<Object> surrounding,
Stack<String> after,
Set<Object> visited) {
collectEnclosingElements(userObject, surrounding, visited);
Stack<Object> enclosing = (Stack<Object>) surrounding.clone();
Queue<String> indents = new LinkedList<String>();
for (int i = 0; i < enclosing.size(); i++) {
indents.add(indent);
indent += " ";
}
String currentIndent = indent;
Stack<String> before = new Stack<String>();
while (!enclosing.isEmpty()) {
Object obj = enclosing.pop();
currentIndent = indents.poll();
if (obj == userObject) {
break;
}
StringWriter sw = new StringWriter();
if (obj instanceof Method || obj instanceof ExecutableElement) {
printArgElementDef(new PrintWriter(sw), obj, true, currentIndent);
String definition = sw.toString();
definition = definition.substring(0, definition.indexOf("{") + 1);
before.push(String.format("%s%n", definition));
after.push(String.format("%s}%n", currentIndent));
} else {
printCommandElementDefOpen(new PrintWriter(sw), obj, currentIndent);
before.push(String.format("%s%n", sw.toString()));
sw.getBuffer().setLength(0);
printCommandElementDefClose(new PrintWriter(sw), obj, currentIndent);
after.push(sw.toString());
}
}
while (!before.isEmpty()) {
pw.print(before.pop());
}
return currentIndent;
}
/**
Clone the diagnostic context for the current thread.
<p>Internally a diagnostic context is represented as a stack. A
given thread can supply the stack (i.e. diagnostic context) to a
child thread so that the child can inherit the parent thread's
diagnostic context.
<p>The child thread uses the {@link #inherit inherit} method to
inherit the parent's diagnostic context.
@return Stack A clone of the current thread's diagnostic context.
*/
public
static
Stack cloneStack() {
Stack stack = getCurrentStack();
if(stack == null)
return null;
else {
return (Stack) stack.clone();
}
}