package lrs; /** * Represents the non-empty state of a LStruct. * @author Dung X. Nguyen Copyright 2000 - All rights reserved. * @since 02/15/00 */ class NonNullNode extends ANode { private Object _dat; /** @SBGen Variable (,rest,,64) */ private LRStruct _tail; /** * Initializes this NonNullNode to contain dat and an empty tail list. * @param dat the data object to be stored in this NonNullNode. */ NonNullNode(Object dat) { _dat = dat; _tail = new LRStruct(); } /** * Initializes this NonNullNode to contain dat and a given tail list. * @param dat the data object to be stored in this NonNullNode. * @param tail the LRStruct tail of this NonNullNode. */ NonNullNode(Object dat, LRStruct tail) { _dat = dat; _tail = tail; } LRStruct getRest(LRStruct owner) { return _tail; } Object getFirst(LRStruct owner) { return _dat; } void setRest(LRStruct tail, LRStruct owner) { _tail = tail; } void setFirst(Object first, LRStruct owner) { _dat = first; } /** * Inserts a data object at the front of the LRStruct owner. * @param dat the object to be inserted at the front. * @param owner the LRS referencing this NonNullNode. */ void insertFront(Object dat, LRStruct owner) { owner.setHead (new NonNullNode (dat, new LRStruct (this))); /* Details: LRStruct coOwner = new LRStruct (this); NonNullNode newNode = new NonNullNode (dat, coOwner); owner.setHead (newNode); // "old" style: owner._head = newNode - cannot be done here. */ } Object removeFront(LRStruct owner) { owner.setHead (_tail.getHead()); // owner._head = _tail._head return _dat; } /** * Calls the visitor's non-null case. */ Object execute (IAlgo visitor, Object input, LRStruct owner) { return visitor.nonNullCase (owner, input); } }