Class PartCollection

  • All Implemented Interfaces:
    Iterable<Part>, Collection<Part>, List<Part>

    public final class PartCollection
    extends AbstractList<Part>
    Represents a mutable collection of parts for creating a Multipart geometry from a MultipartBuilder. Parts can be added to, inserted into, and removed from PartCollections in order to define or change the complete shape of a Multipart (for example a Polygon or Polyline).

    The SpatialReference of any Parts added to a PartCollection must match that of the PartCollection, or be null (in which case the geometries in that Part are assumed to have the same SpatialReference as the PartCollection).

    Since:
    100.0.0
    See Also:
    PolylineBuilder, PolygonBuilder, Polyline, Polygon
    • Constructor Detail

      • PartCollection

        public PartCollection​(SpatialReference spatialReference)
        Creates a new empty PartCollection with the given SpatialReference. SpatialReference cannot be changed after instantiation.

        Parts can be instantiated directly, or by using the MultipartBuilder.addPart() method or one of its overloads.

        Parameters:
        spatialReference - the SpatialReference of the new PartCollection. May be null.
        Since:
        100.0.0
      • PartCollection

        public PartCollection​(Part part)
        Creates a new PartCollection and adds the given Part to the collection. The SpatialReference of the new PartCollection will match that of the given Part, and cannot be changed after instantiation.
        Parameters:
        part - the Part to add to the new PartCollection
        Throws:
        NullPointerException - if part is null
        Since:
        100.0.0
      • PartCollection

        public PartCollection​(Part part,
                              SpatialReference spatialReference)
        Creates a new PartCollection with the given SpatialReference, and adds the given Part to the collection. The SpatialReference cannot be changed after instantiation.

        This overload can be used to create a PartCollection with a specific SpatialReference from a Part that has a null SpatialReference (the points are assigned the given SpatialReference-they are not projected).

        Parameters:
        part - the part to add to the new PartCollection
        spatialReference - the SpatialReference of the new PartCollection. May be null.
        Throws:
        ArcGISRuntimeException - if the SpatialReference of part does not match the match the spatialReference argument.
        NullPointerException - if part is null
        Since:
        100.0.0
      • PartCollection

        public PartCollection​(ImmutablePart part)
        Creates a new PartCollection with one Part, and copies the geometries from the given ImmutablePart into the Part. The SpatialReference of the new PartCollection will match that of the given ImmutablePart, and cannot be changed after instantiation.
        Parameters:
        part - the ImmutablePart used to populate the Part in the new PartCollection
        Since:
        100.0.0
      • PartCollection

        public PartCollection​(ImmutablePart part,
                              SpatialReference spatialReference)
        Creates a new PartCollection with one Part and with the given SpatialReference, and copies the geometries from the given ImmutablePart into the Part. The SpatialReference cannot be changed after instantiation.

        This overload can be used to create a PartCollection with a specific SpatialReference by using an ImmutablePart from an existing Multipart geometry that has a null SpatialReference, in which case the input geometries are simply assigned the given SpatialReference.

        Parameters:
        part - the ImmutablePart used to populate the Part in the new PartCollection
        spatialReference - the SpatialReference of the new PartCollection. May be null.
        Since:
        100.0.0
      • PartCollection

        public PartCollection​(PointCollection partAsPoints)
        Creates a new PartCollection with one Part, and copies the Points from the given PointCollection into the Part. The SpatialReference of the new PartCollection will match that of the given PointCollection, and cannot be changed after instantiation.
        Parameters:
        partAsPoints - the PointCollection used to populate the Part in the new PartCollection
        Since:
        100.0.0
      • PartCollection

        public PartCollection​(PointCollection partAsPoints,
                              SpatialReference spatialReference)
        Creates a new PartCollection with one Part and with the given SpatialReference, and copies the Points from the given PointCollection into the Part. The SpatialReference of the new PartCollection cannot be changed after instantiation.

        This overload can be used to create a PartCollection with a specific SpatialReference from a PointCollection that has a null SpatialReference, in which case the input geometries are simply assigned the given SpatialReference.

        Parameters:
        partAsPoints - the PointCollection used to populate the Part in the new PartCollection
        spatialReference - the SpatialReference of the new PartCollection. May be null.
        Since:
        100.0.0
      • PartCollection

        public PartCollection​(ImmutablePointCollection partAsPoints)
        Creates a new PartCollection with one Part, and copies the geometries from the given ImmutablePointCollection into the Part. The SpatialReference of the new PartCollection will match that of the given ImmutablePointCollection, and cannot be changed after instantiation.
        Parameters:
        partAsPoints - the ImmutablePointCollection used to populate the Part in the new PartCollection
        Since:
        100.0.0
      • PartCollection

        public PartCollection​(ImmutablePointCollection partAsPoints,
                              SpatialReference spatialReference)
        Creates a new PartCollection with one Part and the given SpatialReference, and copies the geometries from the given ImmutablePointCollection into the Part. The SpatialReference of the new PartCollection cannot be changed after instantiation.

        This overload can be used to create a PartCollection with a specific SpatialReference from an ImmutablePointCollection that has a null SpatialReference, in which case the input geometries are simply assigned the given SpatialReference.

        Parameters:
        partAsPoints - the ImmutablePointCollection used to populate the Part in the new PartCollection
        spatialReference - the SpatialReference of the new PartCollection. May be null.
        Since:
        100.0.0
      • PartCollection

        public PartCollection​(PartCollection parts)
        Creates a new PartCollection containing the Parts in the given PartCollection. The SpatialReference of the new PartCollection will match that of the given PartCollection, and cannot be changed after instantiation.
        Parameters:
        parts - the collection of Parts to add to the new PartCollection
        Throws:
        NullPointerException - if parts is null
        Since:
        100.0.0
      • PartCollection

        public PartCollection​(PartCollection parts,
                              SpatialReference spatialReference)
        Creates a new PartCollection with the given SpatialReference, containing the Parts in the given PartCollection. This overload can be used to create a PartCollection with a specific SpatialReference from a PartCollection that has a null SpatialReference, in which case the input geometries are simply assigned the given SpatialReference.
        Parameters:
        parts - the collection of Parts to add to the new PartCollection
        spatialReference - the SpatialReference of the new PartCollection. May be null.
        Throws:
        NullPointerException - if parts is null
        Since:
        100.0.0
      • PartCollection

        public PartCollection​(ImmutablePartCollection parts)
        Creates a new PartCollection and copies the ImmutableParts in the given ImmutablePartCollection into new Parts in the new PartCollection. The SpatialReference of the new PartCollection will match that of the given ImmutablePartCollection, and cannot be changed after instantiation.
        Parameters:
        parts - the collection of ImmutableParts used to populate new Parts in the new PartCollection
        Since:
        100.0.0
      • PartCollection

        public PartCollection​(ImmutablePartCollection parts,
                              SpatialReference spatialReference)
        Creates a new PartCollection with the given SpatialReference, and copies the ImmutableParts in the given ImmutablePartCollection into new Parts in the new PartCollection.

        This overload can be used to create a PartCollection with a specific SpatialReference from an ImmutablePartCollection that has a null SpatialReference, in which case the input geometries are simply assigned the given SpatialReference.

        Parameters:
        parts - the collection of ImmutableParts used to populate new Parts in the new PartCollection
        spatialReference - the SpatialReference of the new PartCollection. May be null.
        Since:
        100.0.0
    • Method Detail

      • getSpatialReference

        public SpatialReference getSpatialReference()
        Gets the SpatialReference of the geometries in this PartCollection. The SpatialReference defines how coordinates correspond to locations in the real world. This is set during instantiation and cannot be changed. May be null.
        Returns:
        the SpatialReference of the geometries in this PartCollection
        Since:
        100.0.0
      • get

        public Part get​(int index)
        Gets the Part at the given index position in this PartCollection. Use this to access the individual parts that compose a MultipartBuilders current state. The part is returned by reference, therefore changes made to the part affect the builder.
        Specified by:
        get in interface List<Part>
        Specified by:
        get in class AbstractList<Part>
        Parameters:
        index - the index of the Part to return
        Returns:
        the Part at the given index
        Throws:
        IndexOutOfBoundsException - if index < 0 || index >= size()
        Since:
        100.0.0
      • getPartsAsPoints

        public Iterable<Point> getPartsAsPoints()
        Returns a copy of an iterable containing all the Points in all of the parts of this PartCollection, ordered continuously from the first to last part in this collection. If the PartCollection isEmpty(), this method returns an empty iterable.

        The points represent the ends of the Segments in all of the Parts in this collection (all the vertices in the shape currently under construction in the MultipartBuilder). Where two adjacent segments share a start and end location (there is no gap between the segments), this is represented by a single Point.

        Returns:
        an iterable set of all the Points in all the parts of this PartCollection
        Since:
        100.0.0
        See Also:
        Part.getPoints()
      • set

        public Part set​(int index,
                        Part part)
        Replaces the Part at the given index position with the given Part. The Part is set by reference-changes made to the added Part are reflected immediately in the PartCollection.

        Use this method to change a Part of a PartCollection-for example, to replace one ring in a Polygon with a different existing ring.

        Specified by:
        set in interface List<Part>
        Overrides:
        set in class AbstractList<Part>
        Parameters:
        index - the index of the Part to replace
        part - the Part to set into the PartCollection
        Throws:
        IndexOutOfBoundsException - if index < 0 || index >= size()
        NullPointerException - if part is null
        ArcGISRuntimeException - if the part has a SpatialReference that does not match that of this PartCollection. The SpatialReference of the part may however be null.
        Since:
        100.0.0
        See Also:
        add(int, Part)
      • add

        public boolean add​(Part part)
        Appends the given Part to the end of this PartCollection. The Part is added by reference-changes made to the added Part are reflected immediately in the PartCollection.

        Alternatively, use the addPart convenience methods directly on MultipartBuilder.

        Specified by:
        add in interface Collection<Part>
        Specified by:
        add in interface List<Part>
        Overrides:
        add in class AbstractList<Part>
        Parameters:
        part - the Part to add to the PartCollection
        Returns:
        always true
        Throws:
        NullPointerException - if part is null
        ArcGISRuntimeException - if the part has a SpatialReference that does not match that of this PartCollection. The SpatialReference of part may however be null.
        Since:
        100.0.0
        See Also:
        add(int, Part), MultipartBuilder.addPart(Part)
      • add

        public void add​(int index,
                        Part part)
        Inserts the given Part at the given index position in this PartCollection. The index positions of all existing Parts at that index or greater increase by one.

        The Part is added by reference-changes made to the inserted Part are reflected immediately in the PartCollection.

        Specified by:
        add in interface List<Part>
        Overrides:
        add in class AbstractList<Part>
        Parameters:
        index - the index position at which to add the Part
        part - the Part to insert into the PartCollection
        Throws:
        IndexOutOfBoundsException - if index < 0 || index > size()
        NullPointerException - if part is null
        See Also:
        MultipartBuilder.addPart(Part)
      • add

        public void add​(int index,
                        PointCollection pointCollection)
        Inserts a new Part at the given index position in this PartCollection, and copies each Point from the given PointCollection into the added Part. The index positions of all existing Parts at that index or greater increase by one.
        Parameters:
        index - the index position at which to insert the new Part
        pointCollection - the collection of points to copy to the new Part in the PartCollection
        Throws:
        IndexOutOfBoundsException - if index < 0 || index > size()
        NullPointerException - if pointCollection is null
        Since:
        100.0.0
      • remove

        public Part remove​(int index)
        Removes the Part at the specified index position from this PartCollection.

        Note if calling this method on a PartCollection from a Polygon, removing a part from a PolygonBuilder can affect which parts represent outer rings and which represent inner rings.

        Specified by:
        remove in interface List<Part>
        Overrides:
        remove in class AbstractList<Part>
        Parameters:
        index - the index of the Part to remove
        Returns:
        the removed Part
        Throws:
        IndexOutOfBoundsException - if index < 0 || index >= size()
        Since:
        100.0.0
        See Also:
        size(), clear()
      • clear

        public void clear()
        Removes all Parts from the PartCollection. Using this method is more efficient than removing all Parts individually. The state of the removed Parts is not affected.
        Specified by:
        clear in interface Collection<Part>
        Specified by:
        clear in interface List<Part>
        Overrides:
        clear in class AbstractList<Part>
        Since:
        100.0.0