org.jruby.Ruby.newRangeError()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(95)

本文整理了Java中org.jruby.Ruby.newRangeError方法的一些代码示例,展示了Ruby.newRangeError的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.newRangeError方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:newRangeError

Ruby.newRangeError介绍

暂无

代码示例

代码示例来源:origin: bazelbuild/bazel

protected static void checkIntTypePrecision(ThreadContext context, Descriptors.FieldDescriptor.Type type, IRubyObject value) {
  if (value instanceof RubyFloat) {
    double doubleVal = RubyNumeric.num2dbl(value);
    if (Math.floor(doubleVal) != doubleVal) {
      throw context.runtime.newRangeError("Non-integral floating point value assigned to integer field.");
    }
  }
  if (type == Descriptors.FieldDescriptor.Type.UINT32 || type == Descriptors.FieldDescriptor.Type.UINT64) {
    if (RubyNumeric.num2dbl(value) < 0) {
      throw context.runtime.newRangeError("Assigning negative value to unsigned integer field.");
    }
  }
}

代码示例来源:origin: bazelbuild/bazel

public static int num2uint(IRubyObject value) {
  long longVal = RubyNumeric.num2long(value);
  if (longVal > UINT_MAX)
    throw value.getRuntime().newRangeError("Integer " + longVal + " too big to convert to 'unsigned int'");
  long num = longVal;
  if (num > Integer.MAX_VALUE || num < Integer.MIN_VALUE)
    // encode to UINT32
    num = (-longVal ^ (-1l >>> 32) ) + 1;
  RubyNumeric.checkInt(value, num);
  return (int) num;
}

代码示例来源:origin: bazelbuild/bazel

