1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Refactor: Clean up Type_ classes

This commit is contained in:
gnosygnu
2017-10-08 18:24:59 -04:00
parent 209601744e
commit d270cce881
67 changed files with 364 additions and 334 deletions

View File

@@ -70,7 +70,7 @@ public class Array_ {
int len = Len(ary);
for (int i = 0; i < len; i++) {
Object itm = Get_at(ary, i);
if (itm != null && Type_adp_.Is_array(itm.getClass()))
if (itm != null && Type_.Is_array(itm.getClass()))
To_str_nested_ary(bfr, (Object)itm, indent + 1);
else {
if (indent > 0) bfr.Add_byte_repeat(Byte_ascii.Space, indent * 2);

View File

@@ -35,11 +35,11 @@ public class Bry_ {
int len = ary.length;
for (int i = 0; i < len; ++i) {
Object itm = ary[i];
Class<?> type = Type_adp_.ClassOf_obj(itm);
if (Type_adp_.Eq(type, int.class)) bfr.Add_byte((byte)Int_.cast(itm));
else if (Type_adp_.Eq(type, String.class)) bfr.Add_str_u8((String)itm);
else if (Type_adp_.Eq(type, byte[].class)) bfr.Add((byte[])itm);
else throw Err_.new_unhandled(Type_adp_.FullNameOf_type(type));
Class<?> type = Type_.Type_by_obj(itm);
if (Type_.Eq(type, int.class)) bfr.Add_byte((byte)Int_.cast(itm));
else if (Type_.Eq(type, String.class)) bfr.Add_str_u8((String)itm);
else if (Type_.Eq(type, byte[].class)) bfr.Add((byte[])itm);
else throw Err_.new_unhandled(Type_.Canonical_name(type));
}
return bfr.To_bry_and_clear();
}

View File

@@ -19,25 +19,23 @@ public class Err extends RuntimeException {
private final boolean is_gplx;
private final String trace;
private Err_msg[] msgs_ary = new Err_msg[8]; private int msgs_len = 8, msgs_idx = 0;
public Err(boolean is_gplx, String trace, String type, String msg, Object... args) {
this.is_gplx = is_gplx;
this.trace = is_gplx ? Err_.Trace_lang(this) : trace; // NOTE: Err_ factory methods pass in null stack trace for gplx excs; call Stack_trace here, note that trace will not show constructor
// NOTE: Err_ factory methods pass in null stack trace for gplx excs; call Stack_trace here, note that trace will not show constructor
this.trace = is_gplx ? Err_.Trace_lang(this) : trace;
Msgs_add(type, msg, args);
}
// marks messages logged so they can be ignored; used by Gfh_utl
public boolean Logged() {return logged;} public Err Logged_y_() {logged = true; return this;} private boolean logged;
// ignores current frame for reporting messages
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 void Msgs_add(String type, String msg, Object[] args) {
if (msgs_idx == msgs_len) {
int new_len = msgs_len * 2;
Err_msg[] new_ary = new Err_msg[new_len];
Array_.Copy_to(msgs_ary, new_ary, 0);
this.msgs_ary = new_ary;
this.msgs_len = new_len;
}
msgs_ary[msgs_idx] = new Err_msg(type, msg, args);
++msgs_idx;
}
public String To_str__full() {return To_str(Bool_.N, Bool_.Y);}
public String To_str__log() {return To_str(Bool_.Y, Bool_.Y);}
public String To_str__msg_only(){
@@ -76,4 +74,16 @@ public class Err extends RuntimeException {
rv += line_bgn_dlm + lines[i];
return rv;
}
@gplx.Internal protected void Msgs_add(String type, String msg, Object[] args) {
if (msgs_idx == msgs_len) {
int new_len = msgs_len * 2;
Err_msg[] new_ary = new Err_msg[new_len];
Array_.Copy_to(msgs_ary, new_ary, 0);
this.msgs_ary = new_ary;
this.msgs_len = new_len;
}
msgs_ary[msgs_idx] = new Err_msg(type, msg, args);
++msgs_idx;
}
}

View File

@@ -31,9 +31,10 @@ public class Err_ {
public static Err new_unsupported() {return new Err(Bool_.Y, Trace_null, Type__gplx, "method not supported");}
public static Err new_unimplemented() {return new Err(Bool_.Y, Trace_null, Type__gplx, "method not implemented");}
public static Err new_unimplemented_w_msg(String msg, Object... args) {return new Err(Bool_.Y, Trace_null, Type__gplx, msg, args);}
public static Err new_deprecated(String s) {return new Err(Bool_.Y, Trace_null, Type__gplx, "deprecated", "method", s);}
public static Err new_parse_type(Class<?> c, String raw) {return new_parse(Type_adp_.FullNameOf_type(c), raw);}
public static Err new_parse_exc(Exception e, Class<?> c, String raw) {return new_parse(Type_adp_.FullNameOf_type(c), raw).Args_add("e", Err_.Message_lang(e));}
public static Err new_parse_type(Class<?> c, String raw) {return new_parse(Type_.Canonical_name(c), raw);}
public static Err new_parse_exc(Exception e, Class<?> c, String raw) {return new_parse(Type_.Canonical_name(c), raw).Args_add("e", Err_.Message_lang(e));}
public static Err new_parse(String type, String raw) {return new Err(Bool_.Y, Trace_null, Type__gplx, "parse failed", "type", type, "raw", raw);}
public static Err new_null() {return new Err(Bool_.Y, Trace_null, Type__gplx, "null obj");}
public static Err new_null(String arg) {return new Err(Bool_.Y, Trace_null, Type__gplx, "null obj", "arg", arg);}
@@ -43,16 +44,17 @@ public class Err_ {
public static Err new_invalid_arg(String msg, Object... args) {return new Err(Bool_.Y, Trace_null, Type__gplx, msg, args);}
public static Err new_op_canceled() {return new Err(Bool_.Y, Trace_null, Type__op_canceled, "canceled by usr");}
public static Err new_type_mismatch_w_exc(Exception ignore, Class<?> t, Object o) {return new_type_mismatch(t, o);}
public static Err new_type_mismatch(Class<?> t, Object o) {return new Err(Bool_.Y, Trace_null, Type__gplx, "type mismatch", "expdType", Type_adp_.FullNameOf_type(t), "actlType", Type_adp_.NameOf_obj(o), "actlObj", Object_.Xto_str_strict_or_null_mark(o));}
public static Err new_type_mismatch(Class<?> t, Object o) {return new Err(Bool_.Y, Trace_null, Type__gplx, "type mismatch", "expdType", Type_.Canonical_name(t), "actlType", Type_.Name_by_obj(o), "actlObj", Object_.Xto_str_strict_or_null_mark(o));}
public static Err new_cast(Exception ignore, Class<?> t, Object o) {
String o_str = "";
try {o_str = Object_.Xto_str_strict_or_null_mark(o);}
catch (Exception e) {o_str = "<ERROR>"; Err_.Noop(e);}
return new Err(Bool_.Y, Trace_null, Type__gplx, "cast failed", "type", Type_adp_.NameOf_type(t), "obj", o_str);
return new Err(Bool_.Y, Trace_null, Type__gplx, "cast failed", "type", Type_.Name(t), "obj", o_str);
}
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 Message_lang(Throwable e) {
return Error.class.isAssignableFrom(e.getClass())
? e.toString() // error has null for "getMessage()" return "toString()" instead
@@ -69,7 +71,7 @@ public class Err_ {
return rv;
}
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 Err Cast_or_null(Exception e) {return Type_.Eq_by_obj(e, Err.class) ? (Err)e : null;}
public static Err Cast_or_make(Throwable e) {return Type_.Eq_by_obj(e, Err.class) ? (Err)e : new Err(Bool_.N, Err_.Trace_lang(e), Type_.Name_by_obj(e), Err_.Message_lang(e));}
public static final String Type__op_canceled = "gplx.op_canceled";
}

View File

@@ -256,11 +256,11 @@ interface XtoStrWkr {
class XtoStrWkr_gplx implements XtoStrWkr {
public String To_str(Object o) {
if (o == null) return "<<NULL>>";
Class<?> type = Type_adp_.ClassOf_obj(o);
Class<?> type = Type_.Type_by_obj(o);
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_.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, "'", "''");

View File

@@ -49,7 +49,7 @@ public class Keyval_ {
}
sb.Add(itm.Key()).Add("=");
Object itm_val = itm.Val();
if (Type_adp_.Eq_typeSafe(itm_val, Keyval[].class))
if (Type_.Eq_by_obj(itm_val, Keyval[].class))
sb.Add(Ary_to_str((Keyval[])itm_val));
else
sb.Add(Object_.Xto_str_strict_or_null_mark(itm_val));
@@ -81,13 +81,13 @@ public class Keyval_ {
if (val == null)
bfr.Add_str_a7(String_.Null_mark);
else {
Class<?> val_type = Type_adp_.ClassOf_obj(val);
if (Type_adp_.Eq(val_type, Keyval[].class)) { // val is Keyval[]; recurse
Class<?> val_type = Type_.Type_by_obj(val);
if (Type_.Eq(val_type, Keyval[].class)) { // val is Keyval[]; recurse
bfr.Add_byte_nl(); // add nl : "\n"
Ary__to_str__nest(bfr, indent + 1, (Keyval[])val);
continue; // don't add \n below
}
else if (Type_adp_.Eq(val_type, Bool_.Cls_ref_type)) { // val is boolean
else if (Type_.Eq(val_type, Bool_.Cls_ref_type)) { // val is boolean
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
}
@@ -98,8 +98,8 @@ public class Keyval_ {
}
}
public static Keyval as_(Object obj) {return obj instanceof Keyval ? (Keyval)obj : null;}
public static Keyval new_(String key) {return new Keyval(Type_adp_.Tid__str, key, key);}
public static Keyval new_(String key, Object val) {return new Keyval(Type_adp_.Tid__str, key, val);}
public static Keyval int_(int key, Object val) {return new Keyval(Type_adp_.Tid__int, key, val);}
public static Keyval obj_(Object key, Object val) {return new Keyval(Type_adp_.Tid__obj, key, val);}
public static Keyval new_(String key) {return new Keyval(Type_ids_.Id__str, key, key);}
public static Keyval new_(String key, Object val) {return new Keyval(Type_ids_.Id__str, key, val);}
public static Keyval int_(int key, Object val) {return new Keyval(Type_ids_.Id__int, key, val);}
public static Keyval obj_(Object key, Object val) {return new Keyval(Type_ids_.Id__obj, key, val);}
}

View File

@@ -41,17 +41,17 @@ public class Object_ {
public static String Xto_str_strict_or_empty(Object v) {return v == null ? String_.Empty : ToString_lang(v);}
private static String ToString_lang(Object v) {
Class<?> c = v.getClass();
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);
if (Type_.Eq(c, String_.Cls_ref_type)) return (String)v;
else if (Type_.Eq(c, Bry_.Cls_ref_type)) return String_.new_u8((byte[])v);
else return v.toString();
}
public static String Xto_str_loose_or(Object v, String or) { // tries to pretty-print doubles; also standardizes true/false; DATE:2014-07-14
if (v == null) return null;
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, Double_.Cls_ref_type)) return Double_.To_str_loose(Double_.cast(v));
Class<?> c = Type_.Type_by_obj(v);
if (Type_.Eq(c, String_.Cls_ref_type)) return (String)v;
else if (Type_.Eq(c, Bry_.Cls_ref_type)) return String_.new_u8((byte[])v);
else if (Type_.Eq(c, Bool_.Cls_ref_type)) return Bool_.Cast(v) ? Bool_.True_str : Bool_.False_str; // always return "true" / "false"
else if (Type_.Eq(c, Double_.Cls_ref_type)) return Double_.To_str_loose(Double_.cast(v));
else return v.toString();
}
public static final Object Null = null;

View File

@@ -128,8 +128,8 @@ public class Tfds { // URL:doc/gplx.tfds/Tfds.txt
list.Add(itm);
}
public static void Err_classMatch(Exception exc, Class<?> type) {
boolean match = Type_adp_.Eq_typeSafe(exc, type);
if (!match) throw Err_.new_("Tfds", "error types do not match", "expdType", Type_adp_.FullNameOf_type(type), "actlType", Type_adp_.NameOf_obj(exc), "actlMsg", Err_.Message_lang(exc));
boolean match = Type_.Eq_by_obj(exc, type);
if (!match) throw Err_.new_("Tfds", "error types do not match", "expdType", Type_.Canonical_name(type), "actlType", Type_.Name_by_obj(exc), "actlMsg", Err_.Message_lang(exc));
}
public static void Eq_err(Err expd, Exception actlExc) {
Tfds.Eq(Err_.Message_gplx_full(expd), Err_.Message_gplx_full(actlExc));

View File

@@ -0,0 +1,56 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx;
public class Type_ {
public static Class<?> Type_by_obj(Object o) {return o.getClass();}
public static Class<?> Type_by_primitive(Object o) {
Class<?> rv = o.getClass();
if (rv == Integer.class) rv = int.class;
else if (rv == Long.class) rv = long.class;
else if (rv == Byte.class) rv = byte.class;
else if (rv == Short.class) rv = short.class;
return rv;
}
public static boolean Eq_by_obj(Object lhs_obj, Class<?> rhs_type) {
Class<?> lhs_type = lhs_obj == null ? null : lhs_obj.getClass();
return Type_.Eq(lhs_type, rhs_type);
}
public static boolean Eq(Class<?> lhs, Class<?> rhs) {// DUPE_FOR_TRACKING: same as Object_.Eq
if (lhs == null && rhs == null) return true;
else if (lhs == null || rhs == null) return false;
else return lhs.equals(rhs);
}
public static String Canonical_name_by_obj(Object o) {return Canonical_name(o.getClass());}
public static String Canonical_name(Class<?> type) {
return type.getCanonicalName();
}
public static String Name_by_obj(Object obj) {return obj == null ? String_.Null_mark : Name(Type_by_obj(obj));}
public static String Name(Class<?> type) {
return type.getName();
}
public static boolean Is_array(Class<?> t) {
return t.isArray();
}
public static boolean Is_assignable_from_by_obj(Object o, Class<?> generic) {return o == null ? false : Is_assignable_from(generic, o.getClass());}
public static boolean Is_assignable_from(Class<?> generic, Class<?> specific) {
return generic.isAssignableFrom(specific);
}
}

View File

@@ -1,94 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx;
public class Type_adp_ {
public static boolean Eq(Class<?> lhs, Class<?> rhs) {
if (lhs == null && rhs == null) return true;
else if (lhs == null || rhs == null) return false;
else return lhs.equals(rhs);
}
public static boolean Eq_typeSafe(Object o, Class<?> expd) {if (o == null) return false;
Class<?> actl = o.getClass();
return Object_.Eq(expd, actl);
}
public static boolean IsAssignableFrom(Class<?> lhs, Class<?> rhs) {return lhs.isAssignableFrom(rhs);}
public static boolean Implements_intf_obj(Object cur, Class<?> type) {return cur == null ? false : IsAssignableFrom(type, cur.getClass());}
public static boolean Is_array(Class<?> t) {return t.isArray();}
public static Class<?> ClassOf_obj(Object o) {return o.getClass();}
public static Class<?> ClassOf_primitive(Object o) {
Class<?> rv = o.getClass();
if (rv == Integer.class) rv = int.class;
else if (rv == Long.class) rv = long.class;
else if (rv == Byte.class) rv = byte.class;
else if (rv == Short.class) rv = short.class;
return rv;
}
public static String FullNameOf_obj(Object o) {return FullNameOf_type(o.getClass());}
public static String FullNameOf_type(Class<?> type) {return type.getCanonicalName();}
public static String NameOf_type(Class<?> type) {return type.getName();}
public static String NameOf_obj(Object obj) {return obj == null ? String_.Null_mark : obj.getClass().getName();}
public static int To_tid_obj(Object o) {
if (o == null) return Tid__null;
Class<?> type = o.getClass();
return To_tid_type(type);
}
public static int To_tid_type(Class<?> type) {
if (Type_adp_.Eq(type, Int_.Cls_ref_type)) return Tid__int;
else if (Type_adp_.Eq(type, String_.Cls_ref_type)) return Tid__str;
else if (Type_adp_.Eq(type, byte[].class)) return Tid__bry;
else if (Type_adp_.Eq(type, Bool_.Cls_ref_type)) return Tid__bool;
else if (Type_adp_.Eq(type, Byte_.Cls_ref_type)) return Tid__byte;
else if (Type_adp_.Eq(type, Long_.Cls_ref_type)) return Tid__long;
else if (Type_adp_.Eq(type, Double_.Cls_ref_type)) return Tid__double;
else if (Type_adp_.Eq(type, Decimal_adp_.Cls_ref_type)) return Tid__decimal;
else if (Type_adp_.Eq(type, DateAdp_.Cls_ref_type)) return Tid__date;
else if (Type_adp_.Eq(type, Float_.Cls_ref_type)) return Tid__float;
else if (Type_adp_.Eq(type, Short_.Cls_ref_type)) return Tid__short;
else if (Type_adp_.Eq(type, Char_.Cls_ref_type)) return Tid__char;
else return Tid__obj;
}
public static int To_tid(String name) {
if (String_.Eq(name, Int_.Cls_val_name)) return Tid__int;
else if (String_.Eq(name, String_.Cls_val_name)) return Tid__str;
else if (String_.Eq(name, Bry_.Cls_val_name)) return Tid__bry;
else if (String_.Eq(name, Bool_.Cls_val_name)) return Tid__bool;
else if (String_.Eq(name, Byte_.Cls_val_name)) return Tid__byte;
else if (String_.Eq(name, Long_.Cls_val_name)) return Tid__long;
else if (String_.Eq(name, Double_.Cls_val_name)) return Tid__double;
else if (String_.Eq(name, Decimal_adp_.Cls_val_name)) return Tid__decimal;
else if (String_.Eq(name, DateAdp_.Cls_ref_name)) return Tid__date;
else if (String_.Eq(name, Float_.Cls_val_name)) return Tid__float;
else if (String_.Eq(name, Short_.Cls_val_name)) return Tid__short;
else if (String_.Eq(name, Char_.Cls_val_name)) return Tid__char;
else return Tid__obj;
}
public static final int
Tid__obj = 0
, Tid__null = 1
, Tid__bool = 2
, Tid__byte = 3
, Tid__short = 4
, Tid__int = 5
, Tid__long = 6
, Tid__float = 7
, Tid__double = 8
, Tid__char = 9
, Tid__str = 10
, Tid__bry = 11
, Tid__date = 12
, Tid__decimal = 13
;
}

View File

@@ -0,0 +1,56 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx;
public class Type_ids_ {
public static final int // SERIALIZABLE.N
Id__obj = 0
, Id__null = 1
, Id__bool = 2
, Id__byte = 3
, Id__short = 4
, Id__int = 5
, Id__long = 6
, Id__float = 7
, Id__double = 8
, Id__char = 9
, Id__str = 10
, Id__bry = 11
, Id__date = 12
, Id__decimal = 13
;
public static int To_id_by_obj(Object o) {
if (o == null) return Type_ids_.Id__null;
Class<?> type = o.getClass();
return Type_ids_.To_id_by_type(type);
}
public static int To_id_by_type(Class<?> type) {
if (Type_.Eq(type, Int_.Cls_ref_type)) return Id__int;
else if (Type_.Eq(type, String_.Cls_ref_type)) return Id__str;
else if (Type_.Eq(type, byte[].class)) return Id__bry;
else if (Type_.Eq(type, Bool_.Cls_ref_type)) return Id__bool;
else if (Type_.Eq(type, Byte_.Cls_ref_type)) return Id__byte;
else if (Type_.Eq(type, Long_.Cls_ref_type)) return Id__long;
else if (Type_.Eq(type, Double_.Cls_ref_type)) return Id__double;
else if (Type_.Eq(type, Decimal_adp_.Cls_ref_type)) return Id__decimal;
else if (Type_.Eq(type, DateAdp_.Cls_ref_type)) return Id__date;
else if (Type_.Eq(type, Float_.Cls_ref_type)) return Id__float;
else if (Type_.Eq(type, Short_.Cls_ref_type)) return Id__short;
else if (Type_.Eq(type, Char_.Cls_ref_type)) return Id__char;
else return Id__obj;
}
}

View File

@@ -22,8 +22,8 @@ public class Criteria_eq implements Criteria {
public void Val_as_obj_(Object v) {this.val = v;}
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
public boolean Matches(Object comp) {
Class<?> val_type = Type_adp_.ClassOf_obj(val);
if (!Type_adp_.Eq_typeSafe(comp, val_type)) throw Err_.new_type_mismatch(val_type, comp);
Class<?> val_type = Type_.Type_by_obj(val);
if (!Type_.Eq_by_obj(comp, val_type)) throw Err_.new_type_mismatch(val_type, comp);
boolean rv = Object_.Eq(val, comp);
return neg ? !rv : rv;
}

View File

@@ -17,20 +17,20 @@ package gplx.core.criterias; import gplx.*; import gplx.core.*;
public class Criteria_in implements Criteria {
public Criteria_in(boolean neg, Object[] ary) {this.neg = neg; Ary_(ary);}
public byte Tid() {return Criteria_.Tid_in;}
public boolean Neg() {return neg;} private final boolean neg;
public boolean Neg() {return neg;} private final boolean neg;
public Object[] Ary() {return ary;} private Object[] ary;
public int Ary_len() {return ary_len;} private int ary_len;
public Class<?> Itm_type() {return itm_type;} private Class<?> itm_type;
private void Ary_(Object[] v) {
this.ary = v;
this.ary_len = ary.length;
this.itm_type = ary_len == 0 ? Object.class : Type_adp_.ClassOf_obj(ary[0]);
this.itm_type = ary_len == 0 ? Object.class : Type_.Type_by_obj(ary[0]);
}
public void Val_as_obj_(Object v) {Ary_((Object[])v);}
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
public boolean Matches(Object comp) {
if (ary_len == 0) return false; // empty array never matches
if (!Type_adp_.Eq_typeSafe(comp, itm_type)) throw Err_.new_type_mismatch(itm_type, comp);
if (!Type_.Eq_by_obj(comp, itm_type)) throw Err_.new_type_mismatch(itm_type, comp);
boolean rv = false;
for (int i = 0; i < ary_len; ++i) {
Object val = ary[i];

View File

@@ -445,7 +445,7 @@ public class IoEngine_system extends IoEngine_base {
try {closeable.close();}
catch (IOException e) {
if (throwErr)
throw Err_.new_exc(e, "io", "close object failed", "class", Type_adp_.NameOf_obj(closeable), "url", url_str);
throw Err_.new_exc(e, "io", "close object failed", "class", Type_.Name_by_obj(closeable), "url", url_str);
// else
// UsrDlg_._.Finally("failed to close FileChannel", "url", url, "apiErr", Err_.Message_err_arg(e));
}
@@ -522,8 +522,8 @@ public class IoEngine_system extends IoEngine_base {
}
catch (Exception exc) {
xrg.Rslt_err_(exc);
if (Type_adp_.Eq_typeSafe(exc, java.net.UnknownHostException.class)) xrg.Rslt_(IoEngine_xrg_downloadFil.Rslt_fail_host_not_found);
else if (Type_adp_.Eq_typeSafe(exc, java.io.FileNotFoundException.class)) xrg.Rslt_(IoEngine_xrg_downloadFil.Rslt_fail_file_not_found);
if (Type_.Eq_by_obj(exc, java.net.UnknownHostException.class)) xrg.Rslt_(IoEngine_xrg_downloadFil.Rslt_fail_host_not_found);
else if (Type_.Eq_by_obj(exc, java.io.FileNotFoundException.class)) xrg.Rslt_(IoEngine_xrg_downloadFil.Rslt_fail_file_not_found);
else xrg.Rslt_(IoEngine_xrg_downloadFil.Rslt_fail_unknown);
if (prog_dlg != null && !xrg.Prog_cancel()) {
if (session_fil == null) session_fil = prog_dlg.Log_wkr().Session_dir().GenSubFil("internet.txt");
@@ -726,8 +726,8 @@ class Io_stream_rdr_http implements Io_stream_rdr {
read_done = read_failed = true;
len = -1;
xrg.Rslt_err_(exc);
if (Type_adp_.Eq_typeSafe(exc, java.net.UnknownHostException.class)) xrg.Rslt_(IoEngine_xrg_downloadFil.Rslt_fail_host_not_found);
else if (Type_adp_.Eq_typeSafe(exc, java.io.FileNotFoundException.class)) xrg.Rslt_(IoEngine_xrg_downloadFil.Rslt_fail_file_not_found);
if (Type_.Eq_by_obj(exc, java.net.UnknownHostException.class)) xrg.Rslt_(IoEngine_xrg_downloadFil.Rslt_fail_host_not_found);
else if (Type_.Eq_by_obj(exc, java.io.FileNotFoundException.class)) xrg.Rslt_(IoEngine_xrg_downloadFil.Rslt_fail_file_not_found);
else xrg.Rslt_(IoEngine_xrg_downloadFil.Rslt_fail_unknown);
if (prog_dlg != null && !xrg.Prog_cancel()) {
if (session_fil == null) session_fil = prog_dlg.Log_wkr().Session_dir().GenSubFil("internet.txt");

View File

@@ -42,9 +42,9 @@ public class Js_wtr {
Object itm = ary[i];
if (i != 0) bfr.Add_byte(Byte_ascii.Comma);
boolean val_needs_quotes = true;
if ( Type_adp_.Eq_typeSafe(itm, Bool_.Cls_ref_type)
|| Type_adp_.Eq_typeSafe(itm, Int_.Cls_ref_type)
|| Type_adp_.Eq_typeSafe(itm, Long_.Cls_ref_type)
if ( Type_.Eq_by_obj(itm, Bool_.Cls_ref_type)
|| Type_.Eq_by_obj(itm, Int_.Cls_ref_type)
|| Type_.Eq_by_obj(itm, Long_.Cls_ref_type)
) {
val_needs_quotes = false;
}

View File

@@ -17,20 +17,20 @@ package gplx.core.tests; import gplx.*; import gplx.core.*;
import gplx.core.brys.*;
public class Gftest {
private static final Bry_bfr bfr = Bry_bfr_.New();
public static void Eq__ary(boolean[] expd, boolean[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_adp_.Tid__bool, expd, actl, msg_fmt, msg_args);}
public static void Eq__ary(int[] expd, int[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_adp_.Tid__int, expd, actl, msg_fmt, msg_args);}
public static void Eq__ary(long[] expd, long[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_adp_.Tid__long, expd, actl, msg_fmt, msg_args);}
public static void Eq__ary(byte[] expd, byte[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_adp_.Tid__byte, expd, actl, msg_fmt, msg_args);}
public static void Eq__ary(boolean[] expd, boolean[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_ids_.Id__bool, expd, actl, msg_fmt, msg_args);}
public static void Eq__ary(int[] expd, int[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_ids_.Id__int, expd, actl, msg_fmt, msg_args);}
public static void Eq__ary(long[] expd, long[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_ids_.Id__long, expd, actl, msg_fmt, msg_args);}
public static void Eq__ary(byte[] expd, byte[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_ids_.Id__byte, expd, actl, msg_fmt, msg_args);}
public static void Eq__ary__lines(String expd, byte[] actl) {Eq__ary__lines(expd, String_.new_u8(actl), "no_msg");}
public static void Eq__ary__lines(String expd, byte[] actl, String msg_fmt, Object... msg_args) {Eq__ary__lines(expd, String_.new_u8(actl), msg_fmt, msg_args);}
public static void Eq__ary__lines(String expd, String actl, String msg_fmt, Object... msg_args) {Eq__array(Type_adp_.Tid__bry, Bry_split_.Split_lines(Bry_.new_u8_safe(expd)), Bry_split_.Split_lines(Bry_.new_u8_safe(actl)), msg_fmt, msg_args);}
public static void Eq__ary(String[] expd, String[] actl) {Eq__array(Type_adp_.Tid__bry, Bry_.Ary(expd), Bry_.Ary(actl), "no_msg");}
public static void Eq__ary(String[] expd, String[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_adp_.Tid__bry, Bry_.Ary(expd), Bry_.Ary(actl), msg_fmt, msg_args);}
public static void Eq__ary(String[] expd, byte[][] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_adp_.Tid__bry, Bry_.Ary(expd), actl, msg_fmt, msg_args);}
public static void Eq__ary(byte[][] expd, byte[][] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_adp_.Tid__bry, expd, actl, msg_fmt, msg_args);}
public static void Eq__ary__lines(String expd, String actl, String msg_fmt, Object... msg_args) {Eq__array(Type_ids_.Id__bry, Bry_split_.Split_lines(Bry_.new_u8_safe(expd)), Bry_split_.Split_lines(Bry_.new_u8_safe(actl)), msg_fmt, msg_args);}
public static void Eq__ary(String[] expd, String[] actl) {Eq__array(Type_ids_.Id__bry, Bry_.Ary(expd), Bry_.Ary(actl), "no_msg");}
public static void Eq__ary(String[] expd, String[] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_ids_.Id__bry, Bry_.Ary(expd), Bry_.Ary(actl), msg_fmt, msg_args);}
public static void Eq__ary(String[] expd, byte[][] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_ids_.Id__bry, Bry_.Ary(expd), actl, msg_fmt, msg_args);}
public static void Eq__ary(byte[][] expd, byte[][] actl, String msg_fmt, Object... msg_args) {Eq__array(Type_ids_.Id__bry, expd, actl, msg_fmt, msg_args);}
public static void Eq__ary(Bry_bfr_able[] expd_ary, Bry_bfr_able[] actl_ary) {Eq__ary(expd_ary, actl_ary, null);}
public static void Eq__ary(Bry_bfr_able[] expd_ary, Bry_bfr_able[] actl_ary, String msg_fmt, Object... msg_args) {
Eq__array(Type_adp_.Tid__bry, Bry_bfr_able_.To_bry_ary(bfr, expd_ary), Bry_bfr_able_.To_bry_ary(bfr, actl_ary), msg_fmt, msg_args);
Eq__array(Type_ids_.Id__bry, Bry_bfr_able_.To_bry_ary(bfr, expd_ary), Bry_bfr_able_.To_bry_ary(bfr, actl_ary), msg_fmt, msg_args);
}
private static void Eq__array(int type_tid, Object expd_ary, Object actl_ary, String msg_fmt, Object... msg_args) {
boolean[] failures = Calc__failures(type_tid, expd_ary, actl_ary);
@@ -151,11 +151,11 @@ 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__bry: bfr.Add_safe((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;
case Type_adp_.Tid__byte: bfr.Add_int_variable((int)(Byte_.cast(Array_.Get_at(ary, idx)))); break;
case Type_ids_.Id__bool: bfr.Add_yn(Bool_.Cast(Array_.Get_at(ary, idx))); break;
case Type_ids_.Id__bry: bfr.Add_safe((byte[])Array_.Get_at(ary, idx)); break;
case Type_ids_.Id__long: bfr.Add_long_variable(Long_.cast(Array_.Get_at(ary, idx))); break;
case Type_ids_.Id__int: bfr.Add_int_variable(Int_.cast(Array_.Get_at(ary, idx))); break;
case Type_ids_.Id__byte: bfr.Add_int_variable((int)(Byte_.cast(Array_.Get_at(ary, idx)))); break;
default: throw Err_.new_unhandled_default(type_id);
}
}
@@ -176,11 +176,11 @@ 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__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;
case Type_adp_.Tid__byte: eq = Byte_.cast(expd_obj) == Byte_.cast(actl_obj); break;
case Type_ids_.Id__bool: eq = Bool_.Cast(expd_obj) == Bool_.Cast(actl_obj); break;
case Type_ids_.Id__bry: eq = Bry_.Eq((byte[])expd_obj, (byte[])actl_obj); break;
case Type_ids_.Id__long: eq = Long_.cast(expd_obj) == Long_.cast(actl_obj); break;
case Type_ids_.Id__int: eq = Int_.cast(expd_obj) == Int_.cast(actl_obj); break;
case Type_ids_.Id__byte: eq = Byte_.cast(expd_obj) == Byte_.cast(actl_obj); break;
}
}
if (!eq) {

View File

@@ -20,7 +20,7 @@ public abstract class ClassXtn_base {
@gplx.Virtual public Object XtoDb(Object obj) {return obj;}
@gplx.Virtual public String XtoUi(Object obj, String fmt) {return Object_.Xto_str_strict_or_null_mark(obj);}
@gplx.Virtual public boolean MatchesClass(Object obj) {if (obj == null) throw Err_.new_null();
return Type_adp_.Eq_typeSafe(obj, UnderClass());
return Type_.Eq_by_obj(obj, UnderClass());
}
@gplx.Virtual public int compareTo(Object lhs, Object rhs) {return CompareAble_.Compare_obj(lhs, rhs);}
}

View File

@@ -23,10 +23,10 @@ public class GfsCore_ {
if (rv == Gfo_invk_.Rv_cancel) return rv;
else if (rv == Gfo_invk_.Rv_unhandled) {
if (ctx.Fail_if_unhandled())
throw Err_.new_wo_type("Object does not support key", "key", owner_msg.Key(), "ownerType", Type_adp_.FullNameOf_obj(owner_invk));
throw Err_.new_wo_type("Object does not support key", "key", owner_msg.Key(), "ownerType", Type_.Canonical_name_by_obj(owner_invk));
else {
Gfo_usr_dlg usr_dlg = ctx.Usr_dlg();
if (usr_dlg != null) usr_dlg.Warn_many(GRP_KEY, "unhandled_key", "Object does not support key: key=~{0} ownerType=~{1}", owner_msg.Key(), Type_adp_.FullNameOf_obj(owner_invk));
if (usr_dlg != null) usr_dlg.Warn_many(GRP_KEY, "unhandled_key", "Object does not support key: key=~{0} ownerType=~{1}", owner_msg.Key(), Type_.Canonical_name_by_obj(owner_invk));
return Gfo_invk_.Noop;
}
}
@@ -42,7 +42,7 @@ public class GfsCore_ {
Gfo_invk invk = Gfo_invk_.as_(rv);
Object primitive = null;
if (invk == null) { // rv is primitive; find appropriate mgr
throw Err_.new_wo_type("unknown primitive", "type", Type_adp_.NameOf_type(rv.getClass()), "obj", Object_.Xto_str_strict_or_null_mark(rv));
throw Err_.new_wo_type("unknown primitive", "type", Type_.Name(rv.getClass()), "obj", Object_.Xto_str_strict_or_null_mark(rv));
}
Object exec_rv = null;
int len = owner_msg.Subs_count();

View File

@@ -20,7 +20,7 @@ class GfsRegy implements Gfo_invk {
public boolean Has(String k) {return hash.Has(k);}
public GfsRegyItm Get_at(int i) {return (GfsRegyItm)hash.Get_at(i);}
public GfsRegyItm Get_by(String key) {return (GfsRegyItm)hash.Get_by(key);}
public GfsRegyItm FetchByType(Gfo_invk invk) {return (GfsRegyItm)typeHash.Get_by(Type_adp_.FullNameOf_obj(invk));}
public GfsRegyItm FetchByType(Gfo_invk invk) {return (GfsRegyItm)typeHash.Get_by(Type_.Canonical_name_by_obj(invk));}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
Object rv = (GfsRegyItm)hash.Get_by(k); if (rv == null) throw Err_.new_missing_key(k);
return rv;
@@ -29,7 +29,7 @@ class GfsRegy implements Gfo_invk {
public void AddCmd(Gfo_invk invk, String key) {Add(key, invk, true);}
public void Add(String key, Gfo_invk invk, boolean typeCmd) {
if (hash.Has(key)) return;
GfsRegyItm regyItm = new GfsRegyItm().Key_(key).InvkAble_(invk).IsCmd_(typeCmd).TypeKey_(Type_adp_.FullNameOf_obj(invk));
GfsRegyItm regyItm = new GfsRegyItm().Key_(key).InvkAble_(invk).IsCmd_(typeCmd).TypeKey_(Type_.Canonical_name_by_obj(invk));
hash.Add(key, regyItm);
typeHash.Add_if_dupe_use_1st(regyItm.TypeKey(), regyItm); // NOTE: changed to allow same Object to be added under different aliases (app, xowa) DATE:2014-06-09;
}