package rac; /** * This class represents a generalized Restriced Access Container ("RACont"). * Objects can be stored and retrieved from the internal coubly-linked circular * list by using the algorithms defined by an externally installable policy * object. * @author S. Wong */ public class RACont { /** * The externally installable policy that determines the store and retrieve * behavior of the RACont. */ private ARACPolicy aRACPolicy; /** * The RACStopNode that is the head and tail of the contained data list. */ private RACStopNode stopNode = new RACStopNode(); /** * Initializes this RACont to a given ARACPolicy. Note that ARACPolicy.init() * is not called as it is not needed on an empty data list. * @param aRACPolicy The ARACPolicy to be installed. */ public RACont(ARACPolicy aRACPolicy) { this.aRACPolicy = aRACPolicy; } /** * Stores the supplied data object in the RACont using the installed * ARACPolicy. * @param data The data to be stored. */ public void store(Object data) { aRACPolicy.store(data,stopNode); } /** * Retrieves the data element specified by the installed ARACPolicy. * @return The retrieved data element. */ public Object retrieve() { return aRACPolicy.retrieve(stopNode); } /** * Installs the supplied ARACPolicy as the active store/retrieve policy. * ARACPolicy.init() will be called to prepare the internal data list. * @param aPolicy The policy to install. */ public void installPolicy(ARACPolicy aPolicy) { aRACPolicy = aPolicy; aRACPolicy.init(stopNode); } /** * Accessor method for the active ARACPolicy. * @return The installed ARACPolicy. */ public ARACPolicy getRACPolicy() { return(aRACPolicy); } /** * Creates a String representation of the internal list with line feeds * between each data element. * @return The String representation of the RAC. */ public String toString() { return (String)stopNode.getNext().execute(ToString.Singleton, null); } /** * Clears all data from the internal data list. */ public void clear() { stopNode = new RACStopNode(); } /** * Test if the internal data list is empty. * @return true if empty, false if not. */ public boolean isEmpty() { return (stopNode.getNext()== stopNode); } }