Class ExampleUtil


  • public class ExampleUtil
    extends java.lang.Object
    A collection of static utility methods used by the example programs.
    • Constructor Summary

      Constructors 
      Constructor Description
      ExampleUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double[] createRandomGridValues​(int width, int height, double min, double max, int numIterations, double smoothness)
      Creates a 2D grid of random values with an optional smoothing parameter.
      static void goTo​(WorldWindow wwd, Sector sector)
      Causes the View attached to the specified WorldWindow to animate to the specified sector.
      static double[] readCommaDelimitedNumbers​(java.lang.String path)
      Reads the file at the specified path as a list of floating point numbers encoded as comma delimited plain text,
      static java.io.File saveResourceToTempFile​(java.lang.String path, java.lang.String suffix)
      Saves the file at the specified path in a temporary directory and returns a File to the temporary location.
      protected static void scaleValues​(double[] values, int count, double minValue, double maxValue)  
      protected static void smoothBand​(double[] values, int start, int stride, int count, double smoothness)  
      protected static void smoothValues​(int width, int height, double[] values, double smoothness)  
      static java.io.File unzipAndSaveToTempFile​(java.lang.String path, java.lang.String suffix)
      Unzips the sole entry in the specified zip file, and saves it in a temporary directory, and returns a File to the temporary location.
      • Methods inherited from class java.lang.Object

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

      • ExampleUtil

        public ExampleUtil()
    • Method Detail

      • unzipAndSaveToTempFile

        public static java.io.File unzipAndSaveToTempFile​(java.lang.String path,
                                                          java.lang.String suffix)
        Unzips the sole entry in the specified zip file, and saves it in a temporary directory, and returns a File to the temporary location.
        Parameters:
        path - the path to the source file.
        suffix - the suffix to give the temp file.
        Returns:
        a File for the temp file.
        Throws:
        java.lang.IllegalArgumentException - if the path is null or empty.
      • saveResourceToTempFile

        public static java.io.File saveResourceToTempFile​(java.lang.String path,
                                                          java.lang.String suffix)
        Saves the file at the specified path in a temporary directory and returns a File to the temporary location. The path may be one of the following:
        • InputStream
        • URL
        • absolute URI
        • File
        • String containing a valid URL description or a file or resource name available on the classpath.
        Parameters:
        path - the path to the source file.
        suffix - the suffix to give the temp file.
        Returns:
        a File for the temp file.
        Throws:
        java.lang.IllegalArgumentException - if the path is null or empty.
      • goTo

        public static void goTo​(WorldWindow wwd,
                                Sector sector)
        Causes the View attached to the specified WorldWindow to animate to the specified sector. The View starts animating at its current location and stops when the sector fills the window.
        Parameters:
        wwd - the WorldWindow who's View animates.
        sector - the sector to go to.
        Throws:
        java.lang.IllegalArgumentException - if either the wwd or the sector are null.
      • readCommaDelimitedNumbers

        public static double[] readCommaDelimitedNumbers​(java.lang.String path)
        Reads the file at the specified path as a list of floating point numbers encoded as comma delimited plain text,
        Parameters:
        path - the path to the source file.
        Returns:
        an array of floating point numbers extracted from the file.
        Throws:
        java.lang.IllegalArgumentException - if the path is null or empty.
      • createRandomGridValues

        public static double[] createRandomGridValues​(int width,
                                                      int height,
                                                      double min,
                                                      double max,
                                                      int numIterations,
                                                      double smoothness)
        Creates a 2D grid of random values with an optional smoothing parameter. Random grid values are in the range from min to max, inclusive. Increasing the number of iterations results in a less uniform grid.
        Parameters:
        width - the grid width.
        height - the grid height.
        min - the minimum random value.
        max - the maximum random value.
        numIterations - the number of random iterations to perform, a larger number decreases grid uniformity.
        smoothness - the amount of smoothing to apply to the random values. 0 indicates no smoothing, while 1 indicates the most smoothing.
        Returns:
        an array containing width * height floating point numbers in the range from min to max.
      • scaleValues

        protected static void scaleValues​(double[] values,
                                          int count,
                                          double minValue,
                                          double maxValue)
      • smoothValues

        protected static void smoothValues​(int width,
                                           int height,
                                           double[] values,
                                           double smoothness)
      • smoothBand

        protected static void smoothBand​(double[] values,
                                         int start,
                                         int stride,
                                         int count,
                                         double smoothness)