package votorola.g.lang; // Copyright 2003-2005, 2012, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola 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 Votorola Software. THE VOTOROLA 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 VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. /** Object utilities. */ public final class ObjectX { private ObjectX() {} /** An equator that uses the {@linkplain Object#equals(Object) #equals}() method of * the first object, if it is not null. Its thread safety is that of * o1.equals(object). */ public static final Equator EQUATOR = new Equator() { // changing? change also in g/web/gwt/super/ public boolean equals( final Object o1, final Object o2 ) { if( o1 == null ) return o2 == null; return o1.equals( o2 ); } }; // /** 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. This does the same * thing as {@linkplain #EQUATOR EQUATOR} and will eventually be deprecated. The * thread safety is that of o1.equals(object). */ public static boolean nullEquals( final Object o1, final Object o2 ) { // changing? change also in g/web/gwt/super/ if( o1 == null ) return o2 == null; 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 @ThreadSafe boolean tryWait( final 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 @ThreadSafe boolean tryWait( final Object object, final long timeout ) { try { object.wait( timeout ); return true; } catch( InterruptedException x ) { return false; } } }