Class ResourceLocation

  • All Implemented Interfaces:
    PositionIfc, SpatialElementIfc, ObservableIfc, GetNameIfc, IdentityIfc

    public class ResourceLocation
    extends SpatialModelElement
    A ResourceLocation holds a set of resources that are assigned to this location in a spatial model. A ResourceLocation serves a "home base" for the SpatialResource. Clients can use the ResourceLocation to get idle resources that have been assigned to that location Since a ResourceLocation is a SpatialModelElement it is represented in a spatial model and can thus be visited by clients in search of resources that are assigned to the location. SpatialResource are assigned to the location, but that does not mean that the SpatialResource is currently physically located at the ResourceLocation.
    • Field Detail

      • myResources

        protected java.util.Set<SpatialResource> myResources
        Holds the resoures assigned to this location
    • Constructor Detail

      • ResourceLocation

        public ResourceLocation​(ModelElement parent)
        Creates a ResourceLocation with (0.0, 0.0) position. The SpatialModel2D of the parent is used as the SpatialModel2D. If the parent does not have a SpatialModel2D, then an IllegalArgumentException is thrown
        Parameters:
        parent -
      • ResourceLocation

        public ResourceLocation​(ModelElement parent,
                                java.lang.String name)
        Creates a ResourceLocation with (0.0, 0.0) position. The SpatialModel2D of the parent is used as the SpatialModel2D. If the parent does not have a SpatialModel2D, then an IllegalArgumentException is thrown
        Parameters:
        parent -
        name -
      • ResourceLocation

        public ResourceLocation​(ModelElement parent,
                                java.lang.String name,
                                double x,
                                double y)
        Creates a ResourceLocation with the given (x,y) position. The SpatialModel2D of the parent is used as the SpatialModel2D. If the parent does not have a SpatialModel2D, then an IllegalArgumentException is thrown
        Parameters:
        parent -
        name -
        x -
        y -
      • ResourceLocation

        public ResourceLocation​(ModelElement parent,
                                double x,
                                double y)
        Creates a ResourceLocation with the given (x,y) position. The SpatialModel2D of the parent is used as the SpatialModel2D. If the parent does not have a SpatialModel2D, then an IllegalArgumentException is thrown
        Parameters:
        parent -
        x -
        y -
      • ResourceLocation

        public ResourceLocation​(ModelElement parent,
                                java.lang.String name,
                                CoordinateIfc position)
        Creates a ResourceLocation with at the coordinates of the supplied position. The SpatialModel2D of the parent is used as the SpatialModel2D. If the parent does not have a SpatialModel2D, then an IllegalArgumentException is thrown
        Parameters:
        parent -
        name -
        position -
      • ResourceLocation

        public ResourceLocation​(ModelElement parent,
                                CoordinateIfc position)
        Creates a ResourceLocation with at the coordinates of the supplied position. The SpatialModel2D of the parent is used as the SpatialModel2D. If the parent does not have a SpatialModel2D, then an IllegalArgumentException is thrown
        Parameters:
        parent -
        position -
      • ResourceLocation

        public ResourceLocation​(ModelElement parent,
                                java.lang.String name,
                                SpatialModel spatialModel)
        Creates a ResourceLocation with the given parent and SpatialModel2D. The default position is (0.0, 0.0). If the SpatialModel2D is null, the SpatialModel2D of the parent is used as the SpatialModel2D. If the parent does not have a SpatialModel2D, then an IllegalArgumentException is thrown
        Parameters:
        parent -
        name -
        spatialModel -
      • ResourceLocation

        public ResourceLocation​(ModelElement parent,
                                SpatialModel spatialModel)
        Creates a ResourceLocation with the given parent and SpatialModel2D. The default position is (0.0, 0.0). If the SpatialModel2D is null, the SpatialModel2D of the parent is used as the SpatialModel2D. If the parent does not have a SpatialModel2D, then an IllegalArgumentException is thrown
        Parameters:
        parent -
        spatialModel -
      • ResourceLocation

        public ResourceLocation​(ModelElement parent,
                                java.lang.String name,
                                SpatialModel spatialModel,
                                double x,
                                double y,
                                double z)
        Creates a ResourceLocation with the given parent and SpatialModel2D. If the SpatialModel2D is null, the SpatialModel2D of the parent is used as the SpatialModel2D. If the parent does not have a SpatialModel2D, then an IllegalArgumentException is thrown
        Parameters:
        parent -
        name -
        spatialModel -
        x -
        y -
        z -
      • ResourceLocation

        public ResourceLocation​(ModelElement parent,
                                java.lang.String name,
                                SpatialModel spatialModel,
                                CoordinateIfc coordinate)
        Creates a ResourceLocation with the given parent and SpatialModel2D. If the SpatialModel2D is null, the SpatialModel2D of the parent is used as the SpatialModel2D. If the parent does not have a SpatialModel2D, then an IllegalArgumentException is thrown
        Parameters:
        parent -
        name -
        spatialModel -
        coordinate -
    • Method Detail

      • addInitialResource

        public boolean addInitialResource​(SpatialResource resource)
        Adds the supplied resource to this location and sets the initial position of the resource to this coordinates. Only sets the initial position if the add was successful. A SpatialResource can only be assigned to one location at a time. An attempt to add a SpatialResource to a location when it is already assigned to another location will cause an exception. First check the getResourceLocation() method on SpatialResource to see if it is assigned a location. If so, remove it from that location prior to assigning it to this location.
        Parameters:
        resource -
        Returns:
      • add

        public boolean add​(SpatialResource resource)
        Adds the supplied resource to this location and sets the CURRENT position of the resource to this location. Only sets the position if the add was successful A SpatialResource can only be assigned to one location at a time. An attempt to assign a SpatialResource to a location when it is already assigned to another location will cause an exception. First check the getResourceLocation() method on SpatialResource to see if it is assigned a location. If so, remove it from that location prior to assigning it to this location.
        Parameters:
        resource -
        Returns:
      • contains

        public boolean contains​(SpatialResource resource)
        Checks if the supplied resource is assigned to this location
        Parameters:
        resource -
        Returns:
      • isEmpty

        public boolean isEmpty()
        Indicates whether or not this location has resources assigned to it
        Returns:
      • iterator

        public java.util.Iterator<SpatialResource> iterator()
        Returns an iterator to the resources assigned to this location
        Returns:
      • remove

        public boolean remove​(SpatialResource resource)
        Removes the supplied resource from this location. The resource is no longer assigned to this location
        Parameters:
        resource -
        Returns:
        Returns true if the remove was successful
      • getNumberOfResources

        public int getNumberOfResources()
        Returns the number of resources assigned to this location
        Returns:
      • getNumberOfIdleResources

        public int getNumberOfIdleResources()
        Returns the number of idle resources currently assigned to this location
        Returns:
      • findIdleResource2D

        public SpatialResource findIdleResource2D()
        This finds an idle resource assigned to this location. Returns and idle resource or null if none found. This method does not remove the resource from this location.
        Returns:
      • findIdleResources2D

        public java.util.List<SpatialResource> findIdleResources2D()
        Returns a list of the idle resources assigned to this location
        Returns: