Java Code Examples for java.util.Stack#clone()

The following examples show how to use java.util.Stack#clone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Internal.java    From symbolicautomata with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: ReturnBS.java    From symbolicautomata with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: Return.java    From symbolicautomata with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: NDC.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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();
   }
}
 
Example 5
Source File: AnnotatedCommandSourceGenerator.java    From picocli with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 6
Source File: NDC.java    From cacheonix-core with GNU Lesser General Public License v2.1 1 votes vote down vote up
/**
   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();
  }
}