Module: javajava::lang::Iterable

Defined in:
lib/jactive_support/java_ext/iterable.rb

Constant Summary collapse

FrozenError =
TypeError

Instance Method Summary collapse

Instance Method Details

#clearObject

Raises:



69
70
71
72
73
# File 'lib/jactive_support/java_ext/iterable.rb', line 69

def clear
  raise FrozenError, "can't modify frozen iterable" if frozen?
  iterate {|it, o| it.remove}
  self
end

#delete_ifObject

Raises:



19
20
21
22
23
24
25
26
# File 'lib/jactive_support/java_ext/iterable.rb', line 19

def delete_if
  raise FrozenError, "can't modify frozen iterable" if frozen?
  return enum_for(:delete_if) unless block_given?
  iterate do |it,ob|
    it.remove if yield(ob)
  end
  self
end

#empty?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/jactive_support/java_ext/iterable.rb', line 65

def empty?
  !iterator.next?
end

#iterateObject



10
11
12
13
14
15
16
17
# File 'lib/jactive_support/java_ext/iterable.rb', line 10

def iterate
  return enum_for(:iterate) unless block_given?
  it = iterator
  while it.next?
    ob = it.next
    yield(it,ob)
  end
end

#reject!Object

Raises:



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jactive_support/java_ext/iterable.rb', line 28

def reject!
  raise FrozenError, "can't modify frozen iterable" if frozen?
  return enum_for(:reject!) unless block_given?
  ret = nil
  iterate do |it,ob|
    if yield(ob)
      it.remove 
      ret = self
    end
  end
  ret
end

#shift(*args) ⇒ Object

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/jactive_support/java_ext/iterable.rb', line 41

def shift(*args)
  raise ArgumentError, "wrong # of arguments(#{args.size} for 1)" if args.size > 1
  raise FrozenError, "can't modify frozen iterable" if frozen?
  it = iterator
  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
    ret = []
    while n > 0 && it.next?
      ret << it.next
      it.remove
      n -= 1
    end
    ret
  elsif it.next?
    ret = it.next 
    it.remove
    ret
  end
end