package textbender.g.hold; // Copyright 2005-2006, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. import java.util.*; import textbender.g.lang.*; /** Null implementation of a spool; it is always empty and never unwinds. */ public @ThreadSafe class Spool0 extends AbstractCollection implements Spool { /** A common instance of Spool0. */ public static Spool0 i() { return instance; } // - C o l l e c t i o n -------------------------------------------------------------- /** Does nothing. * * @return true */ public boolean add( Hold hold ) { return true; } // throw new IllegalArgumentException( "not an ReferenceHold, cannot add to null spool: " + hold.getClass().getName() ); // unsafe because shutdown of the VM effectively releases all memory, fullfilling the contract on behalf of this non-functional spool, but only for in-VM reference holds //// No, this kind of check is misplaced here. Critical external holds must be added to a spool that is documented to unwind at shutdown. It is the responsibility of the programmer to add to the correct spool. public Iterator iterator() { List emptyList = Collections.emptyList(); return emptyList.iterator(); } /** @return zero */ public int size() { return 0; } // - S p o o l ------------------------------------------------------------------------ /** @return false */ public boolean isUnwinding() { return false; } /** Does nothing. * * @return false */ public boolean unwind() { return false; } /** Does nothing. * * @return false */ public boolean unwind( Catcher catcher ) { return false; } ////////////////////////////////////////////////////////////////////////////////////////// // Last, so static fields above initialize, and are available during instantiation below private static final Spool0 instance = new Spool0(); }