Class Utilities

java.lang.Object
com.nomagic.license.utils.CameoUtilities
com.nomagic.rcpf.product.utils.Utilities

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

    • Utilities

      public Utilities()
  • Method Details

    • hasExtension

      public static boolean hasExtension(String name, List extensions)
      Checks if given file name has one of given file extensions.
      Parameters:
      name -
      extensions -
      Returns:
    • hasExtension

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

      public static String removeExtension(String name, Collection<String> extensions)
      Removes file extension form given file name.
      Parameters:
      name -
      extensions - extensions
      Returns:
    • createStringRepresentation

      public static String createStringRepresentation(Collection value)
    • 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
    • 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.
    • match

      public static boolean match(String pattern, String string)
      algorithm for searching with wildcards.
      Parameters:
      pattern - The given pattern.
      string - String.
      Returns:
      boolean expression.
    • matchEmpty

      public static boolean matchEmpty(String patter, String string)
      Matches empty string also
      Parameters:
      patter - The given pattern.
      string - The given string.
      Returns:
      boolean
    • sortStrings

      public static void sortStrings(Vector elem)
      Sorts elements in strings' vector
      Parameters:
      elem - The given vector.
    • clearLine

      public static String clearLine(String line, String trash)
      removes from line ends wanted characters
      Parameters:
      line - The given line.
      trash - characters as string.
      Returns:
      String.
    • clearAllLine

      public static String clearAllLine(String src, String trash)
      Removes all trash from string
      Parameters:
      src - String that be removed trash
      trash - Trash string.
      Returns:
      String.
    • 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.
    • countOccurrences

      public static int countOccurrences(String string, char c)
      Returns the number of times the character c appears in a string.
      Parameters:
      string - The given string.
      c - character.
      Returns:
      number of time.
    • removeNonUtf8CompliantCharacters

      public static String removeNonUtf8CompliantCharacters(String inString)
    • fitInRectangle

      public static Rectangle fitInRectangle(Rectangle small, Rectangle big)
      recalculate bounds to fit in rectangle
      Parameters:
      small - Small rectangle.
      big - Big rectangle.
      Returns:
      New rectangle.
    • containsOnlyFiles

      public static boolean containsOnlyFiles(List list)
      Indicates if given list contains only file objects.
      Parameters:
      list - list to check.
      Returns:
      true if given list contains only file objects, false otherwise.
    • coverRectangle

      public static Rectangle coverRectangle(Rectangle inner, Rectangle outer)
      Moves outer rectengle in such way that it must cover inner one (if outer is smaller than inner resizes outer). Modifies outer and returns it.
      Parameters:
      inner - Inner rectangle.
      outer - Outer rectangle.
      Returns:
      Moved rectangle.
    • createRectFromList

      public static Rectangle createRectFromList(List v)
      Creates rectangle from vector of points.
      Parameters:
      v - List of point.
      Returns:
      null if vector was empty.
    • swapVector

      public static void swapVector(List v)
      Swaps vector ( first element will be last, same with others elements)
      Parameters:
      v - List that be swaped.
    • getFileWitoutExtention

      public static String getFileWitoutExtention(String filename)
      Returns file name without extention (removes chars from last "." to end of string)
      Parameters:
      filename - The given file name.
    • getFileExtension

      public static String getFileExtension(File file)
      Get The given file extension.
      Parameters:
      file - The given file.
      Returns:
      File extension.
    • getFileName

      public static String getFileName(String text)
    • removeComments

      public static String removeComments(String body)
      Removes / * * / comments from body.
      Parameters:
      body - String body.
      Returns:
      body without comment.
    • trim

      public static String trim(String src, String trashBegin, String trashEnd)
      Removes from begin and end given Strings.
      Parameters:
      src - The given string.
      trashBegin - Trash string that is a beginning.
      trashEnd - Trash string that is a ending.
      Returns:
      String
    • replaceEpsString

      public static String replaceEpsString(String aStr)
      Replace special char for Eps format string
      Parameters:
      aStr - The given string.
      Returns:
      String
    • copy

      public static void copy(InputStream input, OutputStream output, long crc) throws IOException
      Copies all bytes from InputStream into OutputStream. Closes the streams.
      Parameters:
      input - the inputstream.
      output - the output stream.
      crc - crc to check. -1 if do not check crc.
      Throws:
      IOException
    • copy

      public static void copy(InputStream input, OutputStream output) throws IOException
      Copies all bytes from InputStream into OutputStream. Closes the streams.
      Parameters:
      input - the inputstream.
      output - the output stream.
      Throws:
      IOException
    • copyFile

      public static boolean copyFile(String sourceName, String dstName)
      Copy source file to destination file.
      Parameters:
      sourceName - Source file name.
      dstName - destination file name.
      Returns:
      True if work successful.
    • copyFile

      public static boolean copyFile(File source, File dst)
      Copy source file to destination file.
      Parameters:
      source - Source file.
      dst - destination file.
      Returns:
      True if work successful.
    • copyDirectory

      public static boolean copyDirectory(File source, File destination)
      copy all directory recursivelly
      Parameters:
      source -
      destination -
    • extractZip

      public static void extractZip(ZipFile zipFile, String dstDir) throws IOException
      Extracts files from Zip archive
      Parameters:
      zipFile - Zip archive file
      dstDir - name of the destination directory
      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
    • getItemWithText

      public static JMenuItem getItemWithText(JPopupMenu menu, String text)
      Returns inner component (not recursively) with given text.
      Parameters:
      menu - The given JPopupMenu.
      text - The given text.
      Returns:
      JMenuItem.
    • createCursor

      public static Cursor createCursor(Image image, Point pt, String cursorName)
      Creates the cursor for given image.
      Parameters:
      image - the given image.
      pt - the hot point.
      cursorName - the cursor name.
      Returns:
      Curser.
    • getAsStringKeyStrokes

      public static String getAsStringKeyStrokes(List shortcuts, String bracketFirst, String bracketSecond)
      Constructs the string representation of the given key strokes.
      Parameters:
      shortcuts - The given key strokes.
      bracketFirst - Open bracket.
      bracketSecond - Close bracket.
      Returns:
      String.
    • getAsString

      public static String getAsString(KeyStroke e)
      Constructs the string representation of the given key stroke.
      Parameters:
      e - the given key stroke.
      Returns:
      String representation.
    • isValidKeyCode

      public static boolean isValidKeyCode(int keyCode)
      Checks if given code is correct one or not.
      Parameters:
      keyCode - The given key code.
      Returns:
      true if given code is not CTRL, SHIFT, META or ALT.
    • 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)
    • toByteArray

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

      public static boolean areChildrenDisabled(JMenu menu)
      Are all children disabled?
      Parameters:
      menu - the menu
      Returns:
      true, if all menu children are disabled
    • normalize

      public static void normalize(Rectangle mRectToDraw, Point mFirstCorner, Point mSecondCorner)
      normalizes rectangle mRectToDraw; Calculates rectangle size and location using mFirstCorner and mSecondCorner. This method is useful when resizing a shape and only opposite corners are known.
      Parameters:
      mRectToDraw - rectangle to normalize
      mFirstCorner - first corner
      mSecondCorner - second corner
    • normalize

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

      public static String getTempDir()
      Returns directory can be used for writing temporary files.
      Returns:
      string.
    • toString

      public static String toString(InputStream inputStream) throws IOException
      Get String representation of inputStream
      Parameters:
      inputStream - The given inputStream
      Returns:
      String representation.
      Throws:
      IOException
    • insertSeparators

      public static String insertSeparators(char[] chars, String separator, int groupSize)
      Constructs string from arrays of chars. String characters are grouped into groups. Groups are separated by separator.
      Parameters:
      chars - array of characters to divide
      separator - group separator
      groupSize - size if the group
      Returns:
      result string
    • removeSeparators

      public static String removeSeparators(String str, String separator)
      Removes separators from specified str
      Parameters:
      str - string to unite
      separator -
      Returns:
      str without separators
    • getBytes

      public static byte[] getBytes(String str)
      Returns bytes of string. 2 bytes for every char.
      Parameters:
      str -
    • distributeInteger

      public static byte[] distributeInteger(int intValue, int size)
      Distributes integer intValue into array of bytes. int is 4 bytes, so max array size is 4
      Parameters:
      intValue - int intValue to distribute
      size - size of result array
      Returns:
      array of bytes
    • collectInteger

      public static int collectInteger(byte[] bytes)
      Makes int value from array of bytes
      Parameters:
      bytes - array of bytes
      Returns:
      int value
    • compareStreams

      public static boolean compareStreams(InputStream oldStr, InputStream newStr) throws IOException
      Compares two input streams.
      Parameters:
      oldStr - First input stream.
      newStr - Second input stream.
      Returns:
      true if streams contains identical data.
      Throws:
      IOException
    • compareFiles

      public static boolean compareFiles(File f1, File f2) throws IOException
      Compares two files
      Parameters:
      f1 - First file.
      f2 - Second file.
      Returns:
      true if files contains identical data.
      Throws:
      IOException
    • deleteTree

      public static void deleteTree(File f)
      Removes given directory and all its contents. File.delete fails if directory is not empty
      Parameters:
      f - file to delete
    • deleteTreeOnExit

      public static void deleteTreeOnExit(File f)
      Removes given file (directory and all its contents) on exit. File.delete fails if directory is not empty
      Parameters:
      f - file to delete
    • deleteDirContent

      public static void deleteDirContent(File f)
      Removes given directory contents. File.delete fails if directory is not empty
      Parameters:
      f - file to delete
    • getClassName

      public static String getClassName(Class clazz)
      Get class name.
      Parameters:
      clazz - The given class.
      Returns:
      Class name.
    • isAlphaNumeric

      public static boolean isAlphaNumeric(String str)
    • mergeLists

      public static <T> List<T> mergeLists(List<T> l1, List<T> l2)
      Merges two lists into newly created one.
      Parameters:
      l1 - first list.
      l2 - second list.
      Returns:
      newly created list with added elements from l1 and l2.
    • splitString

      public static String[] splitString(String str, String delim, boolean returnDelims)
      Splits string
      Parameters:
      str - string to split
      delim - delimiter
      returnDelims - flag indicating whether to return the delimiters with string
      Returns:
      array of strings
    • implode

      public static String implode(Collection collection, String delimiter)
    • implode

      public static String implode(String[] values, String delimiter)
    • parseExceptQuotes

      public static String[] parseExceptQuotes(String cmd)
      parses string by standard tokens, except parts wrapped in quotes
      Parameters:
      cmd -
      Returns:
    • readFileSkipFirstLines

      public static String readFileSkipFirstLines(File file, int n)
      Reads a file to string and skips a specified number of lines from the beginning.
      Parameters:
      file - - file to read.
      n - - number of lines to skip from the beginning.
      Returns:
      file contents as string with skipped lines.
    • zipDir

      public static void zipDir(String dir2zip, ZipOutputStream zos) throws IOException
      Compress specified directory recursivelly to the specified stream.
      Parameters:
      dir2zip - directory to zip.
      zos - ZipOutputStream object.
      Throws:
      IOException - if any occurs during
    • compressData

      public static byte[] compressData(byte[] data, String zipEntryName) throws IOException
      Compresses specified data using zip output stream and returns the result as bytes array.
      Parameters:
      data - a data.
      zipEntryName - name of how the data will be named in the archive.
      Returns:
      compressed data.
      Throws:
      IOException - if any occurs during compressing the data.
    • compressData

      public static byte[] compressData(byte[] data) throws IOException
      Compresses specified data using gzip output stream and returns the result as bytes array.
      Parameters:
      data - a data.
      Returns:
      compressed data.
      Throws:
      IOException - if any occurs during compressing the data.
    • uncompressData

      public static byte[] uncompressData(byte[] data) throws IOException
      Uncompresses specified data using gzip input stream and returns the result as bytes array.
      Parameters:
      data - a data.
      Returns:
      compressed data.
      Throws:
      IOException - if any occurs during compressing the data.
    • checkSystemProperty

      public static boolean checkSystemProperty(String property, boolean defaultValue)
      Checks given system (boolean) property value
      Parameters:
      property -
      defaultValue -
      Returns:
      value of the system property, or defaultValue if system property is not set
    • checkProperty

      public static boolean checkProperty(Properties properties, String property, boolean defaultValue)
    • checkResolvableException

      public static boolean checkResolvableException(boolean rule)
      if rule is false and it's DEVELOPER mode throws IllegalStateException
      Parameters:
      rule -
      Returns:
      rule
    • internString

      public static List internString(List strings)
      Replace all strings in given collection with String.intern().
      Parameters:
      strings - collection of object. Strings among these objects will be interned, other objects will remain.
      Returns:
      the same collection as given
    • dumpThreads

      public static void dumpThreads()
      Dumps all threads to system out.
    • reverseString

      public static String reverseString(String source)
      Given a string, returns a string with reversed characters.
      Parameters:
      source - string which has to be reversed.
      Returns:
      a string with reversed characters.