mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Refactor: Clean up Int_ classes
This commit is contained in:
@@ -37,20 +37,20 @@ public class Bit__tst {
|
||||
fxt.Test_shift_rhs(8, 1, 4);
|
||||
}
|
||||
@Test public void Shift_lhs_to_int() {
|
||||
int[] shift_ary = Int_.Ary(0, 3, 5);
|
||||
fxt.Test_shift_lhs_to_int(shift_ary, Int_.Ary(0, 0, 0), 0);
|
||||
fxt.Test_shift_lhs_to_int(shift_ary, Int_.Ary(7, 0, 0), 7); // 1st 3 bits
|
||||
fxt.Test_shift_lhs_to_int(shift_ary, Int_.Ary(0, 3, 0), 24); // 2nd 2 bits
|
||||
fxt.Test_shift_lhs_to_int(shift_ary, Int_.Ary(0, 0, 1), 32); // 3rd 1 bit
|
||||
fxt.Test_shift_lhs_to_int(shift_ary, Int_.Ary(7, 3, 1), 63); // many bits
|
||||
int[] shift_ary = Int_ary_.New(0, 3, 5);
|
||||
fxt.Test_shift_lhs_to_int(shift_ary, Int_ary_.New(0, 0, 0), 0);
|
||||
fxt.Test_shift_lhs_to_int(shift_ary, Int_ary_.New(7, 0, 0), 7); // 1st 3 bits
|
||||
fxt.Test_shift_lhs_to_int(shift_ary, Int_ary_.New(0, 3, 0), 24); // 2nd 2 bits
|
||||
fxt.Test_shift_lhs_to_int(shift_ary, Int_ary_.New(0, 0, 1), 32); // 3rd 1 bit
|
||||
fxt.Test_shift_lhs_to_int(shift_ary, Int_ary_.New(7, 3, 1), 63); // many bits
|
||||
}
|
||||
@Test public void Shift_rhs_to_ary() {
|
||||
int[] shift_ary = Int_.Ary(0, 3, 5);
|
||||
fxt.Test_shift_rhs_to_ary(shift_ary, 0, Int_.Ary(0, 0, 0));
|
||||
fxt.Test_shift_rhs_to_ary(shift_ary, 7, Int_.Ary(7, 0, 0)); // 1st 3 bits
|
||||
fxt.Test_shift_rhs_to_ary(shift_ary, 24, Int_.Ary(0, 3, 0)); // 2nd 2 bits
|
||||
fxt.Test_shift_rhs_to_ary(shift_ary, 32, Int_.Ary(0, 0, 1)); // 3rd 1 bit
|
||||
fxt.Test_shift_rhs_to_ary(shift_ary, 63, Int_.Ary(7, 3, 1)); // many bits
|
||||
int[] shift_ary = Int_ary_.New(0, 3, 5);
|
||||
fxt.Test_shift_rhs_to_ary(shift_ary, 0, Int_ary_.New(0, 0, 0));
|
||||
fxt.Test_shift_rhs_to_ary(shift_ary, 7, Int_ary_.New(7, 0, 0)); // 1st 3 bits
|
||||
fxt.Test_shift_rhs_to_ary(shift_ary, 24, Int_ary_.New(0, 3, 0)); // 2nd 2 bits
|
||||
fxt.Test_shift_rhs_to_ary(shift_ary, 32, Int_ary_.New(0, 0, 1)); // 3rd 1 bit
|
||||
fxt.Test_shift_rhs_to_ary(shift_ary, 63, Int_ary_.New(7, 3, 1)); // many bits
|
||||
}
|
||||
}
|
||||
class Bit__fxt {
|
||||
@@ -59,7 +59,7 @@ class Bit__fxt {
|
||||
public void Test_shift_rhs(int val, int shift, int expd) {Tfds.Eq(expd, Bit_.Shift_rhs(val, shift));}
|
||||
public void Test_shift_lhs_to_int(int[] shift_ary, int[] val_ary, int expd) {Tfds.Eq(expd, Bit_.Shift_lhs_to_int(shift_ary, val_ary));}
|
||||
public void Test_shift_rhs_to_ary(int[] shift_ary, int val, int[] expd_ary) {
|
||||
int[] actl_ary = Int_.Ary(0, 0, 0);
|
||||
int[] actl_ary = Int_ary_.New(0, 0, 0);
|
||||
Bit_.Shift_rhs_to_ary(actl_ary, shift_ary, val);
|
||||
Tfds.Eq_ary(expd_ary, actl_ary);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class Gfo_cmd_arg_itm {
|
||||
public boolean Val_as_bool_or(boolean or) {return val == null ? or : String_.Eq((String)val, "y");}
|
||||
public String Val_as_str_or(String or) {return val == null ? or : (String)val;}
|
||||
public String Val_as_str() {return (String)val;}
|
||||
public int Val_as_int_or(int or) {return val == null ? or : Int_.parse_or((String)val, or);}
|
||||
public int Val_as_int_or(int or) {return val == null ? or : Int_.Parse_or((String)val, or);}
|
||||
public Io_url Val_as_url__rel_dir_or(Io_url owner_dir, Io_url or) {return Val_as_url__rel_url_or(Bool_.Y, owner_dir, or);}
|
||||
public Io_url Val_as_url__rel_fil_or(Io_url owner_dir, Io_url or) {return Val_as_url__rel_url_or(Bool_.N, owner_dir, or);}
|
||||
public Io_url Val_as_url__rel_url_or(boolean to_dir, Io_url owner_dir, Io_url or) {return Gfo_cmd_arg_itm_.Val_as_url__rel_url_or(Val_as_str(), to_dir, owner_dir, or);}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class Gfo_url_parser {
|
||||
if (!rel) { // search for ":"; NOTE: only search if not rel; i.e.: "//"
|
||||
int colon_pos = Bry_find_.Find_fwd(src, Byte_ascii.Colon, pos, src_end); // no colon found; EX: "//a.org/b"; "a.org/b"
|
||||
if (colon_pos != Bry_find_.Not_found) // colon found; EX: "http://" or "https://"
|
||||
pos = colon_pos + Int_.Const_dlm_len;
|
||||
pos = colon_pos + Byte_ascii.Len_1;
|
||||
if (pos < src_end && src[pos] == Byte_ascii.Slash) { // skip slash after colon
|
||||
pos += 1;
|
||||
if (pos < src_end && src[pos] == Byte_ascii.Slash) // skip 2nd slash after colon
|
||||
|
||||
@@ -46,7 +46,7 @@ public class Gfo_qarg_mgr {
|
||||
public int Read_int_or(String key, int or) {return Read_int_or(Bry_.new_u8(key), or);}
|
||||
public int Read_int_or(byte[] key, int or) {
|
||||
byte[] val = Read_bry_or(key, null);
|
||||
return val == null ? or : Int_.parse_or(String_.new_a7(val), or);
|
||||
return val == null ? or : Int_.Parse_or(String_.new_a7(val), or);
|
||||
}
|
||||
public int Read_enm_as_int_or(Gfo_qarg_enum_itm enm, int or) {
|
||||
Gfo_qarg_itm arg = (Gfo_qarg_itm)hash.Get_by_bry(enm.Key());
|
||||
|
||||
@@ -34,8 +34,8 @@ public class Int_2_ref {
|
||||
public static Int_2_ref parse(String raw) {
|
||||
try {
|
||||
String[] itms = String_.Split(raw, ",");
|
||||
int v0 = Int_.parse(itms[0]);
|
||||
int v1 = Int_.parse(itms[1]);
|
||||
int v0 = Int_.Parse(itms[0]);
|
||||
int v1 = Int_.Parse(itms[1]);
|
||||
return new Int_2_ref(v0, v1);
|
||||
} catch (Exception e) {Err_.Noop(e); throw Err_.new_parse("Int_2_ref", raw);}
|
||||
}
|
||||
@@ -46,8 +46,8 @@ public class Int_2_ref {
|
||||
Int_2_ref[] rv = new Int_2_ref[itms_len];
|
||||
for (int i = 0; i < itms_len; i++) {
|
||||
String[] vals = String_.Split(itms[i], ",");
|
||||
int v0 = Int_.parse(vals[0]);
|
||||
int v1 = Int_.parse(vals[1]);
|
||||
int v0 = Int_.Parse(vals[0]);
|
||||
int v1 = Int_.Parse(vals[1]);
|
||||
rv[i] = new Int_2_ref(v0, v1);
|
||||
}
|
||||
return rv;
|
||||
|
||||
@@ -16,15 +16,15 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
package gplx.core.primitives; import gplx.*; import gplx.core.*;
|
||||
public class Int_2_val {
|
||||
public Int_2_val(int v0, int v1) {val_0 = v0; val_1 = v1;}
|
||||
public int Val_0() {return val_0;} final int val_0;
|
||||
public int Val_1() {return val_1;} final int val_1;
|
||||
public int Val_0() {return val_0;} final int val_0;
|
||||
public int Val_1() {return val_1;} final int val_1;
|
||||
public String Xto_str(Bry_bfr bfr) {return Xto_str(bfr, val_0, val_1);}
|
||||
public static final Int_2_val Null_ptr = null;
|
||||
public static final Int_2_val Null_ptr = null;
|
||||
public static Int_2_val parse(String raw) {
|
||||
String[] itms = String_.Split(raw, ',');
|
||||
if (itms.length != 2) return Null_ptr;
|
||||
int v0 = Int_.parse_or(itms[0], Int_.Min_value); if (v0 == Int_.Min_value) return Null_ptr;
|
||||
int v1 = Int_.parse_or(itms[1], Int_.Min_value); if (v1 == Int_.Min_value) return Null_ptr;
|
||||
int v0 = Int_.Parse_or(itms[0], Int_.Min_value); if (v0 == Int_.Min_value) return Null_ptr;
|
||||
int v1 = Int_.Parse_or(itms[1], Int_.Min_value); if (v1 == Int_.Min_value) return Null_ptr;
|
||||
return new Int_2_val(v0, v1);
|
||||
}
|
||||
public static String Xto_str(Bry_bfr bfr, int x, int y) {return bfr.Add_int_variable(x).Add_byte_comma().Add_int_variable(y).To_str_and_clear();}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class Int_ary_parser extends Obj_ary_parser_base {
|
||||
}
|
||||
@Override protected void Ary_len_(int v) {
|
||||
if (v == 0)
|
||||
ary = Int_.Ary_empty;
|
||||
ary = Int_ary_.Empty;
|
||||
else {
|
||||
ary = new int[v]; // NOTE: always create new array; never reuse;
|
||||
ary_idx = 0;
|
||||
|
||||
@@ -17,9 +17,9 @@ package gplx.core.primitives; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Int_ary_parser_tst {
|
||||
private final Int_ary_parser_fxt fxt = new Int_ary_parser_fxt();
|
||||
@Test public void Many() {fxt.Test__Parse_ary("1,2,3,4,5" , 0, 9, Int_.Ary(1, 2, 3, 4, 5));}
|
||||
@Test public void One() {fxt.Test__Parse_ary("1" , 0, 1, Int_.Ary(1));}
|
||||
@Test public void None() {fxt.Test__Parse_ary("" , 0, 0, Int_.Ary());}
|
||||
@Test public void Many() {fxt.Test__Parse_ary("1,2,3,4,5" , 0, 9, Int_ary_.New(1, 2, 3, 4, 5));}
|
||||
@Test public void One() {fxt.Test__Parse_ary("1" , 0, 1, Int_ary_.New(1));}
|
||||
@Test public void None() {fxt.Test__Parse_ary("" , 0, 0, Int_ary_.New());}
|
||||
}
|
||||
class Int_ary_parser_fxt {
|
||||
public void Test__Parse_ary(String raw, int bgn, int end, int[] expd) {
|
||||
|
||||
Reference in New Issue
Block a user