Class WWUtil


  • public class WWUtil
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      WWUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void alignComponent​(java.awt.Component parent, java.awt.Component child, java.lang.String alignment)  
      static int compareVersion​(java.lang.String va, java.lang.String vb)
      Compares two version strings, e.g., 1.3.0, and returns 0 if they match, -1 if the first string is less than the second, and 1 if the first string is greater than the second.
      static java.awt.Color computeContrastingColor​(java.awt.Color color)  
      static java.lang.Boolean convertNumericStringToBoolean​(java.lang.String s)
      Converts a specified string to a boolean value.
      static java.lang.Boolean convertStringToBoolean​(java.lang.String s)
      Converts a specified string to a boolean value.
      static java.lang.Double convertStringToDouble​(java.lang.String s)
      Converts a specified string to a floating point value.
      static java.lang.Integer convertStringToInteger​(java.lang.String s)
      Converts a specified string to an integer value.
      static java.lang.Long convertStringToLong​(java.lang.String s)
      Converts a specified string to a long integer value.
      static void convertUTMCoordinatesToGeographic​(int zone, java.lang.String hemisphere, java.nio.DoubleBuffer buffer)
      Converts the specified buffer of UTM tuples to geographic coordinates, according to the specified UTM zone and hemisphere.
      static void copyValues​(AVList srcList, AVList destList, java.lang.String[] keys, boolean forceOverwrite)
      Copies only values of the specified keysfrom srcList to another destList.
      static java.awt.Color decodeColorABGR​(java.lang.String encodedString)
      Decodes a hexadecimal string in the form aabbggrr, 0xaabbggrr or #aabbggrr to a color.
      static java.awt.Color decodeColorRGBA​(java.lang.String encodedString)
      Decodes a hexadecimal string in the form rrggbbaa, rrggbbaa or #rrggbbaa to a color.
      static double[] defaultMinMix()
      Creates a two-element array of default min and max values, typically used to initialize extreme values searches.
      static java.lang.String encodeColorABGR​(java.awt.Color color)
      Creates a hexadecimal string representation of a Color in the form 0xaabbggrr.
      static java.lang.String encodeColorRGBA​(java.awt.Color color)
      Creates a hexadecimal string representation of a Color in the form 0xrrggbbaa.
      static java.lang.String extractExceptionReason​(java.lang.Throwable t)
      Extracts an error message from the exception object
      static void generateTriStripNormals​(java.nio.FloatBuffer vertices, java.nio.IntBuffer indices, java.nio.FloatBuffer normals)
      Generates average normal vectors for the vertices of a triangle strip.
      static java.awt.Color interpolateColor​(double amount, java.awt.Color color1, java.awt.Color color2)
      Returns the component-wise linear interpolation of color1 and color2.
      static java.lang.Object invokePropertyMethod​(java.lang.Object parent, java.lang.String propertyName, java.lang.String propertyValue)
      Uses reflection to invoke a set method for a specified property.
      static boolean isEmpty​(java.lang.Object s)
      Determine whether an object reference is null or a reference to an empty string.
      static boolean isEmpty​(java.util.List<?> list)
      Determine whether an List is null or empty.
      protected static boolean isKMLTimeShift​(java.lang.String timeString)  
      static java.awt.Color makeColorBrighter​(java.awt.Color color)  
      static java.awt.Color makeColorDarker​(java.awt.Color color)  
      static java.lang.Double makeDouble​(java.lang.String s)
      Parses a string to a double value if the string can be parsed as a double.
      static java.lang.Double makeDoubleForLocale​(java.lang.String s)
      Parses a string to a double value using the current locale if the string can be parsed as a double.
      static java.lang.Integer makeInteger​(java.lang.String s)
      Parses a string to an integer value if the string can be parsed as a integer.
      static java.lang.Long makeLong​(java.lang.String s)
      Parses a string to a long value if the string can be parsed as a long.
      static java.awt.Color makeRandomColor​(java.awt.Color color)
      Generates a random Color by scaling each of the red, green and blue components of a specified color with independent random numbers.
      static java.awt.Color makeRandomColor​(java.awt.Color color, java.awt.Color darkestColor, int maxAttempts)
      Generates a random Color by scaling each of the red, green and blue components of a specified color with independent random numbers.
      static void normalizeGeographicCoordinates​(java.nio.DoubleBuffer buffer)
      Normalizes the specified buffer of geographic tuples.
      static java.lang.Long parseTimeString​(java.lang.String timeString)
      Parse a date/time string and return its equivalent in milliseconds (using same time coordinate system as System.currentTimeMillis()).
      static java.lang.String removeWhiteSpace​(java.lang.String inputString)
      Eliminates all white space in a specified string.
      static java.lang.String stripLeadingPeriod​(java.lang.String s)
      Strips leading period from a string (Example: input -> ".ext", output -> "ext")
      static java.lang.CharSequence trimCharSequence​(java.lang.CharSequence charSequence)
      Returns a sub sequence of the specified CharSequence, with leading and trailing whitespace omitted.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • WWUtil

        public WWUtil()
    • Method Detail

      • convertStringToInteger

        public static java.lang.Integer convertStringToInteger​(java.lang.String s)
        Converts a specified string to an integer value. Returns null if the string cannot be converted.
        Parameters:
        s - the string to convert.
        Returns:
        integer value of the string, or null if the string cannot be converted.
        Throws:
        java.lang.IllegalArgumentException - if the string is null.
      • convertStringToDouble

        public static java.lang.Double convertStringToDouble​(java.lang.String s)
        Converts a specified string to a floating point value. Returns null if the string cannot be converted.
        Parameters:
        s - the string to convert.
        Returns:
        floating point value of the string, or null if the string cannot be converted.
        Throws:
        java.lang.IllegalArgumentException - if the string is null.
      • convertStringToLong

        public static java.lang.Long convertStringToLong​(java.lang.String s)
        Converts a specified string to a long integer value. Returns null if the string cannot be converted.
        Parameters:
        s - the string to convert.
        Returns:
        long integer value of the string, or null if the string cannot be converted.
        Throws:
        java.lang.IllegalArgumentException - if the string is null.
      • convertStringToBoolean

        public static java.lang.Boolean convertStringToBoolean​(java.lang.String s)
        Converts a specified string to a boolean value. Returns null if the string cannot be converted.
        Parameters:
        s - the string to convert.
        Returns:
        boolean value of the string, or null if the string cannot be converted.
        Throws:
        java.lang.IllegalArgumentException - if the string is null.
      • convertNumericStringToBoolean

        public static java.lang.Boolean convertNumericStringToBoolean​(java.lang.String s)
        Converts a specified string to a boolean value. Returns null if the string cannot be converted.
        Parameters:
        s - the string to convert.
        Returns:
        boolean value of the string, or null if the string cannot be converted.
        Throws:
        java.lang.IllegalArgumentException - if the string is null.
      • makeInteger

        public static java.lang.Integer makeInteger​(java.lang.String s)
        Parses a string to an integer value if the string can be parsed as a integer. Does not log a message if the string can not be parsed as an integer.
        Parameters:
        s - the string to parse.
        Returns:
        the integer value parsed from the string, or null if the string cannot be parsed as an integer.
      • makeLong

        public static java.lang.Long makeLong​(java.lang.String s)
        Parses a string to a long value if the string can be parsed as a long. Does not log a message if the string can not be parsed as a long.
        Parameters:
        s - the string to parse.
        Returns:
        the long value parsed from the string, or null if the string cannot be parsed as a long.
      • makeDoubleForLocale

        public static java.lang.Double makeDoubleForLocale​(java.lang.String s)
        Parses a string to a double value using the current locale if the string can be parsed as a double. Does not log a message if the string can not be parsed as a double.
        Parameters:
        s - the string to parse.
        Returns:
        the double value parsed from the string, or null if the string cannot be parsed as a double.
      • makeDouble

        public static java.lang.Double makeDouble​(java.lang.String s)
        Parses a string to a double value if the string can be parsed as a double. Does not log a message if the string can not be parsed as a double.
        Parameters:
        s - the string to parse.
        Returns:
        the double value parsed from the string, or null if the string cannot be parsed as a double.
      • trimCharSequence

        public static java.lang.CharSequence trimCharSequence​(java.lang.CharSequence charSequence)
        Returns a sub sequence of the specified CharSequence, with leading and trailing whitespace omitted. If the CharSequence has length zero, this returns a reference to the CharSequence. If the CharSequence represents and empty character sequence, this returns an empty CharSequence.
        Parameters:
        charSequence - the CharSequence to trim.
        Returns:
        a sub sequence with leading and trailing whitespace omitted.
        Throws:
        java.lang.IllegalArgumentException - if the charSequence is null.
      • alignComponent

        public static void alignComponent​(java.awt.Component parent,
                                          java.awt.Component child,
                                          java.lang.String alignment)
      • makeRandomColor

        public static java.awt.Color makeRandomColor​(java.awt.Color color)
        Generates a random Color by scaling each of the red, green and blue components of a specified color with independent random numbers. The alpha component is not scaled and is copied to the new color. The returned color can be any value between white (0x000000aa) and black (0xffffffaa).

        Unless there's a reason to use a specific input color, the best color to use is white.

        Parameters:
        color - the color to generate a random color from. If null, the color white (0x000000aa) is used.
        Returns:
        a new color with random red, green and blue components.
      • makeRandomColor

        public static java.awt.Color makeRandomColor​(java.awt.Color color,
                                                     java.awt.Color darkestColor,
                                                     int maxAttempts)
        Generates a random Color by scaling each of the red, green and blue components of a specified color with independent random numbers. The alpha component is not scaled and is copied to the new color. The returned color can be any value between white (0x000000aa) and a specified darkest color.

        Unless there's a reason to use a specific input color, the best color to use is white.

        Parameters:
        color - the color to generate a random color from. If null, the color white (0x000000aa) is used.
        darkestColor - the darkest color allowed. If any of the generated color's components are less than the corresponding component in this color, new colors are generated until one satisfies this requirement, up to the specified maximum number of attempts.
        maxAttempts - the maximum number of attempts to create a color lighter than the specified darkestColor. If this limit is reached, the last color generated is returned.
        Returns:
        a new color with random red, green and blue components.
      • makeColorBrighter

        public static java.awt.Color makeColorBrighter​(java.awt.Color color)
      • makeColorDarker

        public static java.awt.Color makeColorDarker​(java.awt.Color color)
      • computeContrastingColor

        public static java.awt.Color computeContrastingColor​(java.awt.Color color)
      • interpolateColor

        public static java.awt.Color interpolateColor​(double amount,
                                                      java.awt.Color color1,
                                                      java.awt.Color color2)
        Returns the component-wise linear interpolation of color1 and color2. Each of the RGBA components in the colors are interpolated according to the function: (1 - amount) * c1 + amount * c2, where c1 and c2 are components of color1 and color2, respectively. The interpolation factor amount defines the weight given to each value, and is clamped to the range [0, 1].
        Parameters:
        amount - the interpolation factor.
        color1 - the first color.
        color2 - the second color.
        Returns:
        this returns the linear interpolation of color1 and color2 if <amount> is between 0 and 1, a color equivalent to color1 if amount is 0 or less, or a color equivalent to color2 if amount is 1 or more.
        Throws:
        java.lang.IllegalArgumentException - if either color1 or color2 are null.
      • encodeColorRGBA

        public static java.lang.String encodeColorRGBA​(java.awt.Color color)
        Creates a hexadecimal string representation of a Color in the form 0xrrggbbaa.
        Parameters:
        color - Color to encode.
        Returns:
        String encoding of the specified color.
        Throws:
        java.lang.IllegalArgumentException - If the specified color is null.
        See Also:
        decodeColorRGBA(String), encodeColorABGR(java.awt.Color)
      • encodeColorABGR

        public static java.lang.String encodeColorABGR​(java.awt.Color color)
        Creates a hexadecimal string representation of a Color in the form 0xaabbggrr.
        Parameters:
        color - Color to encode.
        Returns:
        String encoding of the specified color.
        Throws:
        java.lang.IllegalArgumentException - If the specified color is null.
        See Also:
        decodeColorABGR(String), encodeColorRGBA(java.awt.Color)
      • decodeColorRGBA

        public static java.awt.Color decodeColorRGBA​(java.lang.String encodedString)
        Decodes a hexadecimal string in the form rrggbbaa, rrggbbaa or #rrggbbaa to a color.
        Parameters:
        encodedString - String to decode.
        Returns:
        the decoded color, or null if the string cannot be decoded.
        Throws:
        java.lang.IllegalArgumentException - If the specified string is null.
        See Also:
        (String), encodeColorRGBA(java.awt.Color)
      • decodeColorABGR

        public static java.awt.Color decodeColorABGR​(java.lang.String encodedString)
        Decodes a hexadecimal string in the form aabbggrr, 0xaabbggrr or #aabbggrr to a color.
        Parameters:
        encodedString - String to decode.
        Returns:
        the decoded color, or null if the string cannot be decoded.
        Throws:
        java.lang.IllegalArgumentException - If the specified string is null.
        See Also:
        decodeColorRGBA(String), encodeColorABGR(java.awt.Color)
      • isEmpty

        public static boolean isEmpty​(java.lang.Object s)
        Determine whether an object reference is null or a reference to an empty string.
        Parameters:
        s - the reference to examine.
        Returns:
        true if the reference is null or is a zero-length String.
      • isEmpty

        public static boolean isEmpty​(java.util.List<?> list)
        Determine whether an List is null or empty.
        Parameters:
        list - the list to examine.
        Returns:
        true if the list is null or zero-length.
      • defaultMinMix

        public static double[] defaultMinMix()
        Creates a two-element array of default min and max values, typically used to initialize extreme values searches.
        Returns:
        a two-element array of extreme values. Entry 0 is the maximum double value; entry 1 is the negative of the maximum double value;
      • convertUTMCoordinatesToGeographic

        public static void convertUTMCoordinatesToGeographic​(int zone,
                                                             java.lang.String hemisphere,
                                                             java.nio.DoubleBuffer buffer)
        Converts the specified buffer of UTM tuples to geographic coordinates, according to the specified UTM zone and hemisphere. The buffer must be organized as pairs of tightly packed UTM tuples in the order (easting, northing). Each UTM tuple is replaced with its corresponding geographic location in the order (longitude, latitude). Geographic locations are expressed in degrees. Tuples are replaced starting at the buffer's position and ending at its limit.
        Parameters:
        zone - the UTM zone.
        hemisphere - the UTM hemisphere, either AVKey.NORTH or AVKey.SOUTH.
        buffer - the buffer of UTM tuples to convert.
        Throws:
        java.lang.IllegalArgumentException - if zone is outside the range 1-60, if hemisphere is null, if hemisphere is not one of AVKey.NORTH or AVKey.SOUTH, if buffer is null, or if the number of remaining elements in buffer is not a multiple of two.
      • normalizeGeographicCoordinates

        public static void normalizeGeographicCoordinates​(java.nio.DoubleBuffer buffer)
        Normalizes the specified buffer of geographic tuples. The buffer must be organized as pairs of tightly packed geographic tuples in the order (longitude, latitude). Each geographic tuple is normalized to the range +-90 latitude and +-180 longitude and replaced with its normalized values. Geographic locations are expressed in degrees. Tuples are replaced starting at the buffer's position and ending at its limit.
        Parameters:
        buffer - the buffer of geographic tuples to convert.
        Throws:
        java.lang.IllegalArgumentException - if buffer is null, or if the number of remaining elements in buffer is not a multiple of two.
      • invokePropertyMethod

        public static java.lang.Object invokePropertyMethod​(java.lang.Object parent,
                                                            java.lang.String propertyName,
                                                            java.lang.String propertyValue)
                                                     throws java.lang.NoSuchMethodException,
                                                            java.lang.reflect.InvocationTargetException,
                                                            java.lang.IllegalAccessException
        Uses reflection to invoke a set method for a specified property. The specified class must have a method named "set" + propertyName, with either a single String argument, a single double argument, a single int argument or a single long argument. If it does, the method is called with the specified property value argument.
        Parameters:
        parent - the object on which to set the property.
        propertyName - the name of the property.
        propertyValue - the value to give the property. Specify double, int and long values in a String.
        Returns:
        the return value of the set method, or null if the method has no return value.
        Throws:
        java.lang.IllegalArgumentException - if the parent object or the property name is null.
        java.lang.NoSuchMethodException - if no set method exists for the property name.
        java.lang.reflect.InvocationTargetException - if the set method throws an exception.
        java.lang.IllegalAccessException - if the set method is inaccessible due to access control.
      • copyValues

        public static void copyValues​(AVList srcList,
                                      AVList destList,
                                      java.lang.String[] keys,
                                      boolean forceOverwrite)
        Copies only values of the specified keysfrom srcList to another destList. The forceOverwrite controls what to do if the destination list already contains values for specified keys. If forceOverwrite is set to true, the existing value wills be overwritten.
        Parameters:
        srcList - The source list. May not be null.
        destList - The destination list. May not be null.
        forceOverwrite - Allow overwrite existing values in the destination list
        keys - Array of keys
      • removeWhiteSpace

        public static java.lang.String removeWhiteSpace​(java.lang.String inputString)
        Eliminates all white space in a specified string. (Applies the regular expression "\\s+".)
        Parameters:
        inputString - the string to remove white space from.
        Returns:
        the string with white space eliminated, or null if the input string is null.
      • extractExceptionReason

        public static java.lang.String extractExceptionReason​(java.lang.Throwable t)
        Extracts an error message from the exception object
        Parameters:
        t - Exception instance
        Returns:
        A string that contains an error message
      • stripLeadingPeriod

        public static java.lang.String stripLeadingPeriod​(java.lang.String s)
        Strips leading period from a string (Example: input -> ".ext", output -> "ext")
        Parameters:
        s - String to test, must not be null
        Returns:
        String without leading period
      • isKMLTimeShift

        protected static boolean isKMLTimeShift​(java.lang.String timeString)
      • parseTimeString

        public static java.lang.Long parseTimeString​(java.lang.String timeString)
        Parse a date/time string and return its equivalent in milliseconds (using same time coordinate system as System.currentTimeMillis()). The following formats are recognized and conform to those defined in KML version 2.2: "1997", "1997-07", "1997-07-16", "1997-07-16T07:30:15Z", "1997-07-16T07:30:15+03:00" and "1997-07-16T07:30:15+0300".
        Parameters:
        timeString - the date/time string to parse.
        Returns:
        the number of milliseconds since 00:00:00 1970 indicated by the date/time string, or null if the input string is null or the string is not a recognizable format.
      • compareVersion

        public static int compareVersion​(java.lang.String va,
                                         java.lang.String vb)
        Compares two version strings, e.g., 1.3.0, and returns 0 if they match, -1 if the first string is less than the second, and 1 if the first string is greater than the second. The strings can be arbitrary length but the components must be separated by ".". A missing component maps to 0, e.g. 1.3 will match 1.3.0.
        Parameters:
        va - the first version string
        vb - the second version string
        Returns:
        -1 if the first string is less than the second, 0 if the strings match, 1 if the first string is greater than the second string.
      • generateTriStripNormals

        public static void generateTriStripNormals​(java.nio.FloatBuffer vertices,
                                                   java.nio.IntBuffer indices,
                                                   java.nio.FloatBuffer normals)
        Generates average normal vectors for the vertices of a triangle strip.
        Parameters:
        vertices - the triangle strip vertices.
        indices - the indices identifying the triangle strip from the specified vertices.
        normals - a buffer to accept the output normals. The buffer must be allocated and all its values must be initialized to 0. The buffer's size limit must be at least as large as that of the specified vertex buffer.
        Throws:
        java.lang.IllegalArgumentException - if any of the specified buffers are null or the limit of the normal buffer is less than that of the vertex buffer.