/** * Returns <tt>true</tt> if this map contains a mapping for the specified * key. * * @param key is a key to be tested its presence * @return <tt>true</tt> if this map contains a mapping for the specified key */ @Override public boolean containsKey(final Object key) { if ( varNames == null || key == null ) return false; return varNames.contains( checkKey(key) ); }
/** * Returns <tt>true</tt> if this map contains a mapping for the specified * key. * * @param key is a key to be tested its presence * @return <tt>true</tt> if this map contains a mapping for the specified key */ public boolean containsKey(Object key) { if (varNames == null) return false; checkKey(key); return varNames.contains((String)key); }
/** * Returns <tt>true</tt> if this map contains a mapping for the specified * key. * * @param key is a key to be tested its presence * @return <tt>true</tt> if this map contains a mapping for the specified key */ public boolean containsKey(Object key) { if (varNames == null) return false; checkKey(key); return varNames.contains((String)key); }
/** * Returns <tt>true</tt> if this map contains a mapping for the specified * key. * * @param key is a key to be tested its presence * @return <tt>true</tt> if this map contains a mapping for the specified key */ @Override public boolean containsKey(final Object key) { if ( varNames == null || key == null ) return false; return varNames.contains( checkKey(key) ); }
/** * Removes the mapping for a key from this map if it is present in a given * receiver. * * <p>Returns the value to which this map previously associated the key, * or <tt>null</tt> if the map contained no mapping for the key. * @param key the key whose mapping is to be removed from the map * @return the previous value associated with <tt>key</tt>, or * <tt>null</tt> if there was no mapping for <tt>key</tt>. */ public V removeFrom(Object receiver, Object key) { if (varNames == null) return null; checkKey(key); RubyObject robj = getReceiverObject(receiver); String name = ((String)key).intern(); for (int i=0; i<varNames.size(); i++) { if (name.equals(varNames.get(i))) { BiVariable var = variables.get(i); if (var.getReceiver() == robj) { varNames.remove(i); BiVariable v = variables.remove(i); v.remove(); return (V)v.getJavaObject(); } } } return null; }
/** * Removes the mapping for a key from this map if it is present in a given * receiver. * * <p>Returns the value to which this map previously associated the key, * or <tt>null</tt> if the map contained no mapping for the key. * @param key the key whose mapping is to be removed from the map * @return the previous value associated with <tt>key</tt>, or * <tt>null</tt> if there was no mapping for <tt>key</tt>. */ public Object removeFrom(final Object receiver, final Object key) { if ( variables == null ) return null; checkKey(key); final RubyObject robj = getReceiverObject(receiver); for ( int i = 0; i < size(); i++ ) { if ( ((String) key).equals( varNames.get(i) ) ) { final BiVariable var = variables.get(i); if ( var.isReceiverIdentical(robj) ) { varNames.remove(i); variables.remove(i); return var.getJavaObject(); } } } return null; }
/** * Removes the mapping for a key from this map if it is present in a given * receiver. * * <p>Returns the value to which this map previously associated the key, * or <tt>null</tt> if the map contained no mapping for the key. * @param key the key whose mapping is to be removed from the map * @return the previous value associated with <tt>key</tt>, or * <tt>null</tt> if there was no mapping for <tt>key</tt>. */ public V removeFrom(Object receiver, Object key) { if (varNames == null) return null; checkKey(key); RubyObject robj = getReceiverObject(receiver); String name = ((String)key).intern(); for (int i=0; i<varNames.size(); i++) { if (name.equals(varNames.get(i))) { BiVariable var = variables.get(i); if (var.getReceiver() == robj) { varNames.remove(i); BiVariable v = variables.remove(i); v.remove(); return (V)v.getJavaObject(); } } } return null; }
/** * Removes the mapping for a key from this map if it is present in a given * receiver. * * <p>Returns the value to which this map previously associated the key, * or <tt>null</tt> if the map contained no mapping for the key. * @param key the key whose mapping is to be removed from the map * @return the previous value associated with <tt>key</tt>, or * <tt>null</tt> if there was no mapping for <tt>key</tt>. */ public Object removeFrom(final Object receiver, final Object key) { if ( variables == null ) return null; checkKey(key); final RubyObject robj = getReceiverObject(receiver); for ( int i = 0; i < size(); i++ ) { if ( ((String) key).equals( varNames.get(i) ) ) { final BiVariable var = variables.get(i); if ( var.isReceiverIdentical(robj) ) { varNames.remove(i); variables.remove(i); return var.getJavaObject(); } } } return null; }
/** * Returns the value in simple Java object to which the specified receiver * and key is mapped, or {@code null} if this map contains no mapping * for the key in a given receiver. * * @param receiver is a receiver object to get the value from * @param key is the key whose associated value is to be returned * @return the value in simple Java object to which the specified key is mapped, or * {@code null} if this map contains no mapping for the key */ public V get(Object receiver, Object key) { checkKey(key); RubyObject robj = getReceiverObject(receiver); // attemps to retrieve global variables if (lazy) VariableInterceptor.tryLazyRetrieval(provider.getLocalVariableBehavior(), this, robj, key); BiVariable var = getVariable(robj, (String)key); if (var == null) return null; else return (V) var.getJavaObject(); }
/** * Returns the value in simple Java object to which the specified receiver * and key is mapped, or {@code null} if this map contains no mapping * for the key in a given receiver. * * @param receiver is a receiver object to get the value from * @param key is the key whose associated value is to be returned * @return the value in simple Java object to which the specified key is mapped, or * {@code null} if this map contains no mapping for the key */ public V get(Object receiver, Object key) { checkKey(key); RubyObject robj = getReceiverObject(receiver); // attemps to retrieve global variables if (lazy) VariableInterceptor.tryLazyRetrieval(provider.getLocalVariableBehavior(), this, robj, key); BiVariable var = getVariable(robj, (String)key); if (var == null) return null; else return (V) var.getJavaObject(); }
/** * Returns the value in simple Java object to which the specified receiver * and key is mapped, or {@code null} if this map contains no mapping * for the key in a given receiver. * * @param receiver is a receiver object to get the value from * @param key is the key whose associated value is to be returned * @return the value in simple Java object to which the specified key is mapped, or * {@code null} if this map contains no mapping for the key */ public Object get(Object receiver, Object key) { checkKey(key); final RubyObject robj = getReceiverObject(receiver); // attemps to retrieve global variables if ( isLazy() ) { VariableInterceptor.tryLazyRetrieval(provider.getLocalVariableBehavior(), this, robj, key); } BiVariable var = getVariable(robj, (String) key); return var == null ? null : var.getJavaObject(); }
/** * Returns the value in simple Java object to which the specified receiver * and key is mapped, or {@code null} if this map contains no mapping * for the key in a given receiver. * * @param receiver is a receiver object to get the value from * @param key is the key whose associated value is to be returned * @return the value in simple Java object to which the specified key is mapped, or * {@code null} if this map contains no mapping for the key */ public Object get(Object receiver, Object key) { checkKey(key); final RubyObject robj = getReceiverObject(receiver); // attemps to retrieve global variables if ( isLazy() ) { VariableInterceptor.tryLazyRetrieval(provider.getLocalVariableBehavior(), this, robj, key); } BiVariable var = getVariable(robj, (String) key); return var == null ? null : var.getJavaObject(); }
/** * 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. * * @param receiver a receiver object to associate a given key-value pair with * @param key the key with which the specified value is to be associated * @param value a simple Java object to be associated with the specified key * @return the previous value associated with <tt>key</tt>, or * <tt>null</tt> if there was no mapping for <tt>key</tt>. */ public Object put(Object receiver, String key, Object value) { checkKey(key); final RubyObject robj = getReceiverObject(receiver); final String name = key.intern(); BiVariable var = getVariable(robj, name); Object oldValue = null; if ( var != null ) { // updates oldValue = var.getJavaObject(); var.setJavaObject(robj.getRuntime(), value); } else { // creates new value var = VariableInterceptor.getVariableInstance(provider.getLocalVariableBehavior(), robj, name, value); if ( var != null ) update(name, var); } return oldValue; }
/** * 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. * * @param receiver a receiver object to associate a given key-value pair with * @param key the key with which the specified value is to be associated * @param value a simple Java object to be associated with the specified key * @return the previous value associated with <tt>key</tt>, or * <tt>null</tt> if there was no mapping for <tt>key</tt>. */ public V put (Object receiver, K key, V value) { checkKey(key); RubyObject robj = getReceiverObject(receiver); String name = ((String)key).intern(); BiVariable v = getVariable(robj, name); Object oldValue = null; if (v != null) { // updates oldValue = v.getJavaObject(); v.setJavaObject(robj.getRuntime(), value); } else { // creates new value v = VariableInterceptor.getVariableInstance(provider.getLocalVariableBehavior(), robj, name, value); if (v != null) { update(name, v); } } return (V)oldValue; }
/** * 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. * * @param receiver a receiver object to associate a given key-value pair with * @param key the key with which the specified value is to be associated * @param value a simple Java object to be associated with the specified key * @return the previous value associated with <tt>key</tt>, or * <tt>null</tt> if there was no mapping for <tt>key</tt>. */ public V put (Object receiver, K key, V value) { checkKey(key); RubyObject robj = getReceiverObject(receiver); String name = ((String)key).intern(); BiVariable v = getVariable(robj, name); Object oldValue = null; if (v != null) { // updates oldValue = v.getJavaObject(); v.setJavaObject(robj.getRuntime(), value); } else { // creates new value v = VariableInterceptor.getVariableInstance(provider.getLocalVariableBehavior(), robj, name, value); if (v != null) { update(name, v); } } return (V)oldValue; }
/** * 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. * * @param receiver a receiver object to associate a given key-value pair with * @param key the key with which the specified value is to be associated * @param value a simple Java object to be associated with the specified key * @return the previous value associated with <tt>key</tt>, or * <tt>null</tt> if there was no mapping for <tt>key</tt>. */ public Object put(Object receiver, String key, Object value) { checkKey(key); final RubyObject robj = getReceiverObject(receiver); final String name = key.intern(); BiVariable var = getVariable(robj, name); Object oldValue = null; if ( var != null ) { // updates oldValue = var.getJavaObject(); var.setJavaObject(robj.getRuntime(), value); } else { // creates new value var = VariableInterceptor.getVariableInstance(provider.getLocalVariableBehavior(), robj, name, value); if ( var != null ) update(name, var); } return oldValue; }