val = enumDescriptor.findValueByName(value.asJavaString());
  if (val == null)
    throw runtime.newRangeError("Enum value " + value + " is not found.");
} else if(!isRubyNum(value)) {
  throw runtime.newTypeError("Expected number or symbol type for enum field.");

代码示例来源:origin: bazelbuild/bazel

throw runtime.newRangeError("Enum value " + value + " is not found.");

代码示例来源:origin: org.jruby/jruby-complete

/** rb_big2long
 *
 */
public static long big2long(RubyBignum value) {
  BigInteger big = value.getValue();
  if (big.compareTo(LONG_MIN) < 0 || big.compareTo(LONG_MAX) > 0) {
    throw value.getRuntime().newRangeError("bignum too big to convert into `long'");
  }
  return big.longValue();
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public Object coerce(RubyNumeric numeric, Class target) {
    long value = numeric.getLongValue();
    if (isLongShortable(value)) {
      return Short.valueOf((short)value);
    }
    throw numeric.getRuntime().newRangeError("too big for short: " + numeric);
  }
};

代码示例来源:origin: org.jruby/jruby-complete

final long begLen0(long len) {
  long beg = RubyNumeric.num2long(this.begin);
  if (beg < 0) {
    beg += len;
    if (beg < 0) {
      throw getRuntime().newRangeError(beg + ".." + (isExclusive ? "." : "") + end + " out of range");
    }
  }
  return beg;
}

代码示例来源:origin: org.jruby/jruby-core

public static long randomLongLimited(ThreadContext context, IRubyObject obj, long limit) {
  RandomType rnd = tryGetRandomType(context, obj);
  if (rnd == null) {
    RubyInteger v = Helpers.invokePublic(context, obj, "rand", context.runtime.newFixnum(limit + 1)).convertToInteger();
    long r = RubyNumeric.num2long(v);
    if (r < 0) throw context.runtime.newRangeError("random number too small " + r);
    if (r > limit) throw context.runtime.newRangeError("random number too big " + r);
    return r;
  }
  return randLimitedFixnumInner(rnd.impl, limit);
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

private IRubyObject putBytes(ThreadContext context, long off, ByteList bl, int idx, int len) {
  if (idx < 0 || idx > bl.length()) {
    throw context.runtime.newRangeError("invalid string index");
  }
  if (len < 0 || len > (bl.length() - idx)) {
    throw context.runtime.newRangeError("invalid length");
  }
  getMemoryIO().put(off, bl.getUnsafeBytes(), bl.begin() + idx, len);
  return this;
}

代码示例来源:origin: org.jruby/jruby-complete

public static double randomReal(ThreadContext context, IRubyObject obj) {
  RandomType random = tryGetRandomType(context, obj);
  if (random != null) return random.genrandReal();
  double d = RubyNumeric.num2dbl(context, Helpers.invoke(context, obj, "rand"));
  if (d < 0.0 || d >= 1.0) throw context.runtime.newRangeError("random number too big: " + d);
  return d;
}

代码示例来源:origin: org.jruby/jruby-core

/** nucomp_to_r
 * 
 */
@JRubyMethod(name = "to_r")
public IRubyObject to_r(ThreadContext context) {
  if (k_inexact_p(image) || !f_zero_p(context, image)) {
    throw context.runtime.newRangeError("can't convert " + f_to_s(context, this).convertToString() + " into Rational");
  }
  return f_to_r(context, real);
}

代码示例来源:origin: org.jruby/jruby-complete

/** nucomp_to_i
 * 
 */
@JRubyMethod(name = "to_i")
public IRubyObject to_i(ThreadContext context) {
  if (k_inexact_p(image) || !f_zero_p(context, image)) {
    throw context.runtime.newRangeError("can't convert " + f_to_s(context, this).convertToString() + " into Integer");
  }
  return f_to_i(context, real);
}

代码示例来源:origin: org.jruby/jruby-complete

/** nucomp_to_f
 * 
 */
@JRubyMethod(name = "to_f")
public IRubyObject to_f(ThreadContext context) {
  if (k_inexact_p(image) || !f_zero_p(context, image)) {
    throw context.runtime.newRangeError("can't convert " + f_to_s(context, this).convertToString() + " into Float");
  }
  return f_to_f(context, real);
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

/** nucomp_to_r
 * 
 */
@JRubyMethod(name = "to_r")
public IRubyObject to_r(ThreadContext context) {
  if (k_inexact_p(image) || !f_zero_p(context, image)) {
    throw context.runtime.newRangeError("can't convert " + f_to_s(context, this).convertToString() + " into Rational");
  }
  return f_to_r(context, real);
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

/** nucomp_rationalize
 *
 */
@JRubyMethod(name = "rationalize", optional = 1, compat = CompatVersion.RUBY1_9)
public IRubyObject rationalize(ThreadContext context, IRubyObject[] args) {
  if (k_inexact_p(image) || !f_zero_p(context, image)) {
    throw context.runtime.newRangeError("can't convert " + f_to_s(context, this).convertToString() + " into Rational");
  }
  return real.callMethod(context, "rationalize", args);
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

/** nucomp_rationalize
 *
 */
@JRubyMethod(name = "rationalize", optional = 1, compat = CompatVersion.RUBY1_9)
public IRubyObject rationalize(ThreadContext context, IRubyObject[] args) {
  if (k_inexact_p(image) || !f_zero_p(context, image)) {
    throw context.runtime.newRangeError("can't convert " + f_to_s(context, this).convertToString() + " into Rational");
  }
  return real.callMethod(context, "rationalize", args);
}

代码示例来源:origin: org.jruby/jruby-core

/** nucomp_to_i
 * 
 */
@JRubyMethod(name = "to_i")
public IRubyObject to_i(ThreadContext context) {
  if (k_inexact_p(image) || !f_zero_p(context, image)) {
    throw context.runtime.newRangeError("can't convert " + f_to_s(context, this).convertToString() + " into Integer");
  }
  return f_to_i(context, real);
}

代码示例来源:origin: org.jruby/jruby-core

/** nucomp_to_f
 * 
 */
@JRubyMethod(name = "to_f")
public IRubyObject to_f(ThreadContext context) {
  if (k_inexact_p(image) || !f_zero_p(context, image)) {
    throw context.runtime.newRangeError("can't convert " + f_to_s(context, this).convertToString() + " into Float");
  }
  return f_to_f(context, real);
}

代码示例来源:origin: org.jruby/jruby-core

@JRubyMethod(name = {"pos=", "pointer="})
public IRubyObject set_pos(IRubyObject pos) {
  check();
  int i = RubyNumeric.num2int(pos);
  int size = str.getByteList().getRealSize();
  if (i < 0) i += size;
  if (i < 0 || i > size) throw getRuntime().newRangeError("index out of range.");
  this.pos = i;
  return RubyFixnum.newFixnum(getRuntime(), i);
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod(name = {"pos=", "pointer="})
public IRubyObject set_pos(IRubyObject pos) {
  check();
  int i = RubyNumeric.num2int(pos);
  int size = str.getByteList().getRealSize();
  if (i < 0) i += size;
  if (i < 0 || i > size) throw getRuntime().newRangeError("index out of range.");
  this.pos = i;
  return RubyFixnum.newFixnum(getRuntime(), i);
}

相关文章

微信公众号

最新文章

更多

Ruby类方法