Class Safe

java.lang.Object
org.exoplatform.commons.utils.Safe

public class Safe extends Object
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 Details

    • equals

      public static boolean equals(Object o1, Object o2)
      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 object
      o2 - the second object
      Returns:
      true if string are safely equal
    • close

      public static boolean close(Closeable closeable)
      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

      public static byte[] getBytes(InputStream is)
    • unmodifiableSet

      public static <E> Set<E> unmodifiableSet(Set<E> set)
      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

      public static long parseLong(String s)