org.jruby
Class RubyHash

java.lang.Object
  extended by org.jruby.RubyBasicObject
      extended by org.jruby.RubyObject
          extended by org.jruby.RubyHash
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<IRubyObject>, java.util.Map, InstanceVariables, InternalVariables, IRubyObject, CoreObjectType
Direct Known Subclasses:
RubyGlobal.StringOnlyRubyHash

public class RubyHash
extends RubyObject
implements java.util.Map

Implementation of the Hash class. Concurrency: no synchronization is required among readers, but all users must synchronize externally with writers.

See Also:
Serialized Form

Nested Class Summary
static class RubyHash.Visitor
           
 
Nested classes/interfaces inherited from class org.jruby.RubyObject
RubyObject.ObjectMethods
 
Nested classes/interfaces inherited from class org.jruby.RubyBasicObject
RubyBasicObject.BasicObjectMethods, RubyBasicObject.Finalizer
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
static long collisions
           
 
Fields inherited from class org.jruby.RubyObject
OBJECT_ALLOCATOR
 
Fields inherited from class org.jruby.RubyBasicObject
ALL_F, ERR_INSECURE_SET_INST_VAR, FALSE_F, FL_USHIFT, flags, FROZEN_F, metaClass, NEVER, NIL_F, TAINTED_F, UNDEF, UNTRUSTED_F, USER0_F, USER1_F, USER2_F, USER3_F, USER4_F, USER5_F, USER6_F, USER7_F
 
Fields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY
 
Constructor Summary
RubyHash(Ruby runtime)
           
RubyHash(Ruby runtime, IRubyObject defaultValue)
           
RubyHash(Ruby runtime, java.util.Map valueMap, IRubyObject defaultValue)
           
RubyHash(Ruby runtime, RubyClass klass)
           
 
Method Summary
 IRubyObject aref(IRubyObject key)
          Deprecated. use RubyHash.op_aref instead
 IRubyObject aset(IRubyObject key, IRubyObject value)
          Deprecated. use RubyHash.op_aset instead
 IRubyObject assoc(ThreadContext context, IRubyObject obj)
           
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 RubyHash convertToHash()
          Tries to convert this object to a Ruby Hash using the "to_hash" method.
static IRubyObject create(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block)
          rb_hash_s_create
static RubyClass createHashClass(Ruby runtime)
           
 IRubyObject default_proc()
          rb_hash_default_proc
 IRubyObject default_value_get(ThreadContext context)
           
 IRubyObject default_value_get(ThreadContext context, IRubyObject arg)
           
 IRubyObject default_value_get(ThreadContext context, IRubyObject[] args)
          Deprecated. 
 IRubyObject default_value_set(IRubyObject defaultValue)
          rb_hash_set_default
 RubyHash delete_if(ThreadContext context, Block block)
          rb_hash_delete_if
 IRubyObject delete_if19(ThreadContext context, Block block)
           
 IRubyObject delete(ThreadContext context, IRubyObject key, Block block)
          rb_hash_delete
 java.util.Set directEntrySet()
           
 java.util.Set directKeySet()
           
 java.util.Collection directValues()
           
 RubyHash each_key(ThreadContext context, Block block)
          rb_hash_each_key
 IRubyObject each_key19(ThreadContext context, Block block)
           
 RubyHash each_pair(ThreadContext context, Block block)
          rb_hash_each_pair
 IRubyObject each_pair19(ThreadContext context, Block block)
           
 RubyHash each_value(ThreadContext context, Block block)
          rb_hash_each_value
 IRubyObject each_value19(ThreadContext context, Block block)
           
 RubyHash each(ThreadContext context, Block block)
          rb_hash_each
 IRubyObject each19(ThreadContext context, Block block)
           
 RubyBoolean empty_p()
          rb_hash_empty_p
 java.util.Set entrySet()
           
 boolean equals(java.lang.Object other)
          This method is just a wrapper around the Ruby "==" method, provided so that RubyObjects can be used as keys in the Java HashMap object underlying RubyHash.
 IRubyObject fastARef(IRubyObject key)
           
 void fastASet(IRubyObject key, IRubyObject value)
           
 RubyHash fastASetChained(IRubyObject key, IRubyObject value)
           
 boolean fastDelete(IRubyObject key)
           
 IRubyObject fetch(ThreadContext context, IRubyObject[] args, Block block)
          rb_hash_fetch
 IRubyObject flatten(ThreadContext context)
           
 IRubyObject flatten(ThreadContext context, IRubyObject level)
           
 java.lang.Object get(java.lang.Object key)
           
 IRubyObject getIfNone()
           
 java.lang.Class getJavaClass()
          Will return the Java interface that most closely can represent this object, when working through JAva integration translations.
 int getNativeTypeIndex()
          This is overridden in the other concrete Java builtins to provide a fast way to determine what type they are.
 RubyBoolean has_key_p(IRubyObject key)
          rb_hash_has_key
 RubyBoolean has_value_p(ThreadContext context, IRubyObject expected)
          rb_hash_has_value
 boolean hasDefaultProc()
           
 IRubyObject hash19(ThreadContext context)
          rb_hash_hash
 IRubyObject index(ThreadContext context, IRubyObject expected)
          rb_hash_index
 IRubyObject index19(ThreadContext context, IRubyObject expected)
           
 RubyArray indices(ThreadContext context, IRubyObject[] indices)
          rb_hash_indexes
 RubyHash initialize_copy(ThreadContext context, IRubyObject other)
          rb_hash_replace
 IRubyObject initialize(IRubyObject[] args, Block block)
          rb_hash_initialize
 IRubyObject inspect(ThreadContext context)
          rb_hash_inspect
 RubyHash invert(ThreadContext context)
          rb_hash_invert
 boolean isEmpty()
           
 IRubyObject key(ThreadContext context, IRubyObject expected)
           
 RubyArray keys()
          rb_hash_keys
 java.util.Set keySet()
           
