Class SpatialModel

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int ADDED_ELEMENT
      An "enum" to indicate that a element has been added when notifying observers
      protected double myDefaultPositionPrecision
      The default precision when comparing spatial element positions for equality
      protected java.util.List<SpatialElement> myElements
      Holds the elements defined within the model
      static int REMOVED_ELEMENT
      An "enum" to indicate that a element has been reomved when notifying observers
      static int UPDATED_POSITION
      An enum to indicate that the spatial model as just updated the position of a element
    • Constructor Summary

      Constructors 
      Constructor Description
      SpatialModel()
      Constructs a new spatial model
      SpatialModel​(java.lang.String name)
      Constructs a new spatial model
    • Field Detail

      • ADDED_ELEMENT

        public static final int ADDED_ELEMENT
        An "enum" to indicate that a element has been added when notifying observers
      • REMOVED_ELEMENT

        public static final int REMOVED_ELEMENT
        An "enum" to indicate that a element has been reomved when notifying observers
      • UPDATED_POSITION

        public static final int UPDATED_POSITION
        An enum to indicate that the spatial model as just updated the position of a element
      • myElements

        protected java.util.List<SpatialElement> myElements
        Holds the elements defined within the model
      • myDefaultPositionPrecision

        protected double myDefaultPositionPrecision
        The default precision when comparing spatial element positions for equality
    • Constructor Detail

      • SpatialModel

        public SpatialModel()
        Constructs a new spatial model
      • SpatialModel

        public SpatialModel​(java.lang.String name)
        Constructs a new spatial model
        Parameters:
        name -
    • Method Detail

      • getDefaultCoordinate

        public abstract CoordinateIfc getDefaultCoordinate()
        Returns a default set of coordinates to be used to initialize the location of spatial elements if necessary.
        Returns:
      • getCoordinate

        public abstract CoordinateIfc getCoordinate​(double x1,
                                                    double x2,
                                                    double x3)
        Creates a valid coordinate for this spatial model This method should check whether the coordinate can be represented spatially within this spatial model. If not, an IllegalArgumentException should be thrown
        Parameters:
        x1 -
        x2 -
        x3 -
        Returns:
      • isValid

        public abstract boolean isValid​(CoordinateIfc coordinate)
        Checks to see if the supplied coordinate is physically valid within the spatial model. This depends on the underlying spatial representation. This method should check whether the coordinate can be represented spatially within this spatial model. If so, this method should return true.
        Parameters:
        coordinate -
        Returns:
      • distance

        public abstract double distance​(CoordinateIfc fromCoordinate,
                                        CoordinateIfc toCoordinate)
        Computes the distance between the two supplied coordinates
        Parameters:
        fromCoordinate -
        toCoordinate -
        Returns:
      • comparePositions

        public abstract boolean comparePositions​(CoordinateIfc coordinate1,
                                                 CoordinateIfc coordinate2)
        Returns true if the first coordinate is the same as second coordinate within the underlying spatial model. This is not object reference equality, but rather whether or not the positions within the underlying spatial model can be considered spatially (equivalent). Requirement: The coordinates must be valid within the spatial model. If they are not valid within same spatial model, then this method should return false.
        Parameters:
        coordinate1 -
        coordinate2 -
        Returns:
      • getCoordinate

        public final CoordinateIfc getCoordinate​(double x1,
                                                 double x2)
        Creates a valid coordinate for this spatial model, with 3rd coordinate 0.0
        Parameters:
        x1 -
        x2 -
        Returns:
      • isValid

        public final boolean isValid​(SpatialElementIfc element)
        Checks to see if the supplied element can be physically valid within the spatial model. This depends on the underlying spatial representation. The supplied element may or may not be contained by the spatial model. If it is contained in the spatial model, it must be valid for that spatial model and thus this method should return true. If the supplied element is in a different spatial model, then this method should check whether the element can be represented spatially within this spatial model. If so, this method should return true.
        Parameters:
        element -
        Returns:
      • distance

        public final double distance​(SpatialElementIfc fromElement,
                                     SpatialElementIfc toElement)
        Computes the distance between the two supplied elements The elements must be valid within the (same) spatial model or an IllegalArgumentException will be thrown.
        Parameters:
        fromElement -
        toElement -
        Returns:
      • comparePositions

        public final boolean comparePositions​(SpatialElementIfc element1,
                                              SpatialElementIfc element2)
        Returns true if the first element's position is the same as second element's position within the underlying spatial model. This is not object reference equality, but rather whether or not the positions within the underlying spatial model can be considered spatially (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.
        Parameters:
        element1 -
        element2 -
        Returns:
      • getDefaultPositionPrecision

        public final double getDefaultPositionPrecision()
        Gets the default position precision for checking if elements have the same position
        Returns:
        Returns the precision.
      • setDefaultPositionPrecision

        public final void setDefaultPositionPrecision​(double precision)
        Sets the default position precision.
        Parameters:
        precision - The precision to set.
      • getModel

        public final Model getModel()
        Gets the JSL Model related to this spatial model
        Returns:
      • setModel

        public final void setModel​(Model model)
        Sets the JSL Model related to this spatial model. The supplied model cannot be null or an IllegalArgumentException is thrown
        Parameters:
        model -
      • getName

        public final java.lang.String getName()
        Gets this spatial model's name.
        Specified by:
        getName in interface GetNameIfc
        Returns:
        The name of the spatial model.
      • getId

        public final int getId()
        Gets a uniquely assigned integer identifier for this model. This identifier is assigned when the model is created. It may vary if the order of creation changes.
        Specified by:
        getId in interface IdentityIfc
        Returns:
        The identifier for the model.
      • contains

        public final boolean contains​(SpatialElement element)
        Checks if the spatial model contains the supplied element. True indicates that the element is within the spatial model. If the element has already been added to this spatial model then this method should return true
        Parameters:
        element -
        Returns:
      • getUpdatingSpatialElement

        public final SpatialElementIfc getUpdatingSpatialElement()
        Returns a reference to the most recent spatial element that notified the spatial model of an update change. Null if no such element. Subclasses are responsible for setting this within the updatePosition() method This method can be used by observers to ask the SpatialModel for the element that updated its position.
        Returns:
      • getObserverState

        public final int getObserverState()
        Returns the observer state indicator
        Returns:
        Returns the observerState.
      • checkForSpatialElementRemoved

        public final boolean checkForSpatialElementRemoved()
        Checks to see if the model is in the REMOVED_ELEMENT state. That is, has removeSpatialElement() been invoked. This method can be used by observers that are interested in reacting to the removeSpatialElement() for the model.
        Returns:
        True means that this model element is in the REMOVED_ELEMENT state
      • checkSpatialElementAdded

        public final boolean checkSpatialElementAdded()
        Checks to see if the spatial model is in the ADDED_ELEMENT state. That is, has addSpatialElement() been invoked. This method can be used by observers that are interested in reacting to the addSpatialElement() for the model.
        Returns:
        True means that this model element is in the ADDED_ELEMENT state
      • checkSpatialElementPositionChanged

        public final boolean checkSpatialElementPositionChanged()
        Checks to see if the model is in the UPDATED_POSITION state. That is, has updatePosition() been invoked. This method can be used by observers that are interested in reacting to the updatePosition() for the model.
        Returns:
        True means that this model element is in the UPDATED_POSITION state
      • addSpatialElement

        protected void addSpatialElement​(SpatialElement element)
        Adds the supplied element to the spatial model
        Parameters:
        element -
      • removeSpatialElement

        protected final boolean removeSpatialElement​(SpatialElementIfc element)
        Removes the supplied element from the spatial model. Requirements: 1) If the supplied element is null, then an IllegalArgumentException should be thrown 2) If the supplied element is not in the spatial model then an IllegalArgumentException should be thrown Implementors should ensure that element.getSpatialModel() returns null after this method is called
        Parameters:
        element -
        Returns:
      • updatePosition

        protected void updatePosition()
        Should be implemented by subclasses to provide behavior when a spatial element notifies that it has changed its position within the spatial model
      • updatePosition_

        protected final void updatePosition_​(SpatialElementIfc element)
        Called by spatial elements when they update their current position
        Parameters:
        element -
      • setUpdatingElement

        protected void setUpdatingElement​(SpatialElementIfc updatingElement)
        Sets the most recent spatial element that notified the spatial model of an update change. Must not be null. Subclasses are responsible for setting this within the updatePosition() method
        Parameters:
        updatingElement - The updatingElement to set.
      • setObserverState

        protected final void setObserverState​(int observerState)
        Sets the observer state indicator
        Parameters:
        observerState - The observer state to set.
      • setName

        protected final void setName​(java.lang.String str)
        Sets the name of this model
        Parameters:
        str - The name as a string.
      • addObserver

        public final void addObserver​(ObserverIfc observer)
        Description copied from interface: ObservableIfc
        Allows the adding (attaching) of an observer to the observable
        Specified by:
        addObserver in interface ObservableIfc
        Parameters:
        observer - the observer to attach
      • deleteObserver

        public final void deleteObserver​(ObserverIfc observer)
        Description copied from interface: ObservableIfc
        Allows the deletion (removing) of an observer from the observable
        Specified by:
        deleteObserver in interface ObservableIfc
        Parameters:
        observer - the observer to delete
      • deleteObservers

        public final void deleteObservers()
        Description copied from interface: ObservableIfc
        Deletes all the observers from the observable
        Specified by:
        deleteObservers in interface ObservableIfc
      • contains

        public final boolean contains​(ObserverIfc observer)
        Description copied from interface: ObservableIfc
        Returns true if the observer is already attached
        Specified by:
        contains in interface ObservableIfc
        Parameters:
        observer - the observer to check
        Returns:
        true if attached
      • countObservers

        public final int countObservers()
        Description copied from interface: ObservableIfc
        Returns how many observers are currently observing the observable
        Specified by:
        countObservers in interface ObservableIfc
        Returns:
        number of observers
      • notifyObservers

        protected final void notifyObservers​(java.lang.Object theObserved,
                                             java.lang.Object arg)