mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.7.3.1
This commit is contained in:
77
100_core/src/gplx/Err.java
Normal file
77
100_core/src/gplx/Err.java
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
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;
|
||||
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
|
||||
Msgs_add(type, msg, args);
|
||||
}
|
||||
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;
|
||||
Err_msg[] new_ary = new Err_msg[new_len];
|
||||
Array_.CopyTo(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);}
|
||||
public String To_str__log() {return To_str(Bool_.Y);}
|
||||
private String To_str(boolean called_by_log) {
|
||||
String nl_str = called_by_log ? "\t" : "\n";
|
||||
String rv = ""; //nl_str + "----------------------------------------------------------------------" + nl_str;
|
||||
for (int i = 0; i < msgs_idx; ++i) {
|
||||
rv += "[err " + Int_.Xto_str(i) + "] " + msgs_ary[i].To_str() + nl_str;
|
||||
}
|
||||
rv += "[trace]:" + Trace_to_str(is_gplx, called_by_log, trace_ignore, trace == null ? Err_.Trace_lang(this) : trace);
|
||||
return rv;
|
||||
}
|
||||
@Override public String getMessage() {return To_str__full();}
|
||||
public static String Trace_to_str(boolean is_gplx, boolean called_by_log, int ignore_lines, String trace) {
|
||||
String[] lines = String_.Split_lang(trace, '\n'); int lines_len = lines.length;
|
||||
int line_bgn = 0;
|
||||
if (is_gplx) { // remove Err_.new_wo_type lines from trace for gplx exceptions
|
||||
for (int i = 0; i < lines_len; ++i) {
|
||||
String line = lines[i];
|
||||
if (String_.Has_at_bgn(line, "gplx.Err_.new")) continue; // ignore trace frames with "gplx.Err_.new"; EX: throw Err_.new_unimplemented
|
||||
line_bgn = i + ignore_lines;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// concat lines
|
||||
String rv = "";
|
||||
String line_bgn_dlm = called_by_log ? "\t " : "\n "; // "\n " indents
|
||||
for (int i = line_bgn; i < lines_len; ++i)
|
||||
rv += line_bgn_dlm + lines[i];
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
71
100_core/src/gplx/Err_.java
Normal file
71
100_core/src/gplx/Err_.java
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
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;
|
||||
public class Err_ {
|
||||
private static String Type__gplx = "gplx"; @gplx.Internal protected static String 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 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);
|
||||
rv.Msgs_add(type, msg, args);
|
||||
return rv;
|
||||
}
|
||||
public static Err new_unhandled(Object val) {return new Err(Bool_.Y, Trace_null, Type__gplx, "val is not in switch/if", "val", val);}
|
||||
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(ClassAdp_.FullNameOf_type(c), raw);}
|
||||
public static Err new_parse_exc(Exception e, Class<?> c, String raw) {return new_parse(ClassAdp_.FullNameOf_type(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_missing_idx(int idx, int len) {return new Err(Bool_.Y, Trace_null, Type__gplx, "index is out of bounds", "idx", idx, "len", len);}
|
||||
public static Err new_missing_key(String key) {return new Err(Bool_.Y, Trace_null, Type__gplx, "key not found", "key", key);}
|
||||
public static Err new_invalid_op(String msg) {return new Err(Bool_.Y, Trace_null, Type__gplx, msg);}
|
||||
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", ClassAdp_.FullNameOf_type(t), "actlType", ClassAdp_.NameOf_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", ClassAdp_.NameOf_type(t), "obj", o_str);
|
||||
}
|
||||
|
||||
public static String Message_lang(Exception e) {return e.getMessage();}
|
||||
public static String Trace_lang(Exception e) {
|
||||
String rv = "";
|
||||
StackTraceElement[] ary = e.getStackTrace();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (i != 0) rv += "\n";
|
||||
rv += ary[i].toString();
|
||||
}
|
||||
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();}
|
||||
private static Err cast_or_make(Exception e) {return ClassAdp_.Eq_typeSafe(e, Err.class) ? (Err)e : new Err(Bool_.N, Err_.Trace_lang(e), ClassAdp_.NameOf_obj(e), Err_.Message_lang(e));}
|
||||
public static final String Type__op_canceled = "gplx.op_canceled";
|
||||
}
|
||||
@@ -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;
|
||||
class Exc_msg {
|
||||
public class Err_msg {
|
||||
private final String msg; private Object[] args;
|
||||
public Exc_msg(String type, String msg, Object[] args) {
|
||||
public Err_msg(String type, String msg, Object[] args) {
|
||||
this.type = type;
|
||||
this.msg = msg;
|
||||
this.args = args;
|
||||
@@ -27,8 +27,10 @@ class Exc_msg {
|
||||
public void Args_add(Object[] add) {
|
||||
this.args = (Object[])Array_.Resize_add(args, add);
|
||||
}
|
||||
public String To_str() {
|
||||
String rv = String_.Len_eq_0(type) ? "" : "[" + type + "] ";
|
||||
public String To_str() {return To_str_w_type(type, msg, args);}
|
||||
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 + "> ";
|
||||
rv += msg;
|
||||
int len = args.length;
|
||||
if (len > 0) {
|
||||
47
100_core/src/gplx/Err_tst.java
Normal file
47
100_core/src/gplx/Err_tst.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
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.*;
|
||||
public class Err_tst {
|
||||
private final Err_fxt fxt = new Err_fxt();
|
||||
@Test public void Trace_to_str__gplx() {
|
||||
fxt.Test_Trace_to_str(Bool_.Y, Bool_.N, 0, String_.Concat_lines_nl_skip_last
|
||||
( "gplx.Err_.new_wo_type(Err_.java:1)" // ignore this line
|
||||
, "gplx.String_.Len(String_.java:2)"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " gplx.String_.Len(String_.java:2)"
|
||||
));
|
||||
}
|
||||
@Test public void Trace_to_str__gplx_ignore() {
|
||||
fxt.Test_Trace_to_str(Bool_.Y, Bool_.N, 1, String_.Concat_lines_nl_skip_last
|
||||
( "gplx.Err_.new_wo_type(Err_.java:1)" // ignore this line
|
||||
, "gplx.String_.Fail(String_.java:2)" // ignore this line also
|
||||
, "gplx.String_.Len(String_.java:3)"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " gplx.String_.Len(String_.java:3)"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Err_fxt {
|
||||
public void Test_Trace_to_str(boolean is_gplx, boolean called_by_log, int ignore_lines, String trace, String expd) {
|
||||
String actl = Err.Trace_to_str(is_gplx, called_by_log, ignore_lines, trace);
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
}
|
||||
}
|
||||
@@ -1,70 +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;
|
||||
public class Exc extends RuntimeException {
|
||||
private final String stack;
|
||||
private Exc_msg[] msgs_ary = new Exc_msg[8]; private int msgs_len = 8, msgs_idx = 0;
|
||||
public Exc(String stack, String type, String msg, Object... args) {
|
||||
Msgs_add(type, msg, args);
|
||||
this.stack = stack;
|
||||
}
|
||||
public int Stack_erase() {return stack_erase;} public Exc Stack_erase_1_() {stack_erase = 1; return this;} private int stack_erase = 0;
|
||||
public Exc 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;
|
||||
Exc_msg[] new_ary = new Exc_msg[new_len];
|
||||
Array_.CopyTo(msgs_ary, new_ary, 0);
|
||||
this.msgs_ary = new_ary;
|
||||
this.msgs_len = new_len;
|
||||
}
|
||||
msgs_ary[msgs_idx] = new Exc_msg(type, msg, args);
|
||||
++msgs_idx;
|
||||
}
|
||||
public String To_str_all() {
|
||||
String rv = "";
|
||||
for (int i = msgs_idx - 1; i > -1; --i) {
|
||||
rv += "[err " + Int_.Xto_str(i) + "] " + msgs_ary[i].To_str() + "\n";
|
||||
}
|
||||
rv += "[stack]\n " + Stack_to_str(this, stack);
|
||||
return rv;
|
||||
}
|
||||
@Override public String getMessage() {return To_str_all();}
|
||||
private static String Stack_to_str(Exception e, String stack) {
|
||||
String rv = stack;
|
||||
if (rv == Exc_.Stack_null) { // occurs for thrown gplx exceptions; EX: throw Exc_.new_unimplemented
|
||||
rv = ""; // set to "" b/c String concat below;
|
||||
String[] lines = String_.Split_lang(Exc_.Stack_lang(e), '\n');
|
||||
int len = lines.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String line = lines[i];
|
||||
if (String_.Has_at_bgn(line, "gplx.Exc_.new")) continue; // ignore stack frames with "gplx.Exc_.new"; EX: throw Exc_.new_unimplemented
|
||||
if (String_.Len(rv) > 0) rv += "\n";
|
||||
rv += line;
|
||||
}
|
||||
}
|
||||
rv = String_.Replace(rv, "\n", "\n "); // " " is to indent stack stack
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -1,67 +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;
|
||||
public class Exc_ {
|
||||
private static String Type__none = ""; @gplx.Internal protected static String Stack_null = null;
|
||||
public static final String Type__op_canceled = "gplx.op_canceled";
|
||||
public static void Noop(Exception e) {}
|
||||
public static Exc as_(Object obj) {return obj instanceof Exc ? (Exc)obj : null;}
|
||||
public static Exc new_(String msg, Object... args) {return new Exc(Stack_null, Type__none, msg, args);}
|
||||
public static Exc new_w_type(String type, String msg, Object... args) {return new Exc(Stack_null, type, msg, args);}
|
||||
public static Exc new_exc(Exception e, String type, String msg, Object... args) {
|
||||
Exc rv = ClassAdp_.Eq_typeSafe(e, Exc.class) ? (Exc)e : new Exc(Exc_.Stack_lang(e), Type__none, Exc_.Message_lang(e));
|
||||
rv.Msgs_add(type, msg, args);
|
||||
return rv;
|
||||
}
|
||||
public static Exc new_unhandled(Object val) {return new Exc(Stack_null, Type__none, "val is not in switch/if", "val", val);}
|
||||
public static Exc new_unimplemented() {return new Exc(Stack_null, Type__none, "method not implemented");}
|
||||
public static Exc new_unimplemented_w_msg(String msg, Object... args) {return new Exc(Stack_null, Type__none, msg, args);}
|
||||
public static Exc new_deprecated(String s) {return new Exc(Stack_null, Type__none, "deprecated", "method", s);}
|
||||
public static Exc new_parse_type(Class<?> c, String raw) {return new_parse(ClassAdp_.FullNameOf_type(c), raw);}
|
||||
public static Exc new_parse_exc(Exception e, Class<?> c, String raw) {return new_parse(ClassAdp_.FullNameOf_type(c), raw).Args_add("e", Err_.Message_lang(e));}
|
||||
public static Exc new_parse(String type, String raw) {return new Exc(Stack_null, Type__none, "parse failed", "type", type, "raw", raw);}
|
||||
public static Exc new_null(String s) {return new Exc(Stack_null, Type__none, "null obj", "obj", s);}
|
||||
public static Exc new_missing_idx(int idx, int len) {return new Exc(Stack_null, Type__none, "index is out of bounds", "idx", idx, "len", len);}
|
||||
public static Exc new_missing_key(String key) {return new Exc(Stack_null, Type__none, "key not found", "key", key);}
|
||||
public static Exc new_invalid_op(String msg) {return new Exc(Stack_null, Type__none, msg);}
|
||||
public static Exc new_op_canceled() {return new Exc(Stack_null, Type__op_canceled, "canceled by usr");}
|
||||
public static Exc new_type_mismatch_w_exc(Exception ignore, Class<?> t, Object o) {return new_type_mismatch(t, o);}
|
||||
public static Exc new_type_mismatch(Class<?> t, Object o) {return new Exc(Stack_null, Type__none, "type mismatch", "expdType", ClassAdp_.FullNameOf_type(t), "actlType", ClassAdp_.NameOf_obj(o), "actlObj", Object_.Xto_str_strict_or_null_mark(o));}
|
||||
public static Exc 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>"; Exc_.Noop(e);}
|
||||
return new Exc(Stack_null, Type__none, "cast failed", "type", ClassAdp_.NameOf_type(t), "obj", o_str);
|
||||
}
|
||||
|
||||
public static String Message_lang(Exception e) {return e.getMessage();}
|
||||
public static String Stack_lang(Exception e) {
|
||||
String rv = "";
|
||||
StackTraceElement[] ary = e.getStackTrace();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (i != 0) rv += "\n";
|
||||
rv += ary[i].toString();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static boolean Type_match(Exception e, String type) {
|
||||
Exc exc = Exc_.as_(e);
|
||||
return exc == null ? false : exc.Type_match(type);
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class Bry_rdr {
|
||||
public int Read_int_to_pipe() {return Read_int_to(Byte_ascii.Pipe);}
|
||||
public int Read_int_to_nl() {return Read_int_to(Byte_ascii.Nl);}
|
||||
public int Read_int_to_quote() {return Read_int_to(Byte_ascii.Quote);}
|
||||
public int Read_int_to_non_num(){return Read_int_to(Byte_ascii.Nil);}
|
||||
public int Read_int_to_non_num(){return Read_int_to(Byte_ascii.Null);}
|
||||
public int Read_int_to(byte to_char) {
|
||||
int bgn = pos;
|
||||
int rv = 0;
|
||||
@@ -64,7 +64,7 @@ public class Bry_rdr {
|
||||
break;
|
||||
default: {
|
||||
boolean match = b == to_char;
|
||||
if (to_char == Byte_ascii.Nil) {// hack for Read_int_to_non_num
|
||||
if (to_char == Byte_ascii.Null) {// hack for Read_int_to_non_num
|
||||
--pos;
|
||||
match = true;
|
||||
}
|
||||
@@ -141,12 +141,12 @@ public class Bry_rdr {
|
||||
int bry_len = bry.length;
|
||||
boolean match = Bry_.Match(src, pos, pos + bry_len, bry);
|
||||
if (match) pos += bry_len;
|
||||
else throw Exc_.new_("bry.rdr:chk failed", "bry", bry, "pos", pos);
|
||||
else throw Err_.new_wo_type("bry.rdr:chk failed", "bry", bry, "pos", pos);
|
||||
}
|
||||
public void Chk_byte_or_fail(byte b) {
|
||||
boolean match = pos < src_len ? src[pos] == b : false;
|
||||
if (match) ++pos;
|
||||
else throw Exc_.new_("bry.rdr:chk failed", "byte", b, "pos", pos);
|
||||
else throw Err_.new_wo_type("bry.rdr:chk failed", "byte", b, "pos", pos);
|
||||
}
|
||||
public byte[] Mid_by_len_safe(int len) {
|
||||
int end = pos + len; if (end > src_len) end = src_len;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class Btrie_bwd_mgr {
|
||||
}
|
||||
public Btrie_bwd_mgr Add(String key, Object val) {return Add(Bry_.new_u8(key), val);}
|
||||
public Btrie_bwd_mgr Add(byte[] key, Object val) {
|
||||
if (val == null) throw Exc_.new_("null objects cannot be registered", "key", String_.new_u8(key));
|
||||
if (val == null) throw Err_.new_wo_type("null objects cannot be registered", "key", String_.new_u8(key));
|
||||
int key_len = key.length;
|
||||
Btrie_slim_itm cur = root;
|
||||
for (int i = key_len - 1; i > -1; i--) {
|
||||
|
||||
@@ -48,7 +48,7 @@ public class Btrie_fast_mgr {
|
||||
public Btrie_fast_mgr Add(byte key, Object val) {return Add(new byte[] {key}, val);}
|
||||
public Btrie_fast_mgr Add(String key, Object val) {return Add(Bry_.new_u8(key), val);}
|
||||
public Btrie_fast_mgr Add(byte[] key, Object val) {
|
||||
if (val == null) throw Exc_.new_("null objects cannot be registered", "key", String_.new_u8(key));
|
||||
if (val == null) throw Err_.new_wo_type("null objects cannot be registered", "key", String_.new_u8(key));
|
||||
int key_len = key.length; int key_end = key_len - 1;
|
||||
ByteTrieItm_fast cur = root;
|
||||
for (int i = 0; i < key_len; i++) {
|
||||
|
||||
@@ -66,7 +66,7 @@ public class Btrie_slim_mgr implements Btrie_mgr {
|
||||
}
|
||||
public Btrie_mgr Add_obj(String key, Object val) {return Add_obj(Bry_.new_u8(key), val);}
|
||||
public Btrie_mgr Add_obj(byte[] key, Object val) {
|
||||
if (val == null) throw Exc_.new_("null objects cannot be registered", "key", String_.new_u8(key));
|
||||
if (val == null) throw Err_.new_wo_type("null objects cannot be registered", "key", String_.new_u8(key));
|
||||
int key_len = key.length; int key_end = key_len - 1;
|
||||
Btrie_slim_itm cur = root;
|
||||
for (int i = 0; i < key_len; i++) {
|
||||
|
||||
@@ -45,7 +45,7 @@ public class Btrie_utf8_mgr implements Btrie_mgr {
|
||||
public void Clear() {root.Clear(); count = 0;}
|
||||
public Btrie_mgr Add_obj(String key, Object val) {return Add_obj(Bry_.new_u8(key), val);}
|
||||
public Btrie_mgr Add_obj(byte[] key, Object val) {
|
||||
if (val == null) throw Exc_.new_("null objects cannot be registered", "key", String_.new_u8(key));
|
||||
if (val == null) throw Err_.new_wo_type("null objects cannot be registered", "key", String_.new_u8(key));
|
||||
int key_len = key.length;
|
||||
Btrie_utf8_itm cur = root;
|
||||
int c_bgn = 0;
|
||||
|
||||
28
100_core/src/gplx/core/consoles/Console_adp.java
Normal file
28
100_core/src/gplx/core/consoles/Console_adp.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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.core.consoles; import gplx.*; import gplx.core.*;
|
||||
public interface Console_adp {
|
||||
boolean Enabled(); // optimization; allows Write to be skipped (since Write may Concat strings or generate arrays)
|
||||
boolean Canceled_chk();
|
||||
int Chars_per_line_max(); void Chars_per_line_max_(int v);
|
||||
void Write_str(String s);
|
||||
void Write_fmt_w_nl(String fmt, Object... args);
|
||||
void Write_tmp(String s);
|
||||
char Read_key(String msg);
|
||||
String Read_line(String msg);
|
||||
}
|
||||
32
100_core/src/gplx/core/consoles/Console_adp_.java
Normal file
32
100_core/src/gplx/core/consoles/Console_adp_.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
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.core.consoles; import gplx.*; import gplx.core.*;
|
||||
public class Console_adp_ {
|
||||
public static final Console_adp Noop = new Console_adp__noop();
|
||||
public static Console_adp__mem Dev() {return new Console_adp__mem();}
|
||||
}
|
||||
class Console_adp__noop implements Console_adp {
|
||||
public boolean Enabled() {return false;}
|
||||
public boolean Canceled_chk() {return false;}
|
||||
public int Chars_per_line_max() {return 80;} public void Chars_per_line_max_(int v) {}
|
||||
public void Write_str(String s) {}
|
||||
public void Write_fmt_w_nl(String s, Object... args) {}
|
||||
public void Write_tmp(String s) {}
|
||||
public char Read_key(String msg) {return '\0';}
|
||||
public String Read_line(String msg) {return "";}
|
||||
}
|
||||
50
100_core/src/gplx/core/consoles/Console_adp__mem.java
Normal file
50
100_core/src/gplx/core/consoles/Console_adp__mem.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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.core.consoles; import gplx.*; import gplx.core.*;
|
||||
public class Console_adp__mem implements Console_adp {
|
||||
private final List_adp written = List_adp_.new_();
|
||||
private final Hash_adp ignored = Hash_adp_.new_();
|
||||
public boolean Enabled() {return true;}
|
||||
public boolean Canceled_chk() {return false;}
|
||||
public int Chars_per_line_max() {return 80;} public void Chars_per_line_max_(int v) {}
|
||||
public Console_adp__mem Ignore_add(String s) {ignored.Add_as_key_and_val(s); return this;}
|
||||
public void Write_str(String s) {WriteString(s);}
|
||||
public void Write_fmt_w_nl(String s, Object... args) {WriteString(String_.Format(s, args) + String_.CrLf);}
|
||||
public void Write_tmp(String s) {WriteString(s);}
|
||||
public String Read_line(String msg) {return "";}
|
||||
public char Read_key(String msg) {return '\0';}
|
||||
public Console_adp__mem CancelWhenTextWritten(String val) {
|
||||
cancelVal = val;
|
||||
return this;
|
||||
}
|
||||
void WriteString(String s) {
|
||||
if (ignored.Has(s)) return;
|
||||
written.Add(s);
|
||||
if (cancelVal != null && String_.Has(s, cancelVal)) throw Err_.new_wo_type("canceled", "cancel_val", s);
|
||||
}
|
||||
String cancelVal;
|
||||
|
||||
public List_adp Written() {return written;}
|
||||
public void tst_WrittenStr(String... expd) {
|
||||
String[] actl = new String[written.Count()];
|
||||
int actlLength = Array_.Len(actl);
|
||||
for (int i = 0; i < actlLength; i++)
|
||||
actl[i] = written.Get_at(i).toString();
|
||||
Tfds.Eq_ary(actl, expd);
|
||||
}
|
||||
}
|
||||
66
100_core/src/gplx/core/consoles/Console_adp__sys.java
Normal file
66
100_core/src/gplx/core/consoles/Console_adp__sys.java
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
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.core.consoles; import gplx.*; import gplx.core.*;
|
||||
public class Console_adp__sys implements Console_adp {
|
||||
private String tmp_txt;
|
||||
public Console_adp__sys() {
|
||||
this.backspace_by_bytes = Op_sys.Cur().Tid_is_lnx(); // bash shows UTF8 by default; backspace in bytes, else multi-byte characters don't show; DATE:2014-03-04
|
||||
}
|
||||
public boolean Enabled() {return true;}
|
||||
public boolean Canceled() {return canceled;} public void Canceled_set(boolean v) {canceled = v;} private boolean canceled = false;
|
||||
public boolean Canceled_chk() {if (canceled) throw Err_.new_op_canceled(); return canceled;}
|
||||
public int Chars_per_line_max() {return chars_per_line_max;} public void Chars_per_line_max_(int v) {chars_per_line_max = v;} int chars_per_line_max = 80;
|
||||
public boolean Backspace_by_bytes() {return backspace_by_bytes;} public Console_adp__sys Backspace_by_bytes_(boolean v) {backspace_by_bytes = v; return this;} private boolean backspace_by_bytes;
|
||||
public void Write_str(String s) {Clear_tmp(); Write_str_lang(s);}
|
||||
public void Write_str_w_nl(String s) {Clear_tmp(); Write_str_w_nl_lang(s);}
|
||||
public void Write_fmt_w_nl(String fmt, Object... args) {Clear_tmp(); Write_str_w_nl_lang(String_.Format(fmt, args));}
|
||||
public char Read_key(String s) {Write_str(s); return Read_key_lang();}
|
||||
public String Read_line(String s) {Write_str(s); return Read_line_lang();}
|
||||
public void Write_tmp(String s) {
|
||||
Clear_tmp();
|
||||
if (String_.Has(s, "\r")) s = String_.Replace(s, "\r", " ");
|
||||
if (String_.Has(s, "\n")) s = String_.Replace(s, "\n", " ");
|
||||
if (String_.Len(s) >= chars_per_line_max) s = String_.Mid(s, 0, chars_per_line_max - String_.Len("...") - 1) + "..."; // NOTE: >= and -1 needed b/c line needs to be 1 less than max; ex: default cmd is 80 width, but writing 80 chars will automatically create lineBreak
|
||||
tmp_txt = s;
|
||||
Write_str_lang(s);
|
||||
}
|
||||
private void Clear_tmp() {
|
||||
if (tmp_txt == null) return;
|
||||
if (Env_.Mode_debug()) {Write_str_lang(String_.CrLf); return;}
|
||||
int count = backspace_by_bytes ? Bry_.new_u8(tmp_txt).length : String_.Len(tmp_txt);
|
||||
String moveBack = String_.Repeat("\b", count);
|
||||
this.Write_str_lang(moveBack); // move cursor back to beginning of line
|
||||
this.Write_str_lang(String_.Repeat(" ", count)); // overwrite tmp_txt with space
|
||||
this.Write_str_lang(moveBack); // move cursor back to beginning of line (so next Write will start at beginning)
|
||||
tmp_txt = null;
|
||||
}
|
||||
private void Write_str_lang(String s) {System.out.print(s);}
|
||||
private void Write_str_w_nl_lang(String s) {System.out.println(s);}
|
||||
private String Read_line_lang() {return System.console() == null ? "" : System.console().readLine();}
|
||||
private char Read_key_lang() {
|
||||
String text = Read_line_lang();
|
||||
return String_.Len(text) == 0 ? '\0' : String_.CharAt(text, 0);
|
||||
}
|
||||
public void Write_str_w_nl_utf8(String s) {
|
||||
java.io.PrintStream ps;
|
||||
try {ps = new java.io.PrintStream(System.out, true, "UTF-8");}
|
||||
catch (java.io.UnsupportedEncodingException e) {throw Err_.new_wo_type("unsupported exception");}
|
||||
ps.println(s);
|
||||
}
|
||||
public static final Console_adp__sys I = new Console_adp__sys();
|
||||
}
|
||||
@@ -23,7 +23,7 @@ public class Criteria_ {
|
||||
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) {
|
||||
int len = Array_.Len(ary); if (len == 0) throw Exc_.new_("cannot AND 0 criterias;");
|
||||
int len = Array_.Len(ary); if (len == 0) throw Err_.new_wo_type("cannot AND 0 criterias;");
|
||||
Criteria rv = ary[0];
|
||||
for (int i = 1; i < len; i++)
|
||||
rv = And(rv, ary[i]);
|
||||
@@ -31,7 +31,7 @@ public class Criteria_ {
|
||||
}
|
||||
public static Criteria Or(Criteria lhs, Criteria rhs) {return new Criteria_or(lhs, rhs);}
|
||||
public static Criteria Or_many(Criteria... ary) {
|
||||
int len = Array_.Len(ary); if (len == 0) throw Exc_.new_("cannot OR 0 criterias;");
|
||||
int len = Array_.Len(ary); if (len == 0) throw Err_.new_wo_type("cannot OR 0 criterias;");
|
||||
Criteria rv = ary[0];
|
||||
for (int i = 1; i < len; i++)
|
||||
rv = Or(rv, ary[i]);
|
||||
|
||||
@@ -20,7 +20,7 @@ public class Criteria_between implements Criteria {
|
||||
public Criteria_between(boolean negate, Comparable lhs, Comparable rhs) {this.negate = negate; this.lhs = lhs; this.rhs = rhs;}
|
||||
public byte Tid() {return Criteria_.Tid_between;}
|
||||
public boolean Negated() {return negate;} private final boolean negate;
|
||||
public void Val_from_args(Hash_adp args) {throw Exc_.new_unimplemented();}
|
||||
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
|
||||
public void Val_as_obj_(Object v) {
|
||||
Object[] ary = (Object[])v;
|
||||
lhs = (Comparable)ary[0];
|
||||
|
||||
@@ -21,7 +21,7 @@ public abstract class Criteria_bool_base implements Criteria {
|
||||
public abstract byte Tid();
|
||||
public abstract boolean Matches(Object curVal);
|
||||
public void Val_from_args(Hash_adp args) {lhs.Val_from_args(args); rhs.Val_from_args(args);}
|
||||
public void Val_as_obj_(Object v) {throw Exc_.new_unimplemented();}
|
||||
public void Val_as_obj_(Object v) {throw Err_.new_unimplemented();}
|
||||
public String XtoStr() {return String_.Concat(lhs.XtoStr(), " ", this.op_literal, " ", rhs.XtoStr());}
|
||||
public String Op_literal() {return op_literal;} private String op_literal;
|
||||
public Criteria Lhs() {return lhs;} private Criteria lhs;
|
||||
@@ -43,7 +43,7 @@ class Criteria_const implements Criteria {
|
||||
public byte Tid() {return Criteria_.Tid_const;}
|
||||
public boolean Matches(Object comp) {return val;} private final boolean val;
|
||||
public void Val_from_args(Hash_adp args) {;}
|
||||
public void Val_as_obj_(Object v) {throw Exc_.new_unimplemented();}
|
||||
public void Val_as_obj_(Object v) {throw Err_.new_unimplemented();}
|
||||
public String XtoStr() {return String_.Concat(" IS ", Bool_.Xto_str_lower(val));}
|
||||
}
|
||||
class Criteria_not implements Criteria {
|
||||
|
||||
@@ -21,7 +21,7 @@ public class Criteria_comp implements Criteria {
|
||||
@gplx.Internal protected Criteria_comp(int comp_mode, Comparable val) {this.comp_mode = comp_mode; this.val = val;}
|
||||
public byte Tid() {return Criteria_.Tid_comp;}
|
||||
public Comparable Val() {return val;} private Comparable val;
|
||||
public void Val_from_args(Hash_adp args) {throw Exc_.new_unimplemented();}
|
||||
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
|
||||
public void Val_as_obj_(Object v) {val = (Comparable)v;}
|
||||
public boolean Matches(Object compObj) {
|
||||
Comparable comp = CompareAble_.as_(compObj);
|
||||
|
||||
@@ -22,10 +22,10 @@ public class Criteria_eq implements Criteria {
|
||||
public boolean Negated() {return negated;} private final boolean negated;
|
||||
public Object Val() {return val;} private Object val;
|
||||
public void Val_as_obj_(Object v) {this.val = v;}
|
||||
public void Val_from_args(Hash_adp args) {throw Exc_.new_unimplemented();}
|
||||
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
|
||||
public boolean Matches(Object comp) {
|
||||
Class<?> val_type = ClassAdp_.ClassOf_obj(val);
|
||||
if (!ClassAdp_.Eq_typeSafe(comp, val_type)) throw Exc_.new_type_mismatch(val_type, comp);
|
||||
if (!ClassAdp_.Eq_typeSafe(comp, val_type)) throw Err_.new_type_mismatch(val_type, comp);
|
||||
boolean rv = Object_.Eq(val, comp);
|
||||
return negated ? !rv : rv;
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ public class Criteria_fld implements Criteria {
|
||||
public byte Tid() {return Criteria_.Tid_wrapper;}
|
||||
public String Key() {return key;} private final String key;
|
||||
public Criteria Crt() {return crt;} private final Criteria crt;
|
||||
public void Val_as_obj_(Object v) {throw Exc_.new_unimplemented();}
|
||||
public void Val_as_obj_(Object v) {throw Err_.new_unimplemented();}
|
||||
public void Val_from_args(Hash_adp args) {
|
||||
List_adp list = (List_adp)args.Get_by(key); if (list == null) throw Exc_.new_("criteria.fld key not found", "key", key);
|
||||
List_adp list = (List_adp)args.Get_by(key); if (list == null) throw Err_.new_wo_type("criteria.fld key not found", "key", key);
|
||||
Object o = Fill_val(key, crt.Tid(), list);
|
||||
crt.Val_as_obj_(o);
|
||||
}
|
||||
@@ -44,24 +44,24 @@ public class Criteria_fld implements Criteria {
|
||||
case Criteria_.Tid_comp:
|
||||
case Criteria_.Tid_like:
|
||||
case Criteria_.Tid_iomatch:
|
||||
if (len != 1) throw Exc_.new_("list.len should be 1", "key", key, "tid", tid, "len", len);
|
||||
if (len != 1) throw Err_.new_wo_type("list.len should be 1", "key", key, "tid", tid, "len", len);
|
||||
return list.Get_at(0);
|
||||
case Criteria_.Tid_between:
|
||||
if (len != 2) throw Exc_.new_("list.len should be 2", "key", key, "tid", tid, "len", len);
|
||||
if (len != 2) throw Err_.new_wo_type("list.len should be 2", "key", key, "tid", tid, "len", len);
|
||||
return new Object[] {list.Get_at(0), list.Get_at(1)};
|
||||
case Criteria_.Tid_in:
|
||||
if (len == 0) throw Exc_.new_("list.len should be > 0", "key", key, "tid", tid, "len", len);
|
||||
if (len == 0) throw Err_.new_wo_type("list.len should be > 0", "key", key, "tid", tid, "len", len);
|
||||
return list.To_obj_ary();
|
||||
case Criteria_.Tid_const:
|
||||
case Criteria_.Tid_not:
|
||||
case Criteria_.Tid_and:
|
||||
case Criteria_.Tid_or:
|
||||
if (len != 0) throw Exc_.new_("list.len should be 0", "key", key, "tid", tid, "len", len);
|
||||
if (len != 0) throw Err_.new_wo_type("list.len should be 0", "key", key, "tid", tid, "len", len);
|
||||
return key; // no values to fill in; return back key
|
||||
case Criteria_.Tid_wrapper: // not recursive
|
||||
case Criteria_.Tid_db_obj_ary: // unsupported
|
||||
case Criteria_.Tid_custom:
|
||||
default: throw Exc_.new_unhandled(tid);
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@ public class Criteria_in implements Criteria {
|
||||
ary_type = ary_len == 0 ? Object.class : ClassAdp_.ClassOf_obj(ary[0]);
|
||||
}
|
||||
public void Val_as_obj_(Object v) {Val_as_obj_ary_((Object[])v);}
|
||||
public void Val_from_args(Hash_adp args) {throw Exc_.new_unimplemented();}
|
||||
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 (!ClassAdp_.Eq_typeSafe(comp, ary_type)) throw Exc_.new_type_mismatch(ary_type, comp);
|
||||
if (!ClassAdp_.Eq_typeSafe(comp, ary_type)) throw Err_.new_type_mismatch(ary_type, comp);
|
||||
boolean rv = false;
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
Object val = ary[i];
|
||||
|
||||
@@ -21,7 +21,7 @@ public class Criteria_ioMatch implements Criteria { // EX: url IOMATCH '*.xml|*.
|
||||
public Criteria_ioMatch(boolean match, RegxPatn_cls_ioMatch pattern) {this.match = match; this.pattern = pattern;}
|
||||
public byte Tid() {return Criteria_.Tid_iomatch;}
|
||||
public boolean Negated() {return !match;} private final boolean match;
|
||||
public void Val_from_args(Hash_adp args) {throw Exc_.new_unimplemented();}
|
||||
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
|
||||
public void Val_as_obj_(Object v) {this.pattern = (RegxPatn_cls_ioMatch)v;}
|
||||
public RegxPatn_cls_ioMatch Pattern() {return pattern;} private RegxPatn_cls_ioMatch pattern;
|
||||
public boolean Matches(Object compObj) {
|
||||
|
||||
@@ -24,10 +24,10 @@ public class Criteria_like implements Criteria {
|
||||
public byte Tid() {return Criteria_.Tid_like;}
|
||||
public boolean Negated() {return negated;} private final boolean negated;
|
||||
public RegxPatn_cls_like Pattern() {return pattern;} private RegxPatn_cls_like pattern;
|
||||
public void Val_from_args(Hash_adp args) {throw Exc_.new_unimplemented();}
|
||||
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
|
||||
public void Val_as_obj_(Object v) {this.pattern = (RegxPatn_cls_like)v;}
|
||||
public boolean Matches(Object compObj) {
|
||||
String comp = String_.as_(compObj); if (comp == null) throw Exc_.new_type_mismatch(String.class, compObj);
|
||||
String comp = String_.as_(compObj); if (comp == null) throw Err_.new_type_mismatch(String.class, compObj);
|
||||
boolean rv = pattern.Matches(comp);
|
||||
return negated ? !rv : rv;
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ class CriteriaFxt {
|
||||
public void tst_MatchesNot(Criteria crt, Object... ary) {for (Object val : ary) Tfds.Eq(false, crt.Matches(val));}
|
||||
public void tst_MatchesFail(Criteria crt, Object val) {
|
||||
try {crt.Matches(val);}
|
||||
catch(Exception exc) {Exc_.Noop(exc); return;}
|
||||
catch(Exception exc) {Err_.Noop(exc); return;}
|
||||
Tfds.Fail_expdError();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,6 @@ public class Bool_obj_val {
|
||||
if (String_.Eq(raw, "y")) return Bool_obj_val.True;
|
||||
else if (String_.Eq(raw, "n")) return Bool_obj_val.False;
|
||||
else if (String_.Eq(raw, "")) return Bool_obj_val.Null;
|
||||
else throw Exc_.new_parse_type(Bool_obj_val.class, raw);
|
||||
else throw Err_.new_parse_type(Bool_obj_val.class, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class Thread_adp implements Runnable {
|
||||
public void Interrupt() {thread.interrupt();}
|
||||
public void Join() {
|
||||
try {thread.join();}
|
||||
catch (Exception e) {Exc_.Noop(e);}
|
||||
catch (Exception e) {Err_.Noop(e);}
|
||||
}
|
||||
// public void Stop() {thread.stop();}
|
||||
public boolean IsAlive() {return thread.isAlive();}
|
||||
|
||||
@@ -18,12 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.core.threads; import gplx.*; import gplx.core.*;
|
||||
public class Thread_adp_ {
|
||||
public static void Sleep(int milliseconds) {
|
||||
try {Thread.sleep(milliseconds);} catch (InterruptedException e) {throw Exc_.new_exc(e, "core", "thread interrupted", "milliseconds", milliseconds);}
|
||||
try {Thread.sleep(milliseconds);} catch (InterruptedException e) {throw Err_.new_exc(e, "core", "thread interrupted", "milliseconds", milliseconds);}
|
||||
}
|
||||
public static void Notify_all(Object o) {o.notifyAll();}
|
||||
public static void Wait(Object o) {
|
||||
try {o.wait();}
|
||||
catch (InterruptedException e) {throw Exc_.new_exc(e, "core", "thread wait");}
|
||||
catch (InterruptedException e) {throw Err_.new_exc(e, "core", "thread wait");}
|
||||
}
|
||||
public static Thread_adp invk_(GfoInvkAble invk, String cmd) {return invk_(Name_null, invk, cmd);}
|
||||
public static Thread_adp invk_(String name, GfoInvkAble invk, String cmd) {return new Thread_adp(name, invk, cmd, GfoMsg_.Null);}
|
||||
|
||||
Reference in New Issue
Block a user