static void marshalTo(RubyHash hash, MarshalStream output)
           
 RubyHash merge_bang(ThreadContext context, IRubyObject other, Block block)
          rb_hash_update
 RubyHash merge(ThreadContext context, IRubyObject other, Block block)
          rb_hash_merge
 void modify()
          rb_hash_modify
static RubyHash newHash(Ruby runtime)
          rb_hash_new
static RubyHash newHash(Ruby runtime, java.util.Map valueMap, IRubyObject defaultValue)
          rb_hash_new
 IRubyObject op_aref(ThreadContext context, IRubyObject key)
          rb_hash_aref
 IRubyObject op_aset(IRubyObject key, IRubyObject value)
          Deprecated. 
 IRubyObject op_aset(ThreadContext context, IRubyObject key, IRubyObject value)
          rb_hash_aset
 IRubyObject op_aset19(ThreadContext context, IRubyObject key, IRubyObject value)
           
 IRubyObject op_eql19(ThreadContext context, IRubyObject other)
          rb_hash_eql
 IRubyObject op_equal(ThreadContext context, IRubyObject other)
          rb_obj_equal Will by default use identity equality to compare objects.
 IRubyObject op_equal19(ThreadContext context, IRubyObject other)
          rb_hash_equal
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 void putAll(java.util.Map map)
           
 IRubyObject rassoc(ThreadContext context, IRubyObject obj)
           
 RubyHash rb_clear()
          rb_hash_clear
 RubyFixnum rb_size()
          rb_hash_size
 RubyArray rb_values()
          rb_hash_values
 RubyHash rehash()
          rb_hash_rehash
 IRubyObject reject_bang(ThreadContext context, Block block)
          rb_hash_reject_bang
 RubyHash reject(ThreadContext context, Block block)
          rb_hash_reject
 IRubyObject reject19(ThreadContext context, Block block)
           
 java.lang.Object remove(java.lang.Object key)
           
 RubyHash replace(ThreadContext context, IRubyObject other)
          rb_hash_replace
 IRubyObject select(ThreadContext context, Block block)
          rb_hash_select
 IRubyObject select19(ThreadContext context, Block block)
           
 IRubyObject shift(ThreadContext context)
          rb_hash_shift
 int size()
           
 IRubyObject sort(ThreadContext context, Block block)
          rb_hash_sort
 RubyArray to_a()
          rb_hash_to_a
 RubyHash to_hash()
          rb_hash_to_hash
 IRubyObject to_s(ThreadContext context)
          rb_hash_to_s & to_s_hash
 IRubyObject to_s19(ThreadContext context)
           
static IRubyObject try_convert(ThreadContext context, IRubyObject recv, IRubyObject args)
           
