Class JsonIO

java.lang.Object
me.wobblyyyy.pathfinder.json.JsonIO

public class JsonIO
extends java.lang.Object
Input/output class for use in loading and saving JSON information to the host device's local file system. In cases where there's a very large path or very dense trajectory that would take up a lot of time to generate on the fly, saving and loading that path or trajectory to the host's filesystem can decrease the amount of time it takes to deal with that path.
Since:
0.5.0
Author:
Colin Robertson
  • Field Summary

    Fields
    Modifier and Type Field Description
    private static com.google.gson.Gson gson
    GSON instance used for doing lovely GSON things.
    private static java.lang.reflect.Type POINT_LIST_TYPE
    Type used for point lists.
    private static java.lang.reflect.Type SEGMENT_LIST_TYPE
    Type used for segment lists.
  • Constructor Summary

    Constructors
    Modifier Constructor Description
    private JsonIO()
    Empty private constructor to ensure that utility class cannot be instantiated by a user.
  • Method Summary

    Modifier and Type Method Description
    private static void assureFileExists​(java.lang.String pathToFile)
    Ensure that a file exists, and if it doesn't, create it.
    private static java.io.FileReader getFileReader​(java.lang.String path)
    Get a file reader for the specified path.
    private static java.io.FileWriter getFileWriter​(java.lang.String path)
    Get a file writer for the specified path.
    static java.util.ArrayList<HeadingPoint> loadPoints​(java.lang.String path)
    Read an ArrayList of HeadingPoints from a JSON file.
    static java.util.ArrayList<HeadingPoint> pointsFromJson​(java.lang.String json)
    Get an ArrayList of points from a JSON string.
    static java.lang.String pointsToJson​(java.util.ArrayList<HeadingPoint> points)
    Convert an ArrayList of points to a JSON string.
    static void savePoints​(java.lang.String path, java.util.ArrayList<HeadingPoint> pointList)
    Save an ArrayList of HeadingPoints to a JSON file.
    static java.util.ArrayList<HeadingPoint> toArrayList​(me.wobblyyyy.edt.Arrayable<HeadingPoint> points)
    Convert an Arrayable to an ArrayList of heading points.
    static me.wobblyyyy.edt.DynamicArray<HeadingPoint> toDynamicArray​(java.util.ArrayList<HeadingPoint> points)
    Convert an ArrayList into a DynamicArray.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • gson

      private static final com.google.gson.Gson gson
      GSON instance used for doing lovely GSON things.
    • POINT_LIST_TYPE

      private static final java.lang.reflect.Type POINT_LIST_TYPE
      Type used for point lists.
    • SEGMENT_LIST_TYPE

      private static final java.lang.reflect.Type SEGMENT_LIST_TYPE
      Type used for segment lists.
  • Constructor Details

    • JsonIO

      private JsonIO()
      Empty private constructor to ensure that utility class cannot be instantiated by a user.
  • Method Details

    • assureFileExists

      private static void assureFileExists​(java.lang.String pathToFile)
      Ensure that a file exists, and if it doesn't, create it.
      Parameters:
      pathToFile - the path of the file that will be assured.
    • getFileWriter

      private static java.io.FileWriter getFileWriter​(java.lang.String path)
      Get a file writer for the specified path.
      Parameters:
      path - the path that the writer will write to.
      Returns:
      a file writer from the path.
    • getFileReader

      private static java.io.FileReader getFileReader​(java.lang.String path)
      Get a file reader for the specified path.
      Parameters:
      path - the path that the reader will read from.
      Returns:
      a file reader from the path.
    • pointsToJson

      public static java.lang.String pointsToJson​(java.util.ArrayList<HeadingPoint> points)
      Convert an ArrayList of points to a JSON string.
      Parameters:
      points - the points to parse.
      Returns:
      a JSON string, representing all of the points.
    • pointsFromJson

      public static java.util.ArrayList<HeadingPoint> pointsFromJson​(java.lang.String json)
      Get an ArrayList of points from a JSON string.
      Parameters:
      json - the string to parse.
      Returns:
      the points from the string.
    • savePoints

      public static void savePoints​(java.lang.String path, java.util.ArrayList<HeadingPoint> pointList)
      Save an ArrayList of HeadingPoints to a JSON file.
      Parameters:
      path - the path of the JSON file to save.
      pointList - the ArrayList of points to save.
    • loadPoints

      public static java.util.ArrayList<HeadingPoint> loadPoints​(java.lang.String path)
      Read an ArrayList of HeadingPoints from a JSON file.
      Parameters:
      path - the path to the JSON file that will be read from.
      Returns:
      the generated ArrayList.
    • toArrayList

      public static java.util.ArrayList<HeadingPoint> toArrayList​(me.wobblyyyy.edt.Arrayable<HeadingPoint> points)
      Convert an Arrayable to an ArrayList of heading points.
      Parameters:
      points - the points to convert to an ArrayList.
      Returns:
      the converted ArrayList.
    • toDynamicArray

      public static me.wobblyyyy.edt.DynamicArray<HeadingPoint> toDynamicArray​(java.util.ArrayList<HeadingPoint> points)
      Convert an ArrayList into a DynamicArray.
      Parameters:
      points - the points to convert.
      Returns:
      the converted points.