Class CameoUtilities

java.lang.Object
com.nomagic.utils.CameoUtilities
Direct Known Subclasses:
Utilities

@OpenApiAll public class CameoUtilities extends Object
General purpose utilities.
  • Constructor Details

    • CameoUtilities

      public CameoUtilities()
  • Method Details

    • clearAllLine

      public static String clearAllLine(String src, String trash)
      Removes all trash from string
      Parameters:
      src - String from witch thrash should be removed
      trash - Trash string.
      Returns:
      cleared string or same if nothing was cleared
    • isEqual

      public static boolean isEqual(@CheckForNull Object obj1, @CheckForNull Object obj2)
      Returns true of both objects are nulls or equal
      Parameters:
      obj1 - First object.
      obj2 - Second object.
      Returns:
      boolean
    • isEqual

      public static boolean isEqual(@CheckForNull Object[] obj1, @CheckForNull Object[] obj2)
      Returns true of both objects are nulls or equal
      Parameters:
      obj1 - object list.
      obj2 - object list.
      Returns:
      boolean
    • toString

      public static String toString(InputStream inputStream, @CheckForNull String encoding) throws IOException
      Get String representation of inputStream
      Parameters:
      inputStream - The given inputStream
      Returns:
      String representation
      Throws:
      IOException
    • replaceNewLine

      public static String replaceNewLine(String string, String lineSeparator)
      Separate lines with the provided separator string.
      Parameters:
      string - input string.
      lineSeparator - line separator.
      Returns:
      result string.
    • copy

      public static void copy(Reader input, Writer output) throws IOException
      Copies all bytes from Reader into Writer. Closes the reader and writer.
      Parameters:
      input - the reader.
      output - the writer.
      Throws:
      IOException
    • copy

      public static void copy(InputStream input, OutputStream output) throws IOException
      Throws:
      IOException
    • toByteArray

      public static byte[] toByteArray(InputStream stream)
      Copies the given file into the array of bytes.
      Parameters:
      stream - the given file.
      Returns:
      the byte array with the context of the file;null if some errors occurs
    • toByteArray

      public static byte[] toByteArray(String bytes)
      Returns byte array from string formatted in toString(byte[]) method.
      Parameters:
      bytes - the given string.
      Returns:
      the byte array.
    • toString

      public static String toString(byte[] data)
      Returns string representation of the given byte array.
      Parameters:
      data - the given bytes array.
      Returns:
      the string representation (every byte is represented as hex string separated by space)
    • removeFromLine

      public static String removeFromLine(String line, String trash)
      Removes from line trash line
      Parameters:
      line - the given line.
      trash - characters as string.
      Returns:
      The given string without From Line.
    • hasExtension

      public static boolean hasExtension(String name, List<String> extensions)
      Checks if given file name has one of given file extensions.
    • hasExtension

      public static boolean hasExtension(String name, String extension)
      Checks if given file name has given file extension.
    • removeExtension

      public static String removeExtension(String name, Collection<String> extensions)
      Removes file extension form given file name.
    • deepPointsClone

      public static List<Point> deepPointsClone(List<Point> v)
      Makes a deep clone of vector that contains points.
      Parameters:
      v - List of point.
      Returns:
      vector
    • deepPointsClone

      public static List<Point> deepPointsClone(List<Point> v, boolean cloneList)
      Makes a deep clone of vector that contains points.
      Parameters:
      v - List of point.
      cloneList - True if clone to new list.
      Returns:
      vector
    • normalize

      public static void normalize(Rectangle rectangle, Point firstCorner, Point secondCorner)
      Normalizes rectangle; Calculates rectangle size and location using firstCorner and secondCorner.
      Parameters:
      rectangle - rectangle to normalize
      firstCorner - first corner
      secondCorner - second corner
    • normalize

      public static void normalize(Rectangle rect)
      normalizes rectangle mRectToDraw;
      Parameters:
      rect - rectangle to normalize
    • createRectFromList

      @CheckForNull public static Rectangle createRectFromList(List<Point> v)
      Creates rectangle from vector of points.
      Parameters:
      v - List of point
      Returns:
      null if vector was empty
    • replace

      public static String replace(String src, String pattern, String replaceWith)
      Replaces string fragment with another string
      Parameters:
      src - Source string.
      pattern - String pattern.
      replaceWith - The another string.
      Returns:
      string.
    • removeClosestToTheMiddle

      public static void removeClosestToTheMiddle(List objects, Object o1, Object o2)
      Removes an object from the list which is closest to the middle.
      Parameters:
      objects - - a list of objects.
      o1 - - first object.
      o2 - - second object.