static RubyHash unmarshalFrom(UnmarshalStream input, boolean defaultValue)
           
 RubyArray values_at(ThreadContext context, IRubyObject[] args)
          rb_hash_values_at
 java.util.Collection values()
           
 void visitAll(RubyHash.Visitor visitor)
           
 
Methods inherited from class org.jruby.RubyObject
as, attachToObjectSpace, callInit, checkFrozen, convertToType, createObjectClass, display, dup, eql_p, eqlInternal, equal_p, equalInternal, evalUnder, evalUnder, extend, freeze, frozen_p, hash, hashCode, id_deprecated, id, initialize_copy, initialize, inspect, instance_eval, instance_eval, instance_eval, instance_eval, instance_eval, instance_exec, instance_of_p, instance_variable_defined_p, instance_variable_get, instance_variable_set, instance_variables, kind_of_p, method, methods, nil_p, op_eqq, op_match, private_methods, protected_methods, public_methods, puts, rbClone, remove_instance_variable, respond_to_p, respond_to_p, send, send, send, send, send, singleton_methods, singleton_methods19, singletonMethods, specificEval, specificEval, specificEval, specificEval, specificEval, taint, tainted_p, to_java, to_s, toString, trust, type_deprecated, type, untaint, untrust, untrusted_p, validateInstanceVariable
 
Methods inherited from class org.jruby.RubyBasicObject
addFinalizer, anyToString, asJavaString, asString, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkStringType, compareTo, convertToArray, convertToFloat, convertToInteger, convertToInteger, convertToInteger, convertToString, copyInstanceVariablesInto, copySpecialInstanceVariables, createBasicObjectClass, dataGetStruct, dataWrapStruct, ensureInstanceVariablesSettable, eql, fastGetInstanceVariable, fastGetInternalVariable, fastHasInstanceVariable, fastHasInternalVariable, fastSetInstanceVariable, fastSetInternalVariable, getFlag, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariables, getMetaClass, getRuntime, getSingletonClass, getSingletonClassClone, getType, getVariable, getVariableCount, getVariableList, getVariableNameList, hasInstanceVariable, hasInternalVariable, hasVariables, infectBy, isClass, isFalse, isFrozen, isImmediate, isModule, isNil, isTaint, isTrue, isUntrusted, makeMetaClass, op_not_equal, op_not, removeFinalizers, removeInstanceVariable, removeInternalVariable, respondsTo, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setTaint, setUntrusted, setVariable, syncVariables, taint, testFrozen, testFrozen, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableGetSize, variableTableRemove, variableTableStore, variableTableSync
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
hashCode
 

Field Detail

collisions

public static long collisions
Constructor Detail

RubyHash

public RubyHash(Ruby runtime,
                RubyClass klass)

RubyHash

public RubyHash(Ruby runtime)

RubyHash

public RubyHash(Ruby runtime,
                IRubyObject defaultValue)

RubyHash

public RubyHash(Ruby runtime,
                java.util.Map valueMap,
                IRubyObject defaultValue)
Method Detail

createHashClass

public static RubyClass createHashClass(Ruby runtime)

getNativeTypeIndex

public int getNativeTypeIndex()
Description copied from class: RubyObject
This is overridden in the other concrete Java builtins to provide a fast way to determine what type they are. Will generally return a value from org.jruby.runtime.ClassIndex

Specified by:
getNativeTypeIndex in interface CoreObjectType
Overrides:
getNativeTypeIndex in class RubyObject
Returns:
the ClassIndex of the native type this object was constructed from
See Also:
org.jruby.runtime.ClassInde

create

public static IRubyObject create(ThreadContext context,
                                 IRubyObject recv,
                                 IRubyObject[] args,
                                 Block block)
rb_hash_s_create


try_convert

public static IRubyObject try_convert(ThreadContext context,
                                      IRubyObject recv,
                                      IRubyObject args)

newHash

public static final RubyHash newHash(Ruby runtime)
rb_hash_new


newHash

public static final RubyHash newHash(Ruby runtime,
                                     java.util.Map valueMap,
                                     IRubyObject defaultValue)
rb_hash_new


visitAll

public void visitAll(RubyHash.Visitor visitor)

initialize

public IRubyObject initialize(IRubyObject[] args,
                              Block block)
rb_hash_initialize


default_value_get

