mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Core: Refactor base classes
This commit is contained in:
@@ -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 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)
|
||||
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;
|
||||
}
|
||||
}
|
||||
public static int Compare(Comparable lhs, Comparable rhs) {return lhs.compareTo(rhs);}
|
||||
|
||||
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 * expd) > 0; // actl=More||Less; expd will match if on same side of 0 (ex: expd=Less; actl=Less; -1 * -1 = 1)
|
||||
}
|
||||
|
||||
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
|
||||
;
|
||||
}
|
||||
|
||||
@@ -1,38 +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;
|
||||
import org.junit.*;
|
||||
import gplx.core.lists.*;
|
||||
public class CompareAble_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
|
||||
tst_FindSlot(slotAry, "c", "e"); // c -> -1 1 -> 0 -> 0 1 -> 1
|
||||
tst_FindSlot(slotAry, "a", "b"); // a -> -1 1 -> 0 -> -1 0 -> 0
|
||||
}
|
||||
@Test public void Null() {
|
||||
String[] slotAry = new String[] {"b", "g", "l", "q", "v", null};
|
||||
tst_FindSlot(slotAry, "a", "b");
|
||||
tst_FindSlot(slotAry, "b", "b");
|
||||
tst_FindSlot(slotAry, "c", "g");
|
||||
tst_FindSlot(slotAry, "v", "v");
|
||||
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)]);}
|
||||
}
|
||||
@@ -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() {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user