本文整理汇总了Java中org.jruby.RubyFixnum类的典型用法代码示例。如果您正苦于以下问题:Java RubyFixnum类的具体用法?Java RubyFixnum怎么用?Java RubyFixnum使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RubyFixnum类属于org.jruby包,在下文中一共展示了RubyFixnum类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: collect
import org.jruby.RubyFixnum; //导入依赖的package包/类
public void collect(Object k, Object v) throws IOException {
if (k instanceof String) {
key.set((String)k);
} else if (k instanceof Text) {
key.set((Text)k);
}
if (v instanceof RubyFixnum) {
Long longValue = ((RubyFixnum)v).getLongValue();
value.set(longValue.intValue());
} else if (v instanceof Long) {
value.set(((Long)v).intValue());
} else if (v instanceof Integer) {
value.set(((Integer)v).intValue());
}
collector.collect(key, value);
}
示例2: compare
import org.jruby.RubyFixnum; //导入依赖的package包/类
/**
* This calls to the static method compare of DataByteArray. Given two DataByteArrays, it will call it
* on the underlying bytes.
*
* @param context the context the method is being executed in
* @param self an class which contains metadata on the calling class (required for static Ruby methods)
* @param arg1 a RubyDataByteArray or byte array to compare
* @param arg2 a RubyDataByteArray or byte array to compare
* @return the Fixnum result of comparing arg1 and arg2's bytes
*/
@JRubyMethod
public static RubyFixnum compare(ThreadContext context, IRubyObject self, IRubyObject arg1, IRubyObject arg2) {
byte[] buf1, buf2;
if (arg1 instanceof RubyDataByteArray) {
buf1 = ((RubyDataByteArray)arg1).getDBA().get();
} else {
buf1 = (byte[])arg1.toJava(byte[].class);
}
if (arg2 instanceof RubyDataByteArray) {
buf2 = ((RubyDataByteArray)arg2).getDBA().get();
} else {
buf2 = (byte[])arg2.toJava(byte[].class);
}
return RubyFixnum.newFixnum(context.getRuntime(), DataByteArray.compare(buf1, buf2));
}
示例3: removeNamespceRecursively
import org.jruby.RubyFixnum; //导入依赖的package包/类
private void removeNamespceRecursively(ThreadContext context, XmlNode xmlNode) {
Node node = xmlNode.node;
if (node.getNodeType() == Node.ELEMENT_NODE) {
node.setPrefix(null);
NokogiriHelpers.renameNode(node, null, node.getLocalName());
NamedNodeMap attrs = node.getAttributes();
for (int i=0; i<attrs.getLength(); i++) {
Attr attr = (Attr) attrs.item(i);
if (isNamespace(attr.getNodeName())) {
((org.w3c.dom.Element)node).removeAttributeNode(attr);
} else {
attr.setPrefix(null);
NokogiriHelpers.renameNode(attr, null, attr.getLocalName());
}
}
}
XmlNodeSet nodeSet = (XmlNodeSet) xmlNode.children(context);
for (long i=0; i < nodeSet.length(); i++) {
XmlNode childNode = (XmlNode)nodeSet.slice(context, RubyFixnum.newFixnum(context.getRuntime(), i));
removeNamespceRecursively(context, childNode);
}
}
示例4: each
import org.jruby.RubyFixnum; //导入依赖的package包/类
@JRubyMethod
public IRubyObject each(ThreadContext context, Block block) {
if (!block.isGiven()) return enumeratorize(context.runtime, this, "each");
for(int i=0; i < cnt; i++) {
block.yield(context, nth(context, RubyFixnum.newFixnum(context.runtime, i)));
}
return this;
}
示例5: toRubyArray
import org.jruby.RubyFixnum; //导入依赖的package包/类
@JRubyMethod(name = {"to_a", "to_ary"})
public RubyArray toRubyArray(ThreadContext context) {
IRubyObject[] array = new IRubyObject[cnt];
for(int i=0; i < cnt; i++) {
array[i] = nth(context, RubyFixnum.newFixnum(context.runtime, i));
}
return getRuntime().newArray(array);
}
示例6: get
import org.jruby.RubyFixnum; //导入依赖的package包/类
/**
* This is a version of [] which allows the range to be specified as such: [1,2].
*
* @param context the context the method is being executed in
* @param arg1 a Fixnum start index
* @param arg2 a Fixnum end index
* @return the RubySchema object encapsulated the found Schema
*/
@JRubyMethod(name = {"[]", "slice"})
public RubySchema get(ThreadContext context, IRubyObject arg1, IRubyObject arg2) {
if (arg1 instanceof RubyFixnum && arg2 instanceof RubyFixnum) {
Ruby runtime = context.getRuntime();
int min = (int)((RubyFixnum)arg1).getLongValue();
int max = (int)((RubyFixnum)arg2).getLongValue() - 1;
return new RubySchema(runtime, runtime.getClass("Schema"), new Schema(internalSchema.getFields().subList(min, max + 1)), false);
} else {
throw new RuntimeException("Bad arguments given to get function: ( " + arg1.toString() + " , " + arg2.toString()+ " )");
}
}
示例7: set
import org.jruby.RubyFixnum; //导入依赖的package包/类
/**
* This allows the users to set an index or a range of values to
* a specified RubySchema. The first argument must be a Fixnum or Range,
* and the second argument may optionally be a Fixnum. The given index
* (or range of indices) will be replaced by a RubySchema instantiated
* based on the remaining arguments.
*
* @param context the contextthe method is being executed in
* @param args a varargs which has to be at least length two.
* @return the RubySchema that was added
*/
@JRubyMethod(name = {"[]=", "set"}, required = 2, rest = true)
public RubySchema set(ThreadContext context, IRubyObject[] args) {
IRubyObject arg1 = args[0];
IRubyObject arg2 = args[1];
IRubyObject[] arg3 = Arrays.copyOfRange(args, 1, args.length);
Schema s = internalSchema;
Ruby runtime = context.getRuntime();
List<Schema.FieldSchema> lfs = s.getFields();
int min, max;
if (arg1 instanceof RubyFixnum && arg2 instanceof RubyFixnum) {
min = (int)((RubyFixnum)arg1).getLongValue();
max = (int)((RubyFixnum)arg2).getLongValue();
arg3 = Arrays.copyOfRange(args, 2, args.length);
} else if (arg1 instanceof RubyFixnum) {
min = (int)((RubyFixnum)arg1).getLongValue();
max = min + 1;
} else if (arg1 instanceof RubyRange) {
min = (int)((RubyFixnum)((RubyRange)arg1).min(context, Block.NULL_BLOCK)).getLongValue();
max = (int)((RubyFixnum)((RubyRange)arg1).max(context, Block.NULL_BLOCK)).getLongValue() + 1;
} else {
throw new RuntimeException("Bad arguments given to get function: ( " + arg1.toString() + " , " + arg2.toString()+ " )");
}
for (int i = min; i < max; i++)
lfs.remove(min);
if (arg3 == null || arg3.length == 0)
throw new RuntimeException("Must have schema argument for []=");
RubySchema rs = new RubySchema(runtime, runtime.getClass("Schema")).initialize(arg3);
for (Schema.FieldSchema fs : rs.getInternalSchema().getFields())
lfs.add(min++, fs);
RubySchema.fixSchemaNames(internalSchema);
return rs;
}
示例8: index
import org.jruby.RubyFixnum; //导入依赖的package包/类
/**
* Given a field name, this will return the index of it in the schema.
*
* @param context the context the method is being executed in
* @param arg a field name to look for
* @return the index for that field name
*/
@JRubyMethod
public RubyFixnum index(ThreadContext context, IRubyObject arg) {
if (arg instanceof RubyString) {
try {
return new RubyFixnum(context.getRuntime(), internalSchema.getPosition(arg.toString()));
} catch (FrontendException e) {
throw new RuntimeException("Unable to find position for argument: " + arg);
}
} else {
throw new RuntimeException("Invalid arguement passed to index: " + arg);
}
}
示例9: compareTo
import org.jruby.RubyFixnum; //导入依赖的package包/类
/**
* This calls the compareTo method of the encapsulated DataByteArray.
*
* @param context the context the method is being executed in
* @param arg a RubyDataByteArray or byte array to compare to the
* encapsulated DataByteArray
* @return the result of compareTo on the encapsulated DataByteArray
and arg
*/
@JRubyMethod
public RubyFixnum compareTo(ThreadContext context, IRubyObject arg) {
int compResult;
if (arg instanceof RubyDataByteArray) {
compResult = internalDBA.compareTo(((RubyDataByteArray)arg).getDBA());
} else {
compResult = internalDBA.compareTo(new DataByteArray((byte[])arg.toJava(byte[].class)));
}
return RubyFixnum.newFixnum(context.getRuntime(), compResult);
}
示例10: rubyToPig
import org.jruby.RubyFixnum; //导入依赖的package包/类
/**
* This method facilitates conversion from Ruby objects to Pig objects. This is
* a general class which detects the subclass and invokes the appropriate conversion
* routine. It will fail on an unsupported datatype.
*
* @param rbObject a Ruby object to convert
* @return the Pig analogue of the Ruby object
* @throws ExecException if rbObject is not of a known type that can be converted
*/
@SuppressWarnings("unchecked")
public static Object rubyToPig(IRubyObject rbObject) throws ExecException {
if (rbObject == null || rbObject instanceof RubyNil) {
return null;
} else if (rbObject instanceof RubyArray) {
return rubyToPig((RubyArray)rbObject);
} else if (rbObject instanceof RubyHash) {
return rubyToPig((RubyHash)rbObject);
} else if (rbObject instanceof RubyString) {
return rubyToPig((RubyString)rbObject);
} else if (rbObject instanceof RubyBignum) {
return rubyToPig((RubyBignum)rbObject);
} else if (rbObject instanceof RubyFixnum) {
return rubyToPig((RubyFixnum)rbObject);
} else if (rbObject instanceof RubyFloat) {
return rubyToPig((RubyFloat)rbObject);
} else if (rbObject instanceof RubyInteger) {
return rubyToPig((RubyInteger)rbObject);
} else if (rbObject instanceof RubyDataBag) {
return rubyToPig((RubyDataBag)rbObject);
} else if (rbObject instanceof RubyDataByteArray) {
return rubyToPig((RubyDataByteArray)rbObject);
} else if (rbObject instanceof RubySchema) {
return rubyToPig((RubySchema)rbObject);
} else if (rbObject instanceof RubyBoolean) {
return rubyToPig((RubyBoolean)rbObject);
} else {
throw new ExecException("Cannot cast into any pig supported type: " + rbObject.getClass().getName());
}
}
示例11: XmlEntityDecl
import org.jruby.RubyFixnum; //导入依赖的package包/类
public XmlEntityDecl(Ruby ruby, RubyClass klass, Node entDeclNode, IRubyObject[] argv) {
super(ruby, klass, entDeclNode);
name = argv[0];
entityType = RubyFixnum.newFixnum(ruby, XmlEntityDecl.INTERNAL_GENERAL);
external_id = system_id = content = ruby.getNil();
if (argv.length > 1) entityType = argv[1];
if (argv.length > 4) {
external_id = argv[2];
system_id = argv[3];
content = argv[4];
}
}
示例12: line
import org.jruby.RubyFixnum; //导入依赖的package包/类
@JRubyMethod
public IRubyObject line(ThreadContext context) {
Node root = getOwnerDocument();
int[] counter = new int[1];
count(root, counter);
return RubyFixnum.newFixnum(context.getRuntime(), counter[0]+1);
}
示例13: validate_file
import org.jruby.RubyFixnum; //导入依赖的package包/类
@JRubyMethod(visibility=Visibility.PRIVATE)
public IRubyObject validate_file(ThreadContext context, IRubyObject file) {
Ruby ruby = context.getRuntime();
XmlDomParserContext ctx = new XmlDomParserContext(ruby, RubyFixnum.newFixnum(ruby, 1L));
ctx.setInputSource(context, file, context.getRuntime().getNil());
XmlDocument xmlDocument = ctx.parse(context, getNokogiriClass(ruby, "Nokogiri::XML::Document"), ruby.getNil());
return validate_document_or_file(context, xmlDocument);
}
示例14: resume
import org.jruby.RubyFixnum; //导入依赖的package包/类
public void resume()
{
IRubyObject result = fiber.callMethod(getContext(), "resume");
if (!result.isNil())
waitCount = (int) ((RubyFixnum) result).getLongValue();
else
waitCount = -1;
}
示例15: testEvaluation
import org.jruby.RubyFixnum; //导入依赖的package包/类
@Test
public void testEvaluation() throws RaiseException
{
IRubyObject result = ScriptExecuter.eval("a = 5\n");
assertTrue(result instanceof RubyFixnum);
RubyFixnum num = (RubyFixnum) result;
assertTrue(num.getLongValue() == 5L);
}