public RubyValue replace(int start, int length, RubyValue value) { int index = getRealIndex(start); if (value == RubyConstant.QNIL) { for (int i = 0; i < length; i++) { array_.remove(index); } return value; } if (length < 0) { throw new RubyException(RubyRuntime.IndexErrorClass, "negative length (" + length + ")"); } else if (0 == length) { if (value instanceof RubyArray) { array_.addAll(index, ((RubyArray) value).array_); } else { array_.add(index, value); } } else { for (int i = 0; i < length - 1; ++i) { array_.remove(index); } if (value instanceof RubyArray) { array_.remove(index); array_.addAll(index, ((RubyArray) value).array_); } else { array_.set(index, value); } } return value; }
private boolean remove(RubyValue v) { boolean r = false; while (array_.remove(v)) { r = true; } return r; }
private RubyArray delete_at(int begin, int length) { final int arraySize = array_.size(); if (begin > arraySize) { return null; } if (length < 0) { return null; } if (begin < 0) { begin += arraySize; } if (begin + length > arraySize) { length = arraySize - begin; if (length < 0) { length = 0; } } while (length > 0) { array_.remove(begin); length--; } return this; }
// @RubyLevelMethod(name="delete_if") public RubyValue delete_if(RubyBlock block) { for (int i = 0; i < array_.size(); ) { RubyValue r = block.invoke(this, (RubyValue) array_.get(i)); if (r.isTrue()) { array_.remove(i); } else { ++i; } } return this; }
// @RubyLevelMethod(name="delete") public RubyValue delete(RubyValue item, RubyBlock block) { boolean found = false; while (array_.remove(item)) { found = true; } if (block != null && !found) { return block.invoke(item); } else { return found ? item : RubyConstant.QNIL; } }
public RubyValue delete_at(int index) { if (index >= size()) { return RubyConstant.QNIL; } if (index < 0) { index += size(); } if (index < 0) { return RubyConstant.QNIL; } return (RubyValue) array_.remove(index); }
// @RubyLevelMethod(name="uniq!") public RubyValue uniq_danger() { boolean b = false; for (int i = 0; i < array_.size(); ++i) { for (int j = i + 1; j < array_.size(); ) { if (RubyAPI.testEqual((RubyValue) array_.get(i), (RubyValue) array_.get(j))) { array_.remove(j); b = true; } else { ++j; } } } if (!b) return RubyConstant.QNIL; return this; // return b ? this : RubyConstant.QNIL; }