Top Description Fields Constructors Methods
org.jruby.embed.internal

public Class BiVariableMap

extends Object
implements Map<String, Object>
Class Inheritance
All Implemented Interfaces
java.util.Map
Imports
java.lang.reflect.Constructor, .InvocationTargetException, java.util.ArrayList, .Collection, .HashMap, .LinkedHashSet, .List, .Map, .Set, org.jruby.Ruby, .RubyObject, org.jruby.embed.LocalVariableBehavior, org.jruby.embed.variable.BiVariable, .VariableInterceptor, org.jruby.runtime.DynamicScope, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.scope.ManyVarsDynamicScope

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]>

Field Summary

Modifier and TypeField and Description
private final boolean
private final LocalContextProvider
private List<BiVariable>
private List<String>

Constructor Summary

AccessConstructor and Description
public
BiVariableMap(LocalContextProvider provider, boolean lazy)

Constructs an empty map.

Method Summary

Modifier and TypeMethod and Description
private static String
checkKey(final Object key)

public void
clear()

Implements java.util.Map.clear.

Removes all of the mappings from this map.

public boolean

Returns:

true if this map contains a mapping for the specified key
containsKey
(final Object
is a key to be tested its presence
key
)

Implements java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.

public boolean

Returns:

Returns true if this map maps one or more keys to the specified value.
containsValue
(final Object
is a Java object to be tested it presence
value
)

Implements java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value.

public Set<Map.Entry<String, Object>>

Returns:

an entry set of a map
entrySet
()

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.

public Object

Returns:

the value in simple Java object to which the specified key is mapped, or null if this map contains no mapping for the key
get
(Object
is the key whose associated value is to be returned
key
)

Implements java.util.Map.get.

Returns the value in simple Java object to which the specified key is mapped, or null if this map contains no mapping for the key.

public Object

Returns:

the value in simple Java object to which the specified key is mapped, or null if this map contains no mapping for the key
get
(Object
is a receiver object to get the value from
receiver
,
Object
is the key whose associated value is to be returned
key
)

Returns the value in simple Java object to which the specified receiver and key is mapped, or null if this map contains no mapping for the key in a given receiver.

public LocalVariableBehavior

Returns:

a local variable behavior
getLocalVariableBehavior
()

Returns a local variable behavior

public String[]

Returns:

String array of Ruby's local variable names
getLocalVarNames
()

Returns Ruby's local variable names this map has.

public IRubyObject[]

Returns:

IRubyObject array of Ruby's local variable names.
getLocalVarValues
()

Returns Ruby's local variable values this map has.

public Map<String, Object>

Returns:

a Map of key and value pair, in which values are simple Java objects.
getMap
()

Returns a map whose value is a Java object not a BiVariable type object.

public List<String>

Returns:

a List of all names.
getNames
()

Returns a list of all names in this map.

private RubyObject
getReceiverObject(final Object receiver)

public Ruby
private RubyObject
public BiVariable

Returns:

the BiVariable type object to which the specified key is mapped, or null if this map contains no mapping for the key
getVariable
(final String
is the key whose associated BiVariable object is to be returned
name
)

Returns the value in BiVariable type to which the specified key is mapped, or null if this map contains no mapping for the key.

public BiVariable

Returns:

the BiVariable type object to which the specified key is mapped, or null if this map contains no mapping for the key
getVariable
(final RubyObject
is a receiver object to get key-value pair from
receiver
,
final String
is the key whose associated BiVariable object is to be returned
name
)

Returns the value in BiVariable type to which the specified key is mapped, or null if this map contains no mapping for the key.

public List<BiVariable>

Returns:

a List of all values.
getVariables
()

Returns a list of all values in this map.

pack-priv void
inject(final DynamicScope scope)

public boolean

Returns:

true if this map contains no key-value mappings
isEmpty
()

Implements java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.

public boolean

Returns:

true for eager retrieve, false for on-demand retrieval
isLazy
()

Returns true when eager retrieval is required or false when eager retrieval is unnecessary.

public Set<String>

Returns:

a set view of the keys contained in this map
keySet
()

Implements java.util.Map.keySet.

Returns a Set view of the keys contained in this map.

private static BiVariable
newVariable(final RubyObject receiver, final String name, final IRubyObject value, final Class<? extends BiVariable> type)

public Object

Returns:

the previous value associated with key, or null if there was no mapping for key.
put
(String
the key with which the specified value is to be associated
key
,
Object
a simple Java object to be associated with the specified key
value
)

