Class SpatialResource

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

    public class SpatialResource
    extends Resource
    implements SpatialElementIfc
    A SpatialResource is a resource that can be placed/positioned within a SpatialModel It is not "self-moving" but can be positioned by clients at various locations (coordinates, etc) within the spatial model. A SpatialResource can be assigned a "home location" via the ResourceLocation class In all other respects a SpatialResource acts like a Resource.
    • Field Detail

      • MOVED

        public static final int MOVED
        Indicates that the transporter has changed state to its observers
    • Constructor Detail

      • SpatialResource

        public SpatialResource​(ModelElement parent)
        Creates a SpatialResource with the default position within its spatial model. The spatial model of the parent is used as the spatial model of this object. If the parent does not have a spatial model (i.e. getSpatialModel() == null), then an IllegalArgumentException is thrown
        Parameters:
        parent -
      • SpatialResource

        public SpatialResource​(ModelElement parent,
                               int capacity)
        Creates a SpatialResource with the given capacity at the default position within its spatial model. The spatial model of the parent is used as the spatial model of this object. If the parent does not have a spatial model (i.e. getSpatialModel() == null), then an IllegalArgumentException is thrown
        Parameters:
        parent -
        capacity -
      • SpatialResource

        public SpatialResource​(ModelElement parent,
                               int capacity,
                               java.lang.String name)
        Creates a SpatialResource with the given capacity at the default position within its spatial model. The spatial model of the parent is used as the spatial model of this object. If the parent does not have a spatial model (i.e. getSpatialModel() == null), then an IllegalArgumentException is thrown
        Parameters:
        parent -
        capacity -
        name -
      • SpatialResource

        public SpatialResource​(ModelElement parent,
                               java.lang.String name,
                               double x,
                               double y)
        Creates a SpatialResource with the given capacity at (x,y) within its spatial model. The spatial model of the parent is used as the spatial model of this object. If the parent does not have a spatial model (i.e. getSpatialModel() == null), then an IllegalArgumentException is thrown
        Parameters:
        parent -
        name -
        x -
        y -
      • SpatialResource

        public SpatialResource​(ModelElement parent,
                               int capacity,
                               java.lang.String name,
                               double x,
                               double y)
        Creates a SpatialResource with the given capacity at (x,y) within its spatial model. The spatial model of the parent is used as the spatial model of this object. If the parent does not have a spatial model (i.e. getSpatialModel() == null), then an IllegalArgumentException is thrown
        Parameters:
        parent -
        capacity -
        name -
        x -
        y -
      • SpatialResource

        public SpatialResource​(ModelElement parent,
                               java.lang.String name,
                               CoordinateIfc position)
        Creates a SpatialResource with capacity 1 at the given coordinate within its spatial model. The spatial model of the parent is used as the spatial model of this object. If the parent does not have a spatial model (i.e. getSpatialModel() == null), then an IllegalArgumentException is thrown
        Parameters:
        parent -
        name -
        position -
      • SpatialResource

        public SpatialResource​(ModelElement parent,
                               java.lang.String name,
                               SpatialElementIfc position)
        Creates a SpatialResource with capacity 1 at the coordinates of the supplied spatial element within its spatial model. The spatial model of the parent is used as the spatial model of this object. If the parent does not have a spatial model (i.e. getSpatialModel() == null), then an IllegalArgumentException is thrown
        Parameters:
        parent -
        name -
        position -
      • SpatialResource

        public SpatialResource​(ModelElement parent,
                               int capacity,
                               java.lang.String name,
                               CoordinateIfc position)
        Creates a SpatialResource with the given capacity at the given coordinate within its spatial model. The spatial model of the parent is used as the spatial model of this object. If the parent does not have a spatial model (i.e. getSpatialModel() == null), then an IllegalArgumentException is thrown
        Parameters:
        parent -
        capacity -
        name -
        position -
      • SpatialResource

        public SpatialResource​(ModelElement parent,
                               double x,
                               double y)
        Creates a SpatialResource with capacity 1 at (x,y) within its spatial model. The spatial model of the parent is used as the spatial model of this object. If the parent does not have a spatial model (i.e. getSpatialModel() == null), then an IllegalArgumentException is thrown
        Parameters:
        parent -
        x -
        y -
      • SpatialResource

        public SpatialResource​(ModelElement parent,
                               CoordinateIfc position)
        Creates a SpatialResource with capacity 1 at the given coordinate within its spatial model. The spatial model of the parent is used as the spatial model of this object. If the parent does not have a spatial model (i.e. getSpatialModel() == null), then an IllegalArgumentException is thrown
        Parameters:
        parent -
        position -
      • SpatialResource

        public SpatialResource​(ModelElement parent,
                               int capacity,
                               CoordinateIfc position)
        Creates a SpatialResource with the given capacity at the given coordinate within its spatial model. The spatial model of the parent is used as the spatial model of this object. If the parent does not have a spatial model (i.e. getSpatialModel() == null), then an IllegalArgumentException is thrown
        Parameters:
        parent -
        capacity -
        position -
      • SpatialResource

        public SpatialResource​(ModelElement parent,
                               int capacity,
                               double x,
                               double y)
        Creates a SpatialResource with the given capacity at (x,y) within its spatial model. The spatial model of the parent is used as the spatial model of this object. If the parent does not have a spatial model (i.e. getSpatialModel() == null), then an IllegalArgumentException is thrown
        Parameters:
        parent -
        capacity -
        x -
        y -
      • SpatialResource

        public SpatialResource​(ModelElement parent,
                               int capacity,
                               java.lang.String name,
                               SpatialModel spatialModel)
        Creates a SpatialResource with the given capacity at the default position within the spatial model. If the spatial model is null then the spatial model of the parent is used as the spatial model of this object. If the parent does not have a spatial model (i.e. getSpatialModel() == null), then an IllegalArgumentException is thrown
        Parameters:
        parent -
        capacity -
        name -
        spatialModel -
      • SpatialResource

        public SpatialResource​(ModelElement parent,
                               int capacity,
                               SpatialModel spatialModel)
        Creates a SpatialResource with the given capacity at the default position within the spatial model. If the spatial model is null then the spatial model of the parent is used as the spatial model of this object. If the parent does not have a spatial model (i.e. getSpatialModel() == null), then an IllegalArgumentException is thrown
        Parameters:
        parent -
        capacity -
        spatialModel -
      • SpatialResource

        public SpatialResource​(ModelElement parent,
                               int capacity,
                               java.lang.String name,
                               SpatialModel spatialModel,
                               double x,
                               double y,
                               double z)
        Creates a SpatialResource with the given capacity at (x,y,z) within the spatial model. If the spatial model is null then the spatial model of the parent is used as the spatial model of this object. If the parent does not have a spatial model (i.e. getSpatialModel() == null), then an IllegalArgumentException is thrown
        Parameters:
        parent -
        capacity -
        name -
        spatialModel -
        x -
        y -
        z -
      • SpatialResource

        public SpatialResource​(ModelElement parent,
                               int capacity,
                               java.lang.String name,
                               SpatialModel spatialModel,
                               CoordinateIfc coordinate)
        Creates a SpatialResource with the given capacity at the default position within the spatial model. If the spatial model is null then the spatial model of the parent is used as the spatial model of this object. If the parent does not have a spatial model (i.e. getSpatialModel() == null), then an IllegalArgumentException is thrown
        Parameters:
        parent -
        capacity -
        name -
        spatialModel -
        coordinate -
    • Method Detail

      • attachPositionObserver

        public final void attachPositionObserver​(ObserverIfc observer)
        Description copied from interface: SpatialElementIfc
        Implementor of this interface should allow Observers to be attached. For example, the observers should be notified when the position changes. It is the responsibility of implementers to properly notify the observers.
        Specified by:
        attachPositionObserver in interface SpatialElementIfc
        Parameters:
        observer - the observer
      • changeSpatialModel

        public final void changeSpatialModel​(SpatialModel spatialModel,
                                             CoordinateIfc coordinate)
        Description copied from interface: SpatialElementIfc
        Changes the spatial model for this element and places the element at the supplied coordinate within the new spatial model. Throws IllegalArgumentException if the coordinate is not valid for the supplied spatial model. This spatial element becomes a child element of the new spatial model.
        Specified by:
        changeSpatialModel in interface SpatialElementIfc
        Parameters:
        spatialModel - the spatial model
        coordinate - the coordinate
      • distanceTo

        public final double distanceTo​(CoordinateIfc coordinate)
        Description copied from interface: SpatialElementIfc
        This is a "convenience" method for getting the distance from this element to the supplied coordinate within the underlying spatial model
        Specified by:
        distanceTo in interface SpatialElementIfc
        Parameters:
        coordinate - the coordinate to check
        Returns:
        the distance
      • distanceTo

        public final double distanceTo​(SpatialElementIfc element)
        Description copied from interface: SpatialElementIfc
        This is a "convenience" method for getting the distance from this element to the supplied element within the underlying spatial model Requirement: The elements must be in the same spatial model. The distance should be calculated by the spatial model. If they are not in the same spatial model this method will throw and IllegalArgumentException
        Specified by:
        distanceTo in interface SpatialElementIfc
        Parameters:
        element - the element to check
        Returns:
        the distance
      • initializeSpatialElement

        public final void initializeSpatialElement()
        Description copied from interface: SpatialElementIfc
        This method should be called to initialize the spatial element prior to running a simulation
        Specified by:
        initializeSpatialElement in interface SpatialElementIfc
      • isPositionEqualTo

        public final boolean isPositionEqualTo​(CoordinateIfc coordinate)
        Description copied from interface: SpatialElementIfc
        Returns true if the position of this element is the same as supplied coordinate within the underlying spatial model. This is not necessarily object reference equality, but rather whether or not the positions within the underlying spatial model can be considered the same (equivalent).
        Specified by:
        isPositionEqualTo in interface SpatialElementIfc
        Parameters:
        coordinate - the coordinate to check
        Returns:
        true if position is equal
      • isPositionEqualTo

        public final boolean isPositionEqualTo​(SpatialElementIfc element)
        Description copied from interface: SpatialElementIfc
        Returns true if the position of this element is the same as the position of the supplied element within the underlying spatial model. This is not necessarily object reference equality, but rather whether or not the positions within the underlying spatial model can be considered the same (equivalent). Requirement: The elements must be in the same spatial model. If they are not in the same spatial model, then this method should return false.
        Specified by:
        isPositionEqualTo in interface SpatialElementIfc
        Parameters:
        element - the element to check
        Returns:
        the distance
      • setInitialPosition

        public final void setInitialPosition​(CoordinateIfc c)
        Description copied from interface: SpatialElementIfc
        Sets the initial position of the element. This position should be used when initializeSpatialElement() is called, typically at the beginning of a replication.
        Specified by:
        setInitialPosition in interface SpatialElementIfc
        Parameters:
        c - the coordinate
      • setPosition

        public final void setPosition​(CoordinateIfc location)
        Sets the position to the coordinates of the supplied location
        Parameters:
        location -
      • setPosition

        public final void setPosition​(SpatialElementIfc element)
        Sets the position to the coordinates of the supplied location
        Parameters:
        element -
      • getInitialResourceLocation

        public final ResourceLocation getInitialResourceLocation()
        Gets the initial resource location. This location is used when the element is initialized, prior to a replication.
        Returns:
        Returns the myInitialResourceLocation.
      • getResourceLocation

        public final ResourceLocation getResourceLocation()
        Returns the associated ResourceLocation if one exists. May be null
        Returns:
        Returns the ResourceLocation.
      • initialize

        protected void initialize()
        Description copied from class: ModelElement
        This method should be overridden by subclasses that need actions performed to initialize prior to a replication. It is called once before each replication occurs if the model element wants initialization. It is called after beforeReplication() is called
        Overrides:
        initialize in class Resource
      • getSpatialElement

        protected final SpatialElement getSpatialElement()
      • setInitialResourceLocation

        protected final void setInitialResourceLocation​(ResourceLocation location)
        Sets the initial resource location. This location is used when the element is initialized prior to a replication. This may be null.
        Parameters:
        location - The initial resource locaiton to set for the element
      • setResourceLocation

        protected final void setResourceLocation​(ResourceLocation resourceLocation)
        Sets the ResourceLocation for this SpatialResource. It can be null
        Parameters:
        resourceLocation - The resourceLocation to set.
      • setSpatialElement

        protected final void setSpatialElement​(SpatialElement spatialElement)
        Sets the underlying SpatialElement
        Parameters:
        spatialElement -