Module: javajava::util::List
- Defined in:
- lib/jactive_support/core_ext/to_java_list.rb,
lib/jactive_support/java_ext/list.rb
Constant Summary collapse
- FrozenError =
TypeError
Instance Method Summary collapse
- #clear ⇒ Object
- #inspect ⇒ Object
- #iterate ⇒ Object
- #last(*args) ⇒ Object
- #map! ⇒ Object (also: #collect!)
- #push(*args) ⇒ Object
- #to_java_list ⇒ Object
Instance Method Details
#clear ⇒ Object
59 60 61 62 63 |
# File 'lib/jactive_support/java_ext/list.rb', line 59 def clear raise FrozenError, "can't modify frozen list" if frozen? super self end |
#inspect ⇒ Object
10 11 12 13 |
# File 'lib/jactive_support/java_ext/list.rb', line 10 def inspect content = map{|e| e.inspect}.join(', ') "JavaList[#{content}]" end |
#iterate ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/jactive_support/java_ext/list.rb', line 15 def iterate return enum_for(:iterate) unless block_given? it = listIterator while it.next? ob = it.next yield(it,ob) end end |
#last(*args) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/jactive_support/java_ext/list.rb', line 38 def last(*args) raise ArgumentError, "wrong # of arguments(#{args.size} for 1)" if args.size > 1 if args.size == 1 n = args.first raise TypeError, "Can't convert #{n} into Integer" unless n.respond_to?(:to_int) n = n.to_int raise TypeError, "#to_int should return Integer" unless n.kind_of?(Integer) raise ArgumentError, "negative array size" if n < 0 it = listIterator(size) ret = [] while n > 0 && it.previous? ret.unshift it.previous n -= 1 end ret elsif size > 0 self.get(size-1) end end |
#map! ⇒ Object Also known as: collect!
24 25 26 27 28 29 |
# File 'lib/jactive_support/java_ext/list.rb', line 24 def map! raise FrozenError, "can't modify frozen iterable" if frozen? return enum_for(:map!) unless block_given? iterate{|it, ob| it.set(yield(ob))} self end |
#push(*args) ⇒ Object
32 33 34 35 36 |
# File 'lib/jactive_support/java_ext/list.rb', line 32 def push(*args) raise FrozenError, "can't modify frozen iterable" if frozen? && ( RUBY_VERSION >= '1.9' || args.size > 0 ) args.each{|a| add(a)} self end |
#to_java_list ⇒ Object
8 9 10 |
# File 'lib/jactive_support/core_ext/to_java_list.rb', line 8 def to_java_list self end |