protected RubyRepeatedField deepCopy(ThreadContext context) { RubyRepeatedField copy = new RubyRepeatedField(context.runtime, metaClass, fieldType, typeClass); for (int i = 0; i < size(); i++) { IRubyObject value = storage.eltInternal(i); if (fieldType == Descriptors.FieldDescriptor.Type.MESSAGE) { copy.storage.add(((RubyMessage) value).deepCopy(context)); } else { copy.storage.add(value); } } return copy; }
@JRubyMethod(name = {"push", "<<"}) public IRubyObject push(ThreadContext context, IRubyObject value) { if (!(fieldType == Descriptors.FieldDescriptor.Type.MESSAGE && value == context.runtime.getNil())) { value = Utils.checkType(context, fieldType, value, (RubyModule) typeClass); } this.storage.add(value); return this.storage; }
@JRubyMethod(name = "add_enum") public IRubyObject addEnum(ThreadContext context, IRubyObject name, Block block) { RubyEnumDescriptor enumDef = (RubyEnumDescriptor) cEnumDescriptor.newInstance(context, Block.NULL_BLOCK); IRubyObject ctx = cEnumBuilderContext.newInstance(context, enumDef, Block.NULL_BLOCK); enumDef.setName(context, name); if (block.isGiven()) { if (block.arity() == Arity.ONE_ARGUMENT) { block.yield(context, ctx); } else { Binding binding = block.getBinding(); binding.setSelf(ctx); block.yieldSpecific(context); } } this.pendingList.add(enumDef); return context.runtime.getNil(); }
@JRubyMethod(name = "add_message") public IRubyObject addMessage(ThreadContext context, IRubyObject name, Block block) { RubyDescriptor msgdef = (RubyDescriptor) cDescriptor.newInstance(context, Block.NULL_BLOCK); IRubyObject ctx = cMessageBuilderContext.newInstance(context, msgdef, this, Block.NULL_BLOCK); msgdef.setName(context, name); if (block.isGiven()) { if (block.arity() == Arity.ONE_ARGUMENT) { block.yield(context, ctx); } else { Binding binding = block.getBinding(); binding.setSelf(ctx); block.yieldSpecific(context); } } this.pendingList.add(msgdef); return context.runtime.getNil(); }
RubyArray arr = ary.convertToArray(); for (int i = 0; i < arr.size(); i++) { this.storage.add(arr.eltInternal(i));
this.builder.pendingList.add(mapentryDesc);
public boolean addAll(int index, Collection c) { Iterator iter = c.iterator(); for (int i = index; iter.hasNext(); i++) { add(i, iter.next()); } return !c.isEmpty(); }
private static IRubyObject toRubyArray(Ruby rubyRuntime, List<Object> values) { RubyArray rubyArray = RubyArray.newArray(rubyRuntime, values.size()); for (Object value : values) { rubyArray.add(toRubyObject(rubyRuntime, value)); } return rubyArray; }
@JRubyMethod public static IRubyObject java_class_methods(final ThreadContext context, final IRubyObject self) { final java.lang.Class klass = unwrapJavaObject(self); final RubyArray methods = RubyArray.newArray(context.runtime); for ( java.lang.reflect.Method method : klass.getMethods() ) { if ( Modifier.isStatic(method.getModifiers()) ) methods.add(method); } return methods; }
@Override public void add(int index, Row element) { rubyArray.add(index, ((RowImpl) element).getRubyObject()); TableImpl.this.setAttribute("rowcount", size(), true); }
public static final IRubyObject getArrayOfUnsigned8(Ruby runtime, MemoryIO io, long offset, int count) { byte[] array = new byte[count]; io.get(offset, array, 0, array.length); RubyArray arr = RubyArray.newArray(runtime, array.length); for (int i = 0; i < array.length; ++i) { arr.add(Util.newUnsigned8(runtime, array[i])); } return arr; }
public static final IRubyObject getArrayOfFloat64(Ruby runtime, MemoryIO io, long offset, int count) { double[] array = new double[count]; io.get(offset, array, 0, array.length); RubyArray arr = RubyArray.newArray(runtime, array.length); for (int i = 0; i < array.length; ++i) { arr.add(RubyFloat.newFloat(runtime, array[i])); } return arr; }
@Override public void add(int index, Row element) { rubyArray.add(index, ((RowImpl) element).getRubyObject()); TableImpl.this.setAttribute("rowcount", size(), true); }
public static final IRubyObject getArrayOfUnsigned16(Ruby runtime, MemoryIO io, long offset, int count) { short[] array = new short[count]; io.get(offset, array, 0, array.length); RubyArray arr = RubyArray.newArray(runtime, array.length); for (int i = 0; i < array.length; ++i) { arr.add(Util.newUnsigned16(runtime, array[i])); } return arr; }
public static final IRubyObject getArrayOfUnsigned64(Ruby runtime, MemoryIO io, long offset, int count) { long[] array = new long[count]; io.get(offset, array, 0, array.length); RubyArray arr = RubyArray.newArray(runtime, array.length); for (int i = 0; i < array.length; ++i) { arr.add(Util.newUnsigned64(runtime, array[i])); } return arr; }
@Override public boolean add(Row row) { boolean changed = rubyArray.add(((RowImpl) row).getRubyObject()); TableImpl.this.setAttribute("rowcount", size(), true); return changed; }
@Override public void addSubstitution(String substitution) { RubyArray subs = (RubyArray) getRubyProperty("@subs"); subs.add(RubyUtils.toSymbol(getRuntime(), substitution)); }
@Override public void setSubstitutions(String... substitutions) { RubyArray subs = (RubyArray) getRubyProperty("@subs"); subs.clear(); if (substitutions != null) { for (String substitution : substitutions) { subs.add(RubyUtils.toSymbol(getRuntime(), substitution)); } } }
static ReaderImpl createReader(Ruby runtime, List<String> lines) { RubyArray rubyLines = runtime.newArray(lines.size()); for (String line : lines) { rubyLines.add(runtime.newString(line)); } RubyClass readerClass = runtime.getModule("Asciidoctor").getClass("Reader"); return new ReaderImpl(readerClass.callMethod("new", rubyLines)); }
@JRubyMethod(name = { "get_array_of_pointer" }, required = 2) public IRubyObject get_array_of_pointer(ThreadContext context, IRubyObject offset, IRubyObject length) { final int POINTER_SIZE = (Platform.getPlatform().addressSize / 8); int count = Util.int32Value(length); Ruby runtime = context.runtime; RubyArray arr = RubyArray.newArray(runtime, count); long off = getOffset(offset); for (int i = 0; i < count; ++i) { arr.add(getPointer(runtime, off + (i * POINTER_SIZE))); } return arr; }