Difference between revisions of "Atomic Stack Assignment"

From CSE231 Wiki
Jump to navigation Jump to search
Line 1: Line 1:
=Example=
+
=Node and Stack=
 +
==Node==
 +
<nowiki>public interface Node<E> {
 +
E value();
 +
Optional<Node<E>> nextNode();
 +
}</nowiki>
 +
 
 +
==Stack==
 +
<nowiki>public interface Stack<E> {
 +
void push(E value);
 +
Optional<E> peek();
 +
Optional<E> pop();
 +
}</nowiki>
 +
 
 +
==Example==
 +
===empty===
 +
<nowiki>Stack<String> stack = new NotThreadSafeStack<>(DefaultNode::new);</nowiki>
 +
 
 +
[[File:Stack_empty.svg]]
 +
 
 +
===push A, B, C, D, E===
 
  <nowiki>Stack<String> stack = new NotThreadSafeStack<>(DefaultNode::new);
 
  <nowiki>Stack<String> stack = new NotThreadSafeStack<>(DefaultNode::new);
 
stack.push("A");
 
stack.push("A");
Line 8: Line 28:
  
 
[[File:Stack_edcba.svg]]
 
[[File:Stack_edcba.svg]]
 +
 +
===push A, B, C, D, E, pop===
 +
[[File:Stack_dcba.svg]]
  
 
=Code To Implement=
 
=Code To Implement=

Revision as of 01:59, 10 November 2022

Node and Stack

Node

public interface Node<E> {
	E value();
	Optional<Node<E>> nextNode();
}

Stack

public interface Stack<E> {
	void push(E value);
	Optional<E> peek();
	Optional<E> pop();
}

Example

empty

Stack<String> stack = new NotThreadSafeStack<>(DefaultNode::new);

Stack empty.svg

push A, B, C, D, E

Stack<String> stack = new NotThreadSafeStack<>(DefaultNode::new);
stack.push("A");
stack.push("B");
stack.push("C");
stack.push("D");
stack.push("E");

Stack edcba.svg

push A, B, C, D, E, pop

Stack dcba.svg

Code To Implement

Node

public interface Node<E> {
	E value();

	Optional<Node<E>> nextNode();
}

DefaultNode

@Immutable class DefaultNode.

class: DefaultNode.java Java.png
methods: value
nextNode
package: stack.node.exercise
source folder: main/src/main/java

constructor and instance variables

value

nextNode

Stack

public interface Stack<E> {
	void push(E value);

	Optional<E> peek();

	Optional<E> pop();
}

NotThreadSafeStack

@NotThreadSafe

class: NotThreadSafeStack.java Java.png
methods: constructor
nodeConstructor
push
peek
pop
package: stack.notthreadsafe.exercise
source folder: student/src/main/java

constructor and instance variables

nodeConstructor

push

peek

pop

ConcurrentStack

@ThreadSafe

class: ConcurrentStack.java Java.png
methods: constructor
nodeConstructor
push
peek
pop
package: stack.concurrent.exercise
source folder: student/src/main/java

constructor and instance variables

nodeConstructor

push

peek

pop

AtomicStack

@ThreadSafe

class: AtomicStack.java Java.png
methods: constructor
nodeConstructor
push
peek
pop
package: stack.atomic.exercise
source folder: student/src/main/java

constructor and instance variables

nodeConstructor

push

peek

pop

Testing

class: StackTestSuite.java Junit.png
package: stack.exercise
source folder: testing/src/test/java

DefaultNode

class: _DefaultNodeTestSuite.java Junit.png
package: stack.node.exercise
source folder: testing/src/test/java

NotThreadSafeStack

class: _NotThreadSafeStackTestSuite.java Junit.png
package: stack.notthreadsafe.exercise
source folder: testing/src/test/java

ConcurrentStack

class: __ConcurrentStackTestSuite.java Junit.png
package: stack.concurrent.exercise
source folder: testing/src/test/java

sequential

class: _ConcurrentStackSequentialTestSuite.java Junit.png
package: stack.concurrent.exercise
source folder: testing/src/test/java

parallel

class: _ConcurrentStackParallelTestSuite.java Junit.png
package: stack.concurrent.exercise
source folder: testing/src/test/java

AtomicStack

class: __AtomicStackTestSuite.java Junit.png
package: stack.atomic.exercise
source folder: testing/src/test/java

sequential

class: _AtomicStackSequentialTestSuite.java Junit.png
package: stack.atomic.exercise
source folder: testing/src/test/java

parallel

class: _AtomicStackParallelTestSuite.java Junit.png
package: stack.atomic.exercise
source folder: testing/src/test/java