Package org.exoplatform.commons.utils
Class Safe
java.lang.Object
org.exoplatform.commons.utils.Safe
A class that contains utility method that make the caller not worry much about the unexpectable expected such as argument
nullity or the control flow due to exceptions.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanClose a closable object.static booleanReturn true if both objects are null or both are non null and the equals method of one object returns true when it is invoked with the other object as argument.static byte[]getBytes(InputStream is) static longstatic <E> Set<E> unmodifiableSet(Set<E> set) Wrap the set so that it is unmodifiable when it is not null, otherwise returns null.static <E> org.exoplatform.commons.utils.ListAccess<E> unwrap(org.exoplatform.commons.utils.PageList<E> pageList)
-
Method Details
-
equals
Return true if both objects are null or both are non null and the equals method of one object returns true when it is invoked with the other object as argument.- Parameters:
o1- the first objecto2- the second object- Returns:
- true if string are safely equal
-
close
Close a closable object. The provided object may be null or thrown an IOException or a runtime exception during the invocation of the close method without changing the control flow of the method caller. If the closeable was succesfully closed the method returns true.- Parameters:
closeable- the closeable- Returns:
- true if the object was closed
-
getBytes
-
unmodifiableSet
Wrap the set so that it is unmodifiable when it is not null, otherwise returns null. TODO it would be nice to avoid to rewrap unmodifiable set (not sure it is non proprietary possible)- Type Parameters:
E- the set generic element type- Parameters:
set- the set to wrap- Returns:
- the unmodifiable set
-
unwrap
public static <E> org.exoplatform.commons.utils.ListAccess<E> unwrap(org.exoplatform.commons.utils.PageList<E> pageList) -
parseLong
-