本文整理了Java中org.jruby.Ruby.getRange
方法的一些代码示例,展示了Ruby.getRange
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.getRange
方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:getRange
暂无
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
public static RubyRange newRange(Ruby runtime, ThreadContext context, IRubyObject begin, IRubyObject end, boolean isExclusive) {
RubyRange range = new RubyRange(runtime, runtime.getRange());
range.init(context, begin, end, isExclusive);
return range;
}
代码示例来源:origin: org.jruby/jruby-complete
public IRubyObject getRange(ThreadContext context, IRubyObject arg0) {
if ( arg0 instanceof RubyRange ) {
return arrayRange(context, (RubyRange) arg0);
}
throw context.runtime.newTypeError(arg0, context.runtime.getRange());
}
代码示例来源:origin: org.jruby/jruby-complete
public static RubyRange newRange(ThreadContext context, IRubyObject begin, IRubyObject end, boolean isExclusive) {
RubyRange range = new RubyRange(context.runtime, context.runtime.getRange());
range.init(context, begin, end, isExclusive);
return range;
}
代码示例来源:origin: org.jruby/jruby-core
public IRubyObject getRange(ThreadContext context, IRubyObject arg0) {
if ( arg0 instanceof RubyRange ) {
return arrayRange(context, (RubyRange) arg0);
}
throw context.runtime.newTypeError(arg0, context.runtime.getRange());
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
public static RubyRange newInclusiveRange(Ruby runtime, ThreadContext context, IRubyObject begin, IRubyObject end) {
RubyRange range = new RubyRange(runtime, runtime.getRange());
range.init(context, begin, end, false);
return range;
}
代码示例来源:origin: org.jruby/jruby-core
public static RubyRange newRange(ThreadContext context, IRubyObject begin, IRubyObject end, boolean isExclusive) {
RubyRange range = new RubyRange(context.runtime, context.runtime.getRange());
range.init(context, begin, end, isExclusive);
return range;
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
public static RubyRange newExclusiveRange(Ruby runtime, ThreadContext context, IRubyObject begin, IRubyObject end) {
RubyRange range = new RubyRange(runtime, runtime.getRange());
range.init(context, begin, end, true);
return range;
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
public static RubyRange newExclusiveRange(Ruby runtime, ThreadContext context, IRubyObject begin, IRubyObject end) {
RubyRange range = new RubyRange(runtime, runtime.getRange());
range.init(context, begin, end, true);
return range;
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
public static RubyRange newInclusiveRange(Ruby runtime, ThreadContext context, IRubyObject begin, IRubyObject end) {
RubyRange range = new RubyRange(runtime, runtime.getRange());
range.init(context, begin, end, false);
return range;
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
public static RubyRange newRange(Ruby runtime, ThreadContext context, IRubyObject begin, IRubyObject end, boolean isExclusive) {
RubyRange range = new RubyRange(runtime, runtime.getRange());
range.init(context, begin, end, isExclusive);
return range;
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
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());
}
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
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());
}
}
代码示例来源:origin: org.jruby/jruby-complete
private IRubyObject stepCommon(ThreadContext context, IRubyObject step, Block block) {
Ruby runtime = context.runtime;
if (begin instanceof RubyFixnum && end instanceof RubyFixnum && step instanceof RubyFixnum) {
fixnumStep(context, runtime, ((RubyFixnum) step).getLongValue(), block);
} else if (begin instanceof RubyFloat || end instanceof RubyFloat || step instanceof RubyFloat) {
RubyNumeric.floatStep(context, runtime, begin, end, step, isExclusive, block);
} else if (begin instanceof RubyNumeric
|| !TypeConverter.checkIntegerType(runtime, begin, "to_int").isNil()
|| !TypeConverter.checkIntegerType(runtime, end, "to_int").isNil()) {
numericStep(context, runtime, step, block);
} else {
IRubyObject tmp = begin.checkStringType();
if (!tmp.isNil()) {
StepBlockCallBack callback = new StepBlockCallBack(block, RubyFixnum.one(runtime), step);
Block blockCallback = CallBlock.newCallClosure(this, runtime.getRange(), Signature.ONE_ARGUMENT, callback, context);
((RubyString) tmp).uptoCommon(context, end, isExclusive, blockCallback);
} else {
if (!begin.respondsTo("succ")) {
throw runtime.newTypeError("can't iterate from " + begin.getMetaClass().getName());
}
// range_each_func(range, step_i, b, e, args);
rangeEach(context, new StepBlockCallBack(block, RubyFixnum.one(runtime), step));
}
}
return this;
}
代码示例来源:origin: org.jruby/jruby-core
private IRubyObject stepCommon(ThreadContext context, IRubyObject step, Block block) {
Ruby runtime = context.runtime;
if (begin instanceof RubyFixnum && end instanceof RubyFixnum && step instanceof RubyFixnum) {
fixnumStep(context, runtime, ((RubyFixnum) step).getLongValue(), block);
} else if (begin instanceof RubyFloat || end instanceof RubyFloat || step instanceof RubyFloat) {
RubyNumeric.floatStep(context, runtime, begin, end, step, isExclusive, block);
} else if (begin instanceof RubyNumeric
|| !TypeConverter.checkIntegerType(runtime, begin, "to_int").isNil()
|| !TypeConverter.checkIntegerType(runtime, end, "to_int").isNil()) {
numericStep(context, runtime, step, block);
} else {
IRubyObject tmp = begin.checkStringType();
if (!tmp.isNil()) {
StepBlockCallBack callback = new StepBlockCallBack(block, RubyFixnum.one(runtime), step);
Block blockCallback = CallBlock.newCallClosure(this, runtime.getRange(), Signature.ONE_ARGUMENT, callback, context);
((RubyString) tmp).uptoCommon(context, end, isExclusive, blockCallback);
} else {
if (!begin.respondsTo("succ")) {
throw runtime.newTypeError("can't iterate from " + begin.getMetaClass().getName());
}
// range_each_func(range, step_i, b, e, args);
rangeEach(context, new StepBlockCallBack(block, RubyFixnum.one(runtime), step));
}
}
return this;
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
private IRubyObject stepCommon19(ThreadContext context, IRubyObject step, Block block) {
Ruby runtime = context.runtime;
if (begin instanceof RubyFixnum && end instanceof RubyFixnum && step instanceof RubyFixnum) {
fixnumStep(context, runtime, ((RubyFixnum)step).getLongValue(), block);
} else if (begin instanceof RubyFloat || end instanceof RubyFloat || step instanceof RubyFloat) {
RubyNumeric.floatStep19(context, runtime, begin, end, step, isExclusive, block);
} else if (begin instanceof RubyNumeric ||
!TypeConverter.checkIntegerType(runtime, begin, "to_int").isNil() ||
!TypeConverter.checkIntegerType(runtime, end, "to_int").isNil()) {
numericStep19(context, runtime, step, block);
} else {
IRubyObject tmp = begin.checkStringType();
if (!tmp.isNil()) {
StepBlockCallBack callback = new StepBlockCallBack(block, RubyFixnum.one(runtime), step);
Block blockCallback = CallBlock.newCallClosure(this, runtime.getRange(), Arity.singleArgument(), callback, context);
((RubyString)tmp).uptoCommon19(context, end, isExclusive, blockCallback);
} else {
if (!begin.respondsTo("succ")) throw runtime.newTypeError("can't iterate from " + begin.getMetaClass().getName());
// range_each_func(range, step_i, b, e, args);
rangeEach(context, new StepBlockCallBack(block, RubyFixnum.one(runtime), step));
}
}
return this;
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
private IRubyObject stepCommon19(ThreadContext context, IRubyObject step, Block block) {
Ruby runtime = context.runtime;
if (begin instanceof RubyFixnum && end instanceof RubyFixnum && step instanceof RubyFixnum) {
fixnumStep(context, runtime, ((RubyFixnum)step).getLongValue(), block);
} else if (begin instanceof RubyFloat || end instanceof RubyFloat || step instanceof RubyFloat) {
RubyNumeric.floatStep19(context, runtime, begin, end, step, isExclusive, block);
} else if (begin instanceof RubyNumeric ||
!TypeConverter.checkIntegerType(runtime, begin, "to_int").isNil() ||
!TypeConverter.checkIntegerType(runtime, end, "to_int").isNil()) {
numericStep19(context, runtime, step, block);
} else {
IRubyObject tmp = begin.checkStringType();
if (!tmp.isNil()) {
StepBlockCallBack callback = new StepBlockCallBack(block, RubyFixnum.one(runtime), step);
Block blockCallback = CallBlock.newCallClosure(this, runtime.getRange(), Arity.singleArgument(), callback, context);
((RubyString)tmp).uptoCommon19(context, end, isExclusive, blockCallback);
} else {
if (!begin.respondsTo("succ")) throw runtime.newTypeError("can't iterate from " + begin.getMetaClass().getName());
// range_each_func(range, step_i, b, e, args);
rangeEach(context, new StepBlockCallBack(block, RubyFixnum.one(runtime), step));
}
}
return this;
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
private IRubyObject stepCommon(ThreadContext context, IRubyObject step, Block block) {
final Ruby runtime = context.runtime;
long unit = RubyNumeric.num2long(step);
if (unit < 0) throw runtime.newArgumentError("step can't be negative");
if (begin instanceof RubyFixnum && end instanceof RubyFixnum) {
if (unit == 0) throw runtime.newArgumentError("step can't be 0");
fixnumStep(context, runtime, unit, block);
} else {
IRubyObject tmp = begin.checkStringType();
if (!tmp.isNil()) {
if (unit == 0) throw runtime.newArgumentError("step can't be 0");
// rb_iterate((VALUE(*)_((VALUE)))str_step, (VALUE)args, step_i, (VALUE)iter);
StepBlockCallBack callback = new StepBlockCallBack(block, RubyFixnum.one(runtime), step);
Block blockCallback = CallBlock.newCallClosure(this, runtime.getRange(), Arity.singleArgument(), callback, context);
((RubyString)tmp).uptoCommon18(context, end, isExclusive, blockCallback);
} else if (begin instanceof RubyNumeric) {
if (equalInternal(context, step, RubyFixnum.zero(runtime))) throw runtime.newArgumentError("step can't be 0");
numericStep(context, runtime, step, block);
} else {
if (unit == 0) throw runtime.newArgumentError("step can't be 0");
if (!begin.respondsTo("succ")) throw runtime.newTypeError("can't iterate from " + begin.getMetaClass().getName());
// range_each_func(range, step_i, b, e, args);
rangeEach(context, new StepBlockCallBack(block, RubyFixnum.one(runtime), step));
}
}
return this;
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
private IRubyObject stepCommon(ThreadContext context, IRubyObject step, Block block) {
final Ruby runtime = context.runtime;
long unit = RubyNumeric.num2long(step);
if (unit < 0) throw runtime.newArgumentError("step can't be negative");
if (begin instanceof RubyFixnum && end instanceof RubyFixnum) {
if (unit == 0) throw runtime.newArgumentError("step can't be 0");
fixnumStep(context, runtime, unit, block);
} else {
IRubyObject tmp = begin.checkStringType();
if (!tmp.isNil()) {
if (unit == 0) throw runtime.newArgumentError("step can't be 0");
// rb_iterate((VALUE(*)_((VALUE)))str_step, (VALUE)args, step_i, (VALUE)iter);
StepBlockCallBack callback = new StepBlockCallBack(block, RubyFixnum.one(runtime), step);
Block blockCallback = CallBlock.newCallClosure(this, runtime.getRange(), Arity.singleArgument(), callback, context);
((RubyString)tmp).uptoCommon18(context, end, isExclusive, blockCallback);
} else if (begin instanceof RubyNumeric) {
if (equalInternal(context, step, RubyFixnum.zero(runtime))) throw runtime.newArgumentError("step can't be 0");
numericStep(context, runtime, step, block);
} else {
if (unit == 0) throw runtime.newArgumentError("step can't be 0");
if (!begin.respondsTo("succ")) throw runtime.newTypeError("can't iterate from " + begin.getMetaClass().getName());
// range_each_func(range, step_i, b, e, args);
rangeEach(context, new StepBlockCallBack(block, RubyFixnum.one(runtime), step));
}
}
return this;
}
内容来源于网络,如有侵权,请联系作者删除!