Implements java.util.Map.put.

Associates the specified value with the specified key in this map.

public Object

Returns:

the previous value associated with key, or null if there was no mapping for key.
put
(Object
a receiver object to associate a given key-value pair with
receiver
,
String
the key with which the specified value is to be associated
key
,
Object
a simple Java object to be associated with the specified key
value
)

Associates the specified value with the specified key in this map.

public void
putAll(final Map<? extends String, ? extends Object>
mappings to be stored in this map
map
)

Implements java.util.Map.putAll.

Copies all of the mappings from the specified map to this map.

public Object

Returns:

the previous value associated with key, or null if there was no mapping for key.
remove
(final Object
the key whose mapping is to be removed from the map
key
)

Implements java.util.Map.remove.

Removes the mapping for a key from this map if it is present in a top level.

public Object

Returns:

the previous value associated with key, or null if there was no mapping for key.
removeFrom
(final Object receiver, final Object
the key whose mapping is to be removed from the map
key
)

Removes the mapping for a key from this map if it is present in a given receiver.

pack-priv void
retrieve(final IRubyObject receiver)

public void
public void
setVariable(final RubyObject receiver, final BiVariable var)

public int

Returns:

the number of key-value mappings in this map
size
()

Implements java.util.Map.size.

Returns the number of key-value mappings in this map.

pack-priv void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public void
update(final String
is a Ruby's local variable name
name
,
final BiVariable
is BiVariable type object corresponding to the name
value
)

Adds a key-value pair of Ruby local variable to double array.

public void
updateVariable(final RubyObject receiver, final String name, final IRubyObject value, final Class<? extends BiVariable> type)

public Collection<Object>

Returns:

a collection view of the values contained in this map
values
()

Implements java.util.Map.values.

Returns a Collection view of the values contained in this map.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

lazyback to summary
private final boolean lazy
providerback to summary
private final LocalContextProvider provider
variablesback to summary
private List<BiVariable> variables
varNamesback to summary
private List<String> varNames

Constructor Detail

BiVariableMapback to summary
public BiVariableMap(LocalContextProvider provider, boolean lazy)

Constructs an empty map. Users do not instantiate this map. The map is created internally.

Method Detail

checkKeyback to summary
private static String checkKey(final Object key)
clearback to summary
public void clear()

Implements java.util.Map.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.

Annotations
@Override
containsKeyback to summary
public boolean containsKey(final Object key)

Implements java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.

Parameters
key:Object

is a key to be tested its presence

Returns:boolean

true if this map contains a mapping for the specified key

Annotations
@Override
containsValueback to summary
public boolean containsValue(final Object value)

Implements java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value.

Parameters
value:Object

is a Java object to be tested it presence

Returns:boolean

Returns true if this map maps one or more keys to the specified value.

Annotations
@Override
entrySetback to summary
public Set<Map.Entry<String, Object>> entrySet()

Implements java.util.Map.entrySet.

Returns a Set view 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.

Returns:Set<Map.Entry<String, Object>>

an entry set of a map

Annotations
@Override
getback to summary
public Object get(Object key)

Implements java.util.Map.get.

Returns the value in simple Java object to which the specified key is mapped, or null if this map contains no mapping for the key.

Parameters
key:Object

is the key whose associated value is to be returned

Returns:Object

the value in simple Java object to which the specified key is mapped, or null if this map contains no mapping for the key

Annotations
@Override
getback to summary
public Object get(Object receiver, Object key)

Returns the value in simple Java object to which the specified receiver and key is mapped, or null if this map contains no mapping for the key in a given receiver.

Parameters
receiver:Object

is a receiver object to get the value from

key:Object

is the key whose associated value is to be returned

Returns:Object

the value in simple Java object to which the specified key is mapped, or null if this map contains no mapping for the key

getLocalVariableBehaviorback to summary
public LocalVariableBehavior getLocalVariableBehavior()

Returns a local variable behavior

Returns:LocalVariableBehavior

a local variable behavior

getLocalVarNamesback to summary
public String[] 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[]

String array of Ruby's local variable names

getLocalVarValuesback to summary
public IRubyObject[] 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[]

IRubyObject array of Ruby's local variable names.

getMapback to summary
public Map<String, Object> getMap()

Returns a map whose value is a Java object not a BiVariable type object.

Returns:Map<String, Object>

a Map of key and value pair, in which values are simple Java objects.

