Package org.jruby.ext.set
Class RubySet
java.lang.Object
org.jruby.RubyBasicObject
org.jruby.RubyObject
org.jruby.ext.set.RubySet
- All Implemented Interfaces:
Serializable
,Cloneable
,Comparable<IRubyObject>
,Iterable
,Collection
,Set
,InstanceVariables
,InternalVariables
,IRubyObject
,CoreObjectType
- Direct Known Subclasses:
RubySortedSet
Native implementation of Ruby's Set (set.rb replacement).
- Author:
- kares
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.jruby.RubyObject
RubyObject.Data
Nested classes/interfaces inherited from class org.jruby.RubyBasicObject
RubyBasicObject.Finalizer
-
Field Summary
Fields inherited from class org.jruby.RubyObject
IVAR_INSPECTING_OBJECT_ALLOCATOR, OBJECT_ALLOCATOR, REIFYING_OBJECT_ALLOCATOR
Fields inherited from class org.jruby.RubyBasicObject
ALL_F, BASICOBJECT_ALLOCATOR, COMPARE_BY_IDENTITY_F, ERR_INSECURE_SET_INST_VAR, FALSE_F, FL_USHIFT, flags, FROZEN_F, IS_OVERLAID_F, metaClass, NEVER, NIL_F, REFINED_MODULE_F, STAMP_OFFSET, TAINTED_F, UNDEF, USER0_F, USER1_F, USER2_F, USER3_F, USER4_F, USER5_F, USER6_F, USER7_F, USER8_F, USER9_F, USERA_F, VAR_TABLE_OFFSET, varTable, varTableStamp
Fields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
add
(ThreadContext context, IRubyObject obj) Adds the given object to the set and returns self.add_p
(ThreadContext context, IRubyObject obj) Adds the given object to the set and returns self.boolean
addAll
(Collection coll) protected void
addImpl
(Ruby runtime, IRubyObject obj) Deprecated.protected void
addImpl
(ThreadContext context, IRubyObject obj) protected void
addImplSet
(ThreadContext context, RubySet set) classify
(ThreadContext context, Block block) void
clear()
void
clear
(ThreadContext context) protected void
Deprecated.protected void
clearImpl
(ThreadContext context) collect_bang
(ThreadContext context, Block block) compare_by_identity
(ThreadContext context) compare_by_identity_p
(ThreadContext context) boolean
boolean
containsAll
(Collection coll) static RubySet
create
(ThreadContext context, IRubyObject self, IRubyObject... ary) Creates a new set containing the given objects.delete
(ThreadContext context, IRubyObject obj) delete_if
(ThreadContext context, Block block) delete_p
(ThreadContext context, IRubyObject obj) Deletes the given object from the set and returns self.protected boolean
deleteImpl
(IRubyObject obj) protected void
deleteImplIterator
(IRubyObject obj, Iterator it) disjoint_p
(ThreadContext context, IRubyObject setArg) Returns true if the set and the given set have no element in common.divide
(ThreadContext context, Block block) Divides the set into a set of subsets according to the commonality defined by the given block.each
(ThreadContext context, Block block) protected final Set
<IRubyObject> elements()
protected Set
<IRubyObject> empty_p
(ThreadContext context) boolean
eql
(IRubyObject otherArg) method used for Hash key comparison (specialized for String, Symbol and Fixnum)flatten
(ThreadContext context) flatten_bang
(ThreadContext context) flatten_merge
(ThreadContext context, IRubyObject set) freeze
(ThreadContext context) hash
(ThreadContext context) Will return the hash code of this object.include_p
(ThreadContext context, IRubyObject obj) Returns true if the set contains the given object.initialize
(ThreadContext context, Block block) initialize(enum = nil, &block)protected IRubyObject
initialize
(ThreadContext context, IRubyObject[] args, Block block) initialize
(ThreadContext context, IRubyObject enume, Block block) initialize(enum = nil, &block)initialize_clone
(ThreadContext context, IRubyObject[] args) initialize_dup
(ThreadContext context, IRubyObject orig) inspect
(ThreadContext context) Returns a string containing a human-readable representation of obj.instance_variable_set
(IRubyObject name, IRubyObject value) rb_obj_ivar_set call-seq: obj.instance_variable_set(symbol, obj) => obj Sets the instance variable names by symbol to object, thereby frustrating the efforts of the class's author to attempt to provide proper encapsulation.boolean
intersect_p
(ThreadContext context, IRubyObject setArg) Returns true if the set and the given set have at least one element in common.boolean
isEmpty()
iterator()
join
(ThreadContext context) join
(ThreadContext context, IRubyObject sep) keep_if
(ThreadContext context, Block block) length
(ThreadContext context) protected final void
modifyCheck
(Ruby runtime) Deprecated.protected final void
modifyCheck
(ThreadContext context) static RubySet
Construct a new Set.static RubySet
Construct a new Set.op_and
(ThreadContext context, IRubyObject enume) Returns a new set built by merging the set and the elements of the given enumerable object.op_cmp
(ThreadContext context, IRubyObject other) op_diff
(ThreadContext context, IRubyObject enume) Returns a new set built by duplicating the set, removing every element that appears in the given enumerable object.op_eql
(ThreadContext context, IRubyObject other) op_equal
(ThreadContext context, IRubyObject other) rb_obj_equal Will by default use identity equality to compare objects.op_or
(ThreadContext context, IRubyObject enume) Returns a new set built by merging the set and the elements of the given enumerable object.op_xor
(ThreadContext context, IRubyObject enume) Returns a new set containing elements exclusive between the set and the given enumerable object.proper_subset_p
(ThreadContext context, IRubyObject setArg) proper_superset_p
(ThreadContext context, IRubyObject setArg) rb_clear
(ThreadContext context) rb_merge
(ThreadContext context, IRubyObject enume) rb_merge
(ThreadContext context, IRubyObject... args) Merges the elements of the given enumerable object to the set and returns self.reject_bang
(ThreadContext context, Block block) boolean
boolean
removeAll
(Collection coll) replace
(ThreadContext context, IRubyObject enume) Replaces the contents of the set with the contents of the given enumerable object and returns self.reset
(ThreadContext context) boolean
retainAll
(Collection coll) select_bang
(ThreadContext context, Block block) int
size()
subset_p
(ThreadContext context, IRubyObject setArg) subtract
(ThreadContext context, IRubyObject enume) Deletes every element that appears in the given enumerable object and returns self.superset_p
(ThreadContext context, IRubyObject setArg) taint
(ThreadContext context) Deprecated.to_a
(ThreadContext context) Converts the set to an array.to_set
(ThreadContext context, Block block) to_set
(ThreadContext context, IRubyObject[] args, Block block) Object[]
toArray()
Object[]
untaint
(ThreadContext context) Deprecated.Methods inherited from class org.jruby.RubyObject
attachToObjectSpace, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, convertToType, dig, dig1, dig2, eqlInternal, equalInternal, equals, finishObjectClass, getNativeClassIndex, hashCode, inspect, op_eqq, puts, specificEval, toRubyString, toString
Methods inherited from class org.jruby.RubyBasicObject
addFinalizer, addFinalizer, anyToString, asJavaString, asString, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkCallMethod, checkCallMethod, checkFrozen, checkStringType, cloneSetup, compareTo, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToInteger, convertToInteger, convertToString, copyInstanceVariablesInto, copySpecialInstanceVariables, dataGetStruct, dataGetStructChecked, dataWrapStruct, decode, display, dup, dupFinalizer, dupSetup, ensureInstanceVariablesSettable, eql_p, eql_p, equal_p, evalUnder, extend, fastGetInstanceVariable, fastGetInternalVariable, fastHasInstanceVariable, fastHasInternalVariable, fastSetInstanceVariable, fastSetInternalVariable, finishBasicObjectClass, forEachInstanceVariable, forEachInstanceVariableName, frozen_p, getCurrentContext, getFFIHandle, getFlag, getInstanceEvalClass, getInstanceEvalClass, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariables, getJavaClass, getMarshalVariableList, getMetaClass, getMetaClass, getNativeHandle, getNativeTypeIndex, getObjectId, getRuntime, getSingletonClass, getSingletonClassClone, getSingletonClassCloneAndAttach, getSingletonClassCloneAndAttach, getType, getVariable, getVariableCount, getVariableList, getVariableNameList, hash, hashyInspect, hasInstanceVariable, hasInstanceVariables, hasInternalVariable, hasVariables, id, infectBy, initialize, initialize_copy, initialize_copy, inspect, inspectHashCode, instance_eval, instance_eval, instance_eval, instance_eval, instance_eval, instance_exec, instance_of_p, instance_variable_defined_p, instance_variable_get, instance_variables, isBuiltin, isClass, isFalse, isFrozen, isImmediate, isModule, isNil, isSpecialConst, isSpecialObject, isTaint, isTrue, isUntrusted, kind_of_p, makeMetaClass, makeMetaClass, makeMetaClassBootstrap, method, method, method, method_missing, methods, methods, nil_p, nonFixnumHashCode, nonFixnumHashCode, OBJ_INIT_COPY, objInitCopy, op_match, op_not, op_not_equal, op_not_match, private_methods, protected_methods, public_methods, rbClone, rbClone, rbInspect, remove_instance_variable, removeFinalizers, removeInstanceVariable, removeInternalVariable, respond_to_p, respond_to_p, respondsTo, respondsToMissing, respondsToMissing, send, send, send, send, send, setFFIHandle, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setNativeHandle, setTaint, setUntrusted, setVariable, singleton_method, singleton_method, singleton_method_added, singleton_method_removed, singleton_method_undefined, singleton_methods, singletonClass, specificEval, specificEval, specificEval, specificEval, syncVariables, syncVariables, taint, tainted_p, testFrozen, testFrozen, to_a, to_s, to_s, toJava, trust, type, untrust, untrusted_p, validateInstanceVariable, validateInstanceVariable, validateInstanceVariable, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableRemove, variableTableStore, variableTableSync, yieldUnder, yieldUnder
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface org.jruby.runtime.builtin.IRubyObject
checkStringType19, dup, marshalLiveVariables
Methods inherited from interface java.util.Set
equals, hashCode, spliterator
-
Constructor Details
-
RubySet
-
-
Method Details
-
newSet
Construct a new Set. The Set class will be retrieved from the global namespace.- Parameters:
runtime
- the current runtime- Returns:
- a new Set
-
newSet
Construct a new Set.- Parameters:
runtime
- the current runtimemetaclass
- the class to assign to the new set- Returns:
- a new Set
-
create
Creates a new set containing the given objects. -
initialize
initialize(enum = nil, &block) -
initialize
initialize(enum = nil, &block) -
initialize
-
instance_variable_set
Description copied from class:RubyBasicObject
rb_obj_ivar_set call-seq: obj.instance_variable_set(symbol, obj) => obj Sets the instance variable names by symbol to object, thereby frustrating the efforts of the class's author to attempt to provide proper encapsulation. The variable did not have to exist prior to this call. class Fred def initialize(p1, p2) @a, @b = p1, p2 end end fred = Fred.new('cat', 99) fred.instance_variable_set(:@a, 'dog') #=> "dog" fred.instance_variable_set(:@c, 'cat') #=> "cat" fred.inspect #=> "#<Fred:0x401b3da8 @a=\"dog\", @b=99, @c=\"cat\">"- Overrides:
instance_variable_set
in classRubyBasicObject
- Parameters:
name
- of ivarvalue
- to set- Returns:
- value of old set ivar
-
initialize_dup
-
initialize_clone
-
freeze
- Overrides:
freeze
in classRubyBasicObject
-
length
-
empty_p
-
rb_clear
-
clearImpl
Deprecated. -
clearImpl
-
replace
Replaces the contents of the set with the contents of the given enumerable object and returns self. -
to_a
Converts the set to an array. The order of elements is uncertain.- Overrides:
to_a
in classRubyBasicObject
-
to_set
-
to_set
-
compare_by_identity
-
compare_by_identity_p
-
flatten_merge
-
flatten
-
flatten_bang
-
include_p
Returns true if the set contains the given object. -
superset_p
-
proper_superset_p
-
subset_p
-
proper_subset_p
-
intersect_p
Returns true if the set and the given set have at least one element in common. -
intersect
-
disjoint_p
Returns true if the set and the given set have no element in common. This method is the opposite of +intersect?+. -
each
-
add
Adds the given object to the set and returns self. -
addImpl
Deprecated. -
addImpl
-
addImplSet
-
add_p
Adds the given object to the set and returns self. If the object is already in the set, returns nil. -
delete
-
deleteImpl
-
deleteImplIterator
-
delete_p
Deletes the given object from the set and returns self. If the object is not in the set, returns nil. -
delete_if
-
keep_if
-
collect_bang
-
reject_bang
-
select_bang
-
rb_merge
-
rb_merge
Merges the elements of the given enumerable object to the set and returns self. -
subtract
Deletes every element that appears in the given enumerable object and returns self. -
op_or
Returns a new set built by merging the set and the elements of the given enumerable object. -
op_diff
Returns a new set built by duplicating the set, removing every element that appears in the given enumerable object. -
op_and
Returns a new set built by merging the set and the elements of the given enumerable object. -
op_xor
Returns a new set containing elements exclusive between the set and the given enumerable object. `(set ^ enum)` is equivalent to `((set | enum) - (set & enum))`. -
op_equal
Description copied from class:RubyBasicObject
rb_obj_equal Will by default use identity equality to compare objects. This follows the Ruby semantics. The name of this method doesn't follow the convention because hierarchy problems- Specified by:
op_equal
in interfaceIRubyObject
- Overrides:
op_equal
in classRubyBasicObject
-
reset
-
op_eql
-
eql
Description copied from class:RubyBasicObject
method used for Hash key comparison (specialized for String, Symbol and Fixnum)- Specified by:
eql
in interfaceIRubyObject
- Overrides:
eql
in classRubyBasicObject
- Returns:
- Will by default just call the Ruby method "eql?"
-
hash
Description copied from class:RubyBasicObject
Will return the hash code of this object. In comparison to MRI, this method will use the Java identity hash code instead of using rb_obj_id, since the usage of id in JRuby will incur the cost of some. ObjectSpace maintenance.- Overrides:
hash
in classRubyBasicObject
- Parameters:
context
- the current thread context- Returns:
- the hash value
-
classify
-
divide
Divides the set into a set of subsets according to the commonality defined by the given block. If the arity of the block is 2, elements o1 and o2 are in common if block.call(o1, o2) is true. Otherwise, elements o1 and o2 are in common if block.call(o1) == block.call(o2). e.g.: require 'set' numbers = Set[1, 3, 4, 6, 9, 10, 11] set = numbers.divide { |i,j| (i - j).abs == 1 } p set # => #<Set: {#<Set: {1}>, # #<Set: {11, 9, 10}>, # #<Set: {3, 4}>, # #<Set: {6}>}> -
op_cmp
- Overrides:
op_cmp
in classRubyBasicObject
-
join
-
join
-
inspect
Description copied from class:RubyBasicObject
Returns a string containing a human-readable representation of obj. If not overridden, uses theto_s
method to generate the string. [ 1, 2, 3..4, 'five' ].inspect #=> "[1, 2, 3..4, \"five\"]" Time.new.inspect #=> "Wed Apr 09 08:54:39 CDT 2003"- Specified by:
inspect
in interfaceIRubyObject
- Overrides:
inspect
in classRubyBasicObject
-
elements
-
elementsOrdered
-
modifyCheck
Deprecated. -
modifyCheck
-
size
public int size()- Specified by:
size
in interfaceCollection
- Specified by:
size
in interfaceSet
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection
- Specified by:
isEmpty
in interfaceSet
-
clear
public void clear()- Specified by:
clear
in interfaceCollection
- Specified by:
clear
in interfaceSet
-
clear
-
contains
- Specified by:
contains
in interfaceCollection
- Specified by:
contains
in interfaceSet
-
rawIterator
-
iterator
-
toArray
- Specified by:
toArray
in interfaceCollection
- Specified by:
toArray
in interfaceSet
-
toArray
- Specified by:
toArray
in interfaceCollection
- Specified by:
toArray
in interfaceSet
-
add
- Specified by:
add
in interfaceCollection
- Specified by:
add
in interfaceSet
-
remove
- Specified by:
remove
in interfaceCollection
- Specified by:
remove
in interfaceSet
-
containsAll
- Specified by:
containsAll
in interfaceCollection
- Specified by:
containsAll
in interfaceSet
-
addAll
- Specified by:
addAll
in interfaceCollection
- Specified by:
addAll
in interfaceSet
-
retainAll
- Specified by:
retainAll
in interfaceCollection
- Specified by:
retainAll
in interfaceSet
-
removeAll
- Specified by:
removeAll
in interfaceCollection
- Specified by:
removeAll
in interfaceSet
-
taint
Deprecated.- Overrides:
taint
in classRubyBasicObject
-
untaint
Deprecated.- Overrides:
untaint
in classRubyBasicObject
-