Class Resource<V extends Comparable>

java.lang.Object
gov.nasa.jpl.resource.Resource<V>
Type Parameters:
V - The parameterized type that represents the data type the resource is tracking throughout the simulation
All Implemented Interfaces:
ResourceContainer
Direct Known Subclasses:
BooleanResource, DoubleResource, DurationResource, IntegerResource, StringResource, SumDoubleResource, SumIntegerResource, TimeResource

public abstract class Resource<V extends Comparable> extends Object implements ResourceContainer
The base abstract Resource class that all others inherit from. Contains data structure to track value of variable throughout simulated time, as well as methods to hook into constraints so one can schedule off resource values.
  • Field Details

    • units

      protected String units
    • interpolation

      protected String interpolation
    • subsystem

      protected String subsystem
    • minimum

      protected V extends Comparable minimum
    • maximum

      protected V extends Comparable maximum
    • possibleStates

      protected List<V extends Comparable> possibleStates
  • Constructor Details

    • Resource

      public Resource(String subsystem, String units, String interpolation, V minimum, V maximum)
    • Resource

      public Resource(String subsystem, String units, String interpolation)
    • Resource

      public Resource(String subsystem, String units)
    • Resource

      public Resource(String subsystem)
    • Resource

      public Resource()
  • Method Details

    • clearHistory

      public void clearHistory()
      Clears the history of the resource by notifying its listeners that it is being reset, then pointing the resource history to a clean object. Should not typically be called by adapters - is called before a REMODEL loop
    • set

      public void set(V inVal)
      Inserts a new value into the resource's time history at the current simulated time. This method is the main way adapters should append to resource histories. Notifies any objects that may be listening to the resource, especially Condition objects.
      Parameters:
      inVal -
    • insertRecord

      public void insertRecord(ReaderThreadResource reader, Time t, V inVal)
      We don't want adapters using this, so we use something like C++'s friend mechanism. Used by parallel IO writer
    • update

      public void update()
      No-op method that adapters can override in custom resources
      Specified by:
      update in interface ResourceContainer
    • currentval

      public V currentval()
      Wraps valueAt(now())
      Returns:
      Returns the value of the resource at the current simulated time.
    • valueAt

      public V valueAt(Time t)
      Returns the value of the resource at the specified time. One of the main methods adapters use to query resource timelines.
      Parameters:
      t - The Time one wants the value at.
      Returns:
      The value (of whatever type) at the given time.
    • min

      public Map.Entry<Time,V> min(Time start, Time end)
      Parameters:
      start - Times at or after this will be included in the search for the minimum value. If null, beginning of resource history is used.
      end - Times at or before this will be included in the search for the minimum value. If null, end of resource history is used.
      Returns:
      The minimum value of the resource between the bounds, as determined by the natural comparator of the type the Resource holds. If the minimum value is set before the query window and continues into some portion of the query window, that incoming value is returned, and the time returned is the 'start' query time
    • max

      public Map.Entry<Time,V> max(Time start, Time end)
      Parameters:
      start - Times at or after this will be included in the search for the minimum value. If null, beginning of resource history is used.
      end - Times at or before this will be included in the search for the minimum value. If null, end of resource history is used.
      Returns:
      The maximum value of the resource between the bounds, as determined by the natural comparator of the type the Resource holds If the maximum value is set before the query window and continues into some portion of the query window, that incoming value is returned, and the time returned is the 'start' query time
    • getChangesDuringWindow

      public List<Map.Entry<Time,V>> getChangesDuringWindow(Time start, Time end)
      Parameters:
      start - Times at or after this will be included in the returned list of value changes. If null, beginning of resource history is used.
      end - Times at or before this will be included in the returned list of value changes. If null, end of resource history is used.
      Returns:
      A chronological list of map entries, where each key is the time of the change and the value is the new resource value
    • profile

      public abstract V profile(Time t)
      Returns the default value of the resource before it is set() to a new value. Must be abstract since different data types have different intuitive defaults.
      Parameters:
      t - The time one wants the default value at. Used for custom resources that may have time-varying profiles.
      Returns:
    • isIndexInArrayedResource

      public boolean isIndexInArrayedResource()
      Returns true if this individual resource is 'owned' by an ArrayedResource. Should never be used by adapters.
      Returns:
    • resourceHistoryHasElements

      public boolean resourceHistoryHasElements()
      Returns true if the resource has any usage nodes in it.
      Returns:
    • getSize

      public int getSize()
      Returns number of values in the history of the resource
      Returns:
    • registerResource

      public void registerResource()
      Base case for recursive registerResource() in case of arrayed resource Called by reflection machinery when starting adaptation - not to be called by adapters
      Specified by:
      registerResource in interface ResourceContainer
    • getType

      public String getType()
      Returns the data type of the resource, using reflection. Used for IO.
      Returns:
    • getName

      public String getName()
      Gets the name of the resource. Used for IO.
      Returns:
    • setName

      public void setName(String str)
      Sets the name of a resource. Should only be called by ArrayedResources.
      Specified by:
      setName in interface ResourceContainer
      Parameters:
      str -
    • getIndices

      public List<String> getIndices()
      Gets the 'indices' a resource bin belongs to. Used for IO
      Returns:
    • setIndices

      public void setIndices(List<String> index)
      Sets the 'indices' of a resource. Should only be used by ArrayedResource and not adapters
      Specified by:
      setIndices in interface ResourceContainer
      Parameters:
      index -
    • getUniqueName

      public String getUniqueName()
      Getter for fully qualified name of resource
      Returns:
    • formUniqueName

      public static String formUniqueName(String baseName, List<String> indices)
      Encapsulated method to go from an arrayed resource to a well-defined string name
      Parameters:
      baseName -
      indices -
      Returns:
    • getUnits

      public String getUnits()
      Returns the units string for the resource
      Returns:
    • setUnits

      public void setUnits(String u)
      Sets the units string for the resource
      Parameters:
      u -
    • setSubsystem

      public void setSubsystem(String s)
      Assigns the resource to a different subsystem
      Parameters:
      s -
    • getSubsystem

      public String getSubsystem()
      Gets the subsystem name the resource was assigned to
      Returns:
    • setInterpolation

      public void setInterpolation(String i)
      Sets the interpolation mode of the resource. Usually 'constant' or 'linear'
      Parameters:
      i -
    • getInterpolation

      public String getInterpolation()
      Returns the interpolation mode of the resource
      Returns:
    • setMinimumLimit

      public void setMinimumLimit(V minimum2)
      Set the minimum value of a resource
      Parameters:
      minimum2 -
    • getMinimumLimit

      public String getMinimumLimit()
      Returns a string containing the minimum value of the resource
      Returns:
    • setMaximumLimit

      public void setMaximumLimit(V m)
      Set the maximum value of a resource.
      Parameters:
      m -
    • getMaximumLimit

      public String getMaximumLimit()
      Returns a string containing the maximum value of the resource
      Returns:
    • getPossibleStates

      public List<V> getPossibleStates()
      Returns the possible states in a string resource if they were declared
      Returns:
    • getDataType

      public String getDataType()
      Returns a string containing the type of data the resource is tracking. Mostly used by reflection.
      Returns:
    • setFrozen

      public void setFrozen(boolean isFrozen)
      Freezes or unfreezes a resource. Should be called by IO machinery and not adapter
      Parameters:
      isFrozen -
    • isFrozen

      public boolean isFrozen()
      Returns true if the resource is frozen, which could have happened if it was read in from a file
      Returns:
    • historyIterator

      public Iterator<Map.Entry<Time,V>> historyIterator(Time begin, Time end)
      Returns an iterator over (Time, V) pairs in the resource's history timeline
      Parameters:
      begin -
      end -
      Returns:
    • firstTimeSet

      public Time firstTimeSet()
      Returns the first Time the resource was set
      Returns:
    • lastTimeSet

      public Time lastTimeSet()
      Returns the last Time the resource was set
      Returns:
    • priorTimeSet

      public Time priorTimeSet(Time queryTime, boolean inclusive)
      Intended to be used in decompose() methods when the resource histories are already filled out after a remodel
      Parameters:
      queryTime - The time at which to begin looking earlier for the prior time the resource was set
      inclusive - Whether to return a resource set node at exactly queryTime if one exists - if inclusive is set to false and there is a node at queryTime, it will be ignored and the closest one prior to it will be returned
      Returns:
      The latest Time the resource was set earlier than (or equal to, if inclusive is set to true) the query time, or null if the resource was not set prior
    • nextTimeSet

      public Time nextTimeSet(Time queryTime, boolean inclusive)
      Intended to be used in decompose() methods when the resource histories are already filled out after a remodel
      Parameters:
      queryTime - The time at which to begin looking later for the next time the resource is set
      inclusive - Whether to return a resource set node at exactly queryTime if one exists - if inclusive is set to false and there is a node at queryTime, it will be ignored and the closest one after it will be returned
      Returns:
      The earliest Time the resource is set later than (or equal to, if inclusive is set to true) the query time, or null if the resource was not set afterwards
    • lastValue

      public V lastValue()
      Returns the most recently set value of the resource
      Returns:
    • nextTimeResourceSetToValue

      public Time nextTimeResourceSetToValue(V val, Time queryTime)
      Gets the Time following queryTime when a resource is set to a specified value Intended to be used in decompose() methods when the resource histories are already filled out after a remodel
      Parameters:
      val - a value to compare to
      queryTime - the Time after which the sought-after Time must occur
      Returns:
      the next Time the calling Resource is set to val. null if it is not set to that val anytime after
    • priorTimeResourceSetToValue

      public Time priorTimeResourceSetToValue(V val, Time queryTime)
      Gets the Time before queryTime when a resource is set to a specified value Intended to be used in decompose() methods when the resource histories are already filled out after a remodel
      Parameters:
      val - a value to compare to
      queryTime - the Time before which the sought-after Time must occur
      Returns:
      the prior Time the calling Resource is set to val. null if it is not set to that val anytime before
    • addChangeListener

      public void addChangeListener(PropertyChangeListener newListener)
      Called by Conditions and other objects in core - not to be used by adapters Following Observer design pattern
    • removeChangeListener

      public void removeChangeListener(PropertyChangeListener toBeRemoved)
      Needed to not schedule schedulers every time a remodel is run Not to be called by adapters.
    • whenGreaterThan

      public Condition whenGreaterThan(Comparable value)
      Returns a condition representing >
      Parameters:
      value -
      Returns:
    • whenGreaterThanOrEqualTo

      public Condition whenGreaterThanOrEqualTo(Comparable value)
      Returns a condition representing >=
      Parameters:
      value -
      Returns:
    • whenLessThan

      public Condition whenLessThan(Comparable value)
      Returns a condition representing <
      Parameters:
      value -
      Returns:
    • whenLessThanOrEqualTo

      public Condition whenLessThanOrEqualTo(Comparable value)
      Returns a condition representing <=
      Parameters:
      value -
      Returns:
    • whenEqualTo

      public Condition whenEqualTo(Comparable value)
      Returns a condition representing ==
      Parameters:
      value -
      Returns:
    • whenNotEqualTo

      public Condition whenNotEqualTo(Comparable value)
      Returns a condition representing !=
      Parameters:
      value -
      Returns: