Class PartCollection

java.lang.Object
java.util.AbstractCollection<Part>
java.util.AbstractList<Part>
com.esri.arcgisruntime.geometry.PartCollection
All Implemented Interfaces:
Iterable<Part>, Collection<Part>, List<Part>, SequencedCollection<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:
  • Constructor Details

    • 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 Details

    • 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:
    • size

      public int size()
      Returns the number of Parts in this PartCollection. Use this to find the maximum index for calling get(int).
      Specified by:
      size in interface Collection<Part>
      Specified by:
      size in interface List<Part>
      Specified by:
      size in class AbstractCollection<Part>
      Since:
      100.0.0
      See Also:
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<Part>
      Specified by:
      isEmpty in interface List<Part>
      Overrides:
      isEmpty in class AbstractCollection<Part>
    • indexOf

      public int indexOf(Object o)
      Specified by:
      indexOf in interface List<Part>
      Overrides:
      indexOf in class AbstractList<Part>
    • 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

      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

      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:
    • add

      public boolean add(PointCollection pointCollection)
      Appends a new Part to the end of the PartCollection, and copies each Point from the given PointCollection into the added Part.

      Alternatively, use the MultipartBuilder.addPart(PointCollection) convenience method directly on MultipartBuilder.

      Parameters:
      pointCollection - the collection of points to copy to the new Part in the PartCollection
      Returns:
      true, if successful
      Throws:
      NullPointerException - if pointCollection is null
      Since:
      100.0.0
      See Also:
    • 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:
    • 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