Class Variable
java.lang.Object
edu.uky.cs.nil.tt.world.Asset
edu.uky.cs.nil.tt.world.SignedAsset
edu.uky.cs.nil.tt.world.Variable
- All Implemented Interfaces:
Described, Expression, Logical, Unique, Comparable<Variable>
A variable is a
signed asset that represents a feature of
the story world state that can change. A state assign a value to each of a story world's
variables.- Author:
- Stephen G. Ware
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal StringThe name of theencodingthis variable uses to encode its valuesFields inherited from class SignedAsset
signature -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintUses the variable'svalue encodingtoencodethe given object.Returns the value of this logical expression in the given state.setDescription(String description) Returns a new asset that is the same as this asset, except that itsdescriptionis the given value.protected VariablesetEncoding(String encoding) Returns a new variable that is the same as this variable, except that its value encoding is the given value.protected VariablesetID(int id) Returns a new asset that is the same as this asset, except that its ID number is the given value.protected VariablesetSignature(Signature signature) Returns a new signed asset that is the same as this asset, except that its signature and name are the given value.substitute(Function<Object, Object> substitution) Returns a logical object identical to this one, except that its logical elements have been replaced according to the given substitution.
-
Field Details
-
encoding
-
-
Constructor Details
-
Variable
Constructs a new variable.- Parameters:
id- the variable's unique ID numbersignature- the variable's unique signatureencoding- the name of theencodingused to encode the variable's valuedescription- the variable's description
-
-
Method Details
-
compareTo
- Specified by:
compareToin interfaceComparable<Variable>
-
setID
Description copied from class:AssetReturns a new asset that is the same as this asset, except that its ID number is the given value. -
setSignature
Description copied from class:SignedAssetReturns a new signed asset that is the same as this asset, except that its signature and name are the given value.- Specified by:
setSignaturein classSignedAsset- Parameters:
signature- the signature and name the new asset should have- Returns:
- a signed asset identical to this asset, except with the given signature and name
-
setEncoding
Returns a new variable that is the same as this variable, except that its value encoding is the given value.- Parameters:
encoding- the name of the value encoding the new variable should have- Returns:
- a variable identical to this variable, except with the given value encoding
-
setDescription
Description copied from class:AssetReturns a new asset that is the same as this asset, except that itsdescriptionis the given value.- Specified by:
setDescriptionin classAsset- Parameters:
description- the description the new asset should have- Returns:
- an asset identical to this asset, except with the given description
-
substitute
Description copied from interface:LogicalReturns a logical object identical to this one, except that its logical elements have been replaced according to the given substitution. A substitution defines how some logical formula (the input to the function) should be replaced with a different formula (the output of the function).- Specified by:
substitutein interfaceExpression- Specified by:
substitutein interfaceLogical- Specified by:
substitutein classSignedAsset- Parameters:
substitution- a function which maps logical formula that should be replaced to the formula they should be replaced with- Returns:
- an identical object, except that its logical formula have been replaced according to the substitution
-
evaluate
Description copied from interface:ExpressionReturns the value of this logical expression in the given state.- Specified by:
evaluatein interfaceExpression- Parameters:
state- a mapping of values to all of a story world's variables- Returns:
- the value of the expression in the given state
-
encode
Uses the variable'svalue encodingtoencodethe given object.- Parameters:
value- the object to be encoded- Returns:
- the encoding of the given value
- Throws:
RuntimeException- if the object cannot be encoded
-
decode
- Parameters:
value- the object to be decoded- Returns:
- the object that results from decoding the given object, as a logical value
- Throws:
RuntimeException- if the object cannot be decoded
-