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.DataNested 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_ALLOCATORFields 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, varTableStampFields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(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.booleanaddAll(Collection coll) protected voidaddImpl(Ruby runtime, IRubyObject obj) Deprecated.protected voidaddImpl(ThreadContext context, IRubyObject obj) protected voidaddImplSet(ThreadContext context, RubySet set) classify(ThreadContext context, Block block) voidclear()voidclear(ThreadContext context) protected voidDeprecated.protected voidclearImpl(ThreadContext context) collect_bang(ThreadContext context, Block block) compare_by_identity(ThreadContext context) compare_by_identity_p(ThreadContext context) booleanbooleancontainsAll(Collection coll) static RubySetcreate(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 booleandeleteImpl(IRubyObject obj) protected voiddeleteImplIterator(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) booleaneql(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 IRubyObjectinitialize(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.booleanintersect_p(ThreadContext context, IRubyObject setArg) Returns true if the set and the given set have at least one element in common.booleanisEmpty()iterator()join(ThreadContext context) join(ThreadContext context, IRubyObject sep) keep_if(ThreadContext context, Block block) length(ThreadContext context) protected final voidmodifyCheck(Ruby runtime) Deprecated.protected final voidmodifyCheck(ThreadContext context) static RubySetConstruct a new Set.static RubySetConstruct 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) booleanbooleanremoveAll(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) booleanretainAll(Collection coll) select_bang(ThreadContext context, Block block) intsize()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, toStringMethods 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, yieldUnderMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface org.jruby.runtime.builtin.IRubyObject
checkStringType19, dup, marshalLiveVariablesMethods 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:RubyBasicObjectrb_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_setin classRubyBasicObject- Parameters:
name- of ivarvalue- to set- Returns:
- value of old set ivar
-
initialize_dup
-
initialize_clone
-
freeze
- Overrides:
freezein 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_ain 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:RubyBasicObjectrb_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_equalin interfaceIRubyObject- Overrides:
op_equalin classRubyBasicObject
-
reset
-
op_eql
-
eql
Description copied from class:RubyBasicObjectmethod used for Hash key comparison (specialized for String, Symbol and Fixnum)- Specified by:
eqlin interfaceIRubyObject- Overrides:
eqlin classRubyBasicObject- Returns:
- Will by default just call the Ruby method "eql?"
-
hash
Description copied from class:RubyBasicObjectWill 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:
hashin 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_cmpin classRubyBasicObject
-
join
-
join
-
inspect
Description copied from class:RubyBasicObjectReturns a string containing a human-readable representation of obj. If not overridden, uses theto_smethod 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:
inspectin interfaceIRubyObject- Overrides:
inspectin classRubyBasicObject
-
elements
-
elementsOrdered
-
modifyCheck
Deprecated. -
modifyCheck
-
size
public int size()- Specified by:
sizein interfaceCollection- Specified by:
sizein interfaceSet
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection- Specified by:
isEmptyin interfaceSet
-
clear
public void clear()- Specified by:
clearin interfaceCollection- Specified by:
clearin interfaceSet
-
clear
-
contains
- Specified by:
containsin interfaceCollection- Specified by:
containsin interfaceSet
-
rawIterator
-
iterator
-
toArray
- Specified by:
toArrayin interfaceCollection- Specified by:
toArrayin interfaceSet
-
toArray
- Specified by:
toArrayin interfaceCollection- Specified by:
toArrayin interfaceSet
-
add
- Specified by:
addin interfaceCollection- Specified by:
addin interfaceSet
-
remove
- Specified by:
removein interfaceCollection- Specified by:
removein interfaceSet
-
containsAll
- Specified by:
containsAllin interfaceCollection- Specified by:
containsAllin interfaceSet
-
addAll
- Specified by:
addAllin interfaceCollection- Specified by:
addAllin interfaceSet
-
retainAll
- Specified by:
retainAllin interfaceCollection- Specified by:
retainAllin interfaceSet
-
removeAll
- Specified by:
removeAllin interfaceCollection- Specified by:
removeAllin interfaceSet
-
taint
Deprecated.- Overrides:
taintin classRubyBasicObject
-
untaint
Deprecated.- Overrides:
untaintin classRubyBasicObject
-