@Deprecated
public IRubyObject default_value_get(ThreadContext context,
                                                IRubyObject[] args)
Deprecated. 

rb_hash_default


default_value_get

public IRubyObject default_value_get(ThreadContext context)

default_value_get

public IRubyObject default_value_get(ThreadContext context,
                                     IRubyObject arg)

default_value_set

public IRubyObject default_value_set(IRubyObject defaultValue)
rb_hash_set_default


default_proc

public IRubyObject default_proc()
rb_hash_default_proc


modify

public void modify()
rb_hash_modify


inspect

public IRubyObject inspect(ThreadContext context)
rb_hash_inspect


rb_size

public RubyFixnum rb_size()
rb_hash_size


empty_p

public RubyBoolean empty_p()
rb_hash_empty_p


to_a

public RubyArray to_a()
rb_hash_to_a

Overrides:
to_a in class RubyObject

to_s

public IRubyObject to_s(ThreadContext context)
rb_hash_to_s & to_s_hash


to_s19

public IRubyObject to_s19(ThreadContext context)

rehash

public RubyHash rehash()
rb_hash_rehash


to_hash

public RubyHash to_hash()
rb_hash_to_hash


convertToHash

public RubyHash convertToHash()
Description copied from class: RubyBasicObject
Tries to convert this object to a Ruby Hash using the "to_hash" method.

Specified by:
convertToHash in interface IRubyObject
Overrides:
convertToHash in class RubyBasicObject
Returns:

fastASet

public final void fastASet(IRubyObject key,
                           IRubyObject value)

fastASetChained

public final RubyHash fastASetChained(IRubyObject key,
                                      IRubyObject value)

op_aset

@Deprecated
public IRubyObject op_aset(IRubyObject key,
                                      IRubyObject value)
Deprecated. 


op_aset

public IRubyObject op_aset(ThreadContext context,
                           IRubyObject key,
                           IRubyObject value)
rb_hash_aset


op_aset19

public IRubyObject op_aset19(ThreadContext context,
                             IRubyObject key,
                             IRubyObject value)

aset

public IRubyObject aset(IRubyObject key,
                        IRubyObject value)
Deprecated. use RubyHash.op_aset instead

Note: this is included as a compatibility measure for AR-JDBC


aref

public IRubyObject aref(IRubyObject key)
Deprecated. use RubyHash.op_aref instead

Note: this is included as a compatibility measure for Mongrel+JRuby


fastARef

public final IRubyObject fastARef(IRubyObject key)

op_equal19

public IRubyObject op_equal19(ThreadContext context,
                              IRubyObject other)
rb_hash_equal


op_eql19

public IRubyObject op_eql19(ThreadContext context,
                            IRubyObject other)
rb_hash_eql


op_aref

public IRubyObject op_aref(ThreadContext context,
                           IRubyObject key)
rb_hash_aref


hash19

public IRubyObject hash19(ThreadContext context)
rb_hash_hash


fetch

public IRubyObject fetch(ThreadContext context,
                         IRubyObject[] args,
                         Block block)
rb_hash_fetch


has_key_p

public RubyBoolean has_key_p(IRubyObject key)
rb_hash_has_key


has_value_p

public RubyBoolean has_value_p(ThreadContext context,
                               IRubyObject expected)
rb_hash_has_value


each

public RubyHash each(ThreadContext context,
                     Block block)
rb_hash_each


each19

public IRubyObject each19(ThreadContext context,
                          Block block)

each_pair

public RubyHash each_pair(ThreadContext context,
                          Block block)
rb_hash_each_pair


each_pair19

public IRubyObject each_pair19(ThreadContext context,
                               Block block)

each_value

public RubyHash each_value(ThreadContext context,
                           Block block)
rb_hash_each_value


each_value19

public IRubyObject each_value19(ThreadContext context,
                                Block block)

each_key

public RubyHash each_key(ThreadContext context,
                         Block block)
rb_hash_each_key


each_key19

public IRubyObject each_key19(ThreadContext context,
                              Block block)

sort

public IRubyObject sort(ThreadContext context,
                        Block block)
rb_hash_sort


index

public IRubyObject index(ThreadContext context,
                         IRubyObject expected)
rb_hash_index


index19

public IRubyObject index19(ThreadContext context,
                           IRubyObject expected)

key

public IRubyObject key(ThreadContext context,
                       IRubyObject expected)

indices

