Class ParsingUtils


  • public class ParsingUtils
    extends Object
    • Field Detail

      • urlHelperClass

        public static Class urlHelperClass
    • Constructor Detail

      • ParsingUtils

        public ParsingUtils()
    • Method Detail

      • openInputStream

        public static InputStream openInputStream​(String uri,
                                                  Function<SeekableByteChannel,​SeekableByteChannel> wrapper)
                                           throws IOException
        open an input stream from the given path and wrap the raw byte stream with a wrapper if given the wrapper will only be applied to paths that are not http, https, ftp, or file, i.e. any Path using a custom filesystem plugin
        Parameters:
        uri - a uri like string
        wrapper - to wrap the input stream in, may be used to implement caching or prefetching, etc
        Returns:
        An inputStream appropriately created from uri and conditionally wrapped with wrapper (only in certain cases)
        Throws:
        IOException - when stream cannot be opened against uri
      • sortList

        public static <T extends ComparableList<T> sortList​(Collection<T> list)
        a small utility function for sorting a list
        Type Parameters:
        T -
        Parameters:
        list -
        Returns:
      • sortedString

        public static <T extends Comparable<T>,​V> String sortedString​(Map<T,​V> c)
      • join

        public static String join​(String separator,
                                  String[] strings)
        join an array of strings given a seperator
        Parameters:
        separator - the string to insert between each array element
        strings - the array of strings
        Returns:
        a string, which is the joining of all array values with the separator
      • join

        public static String join​(String separator,
                                  String[] strings,
                                  int start,
                                  int end)
        join a set of strings, using the separator provided, from index start to index stop
        Parameters:
        separator - the separator to use
        strings - the list of strings
        start - the start position (index in the list)0
        end - the end position (index in the list)
        Returns:
        a joined string, or "" if end - start == 0
      • split

        public static List<String> split​(String input,
                                         char delim)
        Split the string into tokens separated by the given delimiter. This looks suspiciously like what String.split should do. It is here because String.split has particularly poor performance for this use case in some versions of the Java SE API because of use of java.util.regex APIs (see bug report at http://bugs.java.com/view_bug.do?bug_id=6840246 for information).
        Parameters:
        input - the string to split
        delim - the character that delimits tokens
        Returns:
        a list of the tokens
      • split

        public static int split​(String aString,
                                String[] tokens,
                                char delim)
        Split the string into tokesn separated by the given delimiter. Profiling has revealed that the standard string.split() method typically takes > 1/2 the total time when used for parsing ascii files.
        Parameters:
        aString - the string to split
        tokens - an array to hold the parsed tokens
        delim - character that delimits tokens
        Returns:
        the number of tokens parsed
      • split

        public static int split​(String aString,
                                String[] tokens,
                                char delim,
                                boolean condenseTrailingTokens)
        Split the string into tokens separated by the given delimiter. Profiling has revealed that the standard string.split() method typically takes > 1/2 the total time when used for parsing ascii files.
        Parameters:
        aString - the string to split
        tokens - an array to hold the parsed tokens
        delim - character that delimits tokens
        condenseTrailingTokens - if true and there are more tokens than will fit in the tokens array, condense all trailing tokens into the last token
        Returns:
        the number of tokens parsed
      • trim

        public static String trim​(String str,
                                  char ch)
      • splitWhitespace

        public static int splitWhitespace​(String aString,
                                          String[] tokens)
        Split the string into tokens separated by tab or space(s). This method was added so support wig and bed files, which apparently accept space delimiters.

        Note: TODO REGEX expressions are not used for speed. This should be re-evaluated with JDK 1.5 or later

        Parameters:
        aString - the string to split
        tokens - an array to hold the parsed tokens
        Returns:
        the number of tokens parsed
      • isSorted

        public static <T extends Comparable<? super T>> boolean isSorted​(Iterable<T> iterable)
      • parseColor

        public static Color parseColor​(String string)
        Convert an rgb string, hex, or symbol to a color.
        Parameters:
        string -
        Returns:
      • getURLHelper

        public static URLHelper getURLHelper​(URL url)
        Return the registered URLHelper, constructed with the provided URL
        Parameters:
        url -
        Returns:
        See Also:
        registerHelperClass(Class)
      • registerHelperClass

        public static void registerHelperClass​(Class helperClass)
        Register a URLHelper class to be used for URL operations. The helper may be used for both FTP and HTTP operations, so if any FTP URLs are used the URLHelper must support it. The default helper class is RemoteURLHelper, which delegates to FTP/HTTP helpers as appropriate.
        Parameters:
        helperClass - Class which implements URLHelper, and have a constructor which takes a URL as it's only argument.
        See Also:
        URLHelper
      • appendToPath

        public static String appendToPath​(String filepath,
                                          String indexExtension)
        Add the indexExtension to the filepath, preserving query string elements if present. Intended for use where filepath is a URL. Will behave correctly on regular file paths (just add the extension to the end)
        Parameters:
        filepath -
        indexExtension -
        Returns: