public IRubyObject emptyJavaArray(ThreadContext context) { return ArrayUtils.emptyJavaArrayDirect(context, javaClass()); }
public IRubyObject emptyJavaArray(ThreadContext context) { return ArrayUtils.emptyJavaArrayDirect(context, javaClass()); }
public IRubyObject emptyJavaArray(ThreadContext context) { return ArrayUtils.emptyJavaArrayDirect(context, javaClass()); }
public IRubyObject emptyJavaArray(ThreadContext context) { return ArrayUtils.emptyJavaArrayDirect(context, javaClass()); }
private IRubyObject arrayRange(final ThreadContext context, final IRubyObject rFirst, final IRubyObject rLength) { final Object array = getObject(); final int arrayLength = Array.getLength( array ); if ( rFirst instanceof RubyFixnum && rLength instanceof RubyFixnum ) { int first = (int) ((RubyFixnum) rFirst).getLongValue(); int length = (int) ((RubyFixnum) rLength).getLongValue(); if ( length > arrayLength ) { throw context.runtime.newIndexError("length specifed is longer than array"); } if ( length <= 0 ) { return ArrayUtils.emptyJavaArrayDirect(context, array.getClass().getComponentType()); } first = first >= 0 ? first : arrayLength + first; return ArrayUtils.javaArraySubarrayDirect(context, array, first, length); } throw context.runtime.newTypeError("only Fixnum ranges supported"); }
private IRubyObject arrayRange(final ThreadContext context, final IRubyObject rFirst, final IRubyObject rLength) { final Object array = getObject(); final int arrayLength = Array.getLength( array ); if ( rFirst instanceof RubyFixnum && rLength instanceof RubyFixnum ) { int first = (int) ((RubyFixnum) rFirst).getLongValue(); int length = (int) ((RubyFixnum) rLength).getLongValue(); if ( length > arrayLength ) { throw context.runtime.newIndexError("length specifed is longer than array"); } if ( length <= 0 ) { return ArrayUtils.emptyJavaArrayDirect(context, array.getClass().getComponentType()); } first = first >= 0 ? first : arrayLength + first; return ArrayUtils.javaArraySubarrayDirect(context, array, first, length); } throw context.runtime.newTypeError("only Fixnum ranges supported"); }
public IRubyObject getRange(ThreadContext context, IRubyObject firstObj, IRubyObject lengthObj) { if (firstObj instanceof RubyFixnum && lengthObj instanceof RubyFixnum) { int first = (int)((RubyFixnum)firstObj).getLongValue(); int length = (int)((RubyFixnum)lengthObj).getLongValue(); if (length > Array.getLength(getObject())) { throw context.runtime.newIndexError("length specifed is longer than array"); } first = first >= 0 ? first : Array.getLength(getObject()) + first; if (length <= 0) { return ArrayUtils.emptyJavaArrayDirect(context, getObject().getClass().getComponentType()); } return ArrayUtils.javaArraySubarrayDirect(context, getObject(), first, length); } else { throw context.runtime.newTypeError("only Fixnum ranges supported"); } }
public IRubyObject getRange(ThreadContext context, IRubyObject firstObj, IRubyObject lengthObj) { if (firstObj instanceof RubyFixnum && lengthObj instanceof RubyFixnum) { int first = (int)((RubyFixnum)firstObj).getLongValue(); int length = (int)((RubyFixnum)lengthObj).getLongValue(); if (length > Array.getLength(getObject())) { throw context.runtime.newIndexError("length specifed is longer than array"); } first = first >= 0 ? first : Array.getLength(getObject()) + first; if (length <= 0) { return ArrayUtils.emptyJavaArrayDirect(context, getObject().getClass().getComponentType()); } return ArrayUtils.javaArraySubarrayDirect(context, getObject(), first, length); } else { throw context.runtime.newTypeError("only Fixnum ranges supported"); } }
private IRubyObject arrayRange(final ThreadContext context, final RubyRange range) { final Object array = getObject(); final int arrayLength = Array.getLength( array ); final IRubyObject rFirst = range.first(context); final IRubyObject rLast = range.last(context); if ( rFirst instanceof RubyFixnum && rLast instanceof RubyFixnum ) { int first = (int) ((RubyFixnum) rFirst).getLongValue(); int last = (int) ((RubyFixnum) rLast).getLongValue(); first = first >= 0 ? first : arrayLength + first; last = last >= 0 ? last : arrayLength + last; int newLength = last - first; if ( range.isExcludeEnd() ) newLength += 1; if ( newLength <= 0 ) { return ArrayUtils.emptyJavaArrayDirect(context, array.getClass().getComponentType()); } return ArrayUtils.javaArraySubarrayDirect(context, array, first, newLength); } throw context.runtime.newTypeError("only Integer ranges supported"); }
private IRubyObject arrayRange(final ThreadContext context, final RubyRange range) { final Object array = getObject(); final int arrayLength = Array.getLength( array ); final IRubyObject rFirst = range.first(context); final IRubyObject rLast = range.last(context); if ( rFirst instanceof RubyFixnum && rLast instanceof RubyFixnum ) { int first = (int) ((RubyFixnum) rFirst).getLongValue(); int last = (int) ((RubyFixnum) rLast).getLongValue(); first = first >= 0 ? first : arrayLength + first; last = last >= 0 ? last : arrayLength + last; int newLength = last - first; if ( range.isExcludeEnd() ) newLength += 1; if ( newLength <= 0 ) { return ArrayUtils.emptyJavaArrayDirect(context, array.getClass().getComponentType()); } return ArrayUtils.javaArraySubarrayDirect(context, array, first, newLength); } throw context.runtime.newTypeError("only Integer ranges supported"); }
public IRubyObject getRange(ThreadContext context, IRubyObject arg0) { int length = Array.getLength(getObject()); if (arg0 instanceof RubyRange) { RubyRange range = (RubyRange)arg0; if (range.first() instanceof RubyFixnum && range.last() instanceof RubyFixnum) { int first = (int)((RubyFixnum)range.first()).getLongValue(); int last = (int)((RubyFixnum)range.last()).getLongValue(); first = first >= 0 ? first : length + first; last = last >= 0 ? last : length + last; int newLength = last - first; if (range.exclude_end_p().isFalse()) newLength += 1; if (newLength <= 0) { return ArrayUtils.emptyJavaArrayDirect(context, getObject().getClass().getComponentType()); } return ArrayUtils.javaArraySubarrayDirect(context, getObject(), first, newLength); } else { throw context.runtime.newTypeError("only Fixnum ranges supported"); } } else { throw context.runtime.newTypeError(arg0, context.runtime.getRange()); } }
public IRubyObject getRange(ThreadContext context, IRubyObject arg0) { int length = Array.getLength(getObject()); if (arg0 instanceof RubyRange) { RubyRange range = (RubyRange)arg0; if (range.first() instanceof RubyFixnum && range.last() instanceof RubyFixnum) { int first = (int)((RubyFixnum)range.first()).getLongValue(); int last = (int)((RubyFixnum)range.last()).getLongValue(); first = first >= 0 ? first : length + first; last = last >= 0 ? last : length + last; int newLength = last - first; if (range.exclude_end_p().isFalse()) newLength += 1; if (newLength <= 0) { return ArrayUtils.emptyJavaArrayDirect(context, getObject().getClass().getComponentType()); } return ArrayUtils.javaArraySubarrayDirect(context, getObject(), first, newLength); } else { throw context.runtime.newTypeError("only Fixnum ranges supported"); } } else { throw context.runtime.newTypeError(arg0, context.runtime.getRange()); } }