Package org.jruby.embed.internal
Class BiVariableMap
java.lang.Object
org.jruby.embed.internal.BiVariableMap
Ruby-Java bi-directional variable map implementation. Keys of this map
should be String, and values should be
BiVariable type object.
This map does not permit null or empty key. Each operation of this class is not
synchronized; however, concurrent access to values are synchronized. When
ScriptingContainer is shared by multiple threads, specify thread safe
for a local context scope, which makes a map thread local.
Usage example:
ScriptingContainer container = new ScriptingContainer();
Map map = container.getVarMap();
map.put("@coefficient", new Float(3.14));
or, using a shortcut method:
ScriptingContainer container = new ScriptingContainer();
container.put("@coefficient", new Float(3.14));- Author:
- Yoko Harada <[email protected]>
-
Nested Class Summary
-
Constructor Summary
ConstructorsConstructorDescriptionBiVariableMap(LocalContextProvider provider, boolean lazy) Constructs an empty map. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all of the mappings from this map.booleancontainsKey(Object key) Returnstrueif this map contains a mapping for the specified key.booleancontainsValue(Object value) Returnstrueif this map maps one or more keys to the specified value.entrySet()Returns aSetview of the mappings contained in this map.Returns the value in simple Java object to which the specified key is mapped, ornullif this map contains no mapping for the key.Returns the value in simple Java object to which the specified receiver and key is mapped, ornullif this map contains no mapping for the key in a given receiver.Returns a local variable behaviorString[]Returns Ruby's local variable names this map has.Returns Ruby's local variable values this map has.getMap()Returns a map whose value is a Java object not a BiVariable type object.getNames()Returns a list of all names in this map.getVariable(String name) Returns the value in BiVariable type to which the specified key is mapped, ornullif this map contains no mapping for the key.getVariable(RubyObject receiver, String name) Returns the value in BiVariable type to which the specified key is mapped, ornullif this map contains no mapping for the key.Returns a list of all values in this map.booleanisEmpty()Returnstrueif this map contains no key-value mappings.booleanisLazy()Returns true when eager retrieval is required or false when eager retrieval is unnecessary.keySet()Returns aSetview of the keys contained in this map.Associates the specified value with the specified key in this map.Associates the specified value with the specified key in this map.voidCopies all of the mappings from the specified map to this map.Removes the mapping for a key from this map if it is present in a top level.removeFrom(Object receiver, Object key) Removes the mapping for a key from this map if it is present in a given receiver.voidsetVariable(BiVariable var) voidsetVariable(RubyObject receiver, BiVariable var) intsize()Returns the number of key-value mappings in this map.toString()voidupdate(String name, BiVariable value) Adds a key-value pair of Ruby local variable to double array.voidupdateVariable(RubyObject receiver, String name, IRubyObject value, Class<? extends BiVariable> type) values()Returns aCollectionview of the values contained in this map.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
BiVariableMap
Constructs an empty map. Users do not instantiate this map. The map is created internally.- Parameters:
provider-lazy-
-
-
Method Details
-
getNames
Returns a list of all names in this map.- Returns:
- a List of all names.
-
getVariables
Returns a list of all values in this map.- Returns:
- a List of all values.
-
getRuntime
-
getLocalVariableBehavior
Returns a local variable behavior- Returns:
- a local variable behavior
-
getMap
Returns a map whose value is a Java object not a BiVariable type object.- Returns:
- a Map of key and value pair, in which values are simple Java objects.
-
size
public int size()Returns the number of key-value mappings in this map. -
isEmpty
public boolean isEmpty()Returnstrueif this map contains no key-value mappings. -
containsKey
Returnstrueif this map contains a mapping for the specified key.- Specified by:
containsKeyin interfaceMap<String,Object> - Parameters:
key- is a key to be tested its presence- Returns:
trueif this map contains a mapping for the specified key
-
containsValue
Returnstrueif this map maps one or more keys to the specified value.- Specified by:
containsValuein interfaceMap<String,Object> - Parameters:
value- is a Java object to be tested it presence- Returns:
- Returns
trueif this map maps one or more keys to the specified value.
-
get
Returns the value in simple Java object to which the specified key is mapped, ornullif this map contains no mapping for the key. -
get
Returns the value in simple Java object to which the specified receiver and key is mapped, ornullif this map contains no mapping for the key in a given receiver.- Parameters:
receiver- is a receiver object to get the value fromkey- is the key whose associated value is to be returned- Returns:
- the value in simple Java object to which the specified key is mapped, or
nullif this map contains no mapping for the key
-
getVariable
Returns the value in BiVariable type to which the specified key is mapped, ornullif this map contains no mapping for the key.- Parameters:
name- is the key whose associated BiVariable object is to be returned- Returns:
- the BiVariable type object to which the specified key is mapped, or
nullif this map contains no mapping for the key
-
getVariable
Returns the value in BiVariable type to which the specified key is mapped, ornullif this map contains no mapping for the key.- Parameters:
receiver- is a receiver object to get key-value pair fromname- is the key whose associated BiVariable object is to be returned- Returns:
- the BiVariable type object to which the specified key is mapped, or
nullif this map contains no mapping for the key
-
setVariable
-
setVariable
-
put
Associates the specified value with the specified key in this map. The values is a simple Java object. If the map previously contained a mapping for the key, the old value is replaced by the specified value. -
put
Associates the specified value with the specified key in this map. The values is a simple Java object. If the map previously contained a mapping for the key, the old value is replaced by the specified value.- Parameters:
receiver- a receiver object to associate a given key-value pair withkey- the key with which the specified value is to be associatedvalue- a simple Java object to be associated with the specified key- Returns:
- the previous value associated with
key, ornullif there was no mapping forkey.
-
getLocalVarNames
Returns Ruby's local variable names this map has. The returned array is mainly used to inject local variables to Ruby scripts while parsing.- Returns:
- String array of Ruby's local variable names
-
getLocalVarValues
Returns Ruby's local variable values this map has. The returned array is mainly used to inject local variables to Ruby scripts while evaluating.- Returns:
- IRubyObject array of Ruby's local variable names.
-
remove
Removes the mapping for a key from this map if it is present in a top level.Returns the value to which this map previously associated the key, or
nullif the map contained no mapping for the key. -
removeFrom
Removes the mapping for a key from this map if it is present in a given receiver.Returns the value to which this map previously associated the key, or
nullif the map contained no mapping for the key.- Parameters:
key- the key whose mapping is to be removed from the map- Returns:
- the previous value associated with
key, ornullif there was no mapping forkey.
-
putAll
Copies all of the mappings from the specified map to this map. -
clear
public void clear()Removes all of the mappings from this map. The map will be empty after this call returns. Ruby variables are also removed from Ruby instance. However, Ruby instance keep having global variable names with null value. -
keySet
Returns aSetview of the keys contained in this map. The set is backed by the map, so changes to the map should be reflected in the set, and vice-versa. However, the implementation does not reflect changes currently. -
values
Returns aCollectionview of the values contained in this map. The collection is backed by the map, so changes to the map should be reflected in the collection, and vice-versa. However, the implementation does not reflect changes currently. -
entrySet
Returns aSetview of the mappings contained in this map. The set is backed by the map, so changes to the map should be reflected in the set, and vice-versa. However, the implementation does not reflect changes currently. -
update
Adds a key-value pair of Ruby local variable to double array.- Parameters:
name- is a Ruby's local variable namevalue- is BiVariable type object corresponding to the name
-
updateVariable
public void updateVariable(RubyObject receiver, String name, IRubyObject value, Class<? extends BiVariable> type) -
isLazy
public boolean isLazy()Returns true when eager retrieval is required or false when eager retrieval is unnecessary.- Returns:
- true for eager retrieve, false for on-demand retrieval
-
toString
-