public RubyArray indices(ThreadContext context,
                         IRubyObject[] indices)
rb_hash_indexes


keys

public RubyArray keys()
rb_hash_keys


rb_values

public RubyArray rb_values()
rb_hash_values


op_equal

public IRubyObject op_equal(ThreadContext context,
                            IRubyObject other)
Description copied from class: RubyObject
rb_obj_equal Will by default use identity equality to compare objects. This follows the Ruby semantics.

Specified by:
op_equal in interface IRubyObject
Overrides:
op_equal in class RubyObject

shift

public IRubyObject shift(ThreadContext context)
rb_hash_shift


fastDelete

public final boolean fastDelete(IRubyObject key)

delete

public IRubyObject delete(ThreadContext context,
                          IRubyObject key,
                          Block block)
rb_hash_delete


select

public IRubyObject select(ThreadContext context,
                          Block block)
rb_hash_select


select19

public IRubyObject select19(ThreadContext context,
                            Block block)

delete_if

public RubyHash delete_if(ThreadContext context,
                          Block block)
rb_hash_delete_if


delete_if19

public IRubyObject delete_if19(ThreadContext context,
                               Block block)

reject

public RubyHash reject(ThreadContext context,
                       Block block)
rb_hash_reject


reject19

public IRubyObject reject19(ThreadContext context,
                            Block block)

reject_bang

public IRubyObject reject_bang(ThreadContext context,
                               Block block)
rb_hash_reject_bang


rb_clear

public RubyHash rb_clear()
rb_hash_clear


invert

public RubyHash invert(ThreadContext context)
rb_hash_invert


merge_bang

public RubyHash merge_bang(ThreadContext context,
                           IRubyObject other,
                           Block block)
rb_hash_update


merge

public RubyHash merge(ThreadContext context,
                      IRubyObject other,
                      Block block)
rb_hash_merge


initialize_copy

public RubyHash initialize_copy(ThreadContext context,
                                IRubyObject other)
rb_hash_replace


replace

public RubyHash replace(ThreadContext context,
                        IRubyObject other)
rb_hash_replace


values_at

public RubyArray values_at(ThreadContext context,
                           IRubyObject[] args)
rb_hash_values_at


assoc

public IRubyObject assoc(ThreadContext context,
                         IRubyObject obj)

rassoc

public IRubyObject rassoc(ThreadContext context,
                          IRubyObject obj)

flatten

public IRubyObject flatten(ThreadContext context)

flatten

public IRubyObject flatten(ThreadContext context,
                           IRubyObject level)

hasDefaultProc

public boolean hasDefaultProc()

getIfNone

public IRubyObject getIfNone()

marshalTo

public static void marshalTo(RubyHash hash,
                             MarshalStream output)
                      throws java.io.IOException
Throws:
java.io.IOException

unmarshalFrom

public static RubyHash unmarshalFrom(UnmarshalStream input,
                                     boolean defaultValue)
                              throws java.io.IOException
Throws:
java.io.IOException

getJavaClass

public java.lang.Class getJavaClass()
Description copied from class: RubyBasicObject
Will return the Java interface that most closely can represent this object, when working through JAva integration translations.

Specified by:
getJavaClass in interface IRubyObject
Overrides:
getJavaClass in class RubyBasicObject
Returns:
Class

size

public int size()
Specified by:
size in interface java.util.Map

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map

remove

public java.lang.Object remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map

putAll

public void putAll(java.util.Map map)
Specified by:
putAll in interface java.util.Map

clear

public void clear()
Specified by:
clear in interface java.util.Map

equals

public boolean equals(java.lang.Object other)
Description copied from class: RubyObject
This method is just a wrapper around the Ruby "==" method, provided so that RubyObjects can be used as keys in the Java HashMap object underlying RubyHash.

Specified by:
equals in interface java.util.Map
Overrides:
equals in class RubyObject

keySet

public java.util.Set keySet()
Specified by:
keySet in interface java.util.Map

directKeySet

public java.util.Set directKeySet()

values

public java.util.Collection values()
Specified by:
values in interface java.util.Map

directValues

public java.util.Collection directValues()

entrySet

public java.util.Set entrySet()
Specified by:
entrySet in interface java.util.Map

directEntrySet

public java.util.Set directEntrySet()


Copyright © 2002-2007 JRuby Team. All Rights Reserved.