Class GMultiPoint

  • All Implemented Interfaces:
    java.lang.Cloneable, java.lang.Iterable<GPoint>
    Direct Known Subclasses:
    GPath, GPointArray, GPoly

    public abstract class GMultiPoint
    extends GFillableE
    implements java.lang.Iterable<GPoint>
    Represents an abstract array of (x, y) coordinates.
    Note: even though this class extends from GFillableE it's the subclass option to enforce the fill methods
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.concurrent.atomic.AtomicInteger modCount
      Modification counter.
      protected java.util.concurrent.locks.Lock mutex
      Mutex used to control modification access
      protected int size
      Current size of the GMultiPoint
      protected int[] xs
      X coordinates
      protected int[] ys
      Y coordinates
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void append​(int x, int y)
      Appends a new point to the path.
      void append​(GPoint p)
      Appends a new point to the path
      void appendNR​(int x, int y)
      Appends a new point to the path if and only if this point doesn't exist within the array.
      void clear()
      Clears the object
      void ensureCapacity​(int nElements)
      Allocates enough space for the specified number of elements
      boolean equals​(java.lang.Object obj)  
      GPoint getPointAt​(int idx)
      Retrieves a given GPoint from the path
      GPoint[] getPoints()
      Retrieves a COPY of the GPoint's in the path
      java.awt.geom.Area getShape()
      This method should return a Area that represents the GFillableE.
      int hashCode()  
      int indexOf​(int x, int y)
      Retrieves the index of the first occurrence of this point
      int indexOf​(int x, int y, int start)
      Retrieves the index of the first occurrence of this point after the starting point
      int indexOf​(GPoint point)
      Retrieves the index of the first occurrence of this point
      int indexOf​(GPoint point, int start)
      Retrieves the index of the first occurrence of this point after the starting point
      boolean isEmpty()
      Tells if the object doesn't contain any points
      java.util.Iterator<GPoint> iterator()  
      boolean remove​(int idx)
      Removes the element at the specified index
      boolean remove​(int x, int y)
      Removes the first occurrence of this point in the array
      boolean remove​(GPoint point)
      Removes the first occurrence of this point in the array
      int size()
      Retrieves the number of vertices
      void sortByX()
      Sorts all the points in this array by it's X value, and breaks ties with the Y value
      void traslate​(int x, int y)
      Traslates this element on X and Y
      void trimToSize()
      Removes all the extra space used by the object
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GMultiPoint

        protected GMultiPoint​(GMultiPoint e)
        Copy constructor
        Parameters:
        e - GMultiPoint to copy
        Throws:
        java.lang.IllegalArgumentException - if e is null
      • GMultiPoint

        protected GMultiPoint​(int initial)
        Parameters:
        initial - initial reserved size
        Throws:
        java.lang.NegativeArraySizeException - if the size is less than zero
      • GMultiPoint

        protected GMultiPoint​(int[] xs,
                              int[] ys)
        Parameters:
        xs - list of X coordinates
        ys - list of Y coordinates
        Throws:
        java.lang.IllegalArgumentException - if either array is null or if the array size doesn't match
    • Method Detail

      • size

        public int size()
        Retrieves the number of vertices
        Returns:
        number of vertices
      • indexOf

        public int indexOf​(GPoint point)
        Retrieves the index of the first occurrence of this point
        Parameters:
        point - point to check
        Returns:
        first index of the point or -1 if the point is not one of the paths 's vertices
        Throws:
        java.lang.IllegalArgumentException - if point is null
      • indexOf

        public int indexOf​(GPoint point,
                           int start)
        Retrieves the index of the first occurrence of this point after the starting point
        Parameters:
        point - point to check
        start - starting point of the search
        Returns:
        first index of the point or -1 if the point is not one of the paths 's vertices
        Throws:
        java.lang.IllegalArgumentException - if point is null
      • indexOf

        public int indexOf​(int x,
                           int y)
        Retrieves the index of the first occurrence of this point
        Parameters:
        x - y coordinate of the point
        y - y coordinate of the point
        Returns:
        first index of the point or -1 if the point is not one of the paths 's vertices
      • indexOf

        public int indexOf​(int x,
                           int y,
                           int start)
        Retrieves the index of the first occurrence of this point after the starting point
        Parameters:
        x - y coordinate of the point
        y - y coordinate of the point
        start - starting point of the search
        Returns:
        first index of the point or -1 if the point is not one of the paths 's vertices
      • clear

        public void clear()
        Clears the object
      • remove

        public boolean remove​(GPoint point)
        Removes the first occurrence of this point in the array
        Parameters:
        point - the point to check
        Returns:
        true if the point was contained and false otherwise
        Throws:
        java.lang.IllegalArgumentException - if point is null
      • remove

        public boolean remove​(int idx)
        Removes the element at the specified index
        Parameters:
        idx - Index of the element
        Returns:
        true if the point was contained and false otherwise
        Throws:
        java.lang.IndexOutOfBoundsException - if idx < 0 | idx >= size
      • remove

        public boolean remove​(int x,
                              int y)
        Removes the first occurrence of this point in the array
        Parameters:
        x - x coordinate of the point
        y - y coordinate of the point
        Returns:
        true if the point was contained and false otherwise
      • getPointAt

        public GPoint getPointAt​(int idx)
        Retrieves a given GPoint from the path
        Parameters:
        idx - the index of the point to retrieve
        Returns:
        GPoint at the specified position
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if (idx < 0 | idx > numberOfVertices)
      • getPoints

        public GPoint[] getPoints()
        Retrieves a COPY of the GPoint's in the path
        Returns:
        array of points
      • append

        public void append​(int x,
                           int y)
        Appends a new point to the path. If the path has run out of space then it will call ensureCapacity(size + 5)
        Parameters:
        x - X coordinate of the point
        y - Y coordinate of the point
        See Also:
        ensureCapacity(int)
      • appendNR

        public void appendNR​(int x,
                             int y)
        Appends a new point to the path if and only if this point doesn't exist within the array. If the path has run out of space then it will call ensureCapacity(size + 5)
        Parameters:
        x - X coordinate of the point
        y - Y coordinate of the point
        See Also:
        ensureCapacity(int)
      • append

        public void append​(GPoint p)
        Appends a new point to the path
        Parameters:
        p - the GPoint to append
        Throws:
        java.lang.IllegalArgumentException - if p is null
        See Also:
        ensureCapacity(int)
      • ensureCapacity

        public void ensureCapacity​(int nElements)
        Allocates enough space for the specified number of elements
        Parameters:
        nElements - the capacity the array must be able to hold
        Throws:
        InvalidArgumentException - if nElements is less than 0
      • isEmpty

        public boolean isEmpty()
        Tells if the object doesn't contain any points
        Returns:
        true if the object is empty and false otherwise
      • trimToSize

        public void trimToSize()
        Removes all the extra space used by the object
      • traslate

        public void traslate​(int x,
                             int y)
        Description copied from class: GraphicE
        Traslates this element on X and Y
        Specified by:
        traslate in class GraphicE
        Parameters:
        x - size in px of the horizontal translation
        y - size in px of the vertical translation
      • sortByX

        public void sortByX()
        Sorts all the points in this array by it's X value, and breaks ties with the Y value
      • iterator

        public java.util.Iterator<GPoint> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<GPoint>
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class GFillableE
      • getShape

        public java.awt.geom.Area getShape()
        Description copied from class: GFillableE
        This method should return a Area that represents the GFillableE. Since this is not always possible, and the implementation of Area isn't always easy, it should return null otherwise.
        In jDrawingLibs implementation we use the default shapes for this. Note that this method is only called to create clips for Graphic objects
        Specified by:
        getShape in class GFillableE
        Returns:
        Shape