Core: Refactor base classes

v3.3.4
gnosygnu 8 years ago
parent 12459429b4
commit 83cf992f48

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
import gplx.langs.gfs.*;
public class Bool_ implements Gfo_invk {
public class Bool_ {
public static final String Cls_val_name = "boolean";
public static final Class<?> Cls_ref_type = Boolean.class;
public static final boolean N = false , Y = true;
@ -26,15 +26,16 @@ public class Bool_ implements Gfo_invk {
public static final byte[] N_bry = new byte[] {Byte_ascii.Ltr_n}, Y_bry = new byte[] {Byte_ascii.Ltr_y};
public static final String True_str = "true", False_str = "false";
public static final byte[] True_bry = Bry_.new_a7(True_str), False_bry = Bry_.new_a7(False_str);
public static boolean cast(Object obj) {try {return (Boolean)obj;} catch (Exception e) {throw Err_.new_type_mismatch_w_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;}}
public static boolean parse(String raw) {
public static boolean Cast(Object obj) {try {return (Boolean)obj;} catch (Exception e) {throw Err_.new_type_mismatch_w_exc(e, boolean.class, obj);}}
public static boolean Cast_or(Object obj, boolean or) {try {return (Boolean)obj;} catch (Exception e) {Err_.Noop(e); return or;}}
public static boolean Parse(String raw) {
if ( String_.Eq(raw, True_str)
|| String_.Eq(raw, "True") // needed for Store_Wtr(){boolVal.toString();}
)
return true;
else if ( String_.Eq(raw, "false")
|| String_.Eq(raw, False_str)
else if ( String_.Eq(raw, False_str)
|| String_.Eq(raw, "False")
)
return false;
throw Err_.new_parse_type(boolean.class, raw);
@ -48,17 +49,4 @@ public class Bool_ implements Gfo_invk {
public static int To_int(boolean v) {return v ? Y_int : N_int;}
public static byte To_byte(boolean v) {return v ? Y_byte : N_byte;}
public static String To_str_lower(boolean v) {return v ? True_str : False_str;}
public static final Bool_ Gfs = new Bool_();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_to_str)) {
boolean v = m.ReadBool(GfsCore_.Arg_primitive);
String fmt = m.ReadStrOr("fmt", null);
if (fmt == null) return v ? "true" : "false";
else if (String_.Eq(fmt, "yn")) return v ? "y" : "n";
else if (String_.Eq(fmt, "yes_no")) return v ? "yes" : "no";
else return v ? "true" : "false";
}
else return Gfo_invk_.Rv_unhandled;
} public static final String Invk_to_str = "to_str";
}

@ -431,7 +431,7 @@ public class Bry_bfr {
else if (o_type == Bry_bfr.class) Add_bfr_and_preserve((Bry_bfr)o);
else if (o_type == DateAdp.class) Add_dte((DateAdp)o);
else if (o_type == Io_url.class) Add(((Io_url)o).RawBry());
else if (o_type == Boolean.class) Add_yn(Bool_.cast(o));
else if (o_type == Boolean.class) Add_yn(Bool_.Cast(o));
else if (o_type == Double.class) Add_double(Double_.cast(o));
else if (o_type == Float.class) Add_float(Float_.cast(o));
else ((Bfr_arg)o).Bfr_arg__add(this);
@ -448,7 +448,7 @@ public class Bry_bfr {
else if (o_type == Bry_bfr.class) Add_bfr_and_preserve((Bry_bfr)o);
else if (o_type == DateAdp.class) Add_dte((DateAdp)o);
else if (o_type == Io_url.class) Add(((Io_url)o).RawBry());
else if (o_type == Boolean.class) Add_bool(Bool_.cast(o));
else if (o_type == Boolean.class) Add_bool(Bool_.Cast(o));
else if (o_type == Double.class) Add_double(Double_.cast(o));
else if (o_type == Float.class) Add_float(Float_.cast(o));
else ((Bfr_arg)o).Bfr_arg__add(this);

@ -54,16 +54,17 @@ public class Bry_find_ {
public static int Find_fwd(byte[] src, byte[] lkp) {return Find(src, lkp, 0 , src.length, true);}
public static int Find_fwd(byte[] src, byte[] lkp, int cur) {return Find(src, lkp, cur , src.length, true);}
public static int Find_fwd(byte[] src, byte[] lkp, int cur, int end) {return Find(src, lkp, cur , end, true);}
private static final int OffsetCompare = 1;// handle srcPos >= 1 -> srcPosChk > 0
public static int Find(byte[] src, byte[] lkp, int src_bgn, int src_end, boolean fwd) {
if (src_bgn < 0 || src.length == 0) return Bry_find_.Not_found;
int dif, lkp_len = lkp.length, lkp_bgn, lkp_end, src_end_chk;
if (fwd) {
if (src_bgn > src_end) return Bry_find_.Not_found;
dif = 1; lkp_bgn = 0; lkp_end = lkp_len; src_end_chk = src_end - CompareAble_.OffsetCompare;
dif = 1; lkp_bgn = 0; lkp_end = lkp_len; src_end_chk = src_end - OffsetCompare;
}
else {
if (src_bgn < src_end) return Bry_find_.Not_found;
dif = -1; lkp_bgn = lkp_len - 1; lkp_end = -1; src_end_chk = src.length - CompareAble_.OffsetCompare; // src_end_chk needed when going bwd, b/c lkp_len may be > 1
dif = -1; lkp_bgn = lkp_len - 1; lkp_end = -1; src_end_chk = src.length - OffsetCompare; // src_end_chk needed when going bwd, b/c lkp_len may be > 1
}
while (src_bgn != src_end) { // while src is not done;
int lkp_cur = lkp_bgn;

@ -16,63 +16,30 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
import gplx.core.lists.*;
public class CompareAble_ {
public static Comparable as_(Object obj) {return obj instanceof Comparable ? (Comparable)obj : null;}
public static int Compare_obj(Object lhs, Object rhs) {return CompareComparables(as_(lhs), as_(rhs));}
public static int CompareComparables(Comparable lhs, Comparable rhs) {
public static int Compare_obj(Object lhs, Object rhs) {return Compare_comp(as_(lhs), as_(rhs));}
public static int Compare_comp(Comparable lhs, Comparable rhs) {
if (lhs == null && rhs == null) return CompareAble_.Same;
else if (lhs == null) return CompareAble_.More;
else if (rhs == null) return CompareAble_.Less;
else return Compare(lhs, rhs);
}
public static int Compare(Comparable lhs, Comparable rhs) {return lhs.compareTo(rhs);}
public static boolean Is_more(Comparable lhs, Comparable rhs) {return Is(More, lhs, rhs);}
public static boolean Is_moreOrSame(Comparable lhs, Comparable rhs) {return Is(MoreOrSame, lhs, rhs);}
public static boolean Is_less(Comparable lhs, Comparable rhs) {return Is(Less, lhs, rhs);}
public static boolean Is_lessOrSame(Comparable lhs, Comparable rhs) {return Is(LessOrSame, lhs, rhs);}
public static boolean Is_same(Comparable lhs, Comparable rhs) {return Is(Same, lhs, rhs);}
public static boolean Is(int expt, Comparable lhs, Comparable rhs) {
int actl = CompareComparables(lhs, rhs);
if (actl == Same && expt % 2 == Same) // actl=Same and expt=(Same||MoreOrSame||LessOrSame)
public static boolean Is(int expd, Comparable lhs, Comparable rhs) {
int actl = Compare_comp(lhs, rhs);
if (actl == Same && expd % 2 == Same) // actl=Same and expd=(Same||MoreOrSame||LessOrSame)
return true;
else
return (actl * expt) > 0; // actl=More||Less; expd will match if on same side of 0 (ex: expt=Less; actl=Less; -1 * -1 = 1)
}
// public static int FindSlot(ComparerAble comparer, Object[] ary, Object itm) {return FindSlot(comparer, ary, itm, false);}
public static int FindSlot(ComparerAble comparer, Object[] ary, Object itm) {if (itm == null) throw Err_.new_null();
int aryLen = ary.length;
switch (aryLen) {
case 0: throw Err_.new_wo_type("ary cannot have 0 itms");
case 1: return 0;
}
int lo = -1, hi = aryLen - 1; // NOTE: -1 is necessary; see test
int curPos = (hi - lo) / 2;
int delta = 1;
while (true) {
Object curSeg = ary[curPos];
int comp = curSeg == null ? CompareAble_.More : comparer.compare(itm, curSeg); // nulls should only happen for lastAry
// if (dbg) {
// Tfds.Write(curPos, itm.toString(), comp, comp.toString(), curSeg.toString());
// }
if (comp == CompareAble_.Same) return curPos;
else if (comp > CompareAble_.Same) {lo = curPos; delta = 1;}
else if (comp < CompareAble_.Same) {hi = curPos; delta = -1;}
int dif = hi - lo;
if (dif == 1 || dif == 0) return hi; // NOTE: can be 0 when ary.length == 1 || 2; also, sometimes 0 in some situations
else curPos += (dif / 2) * delta;
}
return (actl * expd) > 0; // actl=More||Less; expd will match if on same side of 0 (ex: expd=Less; actl=Less; -1 * -1 = 1)
}
public static int Compare(Comparable lhs, Comparable rhs) {return lhs.compareTo(rhs);}
public static final int
More = 1
, Less = -1
, Same = 0
, MoreOrSame = 2
, LessOrSame = -2
, ReverseMult = -1
, OffsetCompare = 1 // handle srcPos >= 1 -> srcPosChk > 0
;
public static int Multiplier(boolean v) {return v ? 1 : -1;}
More = 1
, Less = -1
, Same = 0
, More_or_same = 2
, Less_or_same = -2
;
}

@ -29,12 +29,6 @@ public class Err extends RuntimeException {
public boolean Logged() {return logged;} public Err Logged_y_() {logged = true; return this;} private boolean logged;
public int Trace_ignore() {return trace_ignore;} public Err Trace_ignore_add_1_() {++trace_ignore; return this;} private int trace_ignore = 0;
public Err Args_add(Object... args) {msgs_ary[msgs_idx - 1].Args_add(args); return this;} // i - 1 to get current
@gplx.Internal protected boolean Type_match(String type) {
for (int i = 0; i < msgs_len; ++i) {
if (String_.Eq(type, msgs_ary[i].Type())) return true;
}
return false;
}
@gplx.Internal protected void Msgs_add(String type, String msg, Object[] args) {
if (msgs_idx == msgs_len) {
int new_len = msgs_len * 2;
@ -56,7 +50,7 @@ public class Err extends RuntimeException {
}
private String To_str(boolean called_by_log, boolean include_trace) {
String nl_str = called_by_log ? "\t" : "\n";
String rv = ""; //nl_str + "----------------------------------------------------------------------" + nl_str;
String rv = "";
for (int i = 0; i < msgs_idx; ++i) {
rv += "[err " + Int_.To_str(i) + "] " + String_.Replace(msgs_ary[i].To_str(), "\n", nl_str) + nl_str;
}

@ -17,14 +17,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Err_ {
private static String Type__gplx = "gplx"; @gplx.Internal protected static String Trace_null = null;
private static String Type__gplx = "gplx", Trace_null = null;
public static void Noop(Exception e) {}
public static Err as_(Object obj) {return obj instanceof Err ? (Err)obj : null;}
public static Err New(String msg, Object... args) {return new Err(Bool_.Y, Trace_null, "", String_.Format(msg, args));}
public static Err new_(String type, String msg, Object... args) {return new Err(Bool_.Y, Trace_null, type, msg, args);}
public static Err new_wo_type(String msg, Object... args) {return new Err(Bool_.Y, Trace_null, Type__gplx, msg, args);}
public static Err new_exc(Exception e, String type, String msg, Object... args) {
Err rv = cast_or_make(e);
Err rv = Cast_or_make(e);
rv.Msgs_add(type, msg, args);
return rv;
}
@ -54,7 +54,8 @@ public class Err_ {
}
public static String Message_lang(Throwable e) {return e.getMessage();}
public static String To_str(Exception e) {return e.toString();} // e.getMessage() is sometimes null?
public static String Message_gplx_full(Exception e) {return Cast_or_make(e).To_str__full();}
public static String Message_gplx_log(Exception e) {return Cast_or_make(e).To_str__log();}
public static String Trace_lang(Throwable e) {return Trace_lang_exec(e.getStackTrace());}
private static String Trace_lang_exec(StackTraceElement[] ary) {
String rv = "";
@ -65,12 +66,8 @@ public class Err_ {
}
return rv;
}
public static boolean Type_match(Exception e, String type) {
Err exc = Err_.as_(e);
return exc == null ? false : exc.Type_match(type);
}
public static String Message_gplx_full(Exception e) {return cast_or_make(e).To_str__full();}
public static String Message_gplx_log(Exception e) {return cast_or_make(e).To_str__log();}
public static Err cast_or_make(Throwable e) {return Type_adp_.Eq_typeSafe(e, Err.class) ? (Err)e : new Err(Bool_.N, Err_.Trace_lang(e), Type_adp_.NameOf_obj(e), Err_.Message_lang(e));}
public static Err Cast_or_null(Exception e) {return Type_adp_.Eq_typeSafe(e, Err.class) ? (Err)e : null;}
public static Err Cast_or_make(Throwable e) {return Type_adp_.Eq_typeSafe(e, Err.class) ? (Err)e : new Err(Bool_.N, Err_.Trace_lang(e), Type_adp_.NameOf_obj(e), Err_.Message_lang(e));}
public static final String Type__op_canceled = "gplx.op_canceled";
}

@ -132,7 +132,7 @@ class GfoMsg_base implements GfoMsg {
args.Add(Keyval_.new_(k, v));
return this;
}
public boolean ReadBool(String k) {Object rv = ReadOr(k,false); if (rv == Nil) ThrowNotFound(k); return parse ? Yn.parse_or((String)rv, false) : Bool_.cast(rv);}
public boolean ReadBool(String k) {Object rv = ReadOr(k,false); if (rv == Nil) ThrowNotFound(k); return parse ? Yn.parse_or((String)rv, false) : Bool_.Cast(rv);}
public int ReadInt(String k) {Object rv = ReadOr(k, 0) ; if (rv == Nil) ThrowNotFound(k); return parse ? Int_.parse((String)rv) : Int_.cast(rv);}
public byte ReadByte(String k) {Object rv = ReadOr(k, 0) ; if (rv == Nil) ThrowNotFound(k); return parse ? Byte_.parse((String)rv) : Byte_.cast(rv);}
public long ReadLong(String k) {Object rv = ReadOr(k, 0) ; if (rv == Nil) ThrowNotFound(k); return parse ? Long_.parse((String)rv) : Long_.cast(rv);}
@ -143,7 +143,7 @@ class GfoMsg_base implements GfoMsg {
public DateAdp ReadDate(String k) {Object rv = ReadOr(k, null); if (rv == Nil) ThrowNotFound(k); return parse ? DateAdp_.parse_gplx((String)rv) : DateAdp_.cast(rv);}
public Io_url ReadIoUrl(String k) {Object rv = ReadOr(k, null); if (rv == Nil) ThrowNotFound(k); return parse ? Io_url_.new_any_((String)rv) : Io_url_.cast(rv);}
public Object CastObj(String k) {Object rv = ReadOr(k, null); if (rv == Nil) ThrowNotFound(k); return rv;}
public boolean ReadBoolOr(String k, boolean or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Yn.parse_or((String)rv, or) : Bool_.cast(rv);}
public boolean ReadBoolOr(String k, boolean or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Yn.parse_or((String)rv, or) : Bool_.Cast(rv);}
public int ReadIntOr(String k, int or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Int_.parse((String)rv) : Int_.cast(rv);}
public long ReadLongOr(String k, long or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Long_.parse((String)rv) : Long_.cast(rv);}
public float ReadFloatOr(String k, float or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Float_.parse((String)rv) : Float_.cast(rv);}
@ -152,9 +152,9 @@ class GfoMsg_base implements GfoMsg {
public String ReadStrOr(String k, String or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return (String)rv;}
public DateAdp ReadDateOr(String k, DateAdp or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? DateAdp_.parse_gplx((String)rv) : DateAdp_.cast(rv);}
public Io_url ReadIoUrlOr(String k, Io_url or) {Object rv = ReadOr(k, or) ; if (rv == Nil) return or ; return parse ? Io_url_.new_any_((String)rv) : Io_url_.cast(rv);}
public boolean ReadBoolOrFalse(String k) {Object rv = ReadOr(k,false); if (rv == Nil) return false ; return parse ? Yn.parse_or((String)rv, false) : Bool_.cast(rv);}
public boolean ReadBoolOrTrue(String k) {Object rv = ReadOr(k, true); if (rv == Nil) return true ; return parse ? Yn.parse_or((String)rv, true) : Bool_.cast(rv);}
public boolean ReadYnOrY(String k) {Object rv = ReadOr(k, true); if (rv == Nil) return true ; return parse ? Yn.parse_or((String)rv, true) : Bool_.cast(rv);}
public boolean ReadBoolOrFalse(String k) {Object rv = ReadOr(k,false); if (rv == Nil) return false ; return parse ? Yn.parse_or((String)rv, false) : Bool_.Cast(rv);}
public boolean ReadBoolOrTrue(String k) {Object rv = ReadOr(k, true); if (rv == Nil) return true ; return parse ? Yn.parse_or((String)rv, true) : Bool_.Cast(rv);}
public boolean ReadYnOrY(String k) {Object rv = ReadOr(k, true); if (rv == Nil) return true ; return parse ? Yn.parse_or((String)rv, true) : Bool_.Cast(rv);}
public boolean ReadYn(String k) {Object rv = ReadOr(k,false); if (rv == Nil) ThrowNotFound(k); return parse ? Yn.parse_or((String)rv, false) : Yn.coerce_(rv);}
public boolean ReadYn_toggle(String k, boolean cur) {
Object rv = ReadOr(k, "!");
@ -262,7 +262,7 @@ class XtoStrWkr_gplx implements XtoStrWkr {
String rv = null;
if (type == String.class) rv = String_.cast(o);
else if (Int_.TypeMatch(type)) return Int_.To_str(Int_.cast(o));
else if (Type_adp_.Eq(type, Bool_.Cls_ref_type)) return Yn.To_str(Bool_.cast(o));
else if (Type_adp_.Eq(type, Bool_.Cls_ref_type)) return Yn.To_str(Bool_.Cast(o));
else if (type == DateAdp.class) return DateAdp_.cast(o).XtoStr_gplx();
else rv = Object_.Xto_str_strict_or_empty(o);
return String_.Replace(rv, "'", "''");

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
import gplx.core.strings.*; import gplx.langs.gfs.*;
public class Int_ implements Gfo_invk {
public class Int_ {
public static final String Cls_val_name = "int";
public static final Class<?> Cls_ref_type = Integer.class;
public static final int Base1 = 1;
@ -151,10 +151,6 @@ public class Int_ implements Gfo_invk {
}
return rv * sign;
} public static int[] Log10Ary = new int[] {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, Int_.Max_value}; public static int Log10AryLen = 11;
public Int_ FailIfNeg1(String key, int val) {
if (val < 0) throw Err_.new_wo_type("key must be >= 0", "key", key, "val", val);
return this;
}
public static String To_str_pad_bgn_space(int v, int reqdPlaces) {return To_str_pad_bgn_zero(v, reqdPlaces, Byte_ascii.Space, true);} // EX: 1, 3 returns " 1"
public static String To_str_pad_bgn_zero(int v, int reqdPlaces) {return To_str_pad_bgn_zero(v, reqdPlaces, Byte_ascii.Num_0, true);} // EX: 1, 3 returns "001"
static String To_str_pad_bgn_zero(int val, int places, byte pad_chr, boolean bgn) {
@ -183,18 +179,6 @@ public class Int_ implements Gfo_invk {
public static String To_str(int v) {return new Integer(v).toString();}
public static String To_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 : To_str_pad_bgn_zero(v, pad);
}
else if (ctx.Match(k, "Add")) {
int v = m.ReadInt(GfsCore_.Arg_primitive), operand = m.ReadInt("operand");
return ctx.Deny() ? (Object)this : v + operand;
}
else return Gfo_invk_.Rv_unhandled;
} public static final String Invk_XtoStr_PadBgn = "XtoStr_PadBgn";
public static final Int_ Gfs = new Int_();
public static int To_int_hex(byte[] src) {return To_int_hex(src, 0, src.length);}
public static int To_int_hex(byte[] src, int bgn, int end) {
int rv = 0; int factor = 1;

@ -86,7 +86,7 @@ public class Keyval_ {
continue; // don't add \n below
}
else if (Type_adp_.Eq(val_type, Bool_.Cls_ref_type)) { // val is boolean
boolean val_as_bool = Bool_.cast(val);
boolean val_as_bool = Bool_.Cast(val);
bfr.Add(val_as_bool ? Bool_.True_bry : Bool_.False_bry); // add "true" or "false"; don't call toString
}
else

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
public class Long_ {
public static final String Cls_val_name = "long";
public static final Class<?> Cls_ref_type = Long.class;
public static final Class<?> Cls_ref_type = Long.class;
public static final int Log10Ary_len = 21;
public static long[] Log10Ary = new long[]
{ 1, 10, 100, 1000, 10000
@ -55,7 +55,7 @@ public class Long_ {
else if (lhs < rhs) return CompareAble_.Less;
else return CompareAble_.More;
}
public static int FindIdx(long[] ary, long find_val) {
private static int FindIdx(long[] ary, long find_val) {
int ary_len = ary.length;
int adj = 1;
int prv_pos = 0;

@ -16,9 +16,9 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Object_ {
public class Object_ {
public static final String Cls_val_name = "Object";
public static final Object[] Ary_empty = new Object[0];
public static final Object[] Ary_empty = new Object[0];
public static Object[] Ary(Object... ary) {return ary;}
public static Object[] Ary_add(Object[] lhs, Object[] rhs) {
int lhs_len = lhs.length, rhs_len = rhs.length;
@ -32,13 +32,6 @@ public class Object_ {
rv[i] = rhs[i - lhs_len];
return rv;
}
public static String[] Ary__to_str_ary(Object[]... ary) {
int len = ary.length;
String[] rv = new String[len];
for (int i = 0; i < len; ++i)
rv[i] = String_.Concat_with_obj("|", (Object[])ary[i]);
return rv;
}
public static boolean Eq(Object lhs, Object rhs) {
if (lhs == null && rhs == null) return true;
else if (lhs == null || rhs == null) return false;
@ -59,10 +52,10 @@ public class Object_ {
Class<?> c = Type_adp_.ClassOf_obj(v);
if (Type_adp_.Eq(c, String_.Cls_ref_type)) return (String)v;
else if (Type_adp_.Eq(c, Bry_.Cls_ref_type)) return String_.new_u8((byte[])v);
else if (Type_adp_.Eq(c, Bool_.Cls_ref_type)) return Bool_.cast(v) ? Bool_.True_str : Bool_.False_str; // always return "true" / "false"
else if (Type_adp_.Eq(c, Bool_.Cls_ref_type)) return Bool_.Cast(v) ? Bool_.True_str : Bool_.False_str; // always return "true" / "false"
else if (Type_adp_.Eq(c, Double_.Cls_ref_type)) return Double_.To_str_loose(Double_.cast(v));
else return v.toString();
}
public static final Object Null = null;
public static final byte[] Bry__null = Bry_.new_a7("null");
public static final Object Null = null;
public static final byte[] Bry__null = Bry_.new_a7("null");
}

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
import java.lang.*;
import gplx.core.strings.*; import gplx.langs.gfs.*; import gplx.core.envs.*;
public class String_ implements Gfo_invk {
public class String_ {
public static int Len(String s) {return s.length();}
public static char CharAt(String s, int i) {return s.charAt(i);}
public static String new_u8(byte[] v, int bgn, int end) {
@ -470,25 +470,6 @@ public class String_ implements Gfo_invk {
return (String[])list.To_ary(String.class);
}
static String Mid_lang(String s, int bgn, int len) {return s.substring(bgn, bgn + len);}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_Replace)) {
String s = m.ReadStr(GfsCore_.Arg_primitive), find = m.ReadStr("find"), replace = m.ReadStr("replace");
if (ctx.Deny()) return this;
return Replace(s, find, replace);
}
else if (ctx.Match(k, Invk_Len)) {
String s = m.ReadStr(GfsCore_.Arg_primitive);
if (ctx.Deny()) return this;
return Len(s);
}
else if (ctx.Match(k, Invk_PadBgn)) {
String s = m.ReadStr(GfsCore_.Arg_primitive); int totalLen = m.ReadInt("totalLen"); String pad = m.ReadStr("pad");
if (ctx.Deny()) return this;
return PadBgn(s, totalLen, pad);
}
else return Gfo_invk_.Rv_unhandled;
} public static final String Invk_Replace = "Replace", Invk_Len = "Len", Invk_PadBgn = "PadBgn";
public static final String_ Gfs = new String_();
public static String Extract_after_bwd(String src, String dlm) {
int dlm_pos = String_.FindBwd(src, dlm); if (dlm_pos == String_.Find_none) return String_.Empty;
int src_len = String_.Len(src); if (dlm_pos == src_len - 1) return String_.Empty;

@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
import gplx.core.stores.*;
public class Yn {
public static final String Y = "y", N = "n";
public static final String Y = "y", N = "n";
public static boolean parse_by_char_or(String v, boolean or) {
if (String_.Eq(v, Y)) return true;
else if (String_.Eq(v, N)) return false;
@ -69,7 +69,7 @@ public class Yn {
String v = mgr.SrlStrOr(key, "");
return mgr.Type_rdr() ? parse_or(v, or) : or;
}
public static boolean coerce_(Object o) {String s = String_.as_(o); return s != null ? parse_or(s, false) : Bool_.cast(o);}
public static boolean coerce_(Object o) {String s = String_.as_(o); return s != null ? parse_or(s, false) : Bool_.Cast(o);}
public static boolean readOrFalse_(DataRdr rdr, String key) {return read_(rdr, key, false);}
public static boolean readOrTrue_(DataRdr rdr, String key) {return read_(rdr, key, true);}
static boolean read_(DataRdr rdr, String key, boolean or) {

@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.core.criterias; import gplx.*; import gplx.core.*;
import gplx.core.texts.*; /*RegxPatn_cls_like*/
public class Criteria_ {
public static final Criteria All = new Criteria_const(true);
public static final Criteria None = new Criteria_const(false);
public static final Criteria All = new Criteria_const(true);
public static final Criteria None = new Criteria_const(false);
public static Criteria Not(Criteria arg) {return new Criteria_not(arg);}
public static Criteria And(Criteria lhs, Criteria rhs) {return new Criteria_and(lhs, rhs);}
public static Criteria And_many(Criteria... ary) {
@ -42,9 +42,9 @@ public class Criteria_ {
public static Criteria in_(Object... array) {return new Criteria_in(false, array);}
public static Criteria inn_(Object... array) {return new Criteria_in(true, array);}
public static Criteria lt_(Comparable val) {return new Criteria_comp(CompareAble_.Less, val);}
public static Criteria lte_(Comparable val) {return new Criteria_comp(CompareAble_.LessOrSame, val);}
public static Criteria lte_(Comparable val) {return new Criteria_comp(CompareAble_.Less_or_same, val);}
public static Criteria mt_(Comparable val) {return new Criteria_comp(CompareAble_.More, val);}
public static Criteria mte_(Comparable val) {return new Criteria_comp(CompareAble_.MoreOrSame, val);}
public static Criteria mte_(Comparable val) {return new Criteria_comp(CompareAble_.More_or_same, val);}
public static Criteria between_(Comparable lhs, Comparable rhs) {return new Criteria_between(false, lhs, rhs);}
public static Criteria between_(boolean negated, Comparable lhs, Comparable rhs) {return new Criteria_between(negated, lhs, rhs);}
public static Criteria like_(String pattern) {return new Criteria_like(false, RegxPatn_cls_like_.parse(pattern, RegxPatn_cls_like.EscapeDefault));}

@ -19,7 +19,7 @@ package gplx.core.criterias; import gplx.*; import gplx.core.*;
public class Criteria_between implements Criteria {
public Criteria_between(boolean neg, Comparable lo, Comparable hi) {this.neg = neg; this.lo = lo; this.hi = hi;}
public byte Tid() {return Criteria_.Tid_between;}
public boolean Neg() {return neg;} private final boolean neg;
public boolean Neg() {return neg;} private final boolean neg;
public Comparable Lo() {return lo;} private Comparable lo; public void Lo_(Comparable v) {this.lo = v;}
public Comparable Hi() {return hi;} private Comparable hi; public void Hi_(Comparable v) {this.hi = v;}
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
@ -30,8 +30,8 @@ public class Criteria_between implements Criteria {
}
public boolean Matches(Object comp_obj) {
Comparable comp = CompareAble_.as_(comp_obj);
int lo_rslt = CompareAble_.CompareComparables(lo, comp);
int hi_rslt = CompareAble_.CompareComparables(hi, comp);
int lo_rslt = CompareAble_.Compare_comp(lo, comp);
int hi_rslt = CompareAble_.Compare_comp(hi, comp);
boolean rv = (lo_rslt * hi_rslt) != 1;
return neg ? !rv : rv;
}

@ -30,9 +30,10 @@ public class Err_msg {
public String To_str() {return To_str_w_type(type, msg, args);}
public String To_str_wo_type() {return To_str(msg, args);}
public String To_str_wo_args() {return To_str(msg);}
public static String To_str(String msg, Object... args) {return To_str_w_type(null, msg, args);}
public static String To_str_w_type(String type, String msg, Object... args) {
String rv = String_.Len_eq_0(type) ? "" : "<" + type + "> ";
String rv = (type == null) ? "" : "<" + type + "> ";
rv += msg;
int len = args.length;
if (len > 0) {

@ -79,12 +79,12 @@ public abstract class DataRdr_base implements SrlMgr {
}
@gplx.Virtual public boolean ReadBool(String key) {
Object val = Read(key);
try {return (parse) ? Bool_.cast(BoolClassXtn.Instance.ParseOrNull(String_.as_(val))) : Bool_.cast(val);}
try {return (parse) ? Bool_.Cast(BoolClassXtn.Instance.ParseOrNull(String_.as_(val))) : Bool_.Cast(val);}
catch (Exception exc) {throw Err_dataRdr_ReadFailed_err(boolean.class, key, val, exc);}
}
@gplx.Virtual public boolean ReadBoolOr(String key, boolean or) {
Object val = Read(key); if (val == null) return or;
try {return (parse) ? Bool_.parse(String_.as_(val)) : Bool_.cast(val);}
try {return (parse) ? Bool_.Parse(String_.as_(val)) : Bool_.Cast(val);}
catch (Exception exc) {Err_dataRdr_ReadFailed_useOr(exc, boolean.class, key, val, or); return or;}
}
public long ReadLong(String key) {

@ -151,7 +151,7 @@ public class Gftest {
private static void Write__itm(Bry_bfr bfr, int type_id, Object ary, int len, int idx) {
if (idx < len) {
switch (type_id) {
case Type_adp_.Tid__bool: bfr.Add_yn(Bool_.cast(Array_.Get_at(ary, idx))); break;
case Type_adp_.Tid__bool: bfr.Add_yn(Bool_.Cast(Array_.Get_at(ary, idx))); break;
case Type_adp_.Tid__bry: bfr.Add((byte[])Array_.Get_at(ary, idx)); break;
case Type_adp_.Tid__long: bfr.Add_long_variable(Long_.cast(Array_.Get_at(ary, idx))); break;
case Type_adp_.Tid__int: bfr.Add_int_variable(Int_.cast(Array_.Get_at(ary, idx))); break;
@ -175,7 +175,7 @@ public class Gftest {
else if (expd_obj == null || actl_obj == null) eq = false;
else {
switch (tid) {
case Type_adp_.Tid__bool: eq = Bool_.cast(expd_obj) == Bool_.cast(actl_obj); break;
case Type_adp_.Tid__bool: eq = Bool_.Cast(expd_obj) == Bool_.Cast(actl_obj); break;
case Type_adp_.Tid__bry: eq = Bry_.Eq((byte[])expd_obj, (byte[])actl_obj); break;
case Type_adp_.Tid__long: eq = Long_.cast(expd_obj) == Long_.cast(actl_obj); break;
case Type_adp_.Tid__int: eq = Int_.cast(expd_obj) == Int_.cast(actl_obj); break;

@ -17,11 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.type_xtns; import gplx.*; import gplx.core.*;
public class BoolClassXtn extends ClassXtn_base implements ClassXtn {
public static final String Key_const = "bo" + "ol";
public static final String Key_const = "bo" + "ol";
public String Key() {return Key_const;}
@Override public Class<?> UnderClass() {return boolean.class;}
public Object DefaultValue() {return false;}
public boolean Eq(Object lhs, Object rhs) {try {return Bool_.cast(lhs) == Bool_.cast(rhs);} catch (Exception e) {Err_.Noop(e); return false;}}
public boolean Eq(Object lhs, Object rhs) {try {return Bool_.Cast(lhs) == Bool_.Cast(rhs);} catch (Exception e) {Err_.Noop(e); return false;}}
@Override public Object ParseOrNull(String raw) {
if ( String_.Eq(raw, "true")
|| String_.Eq(raw, "True") // needed for Store_Wtr() {boolVal.toString();}
@ -37,5 +37,5 @@ public class BoolClassXtn extends ClassXtn_base implements ClassXtn {
throw Err_.new_parse_type(boolean.class, raw);
}
@Override public Object XtoDb(Object obj) {return obj;}
public static final BoolClassXtn Instance = new BoolClassXtn(); BoolClassXtn() {} // added to ClassXtnPool by default
public static final BoolClassXtn Instance = new BoolClassXtn(); BoolClassXtn() {} // added to ClassXtnPool by default
}

@ -44,12 +44,7 @@ public class GfsCore_ {
Gfo_invk invk = Gfo_invk_.as_(rv);
Object primitive = null;
if (invk == null) { // rv is primitive; find appropriate mgr
Class<?> type = rv.getClass();
if (type == String.class) invk = String_.Gfs;
else if (Int_.TypeMatch(type)) invk = Int_.Gfs;
else if (Type_adp_.Eq(type, Bool_.Cls_ref_type)) invk = Bool_.Gfs;
else throw Err_.new_wo_type("unknown primitive", "type", Type_adp_.NameOf_type(type), "obj", Object_.Xto_str_strict_or_null_mark(rv));
primitive = rv;
throw Err_.new_wo_type("unknown primitive", "type", Type_adp_.NameOf_type(rv.getClass()), "obj", Object_.Xto_str_strict_or_null_mark(rv));
}
Object exec_rv = null;
int len = owner_msg.Subs_count();

@ -1,113 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.langs.gfs; import gplx.*; import gplx.langs.*;
import org.junit.*;
public class GfsCore_tst {
@Before public void setup() {
core = GfsCore.new_();
core.AddObj(String_.Gfs, "String_");
core.AddObj(Int_.Gfs, "Int_");
} GfsCore core;
@Test public void Basic() { // String_.Len('abc') >> 3
tst_Msg
( msg_("String_").Subs_
( msg_("Len").Add("v", "abc"))
, 3);
}
@Test public void PrimitiveConversion() { // String_.Len('abc').Add(-3) >> 0
tst_Msg
( msg_("String_").Subs_
( msg_("Len").Add("v", "abc").Subs_
( msg_("Add").Add("operand", -3))
)
, 0);
}
// @Test public void Fail_notFound() { // String_.DoesNotExists
// tst_Err
// ( msg_("help").Add("", "String_.DoesNotExist")
// , GfsHelp.Err_Unhandled("String_", "DoesNotExist"));
// }
@Test public void Cmd() { // cmd
core.AddCmd(new GfsTest_cmd(), "testCmd");
tst_Msg
( msg_("testCmd").Add("s", "pass")
, "pass");
}
@Test public void EmptyMsg() {
tst_Msg
( msg_("")
, Gfo_invk_.Rv_unhandled);
}
// @Test public void Fail_argMissing() { // String_.Len()
// tst_String__Len_Err(msg_("Len"), GfsCtx.Err_KeyNotFound("v", "<<EMPTY>>"));
// }
// @Test public void Fail_argWrongKey() { // String_.Len(badKey='abc')
// tst_String__Len_Err(msg_("Len").Add("badKey", "abc"), GfsCtx.Err_KeyNotFound("v", "badKey;"));
// }
// @Test public void Fail_argExtraKey() { // String_.Len(v='abc' extraKey=1)
// tst_String__Len_Err(msg_("Len").Add("v", "abc").Add("extraKey", 1), GfsCtx.Err_KeyNotFound("v", "badKey;"));
// }
@Test public void Add_obj_deep() { // String_.Len(badKey='abc')
GfsCore_tst_nest obj1 = GfsCore_tst_nest.new_("1", "val1");
GfsCore_tst_nest obj1_1 = GfsCore_tst_nest.new_("1_1", "val2");
core.AddObj(obj1, "1");
core.AddDeep(obj1_1, "1", "1_1");
GfoMsg root = GfoMsg_.root_("1", "1_1", GfsCore_tst_nest.Prop2);
Object actl = core.ExecOne(GfsCtx.Instance, root);
Tfds.Eq("val2", actl);
}
void tst_String__Len_Err(GfoMsg m, Err expd) {
tst_Err(msg_("String_").Subs_(m), expd);
}
void tst_Err(GfoMsg msg, Err expd) {
GfoMsg root = msg;
GfsCtx ctx = GfsCtx.new_();
try {
core.ExecOne(ctx, root);
Tfds.Fail_expdError();
}
catch (Exception e) {
Tfds.Eq_err(expd, e);
}
}
GfoMsg msg_(String k) {return GfoMsg_.new_cast_(k);}
void tst_Msg(GfoMsg msg, Object expd) {
GfsCtx ctx = GfsCtx.new_();
Object actl = core.ExecOne(ctx, msg);
Tfds.Eq(expd, actl);
}
}
class GfsCore_tst_nest implements Gfo_invk, Gfo_invk_cmd_mgr_owner {
public Gfo_invk_cmd_mgr InvkMgr() {return invkMgr;} Gfo_invk_cmd_mgr invkMgr = Gfo_invk_cmd_mgr.new_();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Prop1)) {return prop1;}
else if (ctx.Match(k, Prop2)) {return prop2;}
else if (ctx.Match(k, prop1)) {return this;}
else return invkMgr.Invk(ctx, ikey, k, m, this);
} public static final String Prop1 = "Prop1", Prop2 = "Prop2";
String prop1, prop2;
public static GfsCore_tst_nest new_(String prop1, String prop2) {
GfsCore_tst_nest rv = new GfsCore_tst_nest();
rv.prop1 = prop1; rv.prop2 = prop2;
return rv;
} GfsCore_tst_nest() {}
}
class GfsTest_cmd implements Gfo_invk {
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return m.ReadStr("s");}
}

@ -20,8 +20,6 @@ import gplx.core.gfo_regys.*;
public class GfsLibIni_core implements GfsLibIni {
public void Ini(GfsCore core) {
core.AddCmd(GfsCoreHelp.new_(core), "help");
core.AddObj(String_.Gfs, "String_");
core.AddObj(Int_.Gfs, "Int_");
core.AddObj(DateAdp_.Gfs, "Date_");
core.AddObj(RandomAdp_.Gfs, "RandomAdp_");
core.AddObj(GfoTemplateFactory.Instance, "factory");
@ -32,5 +30,5 @@ public class GfsLibIni_core implements GfsLibIni {
GfoRegy.Instance.Parsers().Add("Io_url", Io_url_.Parser);
}
public static final GfsLibIni_core Instance = new GfsLibIni_core(); GfsLibIni_core() {}
public static final GfsLibIni_core Instance = new GfsLibIni_core(); GfsLibIni_core() {}
}

@ -59,7 +59,7 @@ class GfmlScopeList {
GfmlScopeItm rv = null;
for (Object itemObj : list) {
GfmlScopeItm itm = (GfmlScopeItm)itemObj;
if (CompareAble_.Is_moreOrSame(pos, itm.DocPos()))
if (CompareAble_.Is(CompareAble_.More_or_same, pos, itm.DocPos()))
rv = itm;
else
break; // ASSUME: insertion is done in order; first lessThan means rest will also be lessThan

@ -35,7 +35,7 @@ public class Db_conn_utl {
String fld_name = fld.Name();
Object val = row[j];
switch (fld.Type().Tid_ansi()) {
case Dbmeta_fld_tid.Tid__bool: stmt.Val_bool_as_byte (fld_name, Bool_.cast(val)); break;
case Dbmeta_fld_tid.Tid__bool: stmt.Val_bool_as_byte (fld_name, Bool_.Cast(val)); break;
case Dbmeta_fld_tid.Tid__byte: stmt.Val_byte (fld_name, Byte_.cast(val)); break;
case Dbmeta_fld_tid.Tid__int: stmt.Val_int (fld_name, Int_.cast(val)); break;
case Dbmeta_fld_tid.Tid__long: stmt.Val_long (fld_name, Long_.cast(val)); break;

@ -58,7 +58,7 @@ public class Db_stmt_ {
public static void Val_by_obj(Db_stmt stmt, String key, Object val) {
int tid = Type_adp_.To_tid_obj(val);
switch (tid) {
case Type_adp_.Tid__bool: stmt.Val_bool_as_byte (key, Bool_.cast(val)); break;
case Type_adp_.Tid__bool: stmt.Val_bool_as_byte (key, Bool_.Cast(val)); break;
case Type_adp_.Tid__byte: stmt.Val_byte (key, Byte_.cast(val)); break;
case Type_adp_.Tid__int: stmt.Val_int (key, Int_.cast(val)); break;
case Type_adp_.Tid__long: stmt.Val_long (key, Long_.cast(val)); break;

@ -60,7 +60,7 @@ public class Db_qry_sql implements Db_qry {
if (Type_adp_.Eq(val_type, Int_.Cls_ref_type))
bfr.Add_int_variable(Int_.cast(val));
else if (Type_adp_.Eq(val_type, Bool_.Cls_ref_type))
bfr.Add_int_fixed(1, Bool_.To_int(Bool_.cast(val))); // NOTE: save boolean to 0 or 1, b/c (a) db may not support bit datatype (sqllite) and (b) avoid i18n issues with "true"/"false"
bfr.Add_int_fixed(1, Bool_.To_int(Bool_.Cast(val))); // NOTE: save boolean to 0 or 1, b/c (a) db may not support bit datatype (sqllite) and (b) avoid i18n issues with "true"/"false"
else if (Type_adp_.Eq(val_type, Double_.Cls_ref_type))
bfr.Add_double(Double_.cast(val));
else if (Type_adp_.Eq(val_type, Long_.Cls_ref_type))

@ -30,7 +30,7 @@ public class Sql_val_wtr {
}
int tid_type = Type_adp_.To_tid_type(val.getClass());
switch (tid_type) {
case Type_adp_.Tid__bool: Bld_val__bool (bfr, Bool_.cast(val)); break;
case Type_adp_.Tid__bool: Bld_val__bool (bfr, Bool_.Cast(val)); break;
case Type_adp_.Tid__byte: Bld_val__byte (bfr, Byte_.cast(val)); break;
case Type_adp_.Tid__short: Bld_val__short (bfr, Short_.cast(val)); break;
case Type_adp_.Tid__int: Bld_val__int (bfr, Int_.cast(val)); break;

@ -38,7 +38,7 @@ public class Db_stmt_arg_list {
}
public static void Fill_crt(Db_stmt stmt, int tid, String key, Object val) {
switch (tid) {
case Dbmeta_fld_tid.Tid__bool: stmt.Crt_bool_as_byte (key, Bool_.cast(val)); break;
case Dbmeta_fld_tid.Tid__bool: stmt.Crt_bool_as_byte (key, Bool_.Cast(val)); break;
case Dbmeta_fld_tid.Tid__byte: stmt.Crt_byte (key, Byte_.cast(val)); break;
case Dbmeta_fld_tid.Tid__int: stmt.Crt_int (key, Int_.cast(val)); break;
case Dbmeta_fld_tid.Tid__long: stmt.Crt_long (key, Long_.cast(val)); break;
@ -52,7 +52,7 @@ public class Db_stmt_arg_list {
}
public static void Fill_val(Db_stmt stmt, int tid, String key, Object val) {
switch (tid) {
case Dbmeta_fld_tid.Tid__bool: stmt.Val_bool_as_byte (key, Bool_.cast(val)); break;
case Dbmeta_fld_tid.Tid__bool: stmt.Val_bool_as_byte (key, Bool_.Cast(val)); break;
case Dbmeta_fld_tid.Tid__byte: stmt.Val_byte (key, Byte_.cast(val)); break;
case Dbmeta_fld_tid.Tid__int: stmt.Val_int (key, Int_.cast(val)); break;
case Dbmeta_fld_tid.Tid__long: stmt.Val_long (key, Long_.cast(val)); break;

@ -270,7 +270,7 @@ public class GfuiElemBase implements GfuiElem {
underMgr = underElem.Core();
subElems = GfuiElemList.new_(this);
textMgr = GfxStringData.new_(this, underElem);
this.Focus_able_(Bool_.cast(ctorArgs.Get_val_or(GfuiElem_.InitKey_focusAble, true)));
this.Focus_able_(Bool_.Cast(ctorArgs.Get_val_or(GfuiElem_.InitKey_focusAble, true)));
underMgr.Size_set(SizeAdp_.new_(20, 20)); // NOTE: CS inits to 20,20; JAVA inits to 0,0
}
@gplx.Virtual public void ctor_kit_GfuiElemBase(Gfui_kit kit, String key, GxwElem underElem, Keyval_hash ctorArgs) {
@ -281,7 +281,7 @@ public class GfuiElemBase implements GfuiElem {
underMgr = underElem.Core();
subElems = GfuiElemList.new_(this);
textMgr = GfxStringData.new_(this, underElem);
this.Focus_able_(Bool_.cast(ctorArgs.Get_val_or(GfuiElem_.InitKey_focusAble, true)));
this.Focus_able_(Bool_.Cast(ctorArgs.Get_val_or(GfuiElem_.InitKey_focusAble, true)));
// underMgr.Size_set(SizeAdp_.new_(20, 20)); // NOTE: CS inits to 20,20; JAVA inits to 0,0
}
@gplx.Virtual public GxwElem UnderElem_make(Keyval_hash ctorArgs) {return GxwElemFactory_.Instance.control_();}

@ -38,7 +38,7 @@ public class ImageAdp_tst {
DateAdp beforeModifiedTime = Io_mgr.Instance.QueryFil(save).ModifiedTime();
img.SaveAsBmp(save);
DateAdp afterModifiedTime = Io_mgr.Instance.QueryFil(save).ModifiedTime();
Tfds.Eq_true(CompareAble_.Is_more(afterModifiedTime, beforeModifiedTime));
Tfds.Eq_true(CompareAble_.Is(CompareAble_.More, afterModifiedTime, beforeModifiedTime));
Hash_algo algo = Hash_algo_.New__md5();
String loadHash = algo.Hash_stream_as_str(Console_adp_.Noop, Io_mgr.Instance.OpenStreamRead(load));

@ -195,7 +195,7 @@ public class Swt_kit implements Gfui_kit {
int args_len = args.length;
for (int i = 0; i < args_len; i++)
ctor_args.Add(args[i]);
boolean border_on = Bool_.cast(ctor_args.Get_val_or(GfuiTextBox.CFG_border_on_, true));
boolean border_on = Bool_.Cast(ctor_args.Get_val_or(GfuiTextBox.CFG_border_on_, true));
GxwTextFld under = new Swt_text_w_border(Swt_control_.cast_or_fail(owner), New_color(border_on ? ColorAdp_.LightGray : ColorAdp_.White), ctor_args);
GfuiTextBox rv = GfuiTextBox_.kit_(this, key, under, ctor_args);
rv.Owner_(owner);
@ -291,7 +291,7 @@ class Swt_shell_close_lnr implements Listener, Gfo_invk {
@Override public void handleEvent(Event event) {
if (kit.Kit_mode__term()) return; // NOTE: will be term if called again from wait_for_sync_cmd
kit.Kit_mode_(Swt_kit_mode.Tid_term); // NOTE: must mark kit as shutting down, else writing to status_bar will create stack overflow; DATE:2014-05-05
boolean rslt = Bool_.cast(kit.Kit_term_cbk().Exec()); // call bgn term
boolean rslt = Bool_.Cast(kit.Kit_term_cbk().Exec()); // call bgn term
if (!rslt) {
event.doit = false; // cbk canceled term; stop close
kit.Kit_mode_(Swt_kit_mode.Tid_ready); // reset kit back to "running" mode;

@ -91,7 +91,7 @@ public class Swt_html implements Gxw_html, Swt_control, FocusListener, Gfo_evt_m
public void Html_js_cbks_add(String func_name, Gfo_invk invk) {new Swt_html_func(browser, func_name, invk);}
public String Html_js_eval_script(String script) {return Eval_script_as_str(script);}
public Object Html_js_eval_script_as_obj(String script) {return Eval_script(script);}
public boolean Html_js_eval_proc_as_bool(String proc, Object... args) {return Bool_.cast(Html_js_eval_proc_as_obj(proc, args));}
public boolean Html_js_eval_proc_as_bool(String proc, Object... args) {return Bool_.Cast(Html_js_eval_proc_as_obj(proc, args));}
public String Html_js_eval_proc_as_str(String proc, Object... args) {return Object_.Xto_str_strict_or_null(Html_js_eval_proc_as_obj(proc, args));}
public String Html_js_send_json(String name, String data) {
String script = String_.Format("return {0}('{1}');", name, String_.Replace(data, "\n", "") );

@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.core.consoles; import gplx.*; import gplx.core.*;
public class Gfo_cmd_arg_itm {
public Gfo_cmd_arg_itm(int tid, boolean reqd, String key, int val_tid) {this.tid = tid; this.reqd = reqd; this.key = key; this.val_tid = val_tid;}
public int Tid() {return tid;} private final int tid;
public boolean Reqd() {return reqd;} private final boolean reqd;
public String Key() {return key;} private final String key;
public int Tid() {return tid;} private final int tid;
public boolean Reqd() {return reqd;} private final boolean reqd;
public String Key() {return key;} private final String key;
public int Val_tid() {return val_tid;} private int val_tid;
public Object Val() {return val;} public Gfo_cmd_arg_itm Val_(Object v) {this.val = v; dirty = true; return this;} private Object val;
public String Note() {return note;} public Gfo_cmd_arg_itm Note_(String v) {note = v; return this;} private String note = "";
@ -45,7 +45,7 @@ public class Gfo_cmd_arg_itm {
default: return "unknown";
}
}
public boolean Val_as_bool() {return Bool_.cast(val);}
public boolean Val_as_bool() {return Bool_.Cast(val);}
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);}

@ -203,8 +203,8 @@ public class Gfh_utl {// TS:Gfo_url_encoder is TS
return bfr.To_str_and_clear();
}
public static void Log(Exception e, String head, byte[] page_url, byte[] src, int pos) {
Err err = Err_.cast_or_make(e); if (err.Logged()) return;
String msg = String_.Format("{0}; page={1} err={2} mid={3} trace={4}", head, page_url, Err_.To_str(e), Bry_.Escape_ws(Bry_.Mid_by_len_safe(src, pos, 255)), err.To_str__log());
Err err = Err_.Cast_or_make(e); if (err.Logged()) return;
String msg = String_.Format("{0}; page={1} err={2} mid={3} trace={4}", head, page_url, Err_.Message_lang(e), Bry_.Escape_ws(Bry_.Mid_by_len_safe(src, pos, 255)), err.To_str__log());
Gfo_usr_dlg_.Instance.Warn_many("", "", msg);
}
}

@ -28,7 +28,7 @@ public class Json_kv_ary_srl {
}
private static Object Val_by_itm(Json_itm itm) {
switch (itm.Tid()) {
case Json_itm_.Tid__bool: return Bool_.To_str_lower(Bool_.cast(itm.Data()));
case Json_itm_.Tid__bool: return Bool_.To_str_lower(Bool_.Cast(itm.Data()));
case Json_itm_.Tid__int:
case Json_itm_.Tid__null:
case Json_itm_.Tid__str:

@ -165,7 +165,7 @@ public class Json_wtr {
private void Write_val_obj(boolean called_by_ary, int type_tid, Object obj) {
switch (type_tid) {
case Type_adp_.Tid__null: bfr.Add(Object_.Bry__null); break;
case Type_adp_.Tid__bool: bfr.Add_bool(Bool_.cast(obj)); break;
case Type_adp_.Tid__bool: bfr.Add_bool(Bool_.Cast(obj)); break;
case Type_adp_.Tid__byte: bfr.Add_byte(Byte_.cast(obj)); break;
case Type_adp_.Tid__int: bfr.Add_int_variable(Int_.cast(obj)); break;
case Type_adp_.Tid__long: bfr.Add_long_variable(Long_.cast(obj)); break;

@ -33,7 +33,7 @@ public class Srch_html_row_wkr {
public void On_rslt_found(Srch_rslt_row new_row) {
Srch_rslt_row last_row = rows[rows_len - 1];
if (last_row != null) {
if (Compare(new_row, last_row) == CompareAble_.MoreOrSame) return; // new_row is < last_row; exit
if (Compare(new_row, last_row) == CompareAble_.More_or_same) return; // new_row is < last_row; exit
}
int new_row_slot = Find_insert_slot(new_row); if (new_row_slot == -1) return;
Srch_rslt_row insert_row = rows[new_row_slot];

@ -40,7 +40,7 @@ public class Xoi_mirror_parser {
int len = ary.length;
for (int i = len - 1; i > -1; i--) {
String itm = ary[i];
if (CompareAble_.Is_lessOrSame(itm, comp)) return itm;
if (CompareAble_.Is(CompareAble_.Less_or_same, itm, comp)) return itm;
}
return "";
}

@ -75,7 +75,7 @@ public class Site_core_tbl implements Db_tbl {
try {
while (rdr.Move_next()) {
Site_core_itm itm = new_itm(rdr);
if (itm.Json_date().compareTo(cutoff) == CompareAble_.MoreOrSame) continue; // ignore those downloaded after cutoff date
if (itm.Json_date().compareTo(cutoff) == CompareAble_.More_or_same) continue; // ignore those downloaded after cutoff date
itm.Json_text_null_();
list.Add(itm);
}

@ -67,7 +67,7 @@ public class Xog_mnu_bldr {
Gfui_mnu_itm mnu_itm = owner_gui.Itms_add_chk_msg(sub.Gui_text(), img, app, app.Gfs_mgr(), msg_n, msg_y);
sub.Evt_mgr().Sub(mnu_itm);
Xog_cmd_itm cmd = app.Gui_mgr().Cmd_mgr().Get_or_null(sub.Key());
boolean v = Bool_.cast(app.Gfs_mgr().Run_str_for(app, cmd.Cmd()));
boolean v = Bool_.Cast(app.Gfs_mgr().Run_str_for(app, cmd.Cmd()));
mnu_itm.Selected_(v);
return mnu_itm;
}

@ -105,7 +105,7 @@ public class Xog_html_itm implements Xog_js_wkr, Gfo_invk, Gfo_evt_itm {
Gfo_invk_.Invk_by_msg(cmd_sync, Invk_html_elem_delete, m);
}
@gplx.Virtual public String Html_elem_atr_get_str(String id, String atr_key) {return html_box.Html_js_eval_proc_as_str(Xog_js_procs.Doc__atr_get_as_obj, id, atr_key);}
@gplx.Virtual public boolean Html_elem_atr_get_bool(String id, String atr_key) {return Bool_.parse(html_box.Html_js_eval_proc_as_str(Xog_js_procs.Doc__atr_get_to_str, id, atr_key));}
@gplx.Virtual public boolean Html_elem_atr_get_bool(String id, String atr_key) {return Bool_.Parse(html_box.Html_js_eval_proc_as_str(Xog_js_procs.Doc__atr_get_to_str, id, atr_key));}
public void Html_atr_set(String elem_id, String atr_key, String atr_val) {

@ -18,10 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.htmls.bridges; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
import gplx.langs.jsons.*;
public class Bridge_msg_bldr {
private final Json_wtr wtr = new Json_wtr();
private final Json_wtr wtr = new Json_wtr();
private boolean rslt_pass; private String rslt_msg;
private String notify_text; private String notify_status;
private final Gfo_tree_list data_root = new Gfo_tree_list("data");
private final Gfo_tree_list data_root = new Gfo_tree_list("data");
public Bridge_msg_bldr() {
wtr.Opt_ws_(Bool_.N);
this.Clear();
@ -83,7 +83,7 @@ public class Bridge_msg_bldr {
Gfo_tree_data sub_kv = (Gfo_tree_data)itm;
String key = sub_kv.Key(); Object val = sub_kv.Val();
switch (sub_kv.Val_tid()) {
case Type_adp_.Tid__bool: wtr.Kv_bool(key, Bool_.cast(val)); break;
case Type_adp_.Tid__bool: wtr.Kv_bool(key, Bool_.Cast(val)); break;
case Type_adp_.Tid__int: wtr.Kv_int(key, Int_.cast(val)); break;
case Type_adp_.Tid__bry: wtr.Kv_bry(key, (byte[])val); break;
default: wtr.Kv_str(key, Object_.Xto_str_strict_or_null_mark(val)); break;
@ -96,7 +96,7 @@ public class Bridge_msg_bldr {
}
wtr.Nde_end();
}
private static final byte[]
private static final byte[]
Key_rslt = Bry_.new_a7("rslt"), Key_rslt_pass = Bry_.new_a7("pass"), Key_rslt_msg = Bry_.new_a7("msg")
, Key_notify = Bry_.new_a7("notify"), Key_notify_text = Bry_.new_a7("text"), Key_notify_status = Bry_.new_a7("status"), Key_notify_hint = Bry_.new_a7("hint")
;

@ -49,7 +49,7 @@ public class Xoh_js_cbk implements Gfo_invk {
Xop_ctx ctx = wiki.Parser_mgr().Ctx();
boolean old_para_enabled = ctx.Para().Enabled();
byte[] raw = Bry_.new_u8(m.Args_getAt(0).Val_to_str_or_empty());
boolean para_enabled = m.Args_count() < 2 ? false : Bool_.parse(m.Args_getAt(1).Val_to_str_or_empty());
boolean para_enabled = m.Args_count() < 2 ? false : Bool_.Parse(m.Args_getAt(1).Val_to_str_or_empty());
try {
ctx.Para().Enabled_(para_enabled);
wiki.Parser_mgr().Main().Parse_text_to_wdom(root, ctx, ctx.Tkn_mkr(), raw, 0);

@ -70,7 +70,7 @@ public class Xot_invk_mock implements Xot_invk {
if (Type_adp_.Eq_typeSafe(kv_key_obj, Int_.Cls_ref_type)) // key is int; EX: 1 => val
nde_tkn = new Arg_nde_tkn_mock(null, kv.Val_to_str_or_empty()); // add w/o key
else if (Type_adp_.Eq_typeSafe(kv.Val(), Bool_.Cls_ref_type)) { // val is boolean; EX: key => true || key => false
boolean kv_val_bool = Bool_.cast(kv.Val());
boolean kv_val_bool = Bool_.Cast(kv.Val());
if (kv_val_bool)
nde_tkn = new Arg_nde_tkn_mock(kv_key_str, "1"); // true => 1 (PHP behavior)
else
@ -82,7 +82,7 @@ public class Xot_invk_mock implements Xot_invk {
}
return rv;
}
public static final Xot_invk_mock Null = new Xot_invk_mock(Xot_defn_.Tid_null, 1, Bry_.Empty);
public static final Xot_invk_mock Null = new Xot_invk_mock(Xot_defn_.Tid_null, 1, Bry_.Empty);
}
/*
NOTE_1: Xot_invk_mock is being used as a container for two functions

@ -98,7 +98,7 @@ public class Xot_tmpl_wtr {
tkn.Tmpl_evaluate(ctx, src, Xot_invk_temp.Page_is_caller.Src_(src), rslt_bfr);
}
catch (Exception e) {
Err_string = String_.new_u8(src, tkn.Src_bgn(), tkn.Src_end()) + "|" + Type_adp_.NameOf_obj(e) + "|" + Err_.cast_or_make(e).To_str__log();
Err_string = String_.new_u8(src, tkn.Src_bgn(), tkn.Src_end()) + "|" + Type_adp_.NameOf_obj(e) + "|" + Err_.Cast_or_make(e).To_str__log();
if (Env_.Mode_testing())
throw Err_.new_exc(e, "xo", Err_string);
else

@ -179,6 +179,6 @@ class Gfui_html_mok extends Xog_html_itm { private Hash_adp elem_atrs = Hash_adp
return (String)elem_atrs.Get_by(id + "." + atr_key);
}
@Override public boolean Html_elem_atr_get_bool(String id, String atr_key) {
return Bool_.parse((String)elem_atrs.Get_by(id + "." + atr_key));
return Bool_.Parse((String)elem_atrs.Get_by(id + "." + atr_key));
}
}

@ -214,7 +214,7 @@ public class Xodb_load_mgr_txt implements Xodb_load_mgr {
Int_obj_ref count = Int_obj_ref.New_zero();
Xob_random_itm[] files = Build_random_itms(regy_mgr, count);
int random_idx = RandomAdp_.new_().Next(count.Val() - 1); // get a random idx; -1 since count is super 1 (EX: count of 1 mil; random_idx of 0 - 999,999)
int file_idx = CompareAble_.FindSlot(Xob_random_itm_comparer.Instance, files, new Xob_random_itm(-1, random_idx, -1));
int file_idx = Xowd_regy_mgr_.FindSlot(Xob_random_itm_comparer.Instance, files, new Xob_random_itm(-1, random_idx, -1));
Io_url file_url = fsys_mgr.Url_ns_fil(Xotdb_dir_info_.Tid_ttl, ns.Id(), file_idx);
Load_xdat_file(Cancelable_.Never, tmp_xdat_file, file_url);
Xob_random_itm file = files[file_idx];

@ -25,7 +25,7 @@ public class Xow_html_util implements Gfo_invk {
} private static final String Invk_if_bool = "if_bool", Invk_if_yn = "if_yn";
String If_bool(String expr, String true_val, String false_val) {
Object o = wiki.Appe().Gfs_mgr().Run_str(expr);
try {return Bool_.cast(o) ? true_val : false_val;}
try {return Bool_.Cast(o) ? true_val : false_val;}
catch (Exception e) {Err_.Noop(e); return "expr failed: " + expr;}
}
String If_yn(String expr, String true_val, String false_val) {

@ -27,7 +27,7 @@ public class Xowd_regy_mgr {
public void Clear() {files_ary = Xowd_hive_regy_itm.Ary_empty;}
public int Files_find(byte[] key) {
if (files_ary.length == 0) return Xowd_regy_mgr.Regy_null; // NOTE: FindSlot does not accept empty ary; returning 0, b/c Find returns likely file_idx; EX: regy of 0|B|D and 1|F|H; A returns 0; Z returns 1
return CompareAble_.FindSlot(comparer, files_ary, comparer_itm.End_(key));
return Xowd_regy_mgr_.FindSlot(comparer, files_ary, comparer_itm.End_(key));
} ComparerAble comparer = Xowd_ttl_file_comparer_end.Instance; Xowd_hive_regy_itm comparer_itm = Xowd_hive_regy_itm.tmp_().Count_(1);
public Xowd_hive_regy_itm Create(byte[] key) {
int itm_idx = files_ary.length;

@ -0,0 +1,44 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.tdbs.hives; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
import gplx.core.lists.*;
public class Xowd_regy_mgr_ {
public static int FindSlot(ComparerAble comparer, Object[] ary, Object itm) {if (itm == null) throw Err_.new_null();
int aryLen = ary.length;
switch (aryLen) {
case 0: throw Err_.new_wo_type("ary cannot have 0 itms");
case 1: return 0;
}
int lo = -1, hi = aryLen - 1; // NOTE: -1 is necessary; see test
int curPos = (hi - lo) / 2;
int delta = 1;
while (true) {
Object curSeg = ary[curPos];
int comp = curSeg == null ? CompareAble_.More : comparer.compare(itm, curSeg); // nulls should only happen for lastAry
// if (dbg) {
// Tfds.Write(curPos, itm.toString(), comp, comp.toString(), curSeg.toString());
// }
if (comp == CompareAble_.Same) return curPos;
else if (comp > CompareAble_.Same) {lo = curPos; delta = 1;}
else if (comp < CompareAble_.Same) {hi = curPos; delta = -1;}
int dif = hi - lo;
if (dif == 1 || dif == 0) return hi; // NOTE: can be 0 when ary.length == 1 || 2; also, sometimes 0 in some situations
else curPos += (dif / 2) * delta;
}
}
}

@ -15,10 +15,9 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
import org.junit.*;
import gplx.core.lists.*;
public class CompareAble_tst implements ComparerAble {
package gplx.xowa.wikis.tdbs.hives; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
import org.junit.*; import gplx.core.lists.*;
public class Xowd_regy_mgr__tst implements ComparerAble {
@Test public void Basic() {
String[] slotAry = new String[] {"b", "e", "h"}; // 0=b 1=e 2=h
tst_FindSlot(slotAry, "f", "h"); // f -> 1 2 -> 2
@ -34,5 +33,5 @@ public class CompareAble_tst implements ComparerAble {
tst_FindSlot(slotAry, "w", null);
}
public int compare(Object lhsObj, Object rhsObj) {return CompareAble_.Compare_obj(lhsObj, rhsObj);}
void tst_FindSlot(String[] slotAry, String s, String expd) {Tfds.Eq(expd, slotAry[CompareAble_.FindSlot(this, slotAry, s)]);}
void tst_FindSlot(String[] slotAry, String s, String expd) {Tfds.Eq(expd, slotAry[gplx.xowa.wikis.tdbs.hives.Xowd_regy_mgr_.FindSlot(this, slotAry, s)]);}
}

@ -63,7 +63,7 @@ public class Scrib_invoke_func extends Pf_func_base {
invoke_wkr.Eval_end(ctx.Page(), mod_name, fnc_name, log_time_bgn);
}
catch (Throwable e) {
Err err = Err_.cast_or_make(e);
Err err = Err_.Cast_or_make(e);
Error(bfr, wiki.Msg_mgr(), err);
Scrib_err_filter_mgr err_filter_mgr = invoke_wkr == null ? null : invoke_wkr.Err_filter_mgr();
if ( err_filter_mgr == null // no err_filter_mgr defined;
@ -73,7 +73,7 @@ public class Scrib_invoke_func extends Pf_func_base {
wiki.Parser_mgr().Scrib().Terminate_when_page_changes_y_(); // NOTE: terminate core when page changes; not terminating now, else page with many errors will be very slow due to multiple remakes of core; PAGE:th.d:all; DATE:2014-10-03
}
}
public static void Error(Bry_bfr bfr, Xow_msg_mgr msg_mgr, Err err) {Error(bfr, msg_mgr, Err_.cast_or_make(err).To_str__top_wo_args());}// NOTE: must use "short" error message to show in wikitext; DATE:2015-07-27
public static void Error(Bry_bfr bfr, Xow_msg_mgr msg_mgr, Err err) {Error(bfr, msg_mgr, Err_.Cast_or_make(err).To_str__top_wo_args());}// NOTE: must use "short" error message to show in wikitext; DATE:2015-07-27
public static void Error(Bry_bfr bfr, Xow_msg_mgr msg_mgr, String error) {
// for Luaj, msg combines both err; split out traceback else error message will be very long; note that Warn_many will still log traceback; DATE:2016-09-09
String error_visible = error;

@ -88,7 +88,7 @@ public class Scrib_invoke_func_fxt {
fxt.Test_parse_page_tmpl_str(raw, tmp_bfr.To_str_and_clear());
}
public void Test_error(Exception e, String expd) {
Scrib_invoke_func.Error(tmp_bfr, fxt.Wiki().Msg_mgr(), Err_.cast_or_make(e));
Scrib_invoke_func.Error(tmp_bfr, fxt.Wiki().Msg_mgr(), Err_.Cast_or_make(e));
Tfds.Eq_str(expd, tmp_bfr.To_str_and_clear(), "error");
}
public void Test_lib_proc(Scrib_lib lib, String func_name, Object[] args, String expd) {Test_lib_proc_kv(lib, func_name, Scrib_kv_utl_.base1_many_(args), expd);}
@ -214,7 +214,7 @@ class Scrib_lua_rsp_bldr {
Class<?> v_type = v.getClass();
if (Object_.Eq(v_type, Int_.Cls_ref_type)) Bld_int(bfr, Int_.cast(v));
else if (Object_.Eq(v_type, String_.Cls_ref_type)) Bld_str(bfr, String_.cast(v));
else if (Object_.Eq(v_type, Bool_.Cls_ref_type)) Bld_bool(bfr, Bool_.cast(v));
else if (Object_.Eq(v_type, Bool_.Cls_ref_type)) Bld_bool(bfr, Bool_.Cast(v));
else if (Object_.Eq(v_type, Double_.Cls_ref_type)) Bld_double(bfr, Double_.cast(v));
else if (Object_.Eq(v_type, Keyval[].class)) Bld_kv_ary(bfr, (Keyval[])v);
else if (Object_.Eq(v_type, Scrib_lua_proc.class)) Bld_fnc(bfr, (Scrib_lua_proc)v);

@ -82,7 +82,7 @@ public class Process_send_wtr {
public boolean Encode_obj(Bry_bfr bfr, Object o) {
if (o == null) {bfr.Add(CONST_nil); return true;}
Class<?> c = Type_adp_.ClassOf_obj(o);
if (Object_.Eq(c, Bool_.Cls_ref_type)) Encode_bool(bfr, Bool_.cast(o));
if (Object_.Eq(c, Bool_.Cls_ref_type)) Encode_bool(bfr, Bool_.Cast(o));
else if (Object_.Eq(c, Int_.Cls_ref_type)) Encode_int(bfr, Int_.cast(o));
else if (Object_.Eq(c, Long_.Cls_ref_type)) bfr.Add_long_variable(Long_.cast(o));
else if (Object_.Eq(c, Double_.Cls_ref_type)) {if (!Encode_double(bfr, Double_.cast(o))) return false;}

@ -75,7 +75,7 @@ class Process_server_mock_rcvd_val implements Process_server_mock_rcvd {
if (print_key && !kv_val_is_array)
bfr.Add_str_u8(kv.Key()).Add_byte(Byte_ascii.Colon);
if (Type_adp_.Eq(kv_val_type, Bool_.Cls_ref_type))
bfr.Add(Bool_.cast(kv_val) ? gplx.langs.jsons.Json_itm_.Bry__true : gplx.langs.jsons.Json_itm_.Bry__false);
bfr.Add(Bool_.Cast(kv_val) ? gplx.langs.jsons.Json_itm_.Bry__true : gplx.langs.jsons.Json_itm_.Bry__false);
else if (kv_val_is_array) {
Keyval[] sub = (Keyval[])kv_val;
if (sub.length == 0) {bfr.Add_byte(Byte_ascii.Curly_bgn).Add_byte(Byte_ascii.Curly_end);}

@ -174,7 +174,7 @@ public class Scrib_lib_language implements Scrib_lib {
if (kv_ary != null) {
Object skip_commafy_obj = Keyval_.Ary_get_by_key_or_null(kv_ary, "noCommafy");
if (skip_commafy_obj != null)
skip_commafy = Bool_.cast(skip_commafy_obj);
skip_commafy = Bool_.Cast(skip_commafy_obj);
}
}
byte[] rv = lang.Num_mgr().Format_num(num, skip_commafy);

@ -81,7 +81,7 @@ class Scrib_lib_message_data {
break;
case Key_tid_rawMessage: raw_msg_key = kv.Val_to_bry(); break;
case Key_tid_lang: lang_key = kv.Val_to_bry(); break;
case Key_tid_useDB: use_db = Bool_.cast(kv.Val()); break;
case Key_tid_useDB: use_db = Bool_.Cast(kv.Val()); break;
case Key_tid_title: title_bry = kv.Val_to_bry(); break;
case Key_tid_params:
Keyval[] args_ary = (Keyval[])kv.Val();

@ -178,7 +178,7 @@ class Scrib_lib_text__json_util {
else if (Type_adp_.Eq(type, Long_.Cls_ref_type)) wtr.Kv_long(kv.Key(), Long_.cast(kv_val));
else if (Type_adp_.Eq(type, Float_.Cls_ref_type)) wtr.Kv_float(kv.Key(), Float_.cast(kv_val));
else if (Type_adp_.Eq(type, Double_.Cls_ref_type)) wtr.Kv_double(kv.Key(), Double_.cast(kv_val));
else if (Type_adp_.Eq(type, Bool_.Cls_ref_type)) wtr.Kv_bool(kv.Key(), Bool_.cast(kv_val));
else if (Type_adp_.Eq(type, Bool_.Cls_ref_type)) wtr.Kv_bool(kv.Key(), Bool_.Cast(kv_val));
else wtr.Kv_str(kv.Key(), Object_.Xto_str_strict_or_null(kv_val));
}
private void Encode_ary(Object ary) {

@ -166,7 +166,7 @@ public class Scrib_lib_ustring implements Scrib_lib {
for (int j = 0; j < grps_len; j++) {
Regx_group grp = grps[j];
if ( j < capts_len // bounds check b/c null can be passed
&& Bool_.cast(capts[j].Val()) // check if true; indicates that group is "()" or "anypos" see regex converter; DATE:2014-04-23
&& Bool_.Cast(capts[j].Val()) // check if true; indicates that group is "()" or "anypos" see regex converter; DATE:2014-04-23
)
tmp_list.Add(grp.Bgn() + Scrib_lib_ustring.Base1); // return index only for "()"; NOTE: do not return as String; callers expect int and will fail typed comparisons; DATE:2016-01-21
else

@ -52,7 +52,7 @@ public class Scrib_proc_args {
public int Len() {return ary_len;}
public Keyval[] Ary() {return ary;}
public Object Pull_obj(int i) {return Get_or_fail(i);}
public boolean Pull_bool(int i) {return Bool_.cast(Get_or_fail(i));}
public boolean Pull_bool(int i) {return Bool_.Cast(Get_or_fail(i));}
public String Pull_str(int i) {return String_.cast(Get_or_fail(i));}
public byte[] Pull_bry(int i) {return Bry_.new_u8(String_.cast(Get_or_fail(i)));}
public int Pull_int(int i) {
@ -118,8 +118,8 @@ public class Scrib_proc_args {
public byte[] Cast_bry_or_empty(int i) {Object rv = Get_or_null(i); return rv == null ? Bry_.Empty : Bry_.new_u8(String_.cast (rv));}
public byte[] Cast_bry_or(int i, byte[] or) {Object rv = Get_or_null(i); return rv == null ? or : Bry_.new_u8(String_.cast (rv));}
public Object Cast_obj_or_null(int i) {return Get_or_null(i);}
public boolean Cast_bool_or_y(int i) {Object rv = Get_or_null(i); return rv == null ? Bool_.Y : Bool_.cast(rv);}
public boolean Cast_bool_or_n(int i) {Object rv = Get_or_null(i); return rv == null ? Bool_.N : Bool_.cast(rv);}
public boolean Cast_bool_or_y(int i) {Object rv = Get_or_null(i); return rv == null ? Bool_.Y : Bool_.Cast(rv);}
public boolean Cast_bool_or_n(int i) {Object rv = Get_or_null(i); return rv == null ? Bool_.N : Bool_.Cast(rv);}
public int Cast_int_or(int i, int or) {Object rv = Get_or_null(i); return rv == null ? or : Int_.coerce_(rv);} // coerce to handle "1" and 1;
public Keyval[] Cast_kv_ary_or_null(int i) {Object rv = Get_or_null(i); return rv == null ? null : (Keyval[])rv;}
public byte[][] Cast_params_as_bry_ary_or_rest_of_ary(int params_idx) { // PAGE:ru.w:Ленин,_Владимир_Ильич; DATE:2014-07-01 MW:LanguageLibrary.php|ConvertPlural: if (is_array($args[0])) $args = $args[0]; $forms = array_values(array_map('strval', $args));

Loading…
Cancel
Save