protected int compare(byte[] val, byte[] themVal) { return DataByteArray.compare(val, themVal); }
/** * Compare two byte arrays. Comparison is done first using byte values then * length. So "g" will be greater than "abcdefg", but "hello worlds" is * greater than "hello world". If the other object is not a DataByteArray, * {@link DataType#compare} will be called. * * @param other Other object to compare to. * @return -1 if less than, 1 if greater than, 0 if equal. */ public int compareTo(Object other) { if (other instanceof DataByteArray) { DataByteArray dba = (DataByteArray) other; return compare(mData, dba.mData); } else { return DataType.compare(this, other); } }
bb1.get(ba1); bb2.get(ba2); rc = DataByteArray.compare(ba1, ba2); break; case DataType.CHARARRAY:
/** * 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)); }