Class Point

  • All Implemented Interfaces:
    java.io.Serializable

    public final class Point
    extends java.lang.Object
    implements java.io.Serializable
    An immutable class representing the location of an object.

    This class is immutable (unlike a Point), so that the translate(int, int) method returns a new object, rather than modifying the original (for instance).

    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int x
      The (integer) X-value of this point, representing a distance from the left of the parent object.
      static java.lang.String X_KEY
      Map key used to access the X-value.
      int y
      The (integer) Y-value of this point, representing a distance down from the top of the parent object.
      static java.lang.String Y_KEY
      Map key used to access the Y-value.
    • Constructor Summary

      Constructors 
      Constructor Description
      Point​(int xValue, int yValue)
      Construct a point given the X/Y coordinates.
      Point​(Dictionary<java.lang.String,​?> point)
      Construct a point from a dictionary containing the X- and Y-position values as entries.
      Point​(Sequence<?> point)
      Construct a point from a sequence of two number values for the X- and Y-positions respectively.
      Point​(Point point)
      A "copy" constructor to duplicate a point value.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Point decode​(java.lang.String value)
      Decode a string value (which could be a JSON-formatted string (map or list)) that contains the two values for a new point.
      boolean equals​(java.lang.Object object)  
      int hashCode()  
      java.lang.String toString()  
      Point translate​(int dx, int dy)
      Return a new Point object which represents this point moved to a new location, dx and dy away from the original.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • x

        public final int x
        The (integer) X-value of this point, representing a distance from the left of the parent object.
      • y

        public final int y
        The (integer) Y-value of this point, representing a distance down from the top of the parent object.
      • X_KEY

        public static final java.lang.String X_KEY
        Map key used to access the X-value.
        See Also:
        Constant Field Values
      • Y_KEY

        public static final java.lang.String Y_KEY
        Map key used to access the Y-value.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Point

        public Point​(int xValue,
                     int yValue)
        Construct a point given the X/Y coordinates.
        Parameters:
        xValue - The X-position for the point.
        yValue - The Y-position for the point.
      • Point

        public Point​(Point point)
        A "copy" constructor to duplicate a point value.
        Parameters:
        point - The other point to copy.
      • Point

        public Point​(Dictionary<java.lang.String,​?> point)
        Construct a point from a dictionary containing the X- and Y-position values as entries.
        Parameters:
        point - The source dictionary containing the values.
        Throws:
        java.lang.IllegalArgumentException - if the input is null.
        See Also:
        X_KEY, Y_KEY
      • Point

        public Point​(Sequence<?> point)
        Construct a point from a sequence of two number values for the X- and Y-positions respectively.
        Parameters:
        point - The source sequence containing the values (values must be Numbers).
        Throws:
        java.lang.IllegalArgumentException - if the input is null.
    • Method Detail

      • translate

        public Point translate​(int dx,
                               int dy)
        Return a new Point object which represents this point moved to a new location, dx and dy away from the original.
        Parameters:
        dx - The distance to move in the horizontal direction (positive or negative).
        dy - The distance to move in the vertical direction (positive moves downward on the screen, and negative to move upward).
        Returns:
        A new object represented the translated location.
      • equals

        public boolean equals​(java.lang.Object object)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • decode

        public static Point decode​(java.lang.String value)
        Decode a string value (which could be a JSON-formatted string (map or list)) that contains the two values for a new point.

        The format of a JSON map would be:

        { "x":nnn, "y":nnn }

        The format for a JSON list would be:

        [ x, y ]

        Or the string can simply be two numbers:

        x [,;] y
        Parameters:
        value - The string to be interpreted (must not be null).
        Returns:
        The new Point object if the string can be decoded successfully.
        Throws:
        java.lang.IllegalArgumentException - if the input is null or if the value could not be successfully decoded as a JSON map or list, or simply two values.
        See Also:
        Point(Dictionary), Point(Sequence), Point(int, int)