CSE116 Lecture Code Review 2

CSE116 Lecture Code Review 2 - BRSTRUCT public class

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: BRSTRUCT public class BRStruct<E> { /** * The state of the LRStruct. */ private AState<E> _state ; /** * The sole public constructor for the BRStruct. * Only an empty BRStruct can be constructed directly. */ public BRStruct() { _state = (AState<E>) (EmptyState. SINGLETON ) ; } /** * A private constructor to be used by the EmptyState and NonEmptyState * classes to build an BRStruct in a particular state. * @param state */ private BRStruct(AState<E> state) { _state = state; } /** * A method to insert a new element at the top of this BRStruct. * @param item - the new element to be inserted * @return a reference to this BRStruct (to allow chaining of method calls) */ public BRStruct<E> insertRoot(E item) { return _state .insertRoot( this , item); } /** * A method to remove the root element from the front of this BRStruct. * Permitted only if this is a leaf (both the left and right children of this * BRStruct at empty). * @return the removed element. * @throws IllegalStateException if BRStruct is empty, or if this BRStruct * is not a leaf. */ public E removeRoot() { return _state .removeRoot( this ); } /** * A method to set the root datum of this BRStruct to the specified element. * @param item - the new root element. * @return a reference to this BRStruct (to allow chaining of method calls) * @throws IllegalStateException if BRStruct is empty. */ public BRStruct<E> setDatum(E item) { return _state .setDatum( this , item); } /** * A method to return the root datum of this BRStruct. * @return the first element. * @throws IllegalStateException if BRStruct is empty. */ public E getDatum() { return _state .getDatum( this ); } /** * A method to set the left of this BRStruct to the specified list. * @param rest - the new left. * @return a reference to this BRStruct (to allow chaining of method calls) * @throws IllegalStateException if BRStruct is empty. */ public BRStruct<E> setLeft(BRStruct<E> rest) { return _state .setLeft( this , rest); } /** * A method to return the left of this BRStruct. * @return the left. * @throws IllegalStateException if BRStruct is empty. */ public BRStruct<E> getLeft() { return _state .getLeft( this ); } /** * A method to set the of this BRStruct to the specified list. * @param rest - the new right. * @return a reference to this BRStruct (to allow chaining of method calls) * @throws IllegalStateException if BRStruct is empty. */ public BRStruct<E> setRight(BRStruct<E> rest) { return _state .setRight( this , rest); } /** * A method to return the right of this BRStruct. * @return the right. * @throws IllegalStateException if BRStruct is empty. */ public BRStruct<E> getRight() { return _state .getRight( this ); } /** * Visitor support. * @param <I> The type of the visitor's argument....
View Full Document

This document was uploaded on 12/11/2011.

Page1 / 22

CSE116 Lecture Code Review 2 - BRSTRUCT public class

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online