1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2014-09-07 22:38:50 -04:00
parent be63adc5af
commit a022d7f26c
293 changed files with 2546 additions and 1942 deletions

View File

@@ -49,7 +49,7 @@ public class ErrMsgWtr {
String msg = err.Hdr();
String typ = String_.Eq(err.Key(), "") ? "" : String_.Concat(" <", err.Key(), ">");
boolean onlyOne = errAry.length == 1;
String idxStr = onlyOne ? "" : Int_.XtoStr(i);
String idxStr = onlyOne ? "" : Int_.Xto_str(i);
sb.Add(idxStr).Add("\t").Add(msg).Add(typ).Add_char_crlf(); // ex: " @count must be > 0 <gplx.arg>"
WriteKeyValAry(sb, err.Args());
sb.Add("\t").Add(err.Proc().SignatureRaw()).Add_char_crlf();
@@ -87,7 +87,7 @@ public class ErrMsgWtr {
ErrProcData comp = errAry[j].Proc();
if (String_.Eq(proc.Raw(), comp.Raw())) {idx = j; break;}
}
String idxStr = onlyOne ? "" : Int_.XtoStr(idx);
String idxStr = onlyOne ? "" : Int_.Xto_str(idx);
String hdr = idx == -1 ? "\t" : idxStr + "\t";
String ideAddressSpr = String_.CrLf + "\t\t";
String ideAddress = String_.Eq(proc.IdeAddress(), "") ? "" : ideAddressSpr + proc.IdeAddress(); // NOTE: ideAddress will be blank in compiled mode

View File

@@ -59,7 +59,7 @@ class ErrProcData {
int linEnd = String_.FindFwd(raw, ")", linBgn); if (linEnd == String_.Find_none) return rv;
String linRaw = String_.Mid(raw, linBgn, linEnd);
rv.sourceLine = Int_.parse_(linRaw);
rv.ideAddress = String_.Concat("(", rv.sourceFileRaw, ":", Int_.XtoStr(rv.sourceLine), ")");
rv.ideAddress = String_.Concat("(", rv.sourceFileRaw, ":", Int_.Xto_str(rv.sourceLine), ")");
return rv;
}
public static ErrProcData new_() {return new ErrProcData();} ErrProcData() {}

View File

@@ -19,8 +19,8 @@ package gplx;
public class Bool_ implements GfoInvkAble {
public static final boolean[] Ary_empty = new boolean[0];
public static final Class<?> ClassOf = Boolean.class;
public static int XtoInt(boolean v) {return v ? 1 : 0;}
public static String XtoStr_lower(boolean v) {return v ? "true" : "false";}
public static int Xto_int(boolean v) {return v ? 1 : 0;}
public static String Xto_str_lower(boolean v) {return v ? "true" : "false";}
public static byte Xto_byte(boolean v) {return v ? Y_byte : N_byte;}
public static boolean cast_(Object obj) {try {return (Boolean)obj;} catch (Exception e) {throw Err_.type_mismatch_exc_(e, boolean.class, obj);}}
public static boolean cast_or_(Object obj, boolean v) {try {return (Boolean)obj;} catch (Exception e) {Err_.Noop(e); return v;}}

View File

@@ -22,7 +22,7 @@ public class Bool_obj_ref {
public Bool_obj_ref Val_n_() {val = false; return this;}
public Bool_obj_ref Val_(boolean v) {val = v; return this;}
public Bool_obj_ref Val_toggle_() {val = !val; return this;}
@Override public String toString() {return Bool_.XtoStr_lower(val);}
@Override public String toString() {return Bool_.Xto_str_lower(val);}
public static Bool_obj_ref n_() {return new_(false);}
public static Bool_obj_ref y_() {return new_(true);}
public static Bool_obj_ref new_(boolean val) {

View File

@@ -19,6 +19,7 @@ package gplx;
import java.lang.*;
import gplx.ios.*;
public class Bry_ {
public static final String Cls_name = "byte[]";
public static final int NotFound = -1;
public static final byte[] Empty = new byte[0];
public static final byte[][] Ary_empty = new byte[0][];

View File

@@ -248,8 +248,8 @@ public class Bry_bfr {
return this;
}
public Bry_bfr Add_str(String v) {return Add(Bry_.new_utf8_(v));}
public Bry_bfr Add_float(float f) {Add_str(Float_.XtoStr(f)); return this;}
public Bry_bfr Add_double(double v) {Add_str(Double_.XtoStr(v)); return this;}
public Bry_bfr Add_float(float f) {Add_str(Float_.Xto_str(f)); return this;}
public Bry_bfr Add_double(double v) {Add_str(Double_.Xto_str(v)); return this;}
public Bry_bfr Add_dte(DateAdp val) {return Add_dte_segs(val.Year(), val.Month(),val.Day(), val.Hour(), val.Minute(), val.Second(), val.Frac());}
public Bry_bfr Add_dte_segs(int y, int M, int d, int H, int m, int s, int f) { // yyyyMMdd HHmmss.fff
if (bfr_len + 19 > bfr_max) Resize((bfr_len + 19) * 2);

View File

@@ -63,7 +63,7 @@ class Bry_bfr_mkr_mgr {
for (int i = 0; i < ary_max; i++) {
Bry_bfr itm = ary[i];
if (itm != null) {
if (itm.Mkr_mgr() != null) throw Err_.new_("failed to clear bfr: " + Int_.XtoStr(i));
if (itm.Mkr_mgr() != null) throw Err_.new_("failed to clear bfr: " + Int_.Xto_str(i));
itm.Clear();
}
ary[i] = null;

View File

@@ -259,4 +259,5 @@ public class Bry_fmtr {
byte[] bry = bfr.XtoAryAndClear();
this.Fmt_(bry).Compile();
}
public static String Escape_tilde(String v) {return String_.Replace(v, "~", "~~");}
}

View File

@@ -53,6 +53,9 @@ public class Bry_fmtr_tst {
Bry_fmtr_fxt fxt = new Bry_fmtr_fxt().Clear();
fxt.Bld_bfr_many_and_set_fmt("a~{0}c", Object_.Ary("b"), "abc");
}
@Test public void Escape_tilde() {
Tfds.Eq("~~~~~~", Bry_fmtr.Escape_tilde("~~~"));
}
}
class Bry_fmtr_tst_mok implements Bry_fmtr_eval_mgr {
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled;

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
public class Byte_ {
public static final byte MinValue = Byte.MIN_VALUE;
public static final String Cls_name = "byte";
public static byte[] Ary(byte... ary) {return ary;}
public static byte[] Ary_by_ints(int... ary) {
int ary_len = ary.length;
@@ -26,8 +27,8 @@ public class Byte_ {
rv[i] = int_(ary[i]);
return rv;
}
public static String XtoStr(byte v) {return new Byte(v).toString();}
public static int XtoInt(byte v) {return v < 0 ? (int)v + 256 : v;}
public static String Xto_str(byte v) {return new Byte(v).toString();}
public static int Xto_int(byte v) {return v < 0 ? (int)v + 256 : v;}
public static boolean In(byte v, byte... ary) {
for (byte itm : ary)
if (v == itm) return true;

View File

@@ -31,5 +31,5 @@ public class Byte__tst {
tst_XtoInt( 128, 128);
tst_XtoInt( 255, 255);
tst_XtoInt( 256, 0);
} void tst_XtoInt(int v, int expd) {Tfds.Eq(expd, Byte_.XtoInt((byte)v));} // WORKAROUND/JAVA: v is of type int b/c java promotes numbers to ints
} void tst_XtoInt(int v, int expd) {Tfds.Eq(expd, Byte_.Xto_int((byte)v));} // WORKAROUND/JAVA: v is of type int b/c java promotes numbers to ints
}

View File

@@ -21,7 +21,7 @@ public class Byte_obj_ref {
public Byte_obj_ref Val_(byte v) {val = v; return this;}
@Override public int hashCode() {return val;}
@Override public boolean equals(Object obj) {return obj == null ? false : val == ((Byte_obj_ref)obj).Val();}
@Override public String toString() {return Int_.XtoStr(val);}
@Override public String toString() {return Int_.Xto_str(val);}
public static Byte_obj_ref zero_() {return new_(Byte_.Zero);}
public static Byte_obj_ref new_(byte val) {
Byte_obj_ref rv = new Byte_obj_ref();

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
public class Byte_obj_val {
public byte Val() {return val;} private byte val;
@Override public String toString() {return Int_.XtoStr(val);}
@Override public String toString() {return Int_.Xto_str(val);}
@Override public int hashCode() {return val;}
@Override public boolean equals(Object obj) {return obj == null ? false : val == ((Byte_obj_val)obj).Val();}
public static Byte_obj_val new_(byte val) {

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
public class Double_ {
public static final Class<?> ClassOf = Double.class;
public static final String Cls_name = "double";
public static final double Inf_pos = Double.POSITIVE_INFINITY;;
public static final double NaN = Double.NaN;;
public static final byte[] NaN_bry = Bry_.new_ascii_("NaN");
@@ -31,15 +32,15 @@ public class Double_ {
try {String s = String_.as_(v); return s == null ? Double_.cast_(v) : Double_.parse_(s);}
catch (Exception e) {throw Err_.cast_(e, double.class, v);}
}
public static String XtoStr(double v) {
public static String Xto_str(double v) {
int v_int = (int)v;
return v - v_int == 0 ? Int_.XtoStr(v_int) : Double.toString(v);
return v - v_int == 0 ? Int_.Xto_str(v_int) : Double.toString(v);
}
public static String Xto_str_loose(double v) {
int v_as_int = (int)v;
return v == v_as_int
? Int_.XtoStr(v_as_int) // convert to int, and call print String to eliminate any trailing decimal places
: Float_.XtoStr((float)v); // calling ((float)v).toString is better at removing trailing 0s than String.format("%g", v). note that .net .toString() handles it better; EX:2449.600000000000d; DATE:2014-07-29
? Int_.Xto_str(v_as_int) // convert to int, and call print String to eliminate any trailing decimal places
: Float_.Xto_str((float)v); // calling ((float)v).toString is better at removing trailing 0s than String.format("%g", v). note that .net .toString() handles it better; EX:2449.600000000000d; DATE:2014-07-29
}
public static double cast_(Object o) {try {return (Double)o;} catch(Exception e) {throw Err_.type_mismatch_exc_(e, double.class, o);}}
public static double parse_(String raw) {try {return Double.parseDouble(raw);} catch(Exception e) {throw Err_.parse_type_exc_(e, double.class, raw);}}

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
public class Double_obj_val implements CompareAble {
public double Val() {return val;} double val;
@Override public String toString() {return Double_.XtoStr(val);}
@Override public String toString() {return Double_.Xto_str(val);}
@Override public int hashCode() {return (int)val;}
@Override public boolean equals(Object obj) {return obj == null ? false : val == ((Double_obj_val)obj).Val();}
public int compareTo(Object obj) {Double_obj_val comp = (Double_obj_val)obj; return Double_.Compare(val, comp.val);}

View File

@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Float_ {
public static final String Cls_name = "float";
public static final float NaN = Float.NaN;;
public static boolean IsNaN(float v) {return Float.isNaN(v);}
public static int RoundUp(float val) {
@@ -25,9 +26,9 @@ public class Float_ {
}
public static float Div(int val, int divisor) {return (float)val / (float)divisor;}
public static float Div(long val, long divisor) {return (float)val / (float)divisor;}
public static String XtoStr(float v) {
public static String Xto_str(float v) {
int v_int = (int)v;
return v - v_int == 0 ? Int_.XtoStr(v_int) : Float.toString(v);
return v - v_int == 0 ? Int_.Xto_str(v_int) : Float.toString(v);
}
public static float cast_double_(double v) {return (float)v;}
public static float cast_(Object obj) {try {return (Float)obj;} catch(Exception exc) {throw Err_.type_mismatch_exc_(exc, float.class, obj);}}

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
public class Int_ implements GfoInvkAble {
public static final Class<?> ClassOf = Integer.class;
public static final String Cls_name = "int";
public static final int Base1 = 1;
public static final int Const_dlm_len = 1;
public static final int Const_position_after_char = 1;
@@ -132,11 +133,11 @@ public class Int_ implements GfoInvkAble {
if (val < 0) throw Err_.new_("key must be >= 0").Add("key", key).Add("val", val);
return this;
}
public static String XtoStr_PadBgn_space(int v, int reqdPlaces) {return Xto_str_pad_bgn(v, reqdPlaces, Byte_ascii.Space, true);} // EX: 1, 3 returns " 1"
public static String XtoStr_PadBgn(int v, int reqdPlaces) {return Xto_str_pad_bgn(v, reqdPlaces, Byte_ascii.Num_0, true);} // EX: 1, 3 returns "001"
public static String Xto_str_pad_bgn_space(int v, int reqdPlaces) {return Xto_str_pad_bgn(v, reqdPlaces, Byte_ascii.Space, true);} // EX: 1, 3 returns " 1"
public static String Xto_str_pad_bgn(int v, int reqdPlaces) {return Xto_str_pad_bgn(v, reqdPlaces, Byte_ascii.Num_0, true);} // EX: 1, 3 returns "001"
static String Xto_str_pad_bgn(int val, int places, byte pad_chr, boolean bgn) {
int len = DigitCount(val);
int pad_len = places - len; if (pad_len < 0) return Int_.XtoStr(val);
int pad_len = places - len; if (pad_len < 0) return Int_.Xto_str(val);
Bry_bfr bfr = Bry_bfr.new_();
boolean neg = val < 0;
if (bgn) { // special logic to handle negative numbers; EX: -1 -> "-001", not "00-1"
@@ -157,13 +158,13 @@ public class Int_ implements GfoInvkAble {
public static int cast_(Object obj) {try {return (Integer)obj;} catch(Exception exc) {throw Err_.type_mismatch_exc_(exc, int.class, obj);}}
public static int cast_or_(Object obj, int or) {try {return (Integer)obj;} catch(Exception e) {Err_.Noop(e); return or;}}
public static int Xby_double_(double v) {return (int)v;}
public static String XtoStr(int v) {return new Integer(v).toString();}
public static String XtoStr_fmt(int v, String fmt) {return new java.text.DecimalFormat(fmt).format(v);}
public static String Xto_str(int v) {return new Integer(v).toString();}
public static String Xto_str_fmt(int v, String fmt) {return new java.text.DecimalFormat(fmt).format(v);}
public static boolean TypeMatch(Class<?> type) {return type == int.class || type == Integer.class;}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_XtoStr_PadBgn)) {
int v = m.ReadInt(GfsCore_.Arg_primitive), pad = m.ReadInt("pad");
return ctx.Deny() ? (Object)this : XtoStr_PadBgn(v, pad);
return ctx.Deny() ? (Object)this : Xto_str_pad_bgn(v, pad);
}
else if (ctx.Match(k, "Add")) {
int v = m.ReadInt(GfsCore_.Arg_primitive), operand = m.ReadInt("operand");
@@ -196,16 +197,16 @@ public class Int_ implements GfoInvkAble {
return -1;
}
}
public static String XtoStr_hex(int v) {
public static String Xto_str_hex(int v) {
String rv = Integer.toHexString(v);
int rvLen = String_.Len(rv);
if (rvLen < 8) rv = String_.Repeat("0", 8 - rvLen) + rv;
return String_.Upper(rv);
}
public static String XtoStr(int[] ary) {
public static String Xto_str(int[] ary) {
String_bldr sb = String_bldr_.new_();
for (int i = 0; i < ary.length; i++)
sb.Add_spr_unless_first(Int_.XtoStr(ary[i]), " ", i);
sb.Add_spr_unless_first(Int_.Xto_str(ary[i]), " ", i);
return sb.XtoStr();
}
public static int[] Ary_parse(String raw_str, int reqd_len, int[] or) {

View File

@@ -26,7 +26,7 @@ public class Int__tst {
tst_XtoStr_PadLeft_Zeroes(-12 , 3, "-12"); // negative
tst_XtoStr_PadLeft_Zeroes(-123 , 3, "-123"); // negative
tst_XtoStr_PadLeft_Zeroes(-1234 , 3, "-1234"); // negative
} void tst_XtoStr_PadLeft_Zeroes(int val, int zeros, String expd) {Tfds.Eq(expd, Int_.XtoStr_PadBgn(val, zeros));}
} void tst_XtoStr_PadLeft_Zeroes(int val, int zeros, String expd) {Tfds.Eq(expd, Int_.Xto_str_pad_bgn(val, zeros));}
@Test public void parseOr_() {
tst_ParseOr("", -1); // empty
tst_ParseOr("123", 123); // single
@@ -41,7 +41,7 @@ public class Int__tst {
@Test public void Xto_fmt() {
tst_XtoStr_fmt(1, "1");
tst_XtoStr_fmt(1000, "1,000");
} void tst_XtoStr_fmt(int v, String expd) {Tfds.Eq(expd, Int_.XtoStr_fmt(v, "#,###"));}
} void tst_XtoStr_fmt(int v, String expd) {Tfds.Eq(expd, Int_.Xto_str_fmt(v, "#,###"));}
@Test public void AryRng() {
tst_AryRng(1, 3, Int_.Ary(1, 2, 3));
} void tst_AryRng(int bgn, int end, int[] expd) {Tfds.Eq_ary(expd, Int_.AryRng(bgn, end));}
@@ -71,7 +71,7 @@ public class Int__tst {
tst_DigitCount(100, 3);
tst_DigitCount(-1, 2);
tst_DigitCount(-100, 4);
} void tst_DigitCount(int val, int expd) {Tfds.Eq(expd, Int_.DigitCount(val), Int_.XtoStr(val));}
} void tst_DigitCount(int val, int expd) {Tfds.Eq(expd, Int_.DigitCount(val), Int_.Xto_str(val));}
@Test public void Log10() {
tst_Log10( 0, 0);
tst_Log10( 1, 0);
@@ -104,8 +104,8 @@ public class Int__tst {
Ary_parse__tst("123,321,213" , 3, Int_.Ary_empty, 123, 321, 213);
Ary_parse__tst(" 1, 2,3" , 3, Int_.Ary_empty, 1, 2, 3);
Ary_parse__tst("-1,+2,-3" , 3, Int_.Ary_empty, -1, 2, -3);
Ary_parse__tst(Int_.XtoStr(Int_.MinValue) , 1, Int_.Ary_empty, Int_.MinValue);
Ary_parse__tst(Int_.XtoStr(Int_.MaxValue) , 1, Int_.Ary_empty, Int_.MaxValue);
Ary_parse__tst(Int_.Xto_str(Int_.MinValue) , 1, Int_.Ary_empty, Int_.MinValue);
Ary_parse__tst(Int_.Xto_str(Int_.MaxValue) , 1, Int_.Ary_empty, Int_.MaxValue);
Ary_parse__tst("1,2" , 1, Int_.Ary_empty);
Ary_parse__tst("1" , 2, Int_.Ary_empty);
Ary_parse__tst("a" , 1, Int_.Ary_empty);

View File

@@ -23,7 +23,7 @@ public class Int_obj_ref {
public int Val_add(int v) {val += v; return val;}
public Int_obj_ref Val_zero_() {val = 0; return this;}
public Int_obj_ref Val_neg1_() {val = -1; return this;}
@Override public String toString() {return Int_.XtoStr(val);}
@Override public String toString() {return Int_.Xto_str(val);}
@Override public int hashCode() {return val;}
@Override public boolean equals(Object obj) {return val == ((Int_obj_ref)obj).Val();}
public static Int_obj_ref neg1_() {return new_(-1);}

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
public class Int_obj_val implements CompareAble {
public int Val() {return val;} int val;
@Override public String toString() {return Int_.XtoStr(val);}
@Override public String toString() {return Int_.Xto_str(val);}
@Override public int hashCode() {return val;}
@Override public boolean equals(Object obj) {return obj == null ? false : val == ((Int_obj_val)obj).Val();}
public int compareTo(Object obj) {Int_obj_val comp = (Int_obj_val)obj; return Int_.Compare(val, comp.val);}

View File

@@ -19,6 +19,7 @@ package gplx;
public class Long_ {
public static final long MinValue = Long.MIN_VALUE;
public static final long MaxValue = Long.MAX_VALUE;
public static final String Cls_name = "long";
public static final long Neg1 = -1;
public static final int Log10Ary_len = 21;
public static long[] Log10Ary = new long[]
@@ -28,8 +29,8 @@ public class Long_ {
, Long_.Pow(10, 15), Long_.Pow(10, 16), Long_.Pow(10, 17), Long_.Pow(10, 18), Long_.Pow(10, 19)
, Long_.MaxValue
};
public static String XtoStr(long v) {return Long.toString(v);}
public static String XtoStr_PadBgn(long v, int reqdPlaces) {return String_.Pad(XtoStr(v), reqdPlaces, "0", true);} // ex: 1, 3 returns 001
public static String Xto_str(long v) {return Long.toString(v);}
public static String Xto_str_PadBgn(long v, int reqdPlaces) {return String_.Pad(Xto_str(v), reqdPlaces, "0", true);} // ex: 1, 3 returns 001
public static long parse_or_(String raw, int or) {
if (raw == null) return or;
try {

View File

@@ -19,6 +19,7 @@ package gplx;
import java.lang.*;
public class String_ implements GfoInvkAble {
public static final Class<?> ClassOf = String.class;
public static final String Cls_name = "str" + "ing";
public static final int Find_none = -1, Pos_neg1 = -1;
public static final String Null = null, Empty = "", Null_mark = "<<NULL>>", Tab = "\t", Lf = "\n", CrLf = "\r\n";
public static String cast_(Object v) {return (String)v;}

View File

@@ -25,21 +25,21 @@ public class DecimalAdp implements CompareAble {
protected DecimalAdp(BigDecimal v) {this.under = v;} BigDecimal under;
protected DecimalAdp(int v) {this.under = new BigDecimal(v);}
public String XtoStr() {
public String Xto_str() {
BigDecimal tmp = under;
if (tmp.scale() > 14) tmp = tmp.setScale(14, RoundingMode.DOWN); // NOTE: setting to 14 to match PHP/C# values more closely; RoundingMode.Down for same reason; see E, Pi tests
return tmp .stripTrailingZeros() // NOTE: stripTrailingZeros for exp tests; EX: 120.0 -> 120; 0.01200000000000 -> .012
.toPlainString(); // NOTE: toPlainString b/c stripTrailingZeros now converts 120 to 1.2E+2 (and any other value that is a multiple of 10)
}
public String XtoStr(String fmt) {return new DecimalFormat(fmt).format(under);}
public String Xto_str(String fmt) {return new DecimalFormat(fmt).format(under);}
@Override public String toString() {return under.toString();}
public boolean Eq(DecimalAdp v) {return v.under.doubleValue() == under.doubleValue();}
public BigDecimal XtoDecimal() {return under;}
public long XtoLong_Mult1000() {return under.movePointRight(3).longValue();}
public BigDecimal Xto_decimal() {return under;}
public long Xto_long_mult_1000() {return under.movePointRight(3).longValue();}
public int Fraction1000() {return (int)(under.movePointRight(3).floatValue() % 1000);}
public double XtoDouble() {return under.doubleValue();}
public int XtoInt() {return (int)under.doubleValue();}
public long XtoLong() {return (long)under.doubleValue();}
public double Xto_double() {return under.doubleValue();}
public int Xto_int() {return (int)under.doubleValue();}
public long Xto_long() {return (long)under.doubleValue();}
public DecimalAdp Op_add(DecimalAdp v) {return new DecimalAdp(under.add(v.under, DecimalAdp_.Gplx_rounding_context));}
public DecimalAdp Op_subtract(DecimalAdp v) {return new DecimalAdp(under.subtract(v.under, DecimalAdp_.Gplx_rounding_context));}
public DecimalAdp Op_mult(DecimalAdp v) {return new DecimalAdp(under.multiply(v.under));}

View File

@@ -46,7 +46,7 @@ import java.math.BigDecimal; import java.math.MathContext; import java.math.Roun
else if (v > 9999999 && v < 100000000) return 100000000;
else if (v > 99999999 && v < 1000000000) return 1000000000;
else throw Err_.new_("value must be between 0 and 1 billion").Add("v", v);
}
}
public static String CalcPctStr(long dividend, long divisor, String fmt) {
if (divisor == 0) return "%ERR";
return DecimalAdp_.float_(Float_.Div(dividend, divisor) * 100).Xto_str(fmt) + "%";

View File

@@ -22,28 +22,28 @@ public class DecimalAdp__tst {
tst_divide_(1, 1000, "0.001");
tst_divide_(1, 3, "0.33333333333333");
tst_divide_(1, 7, "0.14285714285714");
} void tst_divide_(int lhs, int rhs, String expd) {Tfds.Eq(expd, DecimalAdp_.divide_(lhs, rhs).XtoStr());}
} void tst_divide_(int lhs, int rhs, String expd) {Tfds.Eq(expd, DecimalAdp_.divide_(lhs, rhs).Xto_str());}
@Test public void base1000_() {
tst_base1000_(1000, "1");
tst_base1000_(1234, "1.234");
tst_base1000_(123, "0.123");
} void tst_base1000_(int val, String expd) {Tfds.Eq(expd, DecimalAdp_.base1000_(val).XtoStr());}
} void tst_base1000_(int val, String expd) {Tfds.Eq(expd, DecimalAdp_.base1000_(val).Xto_str());}
@Test public void parts_() {
tst_parts_(1, 0, "1");
tst_parts_(1, 2, "1.2");
tst_parts_(1, 23, "1.23");
tst_parts_(123, 4567, "123.4567");
} void tst_parts_(int num, int fracs, String expd) {Tfds.Eq(expd, DecimalAdp_.parts_(num, fracs).XtoStr());}
} void tst_parts_(int num, int fracs, String expd) {Tfds.Eq(expd, DecimalAdp_.parts_(num, fracs).Xto_str());}
@Test public void parse_() {
tst_parse_("1", "1");
tst_parse_("1.2", "1.2");
tst_parse_("0.1", "0.1");
} void tst_parse_(String raw, String expd) {Tfds.Eq(expd, DecimalAdp_.parse_(raw).XtoStr());}
} void tst_parse_(String raw, String expd) {Tfds.Eq(expd, DecimalAdp_.parse_(raw).Xto_str());}
@Test public void Truncate_decimal() {
tst_Truncate_decimal("1", "1");
tst_Truncate_decimal("1.1", "1");
tst_Truncate_decimal("1.9", "1");
} void tst_Truncate_decimal(String raw, String expd) {Tfds.Eq(DecimalAdp_.parse_(expd).XtoStr(), DecimalAdp_.parse_(raw).Op_truncate_decimal().XtoStr());}
} void tst_Truncate_decimal(String raw, String expd) {Tfds.Eq(DecimalAdp_.parse_(expd).Xto_str(), DecimalAdp_.parse_(raw).Op_truncate_decimal().Xto_str());}
@Test public void Fraction1000() {
tst_Fraction1000(1, 1000, 1); // 0.001
tst_Fraction1000(1, 3, 333); // 0.33333333
@@ -58,5 +58,5 @@ public class DecimalAdp__tst {
tst_XtoStr_fmt(1, 2, "0.0", "0.5");
tst_XtoStr_fmt(1, 3, "0.0", "0.3");
tst_XtoStr_fmt(10000, 7, "0,000.000", "1,428.571");
} void tst_XtoStr_fmt(int l, int r, String fmt, String expd) {Tfds.Eq(expd, DecimalAdp_.divide_(l, r).XtoStr(fmt));}
} void tst_XtoStr_fmt(int l, int r, String fmt, String expd) {Tfds.Eq(expd, DecimalAdp_.divide_(l, r).Xto_str(fmt));}
}

View File

@@ -77,7 +77,7 @@ public class TimeSpanAdp implements CompareAble, EqAble {
case 1: return "s";
case 2: return "m";
case 3: return "h";
default: return "unknown:<" + Int_.XtoStr(i) + ">";
default: return "unknown:<" + Int_.Xto_str(i) + ">";
}
}
@gplx.Internal protected TimeSpanAdp(long fracs) {this.fracs = fracs;}

View File

@@ -25,7 +25,7 @@ public class TimeSpanAdp_ {
return new TimeSpanAdp(fracs);
}
public static TimeSpanAdp decimal_(DecimalAdp seconds) {
return new TimeSpanAdp(seconds.XtoLong_Mult1000());
return new TimeSpanAdp(seconds.Xto_long_mult_1000());
}
public static TimeSpanAdp units_(int frc, int sec, int min, int hour) {
int[] units = new int[] {frc, sec, min, hour};
@@ -92,7 +92,7 @@ public class TimeSpanAdp_ {
sb.Add(Sprs[i]);
if (val < 10) // zeroPad
sb.Add("0");
sb.Add(Int_.XtoStr(val));
sb.Add(Int_.Xto_str(val));
}
return sb.XtoStrAndClear();
}
@@ -115,7 +115,7 @@ public class TimeSpanAdp_ {
zeros = first && !fmt_padZeros ? 1 : padZerosAry[i]; // if first, don't zero pad (avoid "01")
dlm = first ? "" : Sprs[i]; // if first, don't use dlm (avoid ":01")
sb.Add(dlm);
sb.Add(Int_.XtoStr_PadBgn(val, zeros));
sb.Add(Int_.Xto_str_pad_bgn(val, zeros));
first = false;
}
return sb.XtoStr();

View File

@@ -39,7 +39,7 @@ class Criteria_or extends Criteria_bool_base {
class Criteria_const implements Criteria {
public byte Crt_tid() {return Criteria_.Tid_const;}
public boolean Matches(Object comp) {return val;} private boolean val;
public String XtoStr() {return String_.Concat(" IS ", Bool_.XtoStr_lower(val));}
public String XtoStr() {return String_.Concat(" IS ", Bool_.Xto_str_lower(val));}
public Criteria_const(boolean val) {this.val = val;}
}
class Criteria_not implements Criteria {

View File

@@ -118,7 +118,7 @@ public class ListAdp_tst {
list_AddMany("0", "1", "2");
for (Object valObj : list) {
String val = (String)valObj;
Tfds.Eq(Int_.XtoStr(pos++), val);
Tfds.Eq(Int_.Xto_str(pos++), val);
tst_Enumerator("0", "1", "2");
}
}

View File

@@ -62,9 +62,9 @@ public class OrderedHash_base extends HashAdp_base implements OrderedHash, GfoIn
public String XtoStr_ui() {
String_bldr sb = String_bldr_.new_();
int count = ordered.Count();
int pad = String_.Len(Int_.XtoStr(count));
int pad = String_.Len(Int_.Xto_str(count));
for (int i = 0; i < count; i++) {
sb .Add(Int_.XtoStr_PadBgn(i, pad))
sb .Add(Int_.Xto_str_pad_bgn(i, pad))
.Add(":").Add(ordered.FetchAt(i).toString())
.Add(Op_sys.Cur().Nl_str());
}

View File

@@ -74,7 +74,7 @@ public class HexDecUtl {
case 0: return '0'; case 1: return '1'; case 2: return '2'; case 3: return '3'; case 4: return '4';
case 5: return '5'; case 6: return '6'; case 7: return '7'; case 8: return '8'; case 9: return '9';
case 10: return 'A'; case 11: return 'B'; case 12: return 'C'; case 13: return 'D'; case 14: return 'E'; case 15: return 'F';
default: throw Err_.parse_("hexstring", Int_.XtoStr(val));
default: throw Err_.parse_("hexstring", Int_.Xto_str(val));
}
}
static byte Xto_byte(int v) {
@@ -82,7 +82,7 @@ public class HexDecUtl {
case 0: return Byte_ascii.Num_0; case 1: return Byte_ascii.Num_1; case 2: return Byte_ascii.Num_2; case 3: return Byte_ascii.Num_3; case 4: return Byte_ascii.Num_4;
case 5: return Byte_ascii.Num_5; case 6: return Byte_ascii.Num_6; case 7: return Byte_ascii.Num_7; case 8: return Byte_ascii.Num_8; case 9: return Byte_ascii.Num_9;
case 10: return Byte_ascii.Ltr_A; case 11: return Byte_ascii.Ltr_B; case 12: return Byte_ascii.Ltr_C; case 13: return Byte_ascii.Ltr_D; case 14: return Byte_ascii.Ltr_E; case 15: return Byte_ascii.Ltr_F;
default: throw Err_.parse_("hexstring", Int_.XtoStr(v));
default: throw Err_.parse_("hexstring", Int_.Xto_str(v));
}
}
public static void Write(byte[] bry, int bgn, int end, int val) {

View File

@@ -52,7 +52,11 @@ public class RegxAdp {
if (match.Rslt_none()) break;
rv.Add(match);
int find_bgn = match.Find_bgn();
idx = find_bgn + match.Find_len();
int find_len = match.Find_len();
idx = find_len == 0 // find_bgn == find_end
? find_bgn + 1 // add 1 to resume search from next char; DATE:2014-09-02
: find_bgn + find_len // otherwise search after find_end
;
}
return (RegxMatch[])rv.XtoAry(RegxMatch.class);
}

View File

@@ -26,7 +26,8 @@ public class RegxAdp__tst implements TfdsEqListItmStr {
tst_Match("[^a]", "b", true); // charSet_negate
} void tst_Match(String find, String input, boolean expd) {Tfds.Eq(expd, RegxAdp_.Match(input, find));}
@Test public void Match_all() {
tst_Match_all("#REDIRECT [[Template:Error]]", "^\\p{Nd}*", 0); // handle match = true but len = 0 DATE:2013-04-10
tst_Match_all("#REDIRECT [[Template:Error]]", "^\\p{Nd}*", 1); // handle match = true but len = 0; DATE:2013-04-11
tst_Match_all("a", "$", 1); // $ should match once, not zero; DATE:2014-09-02
} void tst_Match_all(String input, String regx, int expd) {Tfds.Eq(expd, RegxAdp_.new_(regx).Match_all(input, 0).length);}
@Test public void Replace() {
tst_Replace("ab", "a", "b", "bb"); // basic

View File

@@ -19,7 +19,7 @@ package gplx.texts; import gplx.*;
public class RegxMatch {
public RegxMatch(boolean rslt, int find_bgn, int find_end, RegxGroup[] groups) {this.rslt = rslt; this.find_bgn = find_bgn; this.find_end = find_end; this.groups = groups;}
public boolean Rslt() {return rslt;} private boolean rslt;
public boolean Rslt_none() {return !rslt || (find_end - find_bgn) == 0;} // NOTE: find_end - find_bgn == 0 means find.length == 0; treating these as failed match, even thought matcher.find = true; DATE:2013-04-10
public boolean Rslt_none() {return !rslt;} // NOTE: was "|| find_end - find_bgn == 0"; DATE:2013-04-11; DATE:2014-09-02
public int Find_bgn() {return find_bgn;} int find_bgn;
public int Find_end() {return find_end;} int find_end;
public int Find_len() {return find_end - find_bgn;}

View File

@@ -159,7 +159,7 @@ class HashDlgWtrDefault implements HashDlgWtr {
current += increment;
int percentage = (current * 100) / total;
if (percentage <= lastPercentage) return;
dialog.WriteTempText(String_.LimitToFirst(p, dialog.CharsPerLineMax()) + Int_.XtoStr(percentage) + "%");
dialog.WriteTempText(String_.LimitToFirst(p, dialog.CharsPerLineMax()) + Int_.Xto_str(percentage) + "%");
lastPercentage = percentage;
}
public void End() {}

View File

@@ -26,7 +26,7 @@ public class Io_size_ {
long div = (long)Math_.Pow((long)1024, (long)pow);
DecimalAdp valDecimal = DecimalAdp_.divide_(val, div);
String[] unit = Io_size_.Units[pow];
return valDecimal.XtoStr("#,###.000") + " " + String_.PadBgn(unit[0], 2, " ");
return valDecimal.Xto_str("#,###.000") + " " + String_.PadBgn(unit[0], 2, " ");
}
public static long parse_or_(String raw, long or) {
if (raw == null || raw == String_.Empty) return or;
@@ -48,7 +48,7 @@ public class Io_size_ {
}
DecimalAdp comp = val.Op_truncate_decimal();
if (!val.Eq(comp)) return or;
return val.XtoLong();
return val.Xto_long();
}
static int parse_unitPow_(String unitStr) {
int unitLen = Array_.Len(Units);
@@ -104,7 +104,7 @@ class Io_size_fmtr_arg implements Bry_fmtr_arg {
}
long div = (long)Math_.Pow((long)1024, (long)pow);
DecimalAdp val_decimal = DecimalAdp_.divide_(val, div);
bfr.Add_str(val_decimal.XtoStr("#,###.000")).Add_byte(Byte_ascii.Space).Add(gplx.ios.Io_size_.Units_bry[pow]);
bfr.Add_str(val_decimal.Xto_str("#,###.000")).Add_byte(Byte_ascii.Space).Add(gplx.ios.Io_size_.Units_bry[pow]);
if (suffix != null)
bfr.Add(suffix);
}

View File

@@ -22,6 +22,6 @@ public class DecimalAdpClassXtn extends ClassXtn_base implements ClassXtn {
public Object DefaultValue() {return 0;}
public boolean Eq(Object lhs, Object rhs) {try {return DecimalAdp_.cast_(lhs).Eq(DecimalAdp_.cast_(rhs));} catch (Exception e) {Err_.Noop(e); return false;}}
@Override public Object ParseOrNull(String raw) {return DecimalAdp_.parse_(raw);}
@Override public String XtoUi(Object obj, String fmt) {return DecimalAdp_.cast_(obj).XtoStr();}
@Override public String XtoUi(Object obj, String fmt) {return DecimalAdp_.cast_(obj).Xto_str();}
public static final DecimalAdpClassXtn _ = new DecimalAdpClassXtn(); DecimalAdpClassXtn() {} // added to ClassXtnPool by default
}

View File

@@ -29,7 +29,7 @@ public class GfoNdeFxt {
static GfoFldList GfoFldList_by_count_(int count) {
GfoFldList rv = GfoFldList_.new_();
for (int i = 0; i < count; i++)
rv.Add("fld" + Int_.XtoStr(i), StringClassXtn._);
rv.Add("fld" + Int_.Xto_str(i), StringClassXtn._);
return rv;
}
}

View File

@@ -259,7 +259,7 @@ class XtoStrWkr_gplx implements XtoStrWkr {
Class<?> type = ClassAdp_.ClassOf_obj(o);
String rv = null;
if (type == String.class) rv = String_.cast_(o);
else if (Int_.TypeMatch(type)) return Int_.XtoStr(Int_.cast_(o));
else if (Int_.TypeMatch(type)) return Int_.Xto_str(Int_.cast_(o));
else if (Bool_.TypeMatch(type)) return Yn.Xto_str(Bool_.cast_(o));
else if (type == DateAdp.class) return DateAdp_.cast_(o).XtoStr_gplx();
else rv = Object_.Xto_str_strict_or_empty(o);

View File

@@ -44,7 +44,7 @@ public abstract class DataWtr_base implements SrlMgr {
public long SrlLongOr(String key, long or) {WriteData(key, or); return or;}
public String SrlStrOr(String key, String or) {WriteData(key, or); return or;}
public DateAdp SrlDateOr(String key, DateAdp or) {WriteData(key, or.XtoStr_gplx()); return or;}
public DecimalAdp SrlDecimalOr(String key, DecimalAdp or) {WriteData(key, or.XtoDecimal()); return or;}
public DecimalAdp SrlDecimalOr(String key, DecimalAdp or) {WriteData(key, or.Xto_decimal()); return or;}
public double SrlDoubleOr(String key, double or) {WriteData(key, or); return or;}
public Object SrlObjOr(String key, Object or) {throw Err_.not_implemented_();}
public void TypeKey_(String v) {}

View File

@@ -24,7 +24,7 @@ public class Tfds { // URL:doc/gplx.tfds/Tfds.txt
public static void Eq_byte(byte expd, byte actl) {Eq_wkr(expd, actl, true, EmptyStr);}
public static void Eq_long(long expd, long actl) {Eq_wkr(expd, actl, true, EmptyStr);}
public static void Eq_float(float expd, float actl) {Eq_wkr(expd, actl, true, EmptyStr);}
public static void Eq_decimal(DecimalAdp expd, DecimalAdp actl) {Eq_wkr(expd.XtoDouble(), actl.XtoDouble(), true, EmptyStr);}
public static void Eq_decimal(DecimalAdp expd, DecimalAdp actl) {Eq_wkr(expd.Xto_double(), actl.Xto_double(), true, EmptyStr);}
public static void Eq_date(DateAdp expd, DateAdp actl) {Eq_wkr(expd.XtoStr_gplx(), actl.XtoStr_gplx(), true, EmptyStr);}
public static void Eq_date(DateAdp expd, DateAdp actl, String fmt, Object... args){Eq_wkr(expd.XtoStr_gplx(), actl.XtoStr_gplx(), true, String_.Format(fmt, args));}
public static void Eq_url(Io_url expd, Io_url actl) {Eq_wkr(expd.Raw(), actl.Raw(), true, EmptyStr);}
@@ -206,14 +206,14 @@ class TfdsMsgBldr {
for (int i = 0; i < list.Count(); i++) {
TfdsEqAryItm itm = (TfdsEqAryItm)list.FetchAt(i);
sb.Add_fmt_line("{0}: {1} {2} {3}"
, Int_.XtoStr_PadBgn(itm.Idx(), 4)
, Int_.Xto_str_pad_bgn(itm.Idx(), 4)
, String_.PadBgn(itm.Lhs(), lhsLenMax, " ")
, itm.Eq() ? "==" : "!="
, String_.PadBgn(itm.Rhs(), rhsLenMax, " ")
);
}
// String compSym = isEq ? " " : "!=";
// String result = String_.Format("{0}: {1}{2} {3} {4}", Int_.XtoStr_PadBgn(i, 4), lhsString, String_.CrLf + "\t\t", compSym, rhsString);
// String result = String_.Format("{0}: {1}{2} {3} {4}", Int_.Xto_str_pad_bgn(i, 4), lhsString, String_.CrLf + "\t\t", compSym, rhsString);
// foreach (Object obj in list) {
// String itmComparison = (String)obj;
// sb.Add_fmt_line("{0}{1}", "\t\t", itmComparison);

View File

@@ -41,8 +41,8 @@ public class HierStrBldr {
multipleAry[i] = (idx / multiple) * multiple; // NOTE: rounds down to multiple; EX: 11 -> 10
}
for (int i = 0; i < multipleAry.length; i++)
sb.Add_fmt(dirFmt, Int_.XtoStr_fmt(multipleAry[i], numFmt));
sb.Add_fmt(filFmt, Int_.XtoStr_fmt(idx, numFmt));
sb.Add_fmt(dirFmt, Int_.Xto_str_fmt(multipleAry[i], numFmt));
sb.Add_fmt(filFmt, Int_.Xto_str_fmt(idx, numFmt));
return sb.XtoStr();
}
public HierStrBldr Ctor_io(Io_url root, String dirFmt, String filFmt, String numFmt, int... filCountMaxs) {