Class Utilities


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

    • Utilities

      public Utilities()
  • Method Details

    • 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)
      Checks if given string matches given pattern with wild cards. Empty string does not match any pattern.
      Parameters:
      pattern - pattern with wildcards
      string - string
      Returns:
      boolean true if string matches pattern
    • matchIncludingEmpty

      public static boolean matchIncludingEmpty(String pattern, String string)
      Checks if given string matches given pattern with wild cards. Empty string matches pattern "*".
      Parameters:
      pattern - pattern with wildcards
      string - string
      Returns:
      boolean true if string matches pattern
    • 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.
    • merge

      public static <T> void merge(List<T> source, List<T> v)
      Merges two vector. Removes non existing in vector v elements from vector source. Adds existing in v into source. Result vector is source
      Parameters:
      source - source list.
      v - The given vector.
    • append

      @Deprecated public static <T> Collection<T> append(Collection<T> source, Collection<? extends T> v, boolean allowDublication)
    • append

      @Deprecated public static <T> Collection<T> append(Collection<T> source, Iterator<? extends T> it, boolean allowDublication)
    • contains

      @Deprecated public static boolean contains(Iterator it, Object o)
    • containsAny

      @Deprecated public static boolean containsAny(Collection location, Collection what)
    • clearFromEveryLine

      public static String clearFromEveryLine(String text, String mask)
      Divides given string into lines and from every line beginning and end removes all chars from given string mask.
      Parameters:
      text - The given string.
      mask - The given string mark.
      Returns:
      String.
    • 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.
    • containsNonDirectory

      public static boolean containsNonDirectory(List<File> fileList)
      Parameters:
      fileList - list of File objects
      Returns:
      true if there is at least one file that is not a directory
    • coverRectangle

      public static Rectangle coverRectangle(Rectangle inner, Rectangle outer)
      Moves outer rectangle 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

      @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
    • swapVector

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

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

      @Deprecated public static String getFileWitoutExtention(String filename)
      Deprecated.
      type error in name
      Returns file name without extension (removes chars from last "." to end of string)
      Parameters:
      filename - The given file name
      See Also:
    • getFileExtension

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

      @CheckForNull public static String getFileExtension(String fileName)
      Get the given file extension.
      Parameters:
      fileName - file name
      Returns:
      File extension
    • getFileName

      public static String getFileName(String text)
    • getCurrentDateFormatted

      public static String getCurrentDateFormatted()
    • removeComments

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

      @Deprecated public static <E extends Collection> E createCollection(Class<E> collection, Iterator it)
    • notDublicatedList

      @Deprecated public static Collection notDublicatedList(Collection col)
    • 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, boolean closeInput) throws IOException
      Copies all bytes from InputStream into OutputStream. Closes the streams.
      Parameters:
      input - the input stream.
      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, @CheckForNull Checksum checksum) throws IOException
      Copies all bytes from InputStream into OutputStream
      Parameters:
      input - the input stream.
      output - the output stream.
      checksum - checksum.
      Throws:
      IOException - exception
    • copy

      public static void copy(InputStream input, OutputStream output) throws IOException
      Copies all bytes from InputStream into OutputStream. Closes the streams.
      Parameters:
      input - the input stream.
      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 destination)
      Copy source file to destination file.
      Parameters:
      source - Source file.
      destination - destination file.
      Returns:
      true if successful.
    • copyDirectory

      public static boolean copyDirectory(File source, File destination)
      Copy all directory recursively
    • 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
    • extractZip

      public static Collection<String> extractZip(InputStream is, String dstDir, Collection<String> onlyTheseEntries, Collection<String> skipTheseEntries) throws IOException
      Extracts files from Zip archive
      Parameters:
      is - Input Stream - must be valid zip file
      dstDir - destination directory
      onlyTheseEntries - if not null specifies which entries must be extracted.
      skipTheseEntries - if not null specifies which entries should be skiped.
      Returns:
      extracted entry names.
      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:
      Cursor.
    • createCursor

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

      public static String getAsStringKeyStrokes(List<KeyStroke> 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(@CheckForNull 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.
    • isPrintableChar

      public static boolean isPrintableChar(char c)
      Checks if char is printable or not.
      Parameters:
      c - char which ic checked.
      Returns:
      true if char is printable.
    • 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 formatted 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 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
    • getTempDir

      public static String getTempDir()
      Returns System temp directory.
      Returns:
      string.
    • openHttpURLConnection

      public static HttpURLConnection openHttpURLConnection(String pageHttpAddress, ProxyServerData proxyServerData) throws IOException
      Opens HttpURLConnection according given page address and proxy server data.
      Parameters:
      pageHttpAddress - page address with protocol e.g "http://www.nomagic.com"
      proxyServerData - proxy server data
      Returns:
      HttpURLConnection.
      Throws:
      IOException
    • isUseProxy

      public static boolean isUseProxy(ProxyServerData proxy)
      Checks if use proxy server according given proxy server data
      Parameters:
      proxy - proxy data.
      Returns:
      true if use; otherwise - false
    • getHtmlPage

      public static String getHtmlPage(String pageHttpAddress, String parameters, ProxyServerData proxy) throws IOException
      Returns HTML page
      Parameters:
      pageHttpAddress - page address with protocol e.g "http://www.nomagic.com"
      parameters - parameters for POST method (null if no data to POST)
      proxy - proxy server data
      Returns:
      HTML page
      Throws:
      IOException
    • toString

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

      public static String toString(Collection<String> strings)
      Get String representation of given strings collection
      Parameters:
      strings - many strings
      Returns:
      String representation.
    • sendHttpParameters

      @Deprecated public static void sendHttpParameters(HttpURLConnection connection, String parameters) throws IOException
      Deprecated.
      use HttpUtilities.sendHttpParameters(HttpURLConnection, String)
      Send Http Parameters.
      Parameters:
      connection - HttpURLConnection
      parameters - Http Parameters.
      Throws:
      IOException
    • constructHttpParameter

      public static String constructHttpParameter(String parameter, String value)
      Constructs http parameter
      Parameters:
      parameter - parameter name
      value - parameter value
      Returns:
      constructed parameter
    • addHttpParameter

      public static String addHttpParameter(String parameters, String parameter, String value)
      Adds http parameter to given parameters string
      Parameters:
      parameters - parameters
      parameter - parameter name to add
      value - parameter value to add
      Returns:
      constructed parameters string
    • concatHttpParameter

      public static String concatHttpParameter(String parameters1, String parameters2)
      Concatenate given http parameters
      Parameters:
      parameters1 -
      parameters2 -
      Returns:
      concatenated parameters
    • 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.
    • 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
    • invokeAndWaitOnDispatcher

      public static void invokeAndWaitOnDispatcher(Runnable r) throws RuntimeException
      Executes given runnable on event dispatcher. Note if current thread is interrupted after runnable is submitted to the queue this method throws exception but runnable will be run on EDT.
      Parameters:
      r - the given runnable
      Throws:
      RuntimeException
    • invokeAndWaitOnDispatcherEvenInterrupted

      public static void invokeAndWaitOnDispatcherEvenInterrupted(Runnable r) throws RuntimeException
      Executes given runnable on event dispatcher. Waits until r is finished even current thread is interrupted.
      Parameters:
      r - the given runnable
      Throws:
      RuntimeException
    • invokeOnDispatcherOrLater

      public static void invokeOnDispatcherOrLater(Runnable r)
      If this thread is event dispatcher, than direct calls "run", else invoke on invoke later
      Parameters:
      r -
    • invokeLaterAfterCondition

      public static void invokeLaterAfterCondition(Runnable runnable, Supplier<Boolean> condition)
      Invokes runnable latter after condition is satisfied.
      Parameters:
      runnable - runnable which will be executed.
      condition - condition condition after which satisfaction runnable will be executed.
    • invokeLaterAfterCondition

      public static void invokeLaterAfterCondition(Runnable runnable, Supplier<Boolean> condition, int conditionCheckAttemptCount)
      Invokes runnable latter after condition is satisfied.
      Parameters:
      runnable - runnable which will be executed.
      condition - condition condition after which satisfaction runnable will be executed.
      conditionCheckAttemptCount - attempts count of the condition check; if count is reached before the condition is satisfied, runnable will not be executed.
    • 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(@Nonnull 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
    • getGrayIcon

      @Deprecated @CheckForNull public static ResizableIcon getGrayIcon(@CheckForNull Icon icon)
      Returns grey(disabled) icon from given one.
      Parameters:
      icon - the given icon.
      Returns:
      disabled icon
    • getGrayIcon

      @Deprecated @CheckForNull public static ResizableIcon getGrayIcon(@CheckForNull Icon icon, Component component)
      Returns grey(disabled) icon from given one.
      Parameters:
      icon - the given icon.
      component - component.
      Returns:
      disabled icon
    • makeEqual

      public static void makeEqual(List destination, List source)
      Make destination the same as source with minimum changes to destination
      Parameters:
      destination - List
      source - List
    • 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.
    • synchronizeDirectories

      public static void synchronizeDirectories(File source, File destination) throws IOException
      Synchronize two directories. If new file appears in source, it should appear in destination. If file is removed from destination it should not appear in destination again. Typical use for this method is when one directory has default settings, and another have working copy.
      Parameters:
      source - source directory.
      destination - destination directory.
      Throws:
      IOException
    • splitString

      public static String[] splitString(String str, String delimiter, boolean returnDelimiter)
      Splits string
      Parameters:
      str - a string to be parsed.
      delimiter - the delimiter.
      returnDelimiter - flag indicating whether to include the delimiter in result.
      Returns:
      array of strings
    • implode

      public static String implode(Collection collection, String delimiter)
      Returns a new String composed of copies of the collection elements joined together with a copy of the specified delimiter. Consider using String.join(CharSequence, Iterable).
      Parameters:
      collection - collection of elements.
      delimiter - delimiter.
      Returns:
      joined string.
      See Also:
    • implode

      @Deprecated 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
    • 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 recursively 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
      Returns:
      rule
    • dumpThreads

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

      public static void dumpThreads(PrintStream out)
      Dumps all threads to given stream.
    • 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.
    • calculateTextWidth

      public static int calculateTextWidth(String text, FontMetrics metrics, int numberOfLines)
      Calculates possible text longest text width of the given text splitted into lines.
      Parameters:
      text - text for which to calculate width.
      metrics - font metrics according which to calculate.
      numberOfLines - number of lines into which to split the text.
      Returns:
      calculated possible text width.
    • isHTMLText

      public static boolean isHTMLText(String s)
      Check the given string to see if it should trigger the html rendering logic.
      Parameters:
      s - the given string.
      Returns:
      true if given text is html, false otherwise.
    • ensureObjectIsInCollection

      public static <T> void ensureObjectIsInCollection(Collection<T> collection, T object)
      Ensures an object is in given collection. If it isn't, the object is added to it.
      Parameters:
      collection - collection in which to check object existence.
      object - object to check.
    • encodeBase64

      public static String encodeBase64(byte[] abyte0)
      Encodes data using base64 encoding.
      Parameters:
      abyte0 - data for encoding
      Returns:
      encoded string
    • decodeBase64

      public static byte[] decodeBase64(String s)
      Decode string using Base64 encoding.
      Parameters:
      s - string for decoding
      Returns:
      decoded data
    • hasModalDialogs

      public static boolean hasModalDialogs(Window window)
      Checks recursively if given window has modal dialog as child (or window itself is a modal dialog)
      Parameters:
      window - window
      Returns:
      true if modal dialog is found
    • removeNewLines

      public static String removeNewLines(String string)
      Removes new lines from the string.
      Parameters:
      string - string for which to remove new lines.
      Returns:
      string with removed new lines.
    • checkIsInstallRootWritable

      @CheckForNull public static String checkIsInstallRootWritable(com.nomagic.runtime.RuntimeEnvironment runtime)
      Get message for install root read only error. Returns null if install root is writable. Method is suitable for read only checking.
      Parameters:
      runtime - Application runtime.
      Returns:
      Message for install root read only error or null if install root is writable
    • checkIsInstallRootWritable

      @CheckForNull public static String checkIsInstallRootWritable(com.nomagic.runtime.RuntimeEnvironment runtime, boolean skipWinUAC)
      Get message for install root read only error. Returns null if install root is writable. Method is suitable for read only checking.
      Parameters:
      runtime - runtime environment.
      skipWinUAC - skip checking writable install root if Windows is supporting UAC.
      Returns:
      Message for install root read only error or null if install root is writable
    • main

      public static void main(String[] args)
    • getVersionFromInternal

      public static String getVersionFromInternal(String internal) throws NumberFormatException, IndexOutOfBoundsException
      Convert internal MagicDraw style version to human version in 17.0.2 format.
      Parameters:
      internal - Internal version.
      Returns:
      Human version
      Throws:
      NumberFormatException - parse exception.
      IndexOutOfBoundsException - if internal version is negative.
    • getVersionFromInternal

      public static String getVersionFromInternal(int internal) throws IndexOutOfBoundsException
      Convert internal MagicDraw style version to human version in 17.0.2 format.
      Parameters:
      internal - Internal version.
      Returns:
      human version
      Throws:
      IndexOutOfBoundsException - if internal version is negative.
    • containSameElements

      public static boolean containSameElements(Collection<?> collection1, Collection<?> collection2)
    • arrayHash

      public static int arrayHash(byte[] array)
      Calculate hash code for array of bytes
      Parameters:
      array - bytes
      Returns:
      hash code
    • isStreamEmpty

      public static boolean isStreamEmpty(URL url)
      Check if it is possible to open a stream from a given URL and that stream is not empty
      Parameters:
      url - url to check
      Returns:
      true if not empty stream is opened from a given url
    • insertPeriodically

      public static String insertPeriodically(String text, String insert, int period)
    • sha1Hex

      public static String sha1Hex(String... strings) throws NoSuchAlgorithmException
      Returns SHA-1 hash key that should be constructed from the specified strings.
      Parameters:
      strings - array of strings.
      Returns:
      SHA-1 hash key.
      Throws:
      NoSuchAlgorithmException
    • sha1Hex

      public static String sha1Hex(byte[] data) throws NoSuchAlgorithmException
      Returns SHA-1 hash key that should be constructed from the specified data.
      Parameters:
      data - array of bytes
      Returns:
      SHA-1 hash key.
      Throws:
      NoSuchAlgorithmException
    • getDistance

      public static <E> int getDistance(E from, E to, Function<E,Collection<E>> connectedNodes)
      Calculate minimal distance in graph.
      Type Parameters:
      E - type of node.
      Parameters:
      from - starting point in graph.
      to - destination point in graph.
      connectedNodes - function to get connected edges.
      Returns:
      minimal number of steps required to get from node from to node to. Return -1 if nodes are not connected.
    • contentEquals

      public static boolean contentEquals(InputStream input1, InputStream input2)
      Compare content of two streams.
      Parameters:
      input1 - first stream.
      input2 - another stream.
      Returns:
      true if stream provides exactly same content.
    • getSystemDateFormat

      public static DateFormat getSystemDateFormat(int style)
      Returns system date format. Ordinary Java date format getting methods returns format taken from locale, which can be different from real system date format, set in calendar settings.
      Parameters:
      style - Format style (e.g. DateFormat.SHORT, DateFormat.LONG).
      Returns:
      System date format. If can't get it, returns SimpleDateFormat.
    • isFileNameValid

      public static boolean isFileNameValid(String fileName)
      Returns if given file name is valid to be created.
      Parameters:
      fileName - file name
      Returns:
      true if file name can be created or already exists, else false
    • excludeCommonElements

      public static <T> Set<T> excludeCommonElements(Collection<T> first, Collection<T> second)
      Creates result collection which contains not common elements from two arguments
      Type Parameters:
      T - type of collection
      Parameters:
      first - first collection
      second - second collection
      Returns:
      not common elements of two arguments
    • isNameValid

      public static boolean isNameValid(@CheckForNull String name)
    • getThreadsInfo

      public static String getThreadsInfo()