getNamesback to summary
public List<String> getNames()

Returns a list of all names in this map.

Returns:List<String>

a List of all names.

getReceiverObjectback to summary
private RubyObject getReceiverObject(final Object receiver)
getRuntimeback to summary
public Ruby getRuntime()
getTopSelfback to summary
private RubyObject getTopSelf()
getVariableback to summary
public BiVariable getVariable(final String name)

Returns the value in BiVariable type to which the specified key is mapped, or null if this map contains no mapping for the key.

Parameters
name:String

is the key whose associated BiVariable object is to be returned

Returns:BiVariable

the BiVariable type object to which the specified key is mapped, or null if this map contains no mapping for the key

getVariableback to summary
public BiVariable getVariable(final RubyObject receiver, final String name)

Returns the value in BiVariable type to which the specified key is mapped, or null if this map contains no mapping for the key.

Parameters
receiver:RubyObject

is a receiver object to get key-value pair from

name:String

is the key whose associated BiVariable object is to be returned

Returns:BiVariable

the BiVariable type object to which the specified key is mapped, or null if this map contains no mapping for the key

getVariablesback to summary
public List<BiVariable> getVariables()

Returns a list of all values in this map.

Returns:List<BiVariable>

a List of all values.

injectback to summary
pack-priv void inject(final DynamicScope scope)
isEmptyback to summary
public boolean isEmpty()

Implements java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.

Returns:boolean

true if this map contains no key-value mappings

Annotations
@Override
isLazyback to summary
public boolean isLazy()

Returns true when eager retrieval is required or false when eager retrieval is unnecessary.

Returns:boolean

true for eager retrieve, false for on-demand retrieval

keySetback to summary
public Set<String> keySet()

Implements java.util.Map.keySet.

Returns a Set view 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.

Returns:Set<String>

a set view of the keys contained in this map

Annotations
@Override
newVariableback to summary
private static BiVariable newVariable(final RubyObject receiver, final String name, final IRubyObject value, final Class<? extends BiVariable> type)
putback to summary
public Object put(String key, Object value)

Implements java.util.Map.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
key:String

the key with which the specified value is to be associated

value:Object

a simple Java object to be associated with the specified key

Returns:Object

the previous value associated with key, or null if there was no mapping for key.

Annotations
@Override
putback to summary
public Object put(Object receiver, String key, Object value)

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:Object

a receiver object to associate a given key-value pair with

key:String

the key with which the specified value is to be associated

value:Object

a simple Java object to be associated with the specified key

Returns:Object

the previous value associated with key, or null if there was no mapping for key.

putAllback to summary
public void putAll(final Map<? extends String, ? extends Object> map)

Implements java.util.Map.putAll.

Copies all of the mappings from the specified map to this map.

Parameters
map:Map<? extends String, ? extends Object>

mappings to be stored in this map

Annotations
@Override
removeback to summary
public Object remove(final Object key)

Implements java.util.Map.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 null if the map contained no mapping for the key.

Parameters
key:Object

the key whose mapping is to be removed from the map

Returns:Object

the previous value associated with key, or null if there was no mapping for key.

Annotations
@Override
removeFromback to summary
public Object removeFrom(final Object receiver, final Object key)

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 null if the map contained no mapping for the key.

Parameters
key:Object

the key whose mapping is to be removed from the map

Returns:Object

the previous value associated with key, or null if there was no mapping for key.

retrieveback to summary
pack-priv void retrieve(final IRubyObject receiver)
setVariableback to summary
public void setVariable(BiVariable var)
setVariableback to summary
public void setVariable(final RubyObject receiver, final BiVariable var)
sizeback to summary
public int size()

Implements java.util.Map.size.

Returns the number of key-value mappings in this map.

Returns:int

the number of key-value mappings in this map

Annotations
@Override
terminateback to summary
pack-priv void terminate()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
updateback to summary
public void update(final String name, final BiVariable value)

Adds a key-value pair of Ruby local variable to double array.

Parameters
name:String

is a Ruby's local variable name

value:BiVariable

is BiVariable type object corresponding to the name

updateVariableback to summary
public void updateVariable(final RubyObject receiver, final String name, final IRubyObject value, final Class<? extends BiVariable> type)
valuesback to summary
public Collection<Object> values()

Implements java.util.Map.values.

Returns a Collection view 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.

Returns:Collection<Object>

a collection view of the values contained in this map

Annotations
@Override