package textbender.g.lang; // Copyright 2003-2005, 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. /** Object utilities. */ public final class ObjectX { private ObjectX() {} // /** Returns null if o is null; o.clone() otherwise. // */ // public static Object nullClone( Object o ) // { // if( o == null ) return o; // else return o.clone(); // } //////// sorry, clone() is protected /** Returns true iff the objects are either 'equal', or both null. */ public static boolean nullEquals( Object o1, Object o2 ) { if( o1 == null || o2 == null ) return o1 == o2; else return o1.equals( o2 ); } // /** Returns o.toString() if o is non-null; null otherwise. // */ // public static String nullToString( Object o ) // { // if( o == null ) return null; // // return o.toString(); // } //////// this sort of thing would have to be done everywhere /** Same as object.wait(), but returns normally if interrupted. * * @return true if the wait ended normally; false if an InterruptedException occured */ public static boolean tryWait( Object object ) { try { object.wait(); return true; } catch( InterruptedException x ) { return false; } } /** Same as object.wait(milliseconds), but returns normally if interrupted. * * @return true if the wait ended normally; false if an InterruptedException occured */ public static boolean tryWait( Object object, long timeout ) { try { object.wait( timeout ); return true; } catch( InterruptedException x ) { return false; } } }