Package org.jruby

Examples of org.jruby.RubyRange$StepBlockCallBack


    public IRubyObject getRange(ThreadContext context, IRubyObject arg0) {
        int length = (int)getJavaArray().length().getLongValue();
        JavaClass arrayClass = JavaClass.get(context.getRuntime(), getJavaArray().getComponentType());
       
        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 arrayClass.emptyJavaArray(context);
                }
       
View Full Code Here


    public IRubyObject getRange(ThreadContext context, IRubyObject arg0) {
        int length = (int)getJavaArray().length().getLongValue();
        JavaClass arrayClass = JavaClass.get(context.getRuntime(), getJavaArray().getComponentType());
       
        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 arrayClass.emptyJavaArray(context);
                }
       
View Full Code Here

                    // Handle a RubyRange passed into a query
                    //
                    // NOTE: see above - need to augment the number of ? params
                    // in the PreparedStatement: (? AND ?)

                    RubyRange range_value = (RubyRange) arg;

                    driver.setPreparedStatementParam(ps, range_value.first(), index++);
                    driver.setPreparedStatementParam(ps, range_value.last(), index++);

                } else {
                    // Otherwise, handle each argument
                    driver.setPreparedStatementParam(ps, arg, index++);
                }
View Full Code Here

   
    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());
                }
       
View Full Code Here

    private IRubyObject aref(ThreadContext context, IRubyObject index_or_range) {
        if (index_or_range instanceof RubyFixnum) {
            Long index = (Long)index_or_range.toJava(Long.class);
            return commonArefIndex(context, index);
        } else if (index_or_range instanceof RubyRange) {
            RubyRange range = (RubyRange)index_or_range;
            Long start = (Long)range.first(context).toJava(Long.class);
            Long last = (Long)range.last(context).toJava(Long.class);
            // subvec returns from 'start' to element (- end 1)
            if (range.exclude_end_p().isTrue()) {
                return commonAref(context, start, null, last);
            } else {
                return commonAref(context, start, null, last + 1);
            }
        } else {
View Full Code Here

   
    public IRubyObject getRange(ThreadContext context, IRubyObject arg0) {
        int length = Array.getLength(getObject());
       
        if (arg0 instanceof RubyRange) {
            RubyRange range = (RubyRange)arg0;
            if (range.first(context) instanceof RubyFixnum && range.last(context) instanceof RubyFixnum) {
                int first = (int)((RubyFixnum)range.first(context)).getLongValue();
                int last = (int)((RubyFixnum)range.last(context)).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());
                }
       
View Full Code Here

TOP

Related Classes of org.jruby.RubyRange$StepBlockCallBack

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.