Package org.jruby

Examples of org.jruby.RubyArray$BlockComparator


        return payload;
      }

      int n = ((RubyArray)payload).getLength(), i;
      long p, m;
      RubyArray unmasked = RubyArray.newArray(runtime, n);

      long[] maskArray = {
        (Long)((RubyArray)mask).get(0),
        (Long)((RubyArray)mask).get(1),
        (Long)((RubyArray)mask).get(2),
        (Long)((RubyArray)mask).get(3)
      };

      for (i = 0; i < n; i++) {
        p = (Long)((RubyArray)payload).get(i);
        m = maskArray[i % 4];
        unmasked.set(i, p ^ m);
      }
      return unmasked;
    }
View Full Code Here


                    "nesting of " + currentNesting + " is too deep");
            }

            // this is guaranteed to be a RubyArray due to the earlier
            // allocator test at OptionsReader#getClass
            RubyArray result =
                (RubyArray)parser.arrayClass.newInstance(context,
                    IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);

           
// line 1583 "Parser.java"
  {
  cs = JSON_array_start;
  }

// line 674 "Parser.rl"
           
// line 1590 "Parser.java"
  {
  int _klen;
  int _trans = 0;
  int _acts;
  int _nacts;
  int _keys;
  int _goto_targ = 0;

  _goto: while (true) {
  switch ( _goto_targ ) {
  case 0:
  if ( p == pe ) {
    _goto_targ = 4;
    continue _goto;
  }
  if ( cs == 0 ) {
    _goto_targ = 5;
    continue _goto;
  }
case 1:
  _match: do {
  _keys = _JSON_array_key_offsets[cs];
  _trans = _JSON_array_index_offsets[cs];
  _klen = _JSON_array_single_lengths[cs];
  if ( _klen > 0 ) {
    int _lower = _keys;
    int _mid;
    int _upper = _keys + _klen - 1;
    while (true) {
      if ( _upper < _lower )
        break;

      _mid = _lower + ((_upper-_lower) >> 1);
      if ( data[p] < _JSON_array_trans_keys[_mid] )
        _upper = _mid - 1;
      else if ( data[p] > _JSON_array_trans_keys[_mid] )
        _lower = _mid + 1;
      else {
        _trans += (_mid - _keys);
        break _match;
      }
    }
    _keys += _klen;
    _trans += _klen;
  }

  _klen = _JSON_array_range_lengths[cs];
  if ( _klen > 0 ) {
    int _lower = _keys;
    int _mid;
    int _upper = _keys + (_klen<<1) - 2;
    while (true) {
      if ( _upper < _lower )
        break;

      _mid = _lower + (((_upper-_lower) >> 1) & ~1);
      if ( data[p] < _JSON_array_trans_keys[_mid] )
        _upper = _mid - 2;
      else if ( data[p] > _JSON_array_trans_keys[_mid+1] )
        _lower = _mid + 2;
      else {
        _trans += ((_mid - _keys)>>1);
        break _match;
      }
    }
    _trans += _klen;
  }
  } while (false);

  _trans = _JSON_array_indicies[_trans];
  cs = _JSON_array_trans_targs[_trans];

  if ( _JSON_array_trans_actions[_trans] != 0 ) {
    _acts = _JSON_array_trans_actions[_trans];
    _nacts = (int) _JSON_array_actions[_acts++];
    while ( _nacts-- > 0 )
  {
      switch ( _JSON_array_actions[_acts++] )
      {
  case 0:
// line 626 "Parser.rl"
  {
                ParserResult res = parseValue(p, pe);
                if (res == null) {
                    p--;
                    { p += 1; _goto_targ = 5; if (truecontinue _goto;}
                } else {
                    if (!parser.arrayClass.getName().equals("Array")) {
                        result.callMethod(context, "<<", res.result);
                    } else {
                        result.append(res.result);
                    }
                    {p = (( res.p))-1;}
                }
            }
  break;
View Full Code Here

            javaType = javaObject.getClass();
        }
    }
   
    private void updateArgvByJavaObject() {
        RubyArray ary = RubyArray.newArray(receiver.getRuntime());
        if (javaObject instanceof Collection) {
            ary.addAll((Collection)javaObject);
        } else if (javaObject instanceof String[]) {
            for (String s : (String[])javaObject) {
                ary.add(s);
            }
        }
        irubyObject = ary;
    }
View Full Code Here

    @Override
    public Object getJavaObject() {
        if (irubyObject == null || !fromRuby) {
            return javaObject;
        }
        RubyArray ary = (RubyArray)irubyObject;
        if (javaType == null) { // firstly retrieved from Ruby
            javaObject = new ArrayList<String>();
            ((ArrayList)javaObject).addAll(ary);
            return javaObject;
        } else if (javaType == String[].class) {
            javaObject = new String[ary.size()];
            for (int i=0; i<ary.size(); i++) {
                ((String[])javaObject)[i] = (String) ary.get(i);
            }
            return javaObject;
        } else if (javaObject instanceof List) {
            try {
                ((List)javaObject).clear();
View Full Code Here

    /**
     * This tests toArray-functionality
     */
    public void testToArray() throws Exception {
        final RubyArray arr = (RubyArray)runtime.evalScriptlet("$h = ['foo','bar']");
        final String val1 = "foo";
        final String val2 = "bar";
        final Object[] outp = arr.toArray();
        assertTrue("toArray should not return null",null != outp);
        assertTrue("toArray should not return empty array",0 != outp.length);
        assertEquals("first element should be \"foo\"",val1,outp[0]);
        assertEquals("second element should be \"bar\"",val2,outp[1]);
        final String[] outp2 = (String[])arr.toArray(new String[0]);
        assertTrue("toArray should not return null",null != outp2);
        assertTrue("toArray should not return empty array",0 != outp2.length);
        assertEquals("first element should be \"foo\"",val1,outp2[0]);
        assertEquals("second element should be \"bar\"",val2,outp2[1]);
        final String[] outp3 = (String[])arr.toArray(new String[arr.size()]);
        assertTrue("toArray should not return null",null != outp3);
        assertTrue("toArray should not return empty array",0 != outp3.length);
        assertEquals("first element should be \"foo\"",val1,outp3[0]);
        assertEquals("second element should be \"bar\"",val2,outp3[1]);
    }
View Full Code Here

        assertEquals("first element should be \"foo\"",val1,outp3[0]);
        assertEquals("second element should be \"bar\"",val2,outp3[1]);
    }

    public void testSetsValuesToNullOnClearWhenNotShared() throws Exception {
        final RubyArray arr = (RubyArray)runtime.evalScriptlet("$h = ['foo','bar']");
        assertNotSame("first element nil", runtime.getNil(), arr.eltInternal(0));
        assertNotSame("second element nil", runtime.getNil(), arr.eltInternal(1));
        arr.rb_clear();
        assertSame("first element not nil", runtime.getNil(), arr.eltInternal(0));
        assertSame("second element not nil", runtime.getNil(), arr.eltInternal(1));
    }
View Full Code Here

        assertSame("first element not nil", runtime.getNil(), arr.eltInternal(0));
        assertSame("second element not nil", runtime.getNil(), arr.eltInternal(1));
    }

    public void testSetsLeftoverValuesToNullWhenRejectingElements() throws Exception {
        final RubyArray arr = (RubyArray)runtime.evalScriptlet("$h = ['foo','bar']");
        assertNotSame("first element nil", runtime.getNil(), arr.eltInternal(0));
        assertNotSame("second element nil", runtime.getNil(), arr.eltInternal(1));
        runtime.evalScriptlet("$h.reject! { |e| e == 'bar' }");
        assertNotSame("first element nil", runtime.getNil(), arr.eltInternal(0));
        assertSame("second element not nil", runtime.getNil(), arr.eltInternal(1));
    }
View Full Code Here

        assertNotSame("first element nil", runtime.getNil(), arr.eltInternal(0));
        assertSame("second element not nil", runtime.getNil(), arr.eltInternal(1));
    }

    public void testSetsLeftoverValuesToNullInDeleteAt() throws Exception {
        final RubyArray arr = (RubyArray)runtime.evalScriptlet("$h = ['foo','bar']");
        assertNotSame("first element nil", runtime.getNil(), arr.eltInternal(0));
        assertNotSame("second element nil", runtime.getNil(), arr.eltInternal(1));
        runtime.evalScriptlet("$h.delete_at(1)");
        assertNotSame("first element nil", runtime.getNil(), arr.eltInternal(0));
        assertSame("second element not nil", runtime.getNil(), arr.eltInternal(1));
    }
View Full Code Here

        assertNotSame("first element nil", runtime.getNil(), arr.eltInternal(0));
        assertSame("second element not nil", runtime.getNil(), arr.eltInternal(1));
    }

    public void testSetsLeftoverValuesToNullInDelete() throws Exception {
        final RubyArray arr = (RubyArray)runtime.evalScriptlet("$h = ['foo','bar']");
        assertNotSame("first element nil", runtime.getNil(), arr.eltInternal(0));
        assertNotSame("second element nil", runtime.getNil(), arr.eltInternal(1));
        runtime.evalScriptlet("$h.delete('foo')");
        assertNotSame("first element nil", runtime.getNil(), arr.eltInternal(0));
        assertSame("second element not nil", runtime.getNil(), arr.eltInternal(1));
    }
View Full Code Here

    @SuppressWarnings("unchecked")
    public Node parse(String file, InputStream content, DynamicScope blockScope,
            ParserConfiguration configuration) {
        long startTime = System.nanoTime();
        IRubyObject scriptLines = runtime.getObject().fastGetConstantAt("SCRIPT_LINES__");
        RubyArray list = null;
       
        if (!configuration.isEvalParse() && scriptLines != null) {
            if (scriptLines instanceof RubyHash) {
                RubyString filename = runtime.newString(file);
                ThreadContext context = runtime.getCurrentContext();
View Full Code Here

TOP

Related Classes of org.jruby.RubyArray$BlockComparator

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.