NASA World Wind

gov.nasa.worldwind.util
Class WWUtil

java.lang.Object
  extended by gov.nasa.worldwind.util.WWUtil

public class WWUtil
extends Object


Constructor Summary
WWUtil()
           
 
Method Summary
static void alignComponent(Component parent, Component child, String alignment)
           
static int compareVersion(String va, 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 Color computeContrastingColor(Color color)
           
static Boolean convertNumericStringToBoolean(String s)
          Converts a specified string to a boolean value.
static Boolean convertStringToBoolean(String s)
          Converts a specified string to a boolean value.
static Double convertStringToDouble(String s)
          Converts a specified string to a floating point value.
static Integer convertStringToInteger(String s)
          Converts a specified string to an integer value.
static Long convertStringToLong(String s)
          Converts a specified string to a long integer value.
static void convertUTMCoordinatesToGeographic(int zone, String hemisphere, 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, String[] keys, boolean forceOverwrite)
          Copies only values of the specified keysfrom srcList to another destList.
static Color decodeColorABGR(String encodedString)
          Decodes a hexadecimal string in the form aabbggrr, 0xaabbggrr or #aabbggrr to a color.
static Color decodeColorRGBA(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 String encodeColorABGR(Color color)
          Creates a hexadecimal string representation of a Color in the form 0xaabbggrr.
static String encodeColorRGBA(Color color)
          Creates a hexadecimal string representation of a Color in the form 0xrrggbbaa.
static String extractExceptionReason(Throwable t)
          Extracts an error message from the exception object
static Color interpolateColor(double amount, Color color1, Color color2)
          Returns the component-wise linear interpolation of color1 and color2.
static Object invokePropertyMethod(Object parent, String propertyName, String propertyValue)
          Uses reflection to invoke a set method for a specified property.
static boolean isEmpty(List<?> list)
          Determine whether an List is null or empty.
static boolean isEmpty(Object s)
          Determine whether an object reference is null or a reference to an empty string.
protected static boolean isKMLTimeShift(String timeString)
           
static Color makeColorBrighter(Color color)
           
static Color makeColorDarker(Color color)
           
static Double makeDouble(String s)
          Parses a string to a double value if the string can be parsed as a double.
static Double makeDoubleForLocale(String s)
          Parses a string to a double value using the current locale if the string can be parsed as a double.
static Integer makeInteger(String s)
          Parses a string to an integer value if the string can be parsed as a integer.
static Long makeLong(String s)
          Parses a string to a long value if the string can be parsed as a long.
static Color makeRandomColor(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 Color makeRandomColor(Color color, 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(DoubleBuffer buffer)
          Normalizes the specified buffer of geographic tuples.
static Long parseTimeString(String timeString)
          Parse a date/time string and return its equivalent in milliseconds (using same time coordinate system as System.currentTimeMillis()).
static String removeWhiteSpace(String inputString)
          Eliminates all white space in a specified string.
static String stripLeadingPeriod(String s)
          Strips leading period from a string (Example: input -> ".ext", output -> "ext")
static CharSequence trimCharSequence(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, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WWUtil

public WWUtil()
Method Detail

alignComponent

public static void alignComponent(Component parent,
                                  Component child,
                                  String alignment)

compareVersion

public static int compareVersion(String va,
                                 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.

computeContrastingColor

public static Color computeContrastingColor(Color color)

convertNumericStringToBoolean

public static Boolean convertNumericStringToBoolean(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:
IllegalArgumentException - if the string is null.

convertStringToBoolean

public static Boolean convertStringToBoolean(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:
IllegalArgumentException - if the string is null.

convertStringToDouble

public static Double convertStringToDouble(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:
IllegalArgumentException - if the string is null.

convertStringToInteger

public static Integer convertStringToInteger(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:
IllegalArgumentException - if the string is null.

convertStringToLong

public static Long convertStringToLong(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:
IllegalArgumentException - if the string is null.

convertUTMCoordinatesToGeographic

public static void convertUTMCoordinatesToGeographic(int zone,
                                                     String hemisphere,
                                                     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:
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.

copyValues

public static void copyValues(AVList srcList,
                              AVList destList,
                              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

decodeColorABGR

public static Color decodeColorABGR(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:
IllegalArgumentException - If the specified string is null.
See Also:
decodeColorRGBA(String), encodeColorABGR(java.awt.Color)

decodeColorRGBA

public static Color decodeColorRGBA(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:
IllegalArgumentException - If the specified string is null.
See Also:
(String), encodeColorRGBA(java.awt.Color)

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;

encodeColorABGR

public static String encodeColorABGR(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:
IllegalArgumentException - If the specified color is null.
See Also:
decodeColorABGR(String), encodeColorRGBA(java.awt.Color)

encodeColorRGBA

public static String encodeColorRGBA(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:
IllegalArgumentException - If the specified color is null.
See Also:
decodeColorRGBA(String), encodeColorABGR(java.awt.Color)

extractExceptionReason

public static String extractExceptionReason(Throwable t)
Extracts an error message from the exception object

Parameters:
t - Exception instance
Returns:
A string that contains an error message

interpolateColor

public static Color interpolateColor(double amount,
                                     Color color1,
                                     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 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:
IllegalArgumentException - if either color1 or color2 are null.

invokePropertyMethod

public static Object invokePropertyMethod(Object parent,
                                          String propertyName,
                                          String propertyValue)
                                   throws NoSuchMethodException,
                                          InvocationTargetException,
                                          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:
IllegalArgumentException - if the parent object or the property name is null.
NoSuchMethodException - if no set method exists for the property name.
InvocationTargetException - if the set method throws an exception.
IllegalAccessException - if the set method is inaccessible due to access control.

isEmpty

public static boolean isEmpty(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.

isEmpty

public static boolean isEmpty(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.

isKMLTimeShift

protected static boolean isKMLTimeShift(String timeString)

makeColorBrighter

public static Color makeColorBrighter(Color color)

makeColorDarker

public static Color makeColorDarker(Color color)

makeDouble

public static Double makeDouble(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.

makeDoubleForLocale

public static Double makeDoubleForLocale(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.

makeInteger

public static Integer makeInteger(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 Long makeLong(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.

makeRandomColor

public static Color makeRandomColor(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 Color makeRandomColor(Color color,
                                    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.

normalizeGeographicCoordinates

public static void normalizeGeographicCoordinates(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:
IllegalArgumentException - if buffer is null, or if the number of remaining elements in buffer is not a multiple of two.

parseTimeString

public static Long parseTimeString(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.

removeWhiteSpace

public static String removeWhiteSpace(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.

stripLeadingPeriod

public static String stripLeadingPeriod(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

trimCharSequence

public static CharSequence trimCharSequence(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:
IllegalArgumentException - if the charSequence is null.

NASA World Wind