Package gov.nasa.jpl.resource
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
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChangeListener
(PropertyChangeListener newListener) Called by Conditions and other objects in core - not to be used by adapters Following Observer design patternvoid
Clears the history of the resource by notifying its listeners that it is being reset, then pointing the resource history to a clean object.Wraps valueAt(now())Returns the first Time the resource was setstatic String
formUniqueName
(String baseName, List<String> indices) Encapsulated method to go from an arrayed resource to a well-defined string namegetChangesDuringWindow
(Time start, Time end) Returns a string containing the type of data the resource is tracking.Gets the 'indices' a resource bin belongs to.Returns the interpolation mode of the resourceReturns a string containing the maximum value of the resourceReturns a string containing the minimum value of the resourcegetName()
Gets the name of the resource.Returns the possible states in a string resource if they were declaredint
getSize()
Returns number of values in the history of the resourceGets the subsystem name the resource was assigned togetType()
Returns the data type of the resource, using reflection.Getter for fully qualified name of resourcegetUnits()
Returns the units string for the resourcehistoryIterator
(Time begin, Time end) Returns an iterator over (Time, V) pairs in the resource's history timelinevoid
insertRecord
(ReaderThreadResource reader, Time t, V inVal) We don't want adapters using this, so we use something like C++'s friend mechanism.boolean
isFrozen()
Returns true if the resource is frozen, which could have happened if it was read in from a fileboolean
Returns true if this individual resource is 'owned' by an ArrayedResource.Returns the last Time the resource was setReturns the most recently set value of the resourcenextTimeResourceSetToValue
(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 remodelnextTimeSet
(Time queryTime, boolean inclusive) Intended to be used in decompose() methods when the resource histories are already filled out after a remodelpriorTimeResourceSetToValue
(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 remodelpriorTimeSet
(Time queryTime, boolean inclusive) Intended to be used in decompose() methods when the resource histories are already filled out after a remodelabstract V
Returns the default value of the resource before it is set() to a new value.void
Base case for recursive registerResource() in case of arrayed resource Called by reflection machinery when starting adaptation - not to be called by adaptersvoid
removeChangeListener
(PropertyChangeListener toBeRemoved) Needed to not schedule schedulers every time a remodel is run Not to be called by adapters.boolean
Returns true if the resource has any usage nodes in it.void
Inserts a new value into the resource's time history at the current simulated time.void
setFrozen
(boolean isFrozen) Freezes or unfreezes a resource.void
setIndices
(List<String> index) Sets the 'indices' of a resource.void
Sets the interpolation mode of the resource.void
setMaximumLimit
(V m) Set the maximum value of a resource.void
setMinimumLimit
(V minimum2) Set the minimum value of a resourcevoid
Sets the name of a resource.void
Assigns the resource to a different subsystemvoid
Sets the units string for the resourcevoid
update()
No-op method that adapters can override in custom resourcesReturns the value of the resource at the specified time.whenEqualTo
(Comparable value) Returns a condition representing ==whenGreaterThan
(Comparable value) Returns a condition representing >Returns a condition representing >=whenLessThan
(Comparable value) Returns a condition representing <whenLessThanOrEqualTo
(Comparable value) Returns a condition representing <=whenNotEqualTo
(Comparable value) Returns a condition representing !=
-
Field Details
-
units
-
interpolation
-
subsystem
-
minimum
-
maximum
-
possibleStates
-
-
Constructor Details
-
Resource
-
Resource
-
Resource
-
Resource
-
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
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
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 interfaceResourceContainer
-
currentval
Wraps valueAt(now())- Returns:
- Returns the value of the resource at the current simulated time.
-
valueAt
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
- 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
- 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
- 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
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 interfaceResourceContainer
-
getType
Returns the data type of the resource, using reflection. Used for IO.- Returns:
-
getName
Gets the name of the resource. Used for IO.- Returns:
-
setName
Sets the name of a resource. Should only be called by ArrayedResources.- Specified by:
setName
in interfaceResourceContainer
- Parameters:
str
-
-
getIndices
Gets the 'indices' a resource bin belongs to. Used for IO- Returns:
-
setIndices
Sets the 'indices' of a resource. Should only be used by ArrayedResource and not adapters- Specified by:
setIndices
in interfaceResourceContainer
- Parameters:
index
-
-
getUniqueName
Getter for fully qualified name of resource- Returns:
-
formUniqueName
Encapsulated method to go from an arrayed resource to a well-defined string name- Parameters:
baseName
-indices
-- Returns:
-
getUnits
Returns the units string for the resource- Returns:
-
setUnits
Sets the units string for the resource- Parameters:
u
-
-
setSubsystem
Assigns the resource to a different subsystem- Parameters:
s
-
-
getSubsystem
Gets the subsystem name the resource was assigned to- Returns:
-
setInterpolation
Sets the interpolation mode of the resource. Usually 'constant' or 'linear'- Parameters:
i
-
-
getInterpolation
Returns the interpolation mode of the resource- Returns:
-
setMinimumLimit
Set the minimum value of a resource- Parameters:
minimum2
-
-
getMinimumLimit
Returns a string containing the minimum value of the resource- Returns:
-
setMaximumLimit
Set the maximum value of a resource.- Parameters:
m
-
-
getMaximumLimit
Returns a string containing the maximum value of the resource- Returns:
-
getPossibleStates
Returns the possible states in a string resource if they were declared- Returns:
-
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
Returns an iterator over (Time, V) pairs in the resource's history timeline- Parameters:
begin
-end
-- Returns:
-
firstTimeSet
Returns the first Time the resource was set- Returns:
-
lastTimeSet
Returns the last Time the resource was set- Returns:
-
priorTimeSet
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 setinclusive
- 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
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 setinclusive
- 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
Returns the most recently set value of the resource- Returns:
-
nextTimeResourceSetToValue
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 toqueryTime
- 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
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 toqueryTime
- 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
Called by Conditions and other objects in core - not to be used by adapters Following Observer design pattern -
removeChangeListener
Needed to not schedule schedulers every time a remodel is run Not to be called by adapters. -
whenGreaterThan
Returns a condition representing >- Parameters:
value
-- Returns:
-
whenGreaterThanOrEqualTo
Returns a condition representing >=- Parameters:
value
-- Returns:
-
whenLessThan
Returns a condition representing <- Parameters:
value
-- Returns:
-
whenLessThanOrEqualTo
Returns a condition representing <=- Parameters:
value
-- Returns:
-
whenEqualTo
Returns a condition representing ==- Parameters:
value
-- Returns:
-
whenNotEqualTo
Returns a condition representing !=- Parameters:
value
-- Returns:
-