mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
'v3.6.3.1'
This commit is contained in:
parent
96636f3161
commit
d4e8590345
@ -22,15 +22,15 @@ public class Array_ {
|
||||
public static Object cast(Object o) {return (Object)o;}
|
||||
public static void Sort(Object[] obj) {List_adp_sorter.new_().Sort(obj, obj.length);}
|
||||
public static void Sort(Object[] obj, gplx.core.lists.ComparerAble comparer) {List_adp_sorter.new_().Sort(obj, obj.length, true, comparer);}
|
||||
public static Object[] Insert(Object[] cur, Object[] add, int addPos) {
|
||||
int curLen = cur.length, addLen = add.length;
|
||||
Object[] rv = (Object[])Array_.Create(Array_.Component_type(cur), curLen + addLen);
|
||||
for (int i = 0; i < addPos; i++) // copy old up to addPos
|
||||
public static Object[] Insert(Object[] cur, Object[] add, int add_pos) {
|
||||
int cur_len = cur.length, add_len = add.length;
|
||||
Object[] rv = (Object[])Array_.Create(Array_.Component_type(cur), cur_len + add_len);
|
||||
for (int i = 0; i < add_pos; i++) // copy old up to add_pos
|
||||
rv[i] = cur[i];
|
||||
for (int i = 0; i < addLen; i++) // insert add
|
||||
rv[i + addPos] = add[i];
|
||||
for (int i = addPos; i < curLen; i++) // copy old after addPos
|
||||
rv[i + addLen] = cur[i];
|
||||
for (int i = 0; i < add_len; i++) // insert add
|
||||
rv[i + add_pos] = add[i];
|
||||
for (int i = add_pos; i < cur_len; i++) // copy old after add_pos
|
||||
rv[i + add_len] = cur[i];
|
||||
return rv;
|
||||
}
|
||||
public static Object[] Replace_insert(Object[] cur, Object[] add, int curReplacePos, int addInsertPos) {
|
||||
@ -58,13 +58,13 @@ public class Array_ {
|
||||
}
|
||||
public static List_adp To_list(Object ary) {
|
||||
int aryLen = Array_.Len(ary);
|
||||
List_adp rv = List_adp_.new_();
|
||||
List_adp rv = List_adp_.New();
|
||||
for (int i = 0; i < aryLen; i++)
|
||||
rv.Add(Array_.Get_at(ary, i));
|
||||
return rv;
|
||||
}
|
||||
public static String To_str_nested_obj(Object o) {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
To_str_nested_ary(bfr, (Object)o, 0);
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
|
@ -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 GfoInvkAble {
|
||||
public class Bool_ implements Gfo_invk {
|
||||
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;
|
||||
@ -59,6 +59,6 @@ public class Bool_ implements GfoInvkAble {
|
||||
else if (String_.Eq(fmt, "yes_no")) return v ? "yes" : "no";
|
||||
else return v ? "true" : "false";
|
||||
}
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
} public static final String Invk_to_str = "to_str";
|
||||
}
|
||||
|
@ -808,7 +808,7 @@ public class Bry_ {
|
||||
Bry_bfr bb = null;
|
||||
if (aryLen > 0 && ary[0] == Dlm_quote) {
|
||||
int pos = bgn + 1; // +1 to skip quote
|
||||
if (make) bb = Bry_bfr.new_(16);
|
||||
if (make) bb = Bry_bfr_.New();
|
||||
while (true) {
|
||||
if (pos == aryLen) throw Err_.new_wo_type("endOfAry reached, but no quote found", "txt", String_.new_u8__by_len(ary, bgn, pos));
|
||||
byte b = ary[pos];
|
||||
@ -915,7 +915,7 @@ public class Bry_ {
|
||||
}
|
||||
public static byte[] Replace(byte[] src, byte[] find, byte[] replace) {return Replace_between(src, find, null, replace);}
|
||||
public static byte[] Replace_between(byte[] src, byte[] bgn, byte[] end, byte[] replace) {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
boolean replace_all = end == null;
|
||||
int src_len = src.length, bgn_len = bgn.length, end_len = replace_all ? 0 : end.length;
|
||||
int pos = 0;
|
||||
|
@ -107,7 +107,7 @@ public class Bry__tst {
|
||||
@Test public void ReadCsvStr() {
|
||||
tst_ReadCsvStr("a|" , "a");
|
||||
tst_ReadCsvStr("|a|", 1 , "a");
|
||||
Int_obj_ref bgn = Int_obj_ref.zero_(); tst_ReadCsvStr("a|b|c|", bgn, "a"); tst_ReadCsvStr("a|b|c|", bgn, "b"); tst_ReadCsvStr("a|b|c|", bgn, "c");
|
||||
Int_obj_ref bgn = Int_obj_ref.New_zero(); tst_ReadCsvStr("a|b|c|", bgn, "a"); tst_ReadCsvStr("a|b|c|", bgn, "b"); tst_ReadCsvStr("a|b|c|", bgn, "c");
|
||||
tst_ReadCsvStr("|", "");
|
||||
tst_ReadCsvStr_err("a");
|
||||
|
||||
@ -140,8 +140,8 @@ public class Bry__tst {
|
||||
void tst_XtoInt(String val, int expd) {tst_XtoInt(val, -1, expd);}
|
||||
void tst_XtoInt(String val, int or, int expd) {Tfds.Eq(expd, Bry_.To_int_or(Bry_.new_u8(val), or));}
|
||||
void tst_XtoIntBy4Bytes(int expd, byte... ary) {Tfds.Eq(expd, Bry_.To_int_by_a7(ary), "XtoInt"); Tfds.Eq_ary(ary, Bry_.new_by_int(expd), "XbyInt");}
|
||||
void tst_ReadCsvStr(String raw, String expd) {tst_ReadCsvStr(raw, Int_obj_ref.zero_() , expd);}
|
||||
void tst_ReadCsvStr(String raw, int bgn, String expd) {tst_ReadCsvStr(raw, Int_obj_ref.new_(bgn), expd);}
|
||||
void tst_ReadCsvStr(String raw, String expd) {tst_ReadCsvStr(raw, Int_obj_ref.New_zero() , expd);}
|
||||
void tst_ReadCsvStr(String raw, int bgn, String expd) {tst_ReadCsvStr(raw, Int_obj_ref.New(bgn), expd);}
|
||||
void tst_ReadCsvStr(String raw, Int_obj_ref bgnRef, String expd) {
|
||||
int bgn = bgnRef.Val();
|
||||
boolean rawHasQuotes = String_.CharAt(raw, bgn) == '\'';
|
||||
@ -155,16 +155,16 @@ public class Bry__tst {
|
||||
Tfds.Eq(bgn + 1 + String_.Len(actl), bgnRef.Val(), "pos"); // +1=lkp.Len
|
||||
}
|
||||
void tst_ReadCsvStr_err(String raw) {
|
||||
try {Bry_.ReadCsvStr(Bry_.new_u8(String_.Replace(raw, "'", "\"")), Int_obj_ref.zero_(), (byte)'|');}
|
||||
try {Bry_.ReadCsvStr(Bry_.new_u8(String_.Replace(raw, "'", "\"")), Int_obj_ref.New_zero(), (byte)'|');}
|
||||
catch (Exception e) {Err_.Noop(e); return;}
|
||||
Tfds.Fail_expdError();
|
||||
}
|
||||
@Test public void ReadCsvDte() {
|
||||
tst_ReadCsvDte("20110801 221435.987");
|
||||
} void tst_ReadCsvDte(String raw) {Tfds.Eq_date(DateAdp_.parse_fmt(raw, Bry_.Fmt_csvDte), Bry_.ReadCsvDte(Bry_.new_u8(raw + "|"), Int_obj_ref.zero_(), (byte)'|'));}
|
||||
} void tst_ReadCsvDte(String raw) {Tfds.Eq_date(DateAdp_.parse_fmt(raw, Bry_.Fmt_csvDte), Bry_.ReadCsvDte(Bry_.new_u8(raw + "|"), Int_obj_ref.New_zero(), (byte)'|'));}
|
||||
@Test public void ReadCsvInt() {
|
||||
tst_ReadCsvInt("1234567890");
|
||||
} void tst_ReadCsvInt(String raw) {Tfds.Eq(Int_.parse(raw), Bry_.ReadCsvInt(Bry_.new_u8(raw + "|"), Int_obj_ref.zero_(), (byte)'|'));}
|
||||
} void tst_ReadCsvInt(String raw) {Tfds.Eq(Int_.parse(raw), Bry_.ReadCsvInt(Bry_.new_u8(raw + "|"), Int_obj_ref.New_zero(), (byte)'|'));}
|
||||
@Test public void Trim() {
|
||||
Trim_tst("a b c", 1, 4, "b");
|
||||
Trim_tst("a c", 1, 3, "");
|
||||
@ -211,7 +211,7 @@ public class Bry__tst {
|
||||
tst_Replace_between("a[0b" , "[", "]", "0", "a[0b");
|
||||
} public void tst_Replace_between(String src, String bgn, String end, String repl, String expd) {Tfds.Eq(expd, String_.new_a7(Bry_.Replace_between(Bry_.new_a7(src), Bry_.new_a7(bgn), Bry_.new_a7(end), Bry_.new_a7(repl))));}
|
||||
@Test public void Replace() {
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
tst_Replace(tmp_bfr, "a0b" , "0", "00", "a00b"); // 1 -> 1
|
||||
tst_Replace(tmp_bfr, "a0b0c" , "0", "00", "a00b00c"); // 1 -> 2
|
||||
tst_Replace(tmp_bfr, "a00b00c" , "00", "0", "a0b0c"); // 2 -> 1
|
||||
|
@ -53,7 +53,7 @@ public class Bry_bfr {
|
||||
rv = To_bry();
|
||||
this.Clear();
|
||||
if (reset > 0) Reset_if_gt(reset);
|
||||
synchronized (mkr_mgr) {
|
||||
synchronized (mkr_mgr) { // SAME: Mkr_rls()
|
||||
mkr_mgr.Rls(mkr_idx);
|
||||
}
|
||||
mkr_mgr = null;
|
||||
@ -61,7 +61,7 @@ public class Bry_bfr {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private Bry_bfr Reset_(int v) {reset = v; return this;}
|
||||
public Bry_bfr Reset_(int v) {reset = v; return this;}
|
||||
public Bry_bfr Reset_if_gt(int limit) {
|
||||
if (bfr_max > limit) {
|
||||
this.bfr_max = limit;
|
||||
@ -640,11 +640,8 @@ public class Bry_bfr {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public static Bry_bfr new_() {return new Bry_bfr(16);}
|
||||
public static Bry_bfr new_(int v) {return new Bry_bfr(v);}
|
||||
public static Bry_bfr reset_(int v) {return new Bry_bfr(16).Reset_(v);} // PERF: set initial size to 16, not reset val; allows for faster "startup"; DATE:2014-06-14
|
||||
protected Bry_bfr() {}
|
||||
Bry_bfr(int bfr_max) {
|
||||
public Bry_bfr(int bfr_max) {
|
||||
Init(bfr_max);
|
||||
}
|
||||
protected void Init(int bfr_max) {
|
||||
|
@ -18,6 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx;
|
||||
import gplx.core.brys.*;
|
||||
public class Bry_bfr_ {
|
||||
public static Bry_bfr New() {return new Bry_bfr(16);}
|
||||
public static Bry_bfr New_w_size(int v) {return new Bry_bfr(v);}
|
||||
public static Bry_bfr Reset(int v) {return new Bry_bfr(16).Reset_(v);} // PERF: set initial size to 16, not reset val; allows for faster "startup"; DATE:2014-06-14
|
||||
|
||||
public static final Bry_bfr[] Ary_empty = new Bry_bfr[0];
|
||||
private static Bry_bfr_mkr_mgr dflt;
|
||||
public static Bry_bfr Get() {if (dflt == null) dflt = new Bry_bfr_mkr_mgr(Bry_bfr_mkr.Tid_b128, 128); return dflt.Get();} // NOTE: lazy else "Object synchronization" error; DATE:2015-11-18
|
||||
|
@ -18,20 +18,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx;
|
||||
import org.junit.*;
|
||||
public class Bry_bfr_tst {
|
||||
private Bry_bfr bb = Bry_bfr.new_(16);
|
||||
private Bry_bfr bb = Bry_bfr_.New();
|
||||
@Before public void setup() {bb.Clear();} private ByteAryBfr_fxt fxt = new ByteAryBfr_fxt();
|
||||
@Test public void AddByte() {
|
||||
bb = Bry_bfr.new_(2); // NOTE: make sure auto-expands
|
||||
bb = Bry_bfr_.New_w_size(2); // NOTE: make sure auto-expands
|
||||
tst_AddByte("a", "a", 2);
|
||||
tst_AddByte("b", "ab", 2);
|
||||
tst_AddByte("c", "abc", 4);
|
||||
}
|
||||
@Test public void AddAry() { // NOTE: make sure auto-expands
|
||||
bb = Bry_bfr.new_(2);
|
||||
bb = Bry_bfr_.New_w_size(2);
|
||||
tst_AddByte("abcd", "abcd", 12);
|
||||
}
|
||||
@Test public void Add_byte_repeat() { // NOTE: make sure auto-expands
|
||||
bb = Bry_bfr.new_(2);
|
||||
bb = Bry_bfr_.New_w_size(2);
|
||||
tst_Add_byte_repeat(Byte_ascii.Space, 12, String_.Repeat(" ", 12));
|
||||
} void tst_Add_byte_repeat(byte b, int len, String expd) {Tfds.Eq(expd, bb.Add_byte_repeat(b, len).To_str_and_clear());}
|
||||
void tst_AddByte(String s, String expdStr, int expdLen) {
|
||||
@ -119,7 +119,7 @@ public class Bry_bfr_tst {
|
||||
// tst_InsertAt_str("ab", 0, "cdefghij", "cdefghijab");
|
||||
// }
|
||||
// void tst_InsertAt_str(String orig, int insertAt, String insertStr, String expd) {
|
||||
// bb = Bry_bfr.new_(16);
|
||||
// bb = Bry_bfr_.New(16);
|
||||
// bb.Add_str(orig);
|
||||
// bb.InsertAt_str(insertAt, insertStr);
|
||||
// String actl = bb.To_str_and_clear();
|
||||
@ -166,7 +166,7 @@ public class Bry_bfr_tst {
|
||||
tst_Add_bfr_trimEnd_and_clear("a ", "a");
|
||||
}
|
||||
void tst_Add_bfr_trimEnd_and_clear(String raw, String expd) {
|
||||
Bry_bfr tmp = Bry_bfr.new_().Add_str_u8(raw);
|
||||
Bry_bfr tmp = Bry_bfr_.New().Add_str_u8(raw);
|
||||
Tfds.Eq(expd, bb.Add_bfr_trim_and_clear(tmp, false, true).To_str_and_clear());
|
||||
}
|
||||
@Test public void Add_bfr_trimAll_and_clear() {
|
||||
@ -176,7 +176,7 @@ public class Bry_bfr_tst {
|
||||
tst_Add_bfr_trimAll_and_clear("", "");
|
||||
}
|
||||
void tst_Add_bfr_trimAll_and_clear(String raw, String expd) {
|
||||
Bry_bfr tmp = Bry_bfr.new_().Add_str_u8(raw);
|
||||
Bry_bfr tmp = Bry_bfr_.New().Add_str_u8(raw);
|
||||
Tfds.Eq(expd, bb.Add_bfr_trim_and_clear(tmp, true, true).To_str_and_clear());
|
||||
}
|
||||
@Test public void Add_int_pad_bgn() {
|
||||
@ -216,7 +216,7 @@ public class Bry_bfr_tst {
|
||||
}
|
||||
}
|
||||
class ByteAryBfr_fxt {
|
||||
private final Bry_bfr bfr = Bry_bfr.reset_(16);
|
||||
private final Bry_bfr bfr = Bry_bfr_.Reset(16);
|
||||
public void Clear() {
|
||||
bfr.ClearAndReset();
|
||||
}
|
||||
|
@ -20,10 +20,11 @@ import gplx.core.brys.*;
|
||||
public class Bry_split_ {
|
||||
private static final Object thread_lock = new Object();
|
||||
public static byte[][] Split(byte[] src, byte dlm) {return Split(src, dlm, false);}
|
||||
public static byte[][] Split(byte[] src, byte dlm, boolean trim) {
|
||||
public static byte[][] Split(byte[] src, byte dlm, boolean trim) {return src == null ? Bry_.Ary_empty : Split(src, 0, src.length, dlm, trim);}
|
||||
public static byte[][] Split(byte[] src, int bgn, int end, byte dlm, boolean trim) {
|
||||
synchronized (thread_lock) {
|
||||
Bry_split_wkr__to_ary wkr = Bry_split_wkr__to_ary.Instance;
|
||||
Split(src, 0, src == null ? 0 : src.length, dlm, trim, wkr);
|
||||
Split(src, bgn, end, dlm, trim, wkr);
|
||||
return wkr.To_ary();
|
||||
}
|
||||
}
|
||||
@ -76,7 +77,7 @@ public class Bry_split_ {
|
||||
int src_len = src.length;
|
||||
if (src_len == 0) return Bry_.Ary_empty;
|
||||
int cur_pos = src_bgn, dlm_len = dlm.length;
|
||||
List_adp rv = List_adp_.new_();
|
||||
List_adp rv = List_adp_.New();
|
||||
while (true) {
|
||||
int find_pos = Bry_find_.Find_fwd(src, dlm, cur_pos);
|
||||
if (find_pos == Bry_find_.Not_found) {
|
||||
@ -92,7 +93,7 @@ public class Bry_split_ {
|
||||
public static byte[][] Split_lines(byte[] src) {
|
||||
if (Bry_.Len_eq_0(src)) return Bry_.Ary_empty;
|
||||
int src_len = src.length, src_pos = 0, fld_bgn = 0;
|
||||
List_adp rv = List_adp_.new_();
|
||||
List_adp rv = List_adp_.New();
|
||||
while (true) {
|
||||
boolean last = src_pos == src_len;
|
||||
byte b = last ? Byte_ascii.Nl : src[src_pos];
|
||||
@ -118,7 +119,7 @@ public class Bry_split_ {
|
||||
public static final int Rv__ok = 0, Rv__extend = 1, Rv__cancel = 2;
|
||||
}
|
||||
class Bry_split_wkr__to_ary implements gplx.core.brys.Bry_split_wkr {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
private final List_adp list = List_adp_.New();
|
||||
public int Split(byte[] src, int itm_bgn, int itm_end) {
|
||||
synchronized (list) {
|
||||
byte[] bry = itm_end == itm_bgn ? Bry_.Empty : Bry_.Mid(src, itm_bgn, itm_end);
|
||||
|
@ -57,7 +57,7 @@ class Bry_split__fxt {
|
||||
}
|
||||
}
|
||||
class Bry_split_wkr__example implements gplx.core.brys.Bry_split_wkr {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
private final List_adp list = List_adp_.New();
|
||||
public int Split(byte[] src, int itm_bgn, int itm_end) {
|
||||
byte[] bry = itm_end == itm_bgn ? Bry_.Empty : Bry_.Mid(src, itm_bgn, itm_end);
|
||||
if (Bry_.Eq(bry, Bry_.new_a7("extend"))) return Bry_split_.Rv__extend;
|
||||
|
@ -36,6 +36,7 @@ public class Byte_ {
|
||||
public static byte By_int(int v) {return v > 127 ? (byte)(v - 256) : (byte)v;} // PERF?: (byte)(v & 0xff)
|
||||
public static int To_int(byte v) {return v < 0 ? (int)v + 256 : v;}
|
||||
public static String To_str(byte v) {return new Byte(v).toString();}
|
||||
public static byte[] To_bry(byte v) {return new byte[] {v};}
|
||||
public static boolean In(byte v, byte... ary) {
|
||||
for (byte itm : ary)
|
||||
if (v == itm) return true;
|
||||
|
@ -20,7 +20,7 @@ import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
import java.text.SimpleDateFormat;
|
||||
public class DateAdp implements CompareAble, GfoInvkAble {
|
||||
public class DateAdp implements CompareAble, Gfo_invk {
|
||||
public int compareTo(Object obj) {DateAdp comp = (DateAdp)obj; return under.compareTo(comp.under);}
|
||||
@Override public String toString() {return XtoStr_gplx_long();}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
@ -30,7 +30,7 @@ public class DateAdp implements CompareAble, GfoInvkAble {
|
||||
if (ctx.Deny()) return this;
|
||||
return this.Add_day(days);
|
||||
}
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
} public static final String Invk_XtoStr_fmt = "XtoStr_fmt", Invk_AddDays = "Add_day";
|
||||
public int Segment(int segmentIdx) {
|
||||
switch (segmentIdx) {
|
||||
|
@ -25,12 +25,12 @@ import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import gplx.core.times.*;
|
||||
public class DateAdp_ implements GfoInvkAble {
|
||||
public class DateAdp_ implements Gfo_invk {
|
||||
public static final String Cls_ref_name = "Date";
|
||||
public static final Class<?> Cls_ref_type = DateAdp.class;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_Now)) return Now();
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
} public static final String Invk_Now = "Now";
|
||||
public static final DateAdp MinValue = new DateAdp( 1, 1, 1, 0, 0, 0, 0);
|
||||
public static final DateAdp MaxValue = new DateAdp(9999, 12, 31, 23, 59, 59, 999);
|
||||
@ -80,6 +80,10 @@ public class DateAdp_ implements GfoInvkAble {
|
||||
else return true;
|
||||
}
|
||||
public static DateAdp unixtime_utc_seconds_(long v) {return unixtime_utc_ms_(v * 1000);}
|
||||
public static DateAdp parse_fmt_or(String raw, String fmt, DateAdp or) {
|
||||
try {return parse_fmt(raw, fmt);}
|
||||
catch (Exception e) {Err_.Noop(e); return or;}
|
||||
}
|
||||
public static DateAdp db_(Object v) {
|
||||
Timestamp ts = (Timestamp)v;
|
||||
Calendar gc = Calendar.getInstance();
|
||||
|
@ -1,45 +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 GfoEvMgr_ {
|
||||
public static void Sub(GfoEvMgrOwner pub, String pubEvt, GfoEvObj sub, String subEvt) {pub.EvMgr().AddSub(pub, pubEvt, sub, subEvt);}
|
||||
public static void SubSame(GfoEvMgrOwner pub, String evt, GfoEvObj sub) {pub.EvMgr().AddSub(pub, evt, sub, evt);}
|
||||
public static void SubSame_many(GfoEvMgrOwner pub, GfoEvObj sub, String... evts) {
|
||||
int len = evts.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
String evt = evts[i];
|
||||
pub.EvMgr().AddSub(pub, evt, sub, evt);
|
||||
}
|
||||
}
|
||||
public static void Pub(GfoEvMgrOwner pub, String pubEvt) {pub.EvMgr().Pub(GfsCtx.new_(), pubEvt, GfoMsg_.new_cast_(pubEvt));}
|
||||
public static void PubObj(GfoEvMgrOwner pub, String pubEvt, String key, Object v) {pub.EvMgr().Pub(GfsCtx.new_(), pubEvt, msg_(pubEvt, Keyval_.new_(key, v)));}
|
||||
public static void PubVal(GfoEvMgrOwner pub, String pubEvt, Object v) {pub.EvMgr().Pub(GfsCtx.new_(), pubEvt, msg_(pubEvt, Keyval_.new_("v", v)));}
|
||||
public static void PubVals(GfoEvMgrOwner pub, String pubEvt, Keyval... ary) {pub.EvMgr().Pub(GfsCtx.new_(), pubEvt, msg_(pubEvt, ary));}
|
||||
public static void PubMsg(GfoEvMgrOwner pub, GfsCtx ctx, String pubEvt, GfoMsg m) {pub.EvMgr().Pub(ctx, pubEvt, m);}
|
||||
public static void Lnk(GfoEvMgrOwner pub, GfoEvMgrOwner sub) {sub.EvMgr().Lnk(pub);}
|
||||
public static void RlsPub(GfoEvMgrOwner pub) {pub.EvMgr().RlsPub(pub);}
|
||||
public static void RlsSub(GfoEvMgrOwner sub) {sub.EvMgr().RlsSub(sub);}
|
||||
static GfoMsg msg_(String evt, Keyval... kvAry) {
|
||||
GfoMsg m = GfoMsg_.new_cast_(evt);
|
||||
for (int i = 0; i < kvAry.length; i++) {
|
||||
Keyval kv = kvAry[i];
|
||||
m.Add(kv.Key(), kv.Val());
|
||||
}
|
||||
return m;
|
||||
}
|
||||
}
|
@ -1,35 +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 GfoInvkAbleCmd {
|
||||
private GfoMsg m;
|
||||
public GfoInvkAble InvkAble() {return invkAble;} private GfoInvkAble invkAble;
|
||||
public String Cmd() {return cmd;} private String cmd;
|
||||
public Object Arg() {return arg;} private Object arg;
|
||||
public Object Invk() {
|
||||
return invkAble.Invk(GfsCtx.Instance, 0, cmd, m);
|
||||
}
|
||||
public static final GfoInvkAbleCmd Null = new GfoInvkAbleCmd();
|
||||
public static GfoInvkAbleCmd new_(GfoInvkAble invkAble, String cmd) {return arg_(invkAble, cmd, null);}
|
||||
public static GfoInvkAbleCmd arg_(GfoInvkAble invkAble, String cmd, Object arg) {
|
||||
GfoInvkAbleCmd rv = new GfoInvkAbleCmd();
|
||||
rv.invkAble = invkAble; rv.cmd = cmd; rv.arg = arg;
|
||||
rv.m = (arg == null) ? GfoMsg_.Null : GfoMsg_.new_parse_(cmd).Add("v", arg);
|
||||
return rv;
|
||||
} GfoInvkAbleCmd() {}
|
||||
}
|
@ -1,40 +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 gplx.core.primitives.*;
|
||||
public class GfoInvkAble_ {
|
||||
public static GfoInvkAble as_(Object obj) {return obj instanceof GfoInvkAble ? (GfoInvkAble)obj : null;}
|
||||
public static GfoInvkAble cast(Object obj) {try {return (GfoInvkAble)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, GfoInvkAble.class, obj);}}
|
||||
public static final String_obj_val Rv_unhandled = String_obj_val.new_("Unhandled"), Rv_handled = String_obj_val.new_("Handled"), Rv_host = String_obj_val.new_("Host")
|
||||
, Rv_cancel = String_obj_val.new_("Cancel"), Rv_error = String_obj_val.new_("Error");
|
||||
|
||||
public static Object InvkCmd(GfoInvkAble invk, String k) {return InvkCmd_msg(invk, k, GfoMsg_.Null);}
|
||||
public static Object InvkCmd_val(GfoInvkAble invk, String k, Object v) {return InvkCmd_msg(invk, k, GfoMsg_.new_cast_(k).Add("v", v));}
|
||||
public static Object InvkCmd_msg(GfoInvkAble invk, String k, GfoMsg m) {
|
||||
Object rv = invk.Invk(GfsCtx.Instance, 0, k, m);
|
||||
if (rv == GfoInvkAble_.Rv_unhandled) throw Err_.new_wo_type("invkable did not handle message", "key", k);
|
||||
return rv;
|
||||
}
|
||||
public static final GfoInvkAble Null = new GfoInvkAble_null();
|
||||
public static Object Invk(GfoInvkAble itm) {return itm.Invk(null, -1, null, null);}
|
||||
public static Object Invk(GfoInvkAble itm, String key) {return itm.Invk(null, -1, key , null);}
|
||||
public static final String Mutator_suffix = "_";
|
||||
}
|
||||
class GfoInvkAble_null implements GfoInvkAble {
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return this;}
|
||||
}
|
@ -46,7 +46,7 @@ public class GfoMsg_ {
|
||||
}
|
||||
public static GfoMsg chain_(GfoMsg owner, String key) {
|
||||
GfoMsg sub = owner;
|
||||
List_adp list = List_adp_.new_();
|
||||
List_adp list = List_adp_.New();
|
||||
list.Add(sub.Key());
|
||||
while (sub != null) {
|
||||
if (sub.Subs_count() == 0) break;
|
||||
@ -77,14 +77,14 @@ public class GfoMsg_ {
|
||||
}
|
||||
class GfoMsg_wtr extends GfoMsg_base {
|
||||
@Override protected Object ReadOr(String k, Object defaultOr) {
|
||||
if (args == null) args = List_adp_.new_();
|
||||
if (args == null) args = List_adp_.New();
|
||||
args.Add(Keyval_.new_(k, null));
|
||||
return defaultOr;
|
||||
}
|
||||
}
|
||||
class GfoMsg_rdr extends GfoMsg_base {
|
||||
@Override protected Object ReadOr(String k, Object defaultOr) {
|
||||
if (args == null) args = List_adp_.new_();
|
||||
if (args == null) args = List_adp_.New();
|
||||
args.Add(Keyval_.new_(k, defaultOr));
|
||||
return defaultOr;
|
||||
}
|
||||
@ -93,7 +93,7 @@ class GfoMsg_base implements GfoMsg {
|
||||
public String Key() {return key;} private String key;
|
||||
public int Subs_count() {return subs == null ? 0 : subs.Count();}
|
||||
public GfoMsg Subs_getAt(int i) {return subs == null ? null : (GfoMsg)subs.Get_at(i);}
|
||||
public GfoMsg Subs_add(GfoMsg m) {if (subs == null) subs = List_adp_.new_(); subs.Add(m); return this;}
|
||||
public GfoMsg Subs_add(GfoMsg m) {if (subs == null) subs = List_adp_.New(); subs.Add(m); return this;}
|
||||
public GfoMsg Subs_(GfoMsg... ary) {for (GfoMsg m : ary) Subs_add(m); return this;}
|
||||
public int Args_count() {return args == null ? 0 : args.Count();}
|
||||
public void Args_reset() {
|
||||
@ -115,7 +115,7 @@ class GfoMsg_base implements GfoMsg {
|
||||
}
|
||||
public Keyval Args_getAt(int i) {return args == null ? null : (Keyval)args.Get_at(i);}
|
||||
public GfoMsg Args_ovr(String k, Object v) {
|
||||
if (args == null) args = List_adp_.new_();
|
||||
if (args == null) args = List_adp_.New();
|
||||
for (int i = 0; i < args.Count(); i++) {
|
||||
Keyval kv = (Keyval)args.Get_at(i);
|
||||
if (String_.Eq(k, kv.Key())) {
|
||||
@ -128,7 +128,7 @@ class GfoMsg_base implements GfoMsg {
|
||||
}
|
||||
public GfoMsg Parse_(boolean v) {parse = v; return this;}
|
||||
public GfoMsg Add(String k, Object v) {
|
||||
if (args == null) args = List_adp_.new_();
|
||||
if (args == null) args = List_adp_.New();
|
||||
args.Add(Keyval_.new_(k, v));
|
||||
return this;
|
||||
}
|
||||
@ -204,12 +204,12 @@ class GfoMsg_base implements GfoMsg {
|
||||
public GfoMsg CloneNew() {
|
||||
GfoMsg_base rv = new GfoMsg_base().ctor_(key, parse);
|
||||
if (args != null) {
|
||||
rv.args = List_adp_.new_();
|
||||
rv.args = List_adp_.New();
|
||||
for (int i = 0; i < args.Count(); i++)
|
||||
rv.args.Add(args.Get_at(i));
|
||||
}
|
||||
if (subs != null) {
|
||||
rv.subs = List_adp_.new_();
|
||||
rv.subs = List_adp_.New();
|
||||
for (int i = 0; i < args.Count(); i++) {
|
||||
GfoMsg sub = (GfoMsg)args.Get_at(i);
|
||||
rv.subs.Add(sub.CloneNew()); // NOTE: recursion
|
||||
|
@ -27,14 +27,14 @@ public class GfoMsg_tst {
|
||||
}
|
||||
@Test public void Write() {
|
||||
Mok mok = new Mok();
|
||||
tst_Msg(GfoInvkXtoStr.WriteMsg(mok, Mok.Invk_Cmd0, true, 1, "a"), "Mok.Cmd0:bool0='y' int0='1' str0='a';");
|
||||
tst_Msg(Gfo_invk_to_str.WriteMsg(mok, Mok.Invk_Cmd0, true, 1, "a"), "Mok.Cmd0:bool0='y' int0='1' str0='a';");
|
||||
mok.Int0 = 2;
|
||||
mok.Bool0 = true;
|
||||
mok.Str0 = "b";
|
||||
tst_Msg(GfoInvkXtoStr.ReadMsg(mok, Mok.Invk_Cmd0), "Mok.Cmd0:bool0='y' int0='2' str0='b';");
|
||||
tst_Msg(Gfo_invk_to_str.ReadMsg(mok, Mok.Invk_Cmd0), "Mok.Cmd0:bool0='y' int0='2' str0='b';");
|
||||
}
|
||||
void tst_Msg(GfoMsg m, String expd) {Tfds.Eq(expd, m.To_str());}
|
||||
class Mok implements GfoInvkAble {
|
||||
class Mok implements Gfo_invk {
|
||||
public boolean Bool0;
|
||||
public int Int0;
|
||||
public String Str0;
|
||||
|
@ -16,7 +16,7 @@ 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 GfoTemplateFactory implements GfoInvkAble {
|
||||
public class GfoTemplateFactory implements Gfo_invk {
|
||||
public void Reg(String key, GfoTemplate template) {hash.Add(key, template);}
|
||||
public Object Make(String key) {
|
||||
GfoTemplate template = (GfoTemplate)hash.Get_by(key);
|
||||
@ -25,8 +25,8 @@ public class GfoTemplateFactory implements GfoInvkAble {
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
ctx.Match(k, k);
|
||||
Object o = hash.Get_by(k);
|
||||
return o == null ? GfoInvkAble_.Rv_unhandled : o;
|
||||
return o == null ? Gfo_invk_.Rv_unhandled : o;
|
||||
}
|
||||
public static final GfoTemplateFactory Instance = new GfoTemplateFactory(); GfoTemplateFactory() {}
|
||||
Hash_adp hash = Hash_adp_.new_();
|
||||
Hash_adp hash = Hash_adp_.New();
|
||||
}
|
||||
|
@ -16,4 +16,4 @@ 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 interface GfoEvObj extends GfoInvkAble, GfoEvMgrOwner {}
|
||||
public interface Gfo_evt_itm extends Gfo_invk, Gfo_evt_mgr_owner {}
|
@ -17,16 +17,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.core.lists.*;
|
||||
public class GfoEvMgr {
|
||||
@gplx.Internal protected void AddSub(GfoEvMgrOwner pub, String pubEvt, GfoEvObj sub, String subPrc) {
|
||||
public class Gfo_evt_mgr {
|
||||
private final Gfo_evt_mgr_owner sender; private Ordered_hash subsRegy, pubsRegy;
|
||||
public Gfo_evt_mgr(Gfo_evt_mgr_owner sender) {this.sender = sender;}
|
||||
@gplx.Internal protected void AddSub(Gfo_evt_mgr_owner pub, String pubEvt, Gfo_evt_itm sub, String subPrc) {
|
||||
GfoEvLnk lnk = new GfoEvLnk(pub, pubEvt, sub, subPrc);
|
||||
if (subsRegy == null) subsRegy = Ordered_hash_.New();
|
||||
AddInList(subsRegy, pubEvt, lnk);
|
||||
sub.EvMgr().AddPub(pubEvt, lnk);
|
||||
sub.Evt_mgr().AddPub(pubEvt, lnk);
|
||||
}
|
||||
@gplx.Internal protected void Lnk(GfoEvMgrOwner pub) {
|
||||
if (pub.EvMgr().lnks == null) pub.EvMgr().lnks = List_adp_.new_();
|
||||
pub.EvMgr().lnks.Add(this);
|
||||
@gplx.Internal protected void Lnk(Gfo_evt_mgr_owner pub) {
|
||||
if (pub.Evt_mgr().lnks == null) pub.Evt_mgr().lnks = List_adp_.New();
|
||||
pub.Evt_mgr().lnks.Add(this);
|
||||
} List_adp lnks;
|
||||
void AddInList(Ordered_hash regy, String key, GfoEvLnk lnk) {
|
||||
GfoEvLnkList list = (GfoEvLnkList)regy.Get_by(key);
|
||||
@ -51,22 +53,22 @@ public class GfoEvMgr {
|
||||
}
|
||||
if (lnks != null) {
|
||||
for (int i = 0; i < lnks.Count(); i++) {
|
||||
GfoEvMgr lnk = (GfoEvMgr)lnks.Get_at(i);
|
||||
Gfo_evt_mgr lnk = (Gfo_evt_mgr)lnks.Get_at(i);
|
||||
lnk.Pub(ctx, evt, m);
|
||||
}
|
||||
}
|
||||
}
|
||||
@gplx.Internal protected void RlsSub(GfoEvMgrOwner eobj) {
|
||||
@gplx.Internal protected void RlsSub(Gfo_evt_mgr_owner eobj) {
|
||||
RlsRegyObj(pubsRegy, eobj, true);
|
||||
RlsRegyObj(subsRegy, eobj, false);
|
||||
}
|
||||
@gplx.Internal protected void RlsPub(GfoEvMgrOwner eobj) {
|
||||
@gplx.Internal protected void RlsPub(Gfo_evt_mgr_owner eobj) {
|
||||
RlsRegyObj(pubsRegy, eobj, true);
|
||||
RlsRegyObj(subsRegy, eobj, false);
|
||||
}
|
||||
@gplx.Internal protected void RlsRegyObj(Ordered_hash regy, GfoEvMgrOwner eobj, boolean pub) {
|
||||
@gplx.Internal protected void RlsRegyObj(Ordered_hash regy, Gfo_evt_mgr_owner eobj, boolean pub) {
|
||||
if (regy == null) return;
|
||||
List_adp delList = List_adp_.new_();
|
||||
List_adp delList = List_adp_.New();
|
||||
for (int i = 0; i < regy.Count(); i++) {
|
||||
GfoEvLnkList pubsList = (GfoEvLnkList)regy.Get_at(i);
|
||||
delList.Clear();
|
||||
@ -76,15 +78,15 @@ public class GfoEvMgr {
|
||||
}
|
||||
for (int j = 0; j < delList.Count(); j++) {
|
||||
GfoEvLnk del = (GfoEvLnk)delList.Get_at(j);
|
||||
del.End(pub).EvMgr().RlsLnk(!pub, pubsList.Key(), del.End(!pub));
|
||||
del.End(pub).Evt_mgr().RlsLnk(!pub, pubsList.Key(), del.End(!pub));
|
||||
pubsList.Del(del);
|
||||
}
|
||||
}
|
||||
}
|
||||
@gplx.Internal protected void RlsLnk(boolean pubEnd, String key, GfoEvMgrOwner endObj) {
|
||||
@gplx.Internal protected void RlsLnk(boolean pubEnd, String key, Gfo_evt_mgr_owner endObj) {
|
||||
Ordered_hash regy = pubEnd ? pubsRegy : subsRegy;
|
||||
GfoEvLnkList list = (GfoEvLnkList)regy.Get_by(key);
|
||||
List_adp delList = List_adp_.new_();
|
||||
List_adp delList = List_adp_.New();
|
||||
for (int i = 0; i < list.Count(); i++) {
|
||||
GfoEvLnk lnk = (GfoEvLnk)list.Get_at(i);
|
||||
if (lnk.End(pubEnd) == endObj) delList.Add(lnk);
|
||||
@ -95,13 +97,6 @@ public class GfoEvMgr {
|
||||
}
|
||||
delList.Clear();
|
||||
}
|
||||
|
||||
Object sender; Ordered_hash subsRegy, pubsRegy;
|
||||
public static GfoEvMgr new_(Object sender) {
|
||||
GfoEvMgr rv = new GfoEvMgr();
|
||||
rv.sender = sender;
|
||||
return rv;
|
||||
} GfoEvMgr() {}
|
||||
}
|
||||
class GfoEvLnkList {
|
||||
public String Key() {return key;} private String key;
|
||||
@ -110,20 +105,20 @@ class GfoEvLnkList {
|
||||
public void Del(GfoEvLnk lnk) {list.Del(lnk);}
|
||||
public GfoEvLnk Get_at(int i) {return (GfoEvLnk)list.Get_at(i);}
|
||||
public GfoEvLnkList(String key) {this.key = key;}
|
||||
List_adp list = List_adp_.new_();
|
||||
List_adp list = List_adp_.New();
|
||||
}
|
||||
class GfoEvLnk {
|
||||
public GfoEvMgrOwner Pub() {return pub;} GfoEvMgrOwner pub;
|
||||
public Gfo_evt_mgr_owner Pub() {return pub;} Gfo_evt_mgr_owner pub;
|
||||
public String PubEvt() {return pubEvt;} private String pubEvt;
|
||||
public GfoEvObj Sub() {return sub;} GfoEvObj sub;
|
||||
public Gfo_evt_itm Sub() {return sub;} Gfo_evt_itm sub;
|
||||
public String SubPrc() {return subPrc;} private String subPrc;
|
||||
public GfoEvMgrOwner End(boolean pubEnd) {return pubEnd ? pub : sub;}
|
||||
public GfoEvLnk(GfoEvMgrOwner pub, String pubEvt, GfoEvObj sub, String subPrc) {this.pub = pub; this.pubEvt = pubEvt; this.sub = sub; this.subPrc = subPrc;}
|
||||
public Gfo_evt_mgr_owner End(boolean pubEnd) {return pubEnd ? pub : sub;}
|
||||
public GfoEvLnk(Gfo_evt_mgr_owner pub, String pubEvt, Gfo_evt_itm sub, String subPrc) {this.pub = pub; this.pubEvt = pubEvt; this.sub = sub; this.subPrc = subPrc;}
|
||||
}
|
||||
class GfoEvItm {
|
||||
public String Key() {return key;} private String key;
|
||||
public GfoInvkAble InvkAble() {return invkAble;} GfoInvkAble invkAble;
|
||||
public static GfoEvItm new_(GfoInvkAble invkAble, String key) {
|
||||
public Gfo_invk InvkAble() {return invkAble;} Gfo_invk invkAble;
|
||||
public static GfoEvItm new_(Gfo_invk invkAble, String key) {
|
||||
GfoEvItm rv = new GfoEvItm();
|
||||
rv.invkAble = invkAble; rv.key = key;
|
||||
return rv;
|
45
100_core/src/gplx/Gfo_evt_mgr_.java
Normal file
45
100_core/src/gplx/Gfo_evt_mgr_.java
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
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 Gfo_evt_mgr_ {
|
||||
public static void Sub(Gfo_evt_mgr_owner pub, String pubEvt, Gfo_evt_itm sub, String subEvt) {pub.Evt_mgr().AddSub(pub, pubEvt, sub, subEvt);}
|
||||
public static void Sub_same(Gfo_evt_mgr_owner pub, String evt, Gfo_evt_itm sub) {pub.Evt_mgr().AddSub(pub, evt, sub, evt);}
|
||||
public static void Sub_same_many(Gfo_evt_mgr_owner pub, Gfo_evt_itm sub, String... evts) {
|
||||
int len = evts.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
String evt = evts[i];
|
||||
pub.Evt_mgr().AddSub(pub, evt, sub, evt);
|
||||
}
|
||||
}
|
||||
public static void Pub(Gfo_evt_mgr_owner pub, String pubEvt) {pub.Evt_mgr().Pub(GfsCtx.new_(), pubEvt, GfoMsg_.new_cast_(pubEvt));}
|
||||
public static void Pub_obj(Gfo_evt_mgr_owner pub, String pubEvt, String key, Object v) {pub.Evt_mgr().Pub(GfsCtx.new_(), pubEvt, msg_(pubEvt, Keyval_.new_(key, v)));}
|
||||
public static void Pub_val(Gfo_evt_mgr_owner pub, String pubEvt, Object v) {pub.Evt_mgr().Pub(GfsCtx.new_(), pubEvt, msg_(pubEvt, Keyval_.new_("v", v)));}
|
||||
public static void Pub_vals(Gfo_evt_mgr_owner pub, String pubEvt, Keyval... ary) {pub.Evt_mgr().Pub(GfsCtx.new_(), pubEvt, msg_(pubEvt, ary));}
|
||||
public static void Pub_msg(Gfo_evt_mgr_owner pub, GfsCtx ctx, String pubEvt, GfoMsg m) {pub.Evt_mgr().Pub(ctx, pubEvt, m);}
|
||||
public static void Lnk(Gfo_evt_mgr_owner pub, Gfo_evt_mgr_owner sub) {sub.Evt_mgr().Lnk(pub);}
|
||||
public static void Rls_pub(Gfo_evt_mgr_owner pub) {pub.Evt_mgr().RlsPub(pub);}
|
||||
public static void Rls_sub(Gfo_evt_mgr_owner sub) {sub.Evt_mgr().RlsSub(sub);}
|
||||
static GfoMsg msg_(String evt, Keyval... kvAry) {
|
||||
GfoMsg m = GfoMsg_.new_cast_(evt);
|
||||
for (int i = 0; i < kvAry.length; i++) {
|
||||
Keyval kv = kvAry[i];
|
||||
m.Add(kv.Key(), kv.Val());
|
||||
}
|
||||
return m;
|
||||
}
|
||||
}
|
@ -16,6 +16,6 @@ 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 interface GfoEvMgrOwner {
|
||||
GfoEvMgr EvMgr();
|
||||
public interface Gfo_evt_mgr_owner {
|
||||
Gfo_evt_mgr Evt_mgr();
|
||||
}
|
@ -17,53 +17,53 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
import org.junit.*;
|
||||
public class GfoEvMgr_tst {
|
||||
public class Gfo_evt_mgr_tst {
|
||||
@Before public void setup() {
|
||||
pub = make_(); sub = make_();
|
||||
} MockEvObj pub, sub;
|
||||
@Test public void Basic() {
|
||||
GfoEvMgr_.SubSame(pub, "ev1", sub);
|
||||
GfoEvMgr_.PubVal(pub, "ev1", "val1");
|
||||
Gfo_evt_mgr_.Sub_same(pub, "ev1", sub);
|
||||
Gfo_evt_mgr_.Pub_val(pub, "ev1", "val1");
|
||||
sub.tst_Handled("val1");
|
||||
}
|
||||
@Test public void None() {// make sure no subscribers does not cause exception
|
||||
GfoEvMgr_.SubSame(pub, "ev1", sub);
|
||||
GfoEvMgr_.PubVal(pub, "ev2", "val1"); //ev2 does not exist
|
||||
Gfo_evt_mgr_.Sub_same(pub, "ev1", sub);
|
||||
Gfo_evt_mgr_.Pub_val(pub, "ev2", "val1"); //ev2 does not exist
|
||||
sub.tst_Handled();
|
||||
}
|
||||
@Test public void Lnk() {
|
||||
MockEvObj mid = make_();
|
||||
mid.EvMgr().Lnk(pub);
|
||||
GfoEvMgr_.SubSame(mid, "ev1", sub);
|
||||
GfoEvMgr_.PubVal(pub, "ev1", "val1");
|
||||
mid.Evt_mgr().Lnk(pub);
|
||||
Gfo_evt_mgr_.Sub_same(mid, "ev1", sub);
|
||||
Gfo_evt_mgr_.Pub_val(pub, "ev1", "val1");
|
||||
sub.tst_Handled("val1");
|
||||
}
|
||||
@Test public void RlsSub() {
|
||||
this.Basic();
|
||||
|
||||
GfoEvMgr_.RlsSub(sub);
|
||||
GfoEvMgr_.PubVal(pub, "ev1", "val1");
|
||||
Gfo_evt_mgr_.Rls_sub(sub);
|
||||
Gfo_evt_mgr_.Pub_val(pub, "ev1", "val1");
|
||||
sub.tst_Handled();
|
||||
}
|
||||
@Test public void RlsPub() {
|
||||
this.Basic();
|
||||
|
||||
GfoEvMgr_.RlsSub(pub);
|
||||
GfoEvMgr_.PubVal(pub, "ev1", "val1");
|
||||
Gfo_evt_mgr_.Rls_sub(pub);
|
||||
Gfo_evt_mgr_.Pub_val(pub, "ev1", "val1");
|
||||
sub.tst_Handled();
|
||||
}
|
||||
MockEvObj make_() {return new MockEvObj();}
|
||||
}
|
||||
class MockEvObj implements GfoEvObj {
|
||||
public GfoEvMgr EvMgr() {return eventMgr;} GfoEvMgr eventMgr;
|
||||
class MockEvObj implements Gfo_evt_itm {
|
||||
public Gfo_evt_mgr Evt_mgr() {return eventMgr;} Gfo_evt_mgr eventMgr;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
handled.Add(m.ReadStr("v"));
|
||||
return this;
|
||||
}
|
||||
List_adp handled = List_adp_.new_();
|
||||
List_adp handled = List_adp_.New();
|
||||
public void tst_Handled(String... expd) {
|
||||
Tfds.Eq_ary_str(expd, handled.To_str_ary());
|
||||
handled.Clear();
|
||||
}
|
||||
public MockEvObj(){eventMgr = GfoEvMgr.new_(this);}
|
||||
public MockEvObj(){eventMgr = new Gfo_evt_mgr(this);}
|
||||
}
|
@ -16,13 +16,13 @@ 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 interface GfoInvkAble {
|
||||
public interface Gfo_invk {
|
||||
Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m);
|
||||
}
|
||||
/*
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk__set)) {}
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk__set = "set";
|
||||
*/
|
43
100_core/src/gplx/Gfo_invk_.java
Normal file
43
100_core/src/gplx/Gfo_invk_.java
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
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 gplx.core.primitives.*;
|
||||
public class Gfo_invk_ {
|
||||
public static final String Mutator_suffix = "_";
|
||||
public static final Gfo_invk Noop = new Gfo_invk__noop();
|
||||
public static final String_obj_val
|
||||
Rv_unhandled = String_obj_val.new_("Unhandled")
|
||||
, Rv_handled = String_obj_val.new_("Handled")
|
||||
, Rv_host = String_obj_val.new_("Host")
|
||||
, Rv_cancel = String_obj_val.new_("Cancel")
|
||||
, Rv_error = String_obj_val.new_("Error");
|
||||
|
||||
public static Gfo_invk as_(Object obj) {return obj instanceof Gfo_invk ? (Gfo_invk)obj : null;}
|
||||
|
||||
public static Object Invk_no_key(Gfo_invk invk) {return Invk_by_msg(invk, "", GfoMsg_.Null);}
|
||||
public static Object Invk_by_key(Gfo_invk invk, String k) {return Invk_by_msg(invk, k , GfoMsg_.Null);}
|
||||
public static Object Invk_by_val(Gfo_invk invk, String k, Object v) {return Invk_by_msg(invk, k , GfoMsg_.new_cast_(k).Add("v", v));}
|
||||
public static Object Invk_by_msg(Gfo_invk invk, String k, GfoMsg m) {
|
||||
Object rv = invk.Invk(GfsCtx.Instance, 0, k, m);
|
||||
if (rv == Gfo_invk_.Rv_unhandled) throw Err_.new_wo_type("invkable did not handle message", "key", k);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
class Gfo_invk__noop implements Gfo_invk {
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return this;}
|
||||
}
|
32
100_core/src/gplx/Gfo_invk_cmd.java
Normal file
32
100_core/src/gplx/Gfo_invk_cmd.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;
|
||||
public class Gfo_invk_cmd {
|
||||
private final Gfo_invk itm; private final String cmd; private final GfoMsg msg;
|
||||
public Gfo_invk_cmd(Gfo_invk itm, String cmd, GfoMsg msg) {
|
||||
this.itm = itm; this.cmd = cmd; this.msg = msg;
|
||||
}
|
||||
public Object Exec() {return itm.Invk(GfsCtx.Instance, 0, cmd, msg);}
|
||||
public Object Exec_by_ctx(GfsCtx ctx, GfoMsg msg) {return itm.Invk(ctx, 0, cmd, msg);}
|
||||
|
||||
public static final Gfo_invk_cmd Noop = new Gfo_invk_cmd(Gfo_invk_.Noop, "", GfoMsg_.Null);
|
||||
public static Gfo_invk_cmd New_by_key(Gfo_invk itm, String cmd) {return New_by_val(itm, cmd, null);}
|
||||
public static Gfo_invk_cmd New_by_val(Gfo_invk itm, String cmd, Object val) {
|
||||
return new Gfo_invk_cmd(itm, cmd, (val == null) ? GfoMsg_.Null : GfoMsg_.new_parse_(cmd).Add("v", val));
|
||||
}
|
||||
}
|
@ -17,21 +17,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.core.primitives.*;
|
||||
public class GfoInvkCmdMgr {
|
||||
public GfoInvkCmdMgr Add_cmd_many(GfoInvkAble invk, String... keys) {
|
||||
public class Gfo_invk_cmd_mgr {
|
||||
public Gfo_invk_cmd_mgr Add_cmd_many(Gfo_invk invk, String... keys) {
|
||||
for (String key : keys)
|
||||
list.Add(GfoInvkCmdItm.new_(key, invk));
|
||||
return this;
|
||||
}
|
||||
public GfoInvkCmdMgr Add_cmd(String key, GfoInvkAble invk) {
|
||||
public Gfo_invk_cmd_mgr Add_cmd(String key, Gfo_invk invk) {
|
||||
list.Add(GfoInvkCmdItm.new_(key, invk));
|
||||
return this;
|
||||
}
|
||||
public GfoInvkCmdMgr Add_mgr(String key, GfoInvkAble invk) {
|
||||
public Gfo_invk_cmd_mgr Add_mgr(String key, Gfo_invk invk) {
|
||||
list.Add(GfoInvkCmdItm.new_(key, invk).Type_isMgr_(true));
|
||||
return this;
|
||||
}
|
||||
public GfoInvkCmdMgr Add_xtn(GfoInvkAble xtn) {
|
||||
public Gfo_invk_cmd_mgr Add_xtn(Gfo_invk xtn) {
|
||||
list.Add(GfoInvkCmdItm.new_("xtn", xtn).Type_isXtn_(true));
|
||||
return this;
|
||||
}
|
||||
@ -40,27 +40,27 @@ public class GfoInvkCmdMgr {
|
||||
GfoInvkCmdItm itm = (GfoInvkCmdItm)list.Get_at(i);
|
||||
if (itm.Type_isXtn()) {
|
||||
Object invkVal = itm.Invk().Invk(ctx, ikey, k, m);
|
||||
if (invkVal != GfoInvkAble_.Rv_unhandled) return invkVal;
|
||||
if (invkVal != Gfo_invk_.Rv_unhandled) return invkVal;
|
||||
}
|
||||
if (!ctx.Match(k, itm.Key())) continue;
|
||||
if (itm.Type_isMgr()) return itm.Invk();
|
||||
Object rv = null;
|
||||
m.Add("host", host);
|
||||
rv = itm.Invk().Invk(ctx, ikey, k, m);
|
||||
return rv == GfoInvkAble_.Rv_host ? host : rv; // if returning "this" return host
|
||||
return rv == Gfo_invk_.Rv_host ? host : rv; // if returning "this" return host
|
||||
}
|
||||
return Unhandled;
|
||||
}
|
||||
public static final String_obj_val Unhandled = String_obj_val.new_("GfoInvkCmdMgr Unhandled");
|
||||
List_adp list = List_adp_.new_();
|
||||
public static GfoInvkCmdMgr new_() {return new GfoInvkCmdMgr();} GfoInvkCmdMgr() {}
|
||||
public static final String_obj_val Unhandled = String_obj_val.new_("Gfo_invk_cmd_mgr Unhandled");
|
||||
List_adp list = List_adp_.New();
|
||||
public static Gfo_invk_cmd_mgr new_() {return new Gfo_invk_cmd_mgr();} Gfo_invk_cmd_mgr() {}
|
||||
}
|
||||
class GfoInvkCmdItm {
|
||||
public String Key() {return key;} private String key;
|
||||
public GfoInvkAble Invk() {return invk;} GfoInvkAble invk;
|
||||
public Gfo_invk Invk() {return invk;} Gfo_invk invk;
|
||||
public boolean Type_isMgr() {return type_isMgr;} public GfoInvkCmdItm Type_isMgr_(boolean v) {type_isMgr = v; return this;} private boolean type_isMgr;
|
||||
public boolean Type_isXtn() {return type_isXtn;} public GfoInvkCmdItm Type_isXtn_(boolean v) {type_isXtn = v; return this;} private boolean type_isXtn;
|
||||
public static GfoInvkCmdItm new_(String key, GfoInvkAble invk) {
|
||||
public static GfoInvkCmdItm new_(String key, Gfo_invk invk) {
|
||||
GfoInvkCmdItm rv = new GfoInvkCmdItm();
|
||||
rv.key = key; rv.invk = invk;
|
||||
return rv;
|
@ -16,6 +16,6 @@ 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 interface GfoInvkCmdMgrOwner {
|
||||
GfoInvkCmdMgr InvkMgr();
|
||||
public interface Gfo_invk_cmd_mgr_owner {
|
||||
Gfo_invk_cmd_mgr InvkMgr();
|
||||
}
|
@ -16,6 +16,6 @@ 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 interface GfoInvkRootWkr {
|
||||
Object Run_str_for(GfoInvkAble invk, GfoMsg msg);
|
||||
public interface Gfo_invk_root_wkr {
|
||||
Object Run_str_for(Gfo_invk invk, GfoMsg msg);
|
||||
}
|
@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.langs.gfs.*;
|
||||
public class GfoInvkXtoStr {
|
||||
public static GfoMsg ReadMsg(GfoInvkAble invk, String k) {
|
||||
public class Gfo_invk_to_str {
|
||||
public static GfoMsg ReadMsg(Gfo_invk invk, String k) {
|
||||
GfsCtx ctx = GfsCtx.wtr_();
|
||||
GfoMsg m = GfoMsg_.rdr_(k);
|
||||
invk.Invk(ctx, 0, k, m);
|
||||
@ -27,8 +27,8 @@ public class GfoInvkXtoStr {
|
||||
root.Subs_add(m);
|
||||
return root;
|
||||
}
|
||||
public static GfoMsg WriteMsg(GfoInvkAble invk, String k, Object... ary) {return WriteMsg(GfsCore.Instance.FetchKey(invk), invk, k, ary);}
|
||||
public static GfoMsg WriteMsg(String invkKey, GfoInvkAble invk, String k, Object... ary) {
|
||||
public static GfoMsg WriteMsg(Gfo_invk invk, String k, Object... ary) {return WriteMsg(GfsCore.Instance.FetchKey(invk), invk, k, ary);}
|
||||
public static GfoMsg WriteMsg(String invkKey, Gfo_invk invk, String k, Object... ary) {
|
||||
GfsCtx ctx = GfsCtx.wtr_();
|
||||
GfoMsg m = GfoMsg_.wtr_();
|
||||
invk.Invk(ctx, 0, k, m);
|
27
100_core/src/gplx/Gfo_log.java
Normal file
27
100_core/src/gplx/Gfo_log.java
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
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 interface Gfo_log {
|
||||
List_adp Itms();
|
||||
Gfo_log Itms_(List_adp v);
|
||||
void Warn(String msg, Object... args);
|
||||
void Note(String msg, Object... args);
|
||||
void Info(String msg, Object... args);
|
||||
void Prog(String msg, Object... args);
|
||||
void Flush();
|
||||
}
|
35
100_core/src/gplx/Gfo_log_.java
Normal file
35
100_core/src/gplx/Gfo_log_.java
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
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 gplx.core.logs.*;
|
||||
public class Gfo_log_ {
|
||||
public static Gfo_log Instance = new Gfo_log__mem();
|
||||
public static Gfo_log Instance__set(Gfo_log v) {
|
||||
v.Itms_(Instance.Itms());
|
||||
Instance = v;
|
||||
return v;
|
||||
}
|
||||
public static final String File__fmt = "yyyyMMdd_HHmmss", File__ext = ".log";
|
||||
public static Io_url New_url(Io_url dir) {
|
||||
return dir.GenSubFil(DateAdp_.Now().XtoUtc().XtoStr_fmt(Gfo_log_.File__fmt) + Gfo_log_.File__ext);
|
||||
}
|
||||
public static Gfo_log New_file(Io_url dir) {
|
||||
Io_url url = dir.GenSubFil(DateAdp_.Now().XtoStr_fmt(File__fmt) + File__ext);
|
||||
return new Gfo_log__file(url, new Gfo_log_itm_wtr__csv());
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
public class Gfo_log_bfr {
|
||||
private Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
private Bry_bfr bfr = Bry_bfr_.Reset(255);
|
||||
public Gfo_log_bfr Add(String s) {
|
||||
bfr.Add_str_a7(DateAdp_.Now().XtoUtc().XtoStr_fmt_yyyyMMdd_HHmmss_fff());
|
||||
bfr.Add_byte_space();
|
||||
|
@ -16,10 +16,10 @@ 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.strings.*;
|
||||
import gplx.core.lists.rings.*;
|
||||
public interface Gfo_usr_dlg__gui {
|
||||
void Clear();
|
||||
String_ring Prog_msgs();
|
||||
Ring__string Prog_msgs();
|
||||
void Write_prog(String text);
|
||||
void Write_note(String text);
|
||||
void Write_warn(String text);
|
||||
|
@ -16,7 +16,7 @@ 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.consoles.*; import gplx.core.strings.*;
|
||||
import gplx.core.consoles.*; import gplx.core.lists.rings.*;
|
||||
public class Gfo_usr_dlg__gui_ {
|
||||
public static final Gfo_usr_dlg__gui Noop = new Gfo_usr_dlg__gui_noop();
|
||||
public static final Gfo_usr_dlg__gui Console = new Gfo_usr_dlg__gui_console();
|
||||
@ -26,7 +26,7 @@ public class Gfo_usr_dlg__gui_ {
|
||||
}
|
||||
class Gfo_usr_dlg__gui_noop implements Gfo_usr_dlg__gui {
|
||||
public void Clear() {}
|
||||
public String_ring Prog_msgs() {return ring;} String_ring ring = new String_ring().Max_(0);
|
||||
public Ring__string Prog_msgs() {return ring;} Ring__string ring = new Ring__string().Max_(0);
|
||||
public void Write_prog(String text) {}
|
||||
public void Write_note(String text) {}
|
||||
public void Write_warn(String text) {}
|
||||
@ -35,7 +35,7 @@ class Gfo_usr_dlg__gui_noop implements Gfo_usr_dlg__gui {
|
||||
class Gfo_usr_dlg__gui_console implements Gfo_usr_dlg__gui {
|
||||
private final Console_adp__sys console = Console_adp__sys.Instance;
|
||||
public void Clear() {}
|
||||
public String_ring Prog_msgs() {return ring;} private final String_ring ring = new String_ring().Max_(0);
|
||||
public Ring__string Prog_msgs() {return ring;} private final Ring__string ring = new Ring__string().Max_(0);
|
||||
public void Write_prog(String text) {console.Write_tmp(text);}
|
||||
public void Write_note(String text) {console.Write_str_w_nl(text);}
|
||||
public void Write_warn(String text) {console.Write_str_w_nl(text);}
|
||||
@ -44,7 +44,7 @@ class Gfo_usr_dlg__gui_console implements Gfo_usr_dlg__gui {
|
||||
class Gfo_usr_dlg__gui_mem_string implements Gfo_usr_dlg__gui {
|
||||
public String file = "";
|
||||
public void Clear() {file = "";}
|
||||
public String_ring Prog_msgs() {return ring;} private final String_ring ring = new String_ring().Max_(0);
|
||||
public Ring__string Prog_msgs() {return ring;} private final Ring__string ring = new Ring__string().Max_(0);
|
||||
public void Write_prog(String text) {file += text + "\n";}
|
||||
public void Write_note(String text) {file += text + "\n";}
|
||||
public void Write_warn(String text) {file += text + "\n";}
|
||||
|
@ -16,11 +16,11 @@ 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.strings.*;
|
||||
import gplx.core.lists.rings.*;
|
||||
public class Gfo_usr_dlg__gui_test implements Gfo_usr_dlg__gui {
|
||||
public List_adp Warns() {return warns;} private final List_adp warns = List_adp_.new_();
|
||||
public List_adp Msgs() {return msgs;} private final List_adp msgs = List_adp_.new_();
|
||||
public String_ring Prog_msgs() {return ring;} private final String_ring ring = new String_ring().Max_(0);
|
||||
public List_adp Warns() {return warns;} private final List_adp warns = List_adp_.New();
|
||||
public List_adp Msgs() {return msgs;} private final List_adp msgs = List_adp_.New();
|
||||
public Ring__string Prog_msgs() {return ring;} private final Ring__string ring = new Ring__string().Max_(0);
|
||||
public void Clear() {msgs.Clear(); warns.Clear();}
|
||||
public void Write_prog(String text) {msgs.Add(text);}
|
||||
public void Write_note(String text) {msgs.Add(text);}
|
||||
|
@ -16,7 +16,7 @@ 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 interface Gfo_usr_dlg__log extends GfoInvkAble {
|
||||
public interface Gfo_usr_dlg__log extends Gfo_invk {
|
||||
boolean Enabled(); void Enabled_(boolean v);
|
||||
boolean Queue_enabled(); void Queue_enabled_(boolean v);
|
||||
Io_url Log_dir(); void Log_dir_(Io_url v);
|
||||
|
@ -21,7 +21,7 @@ public class Gfo_usr_dlg__log_base implements Gfo_usr_dlg__log {
|
||||
private int archive_dirs_max = 8;
|
||||
private Io_url log_dir, err_fil;
|
||||
private Ordered_hash queued_list = Ordered_hash_.New();
|
||||
private Bry_fmtr fmtr = Bry_fmtr.tmp_(); private Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
private Bry_fmtr fmtr = Bry_fmtr.tmp_(); private Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
|
||||
public boolean Queue_enabled() {return queue_enabled;} public void Queue_enabled_(boolean v) {queue_enabled = v; if (!v) this.Flush();} private boolean queue_enabled;
|
||||
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled = true;
|
||||
public Io_url Session_dir() {return session_dir;} private Io_url session_dir;
|
||||
@ -101,7 +101,7 @@ public class Gfo_usr_dlg__log_base implements Gfo_usr_dlg__log {
|
||||
if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_archive_dirs_max_)) archive_dirs_max = m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_log_dir_)) log_dir = m.ReadIoUrl("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} public static final String Invk_enabled_ = "enabled_", Invk_archive_dirs_max_ = "archive_dirs_max_", Invk_log_dir_ = "log_dir_";
|
||||
static final String Dir_name_log = "log", Dir_name_current = "current";
|
||||
|
@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
public class Gfo_usr_dlg_base implements Gfo_usr_dlg {
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
|
||||
private final Bry_fmtr tmp_fmtr = Bry_fmtr.tmp_().Fail_when_invalid_escapes_(false); // do not fail b/c msgs may contain excerpt of random text; EX:[[User:A|~A~]] DATE:2014-11-28
|
||||
public Gfo_usr_dlg_base(Gfo_usr_dlg__log log_wkr, Gfo_usr_dlg__gui gui_wkr) {this.log_wkr = log_wkr; this.gui_wkr = gui_wkr;}
|
||||
public Gfo_usr_dlg__log Log_wkr() {return log_wkr;} public void Log_wkr_(Gfo_usr_dlg__log v) {log_wkr = v;} private Gfo_usr_dlg__log log_wkr;
|
||||
|
@ -21,7 +21,7 @@ public class GfsCtx {
|
||||
public boolean Fail_if_unhandled() {return fail_if_unhandled;} public GfsCtx Fail_if_unhandled_(boolean v) {fail_if_unhandled = v; return this;} private boolean fail_if_unhandled;
|
||||
public Gfo_usr_dlg Usr_dlg() {return usr_dlg;} public GfsCtx Usr_dlg_(Gfo_usr_dlg v) {usr_dlg = v; return this;} Gfo_usr_dlg usr_dlg;
|
||||
public boolean Help_browseMode() {return help_browseMode;} public GfsCtx Help_browseMode_(boolean v) {help_browseMode = v; return this;} private boolean help_browseMode;
|
||||
public List_adp Help_browseList() {return help_browseList;} List_adp help_browseList = List_adp_.new_();
|
||||
public List_adp Help_browseList() {return help_browseList;} List_adp help_browseList = List_adp_.New();
|
||||
public Object MsgSrc() {return msgSrc;} public GfsCtx MsgSrc_(Object v) {msgSrc = v; return this;} Object msgSrc;
|
||||
public boolean Match(String k, String match) {
|
||||
if (help_browseMode) {
|
||||
|
@ -18,7 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx;
|
||||
public class Guid_adp_ {
|
||||
public static final String Cls_ref_name = "Guid";
|
||||
public static final Guid_adp Empty = parse("00000000-0000-0000-0000-000000000000");
|
||||
public static Guid_adp new_() {return new Guid_adp(java.util.UUID.randomUUID());}
|
||||
public static Guid_adp parse(String s) {return new Guid_adp(java.util.UUID.fromString(s));}
|
||||
public static final Guid_adp Empty = Parse("00000000-0000-0000-0000-000000000000");
|
||||
public static String New_str() {return New().To_str();}
|
||||
public static Guid_adp New() {return new Guid_adp(java.util.UUID.randomUUID());}
|
||||
public static Guid_adp Parse(String s) {return new Guid_adp(java.util.UUID.fromString(s));}
|
||||
}
|
@ -22,7 +22,7 @@ public class Guid_adp__tst {
|
||||
tst_parse_("467ffb41-cdfe-402f-b22b-be855425784b");
|
||||
}
|
||||
void tst_parse_(String s) {
|
||||
Guid_adp uuid = Guid_adp_.parse(s);
|
||||
Guid_adp uuid = Guid_adp_.Parse(s);
|
||||
Tfds.Eq(uuid.To_str(), s);
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx;
|
||||
import gplx.core.primitives.*;
|
||||
public class Hash_adp_ {
|
||||
public static Hash_adp new_() {return new Hash_adp_obj();}
|
||||
public static Hash_adp New() {return new Hash_adp_obj();}
|
||||
public static final Hash_adp Noop = new Hash_adp_noop();
|
||||
}
|
||||
class Hash_adp_obj extends gplx.core.lists.Hash_adp_base implements Hash_adp {}//_20110428
|
||||
|
@ -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 GfoInvkAble {
|
||||
public class Int_ implements Gfo_invk {
|
||||
public static final String Cls_val_name = "int";
|
||||
public static final Class<?> Cls_ref_type = Integer.class;
|
||||
public static final int Base1 = 1;
|
||||
@ -133,7 +133,7 @@ public class Int_ implements GfoInvkAble {
|
||||
static String To_str_pad_bgn_zero(int val, int places, byte pad_chr, boolean bgn) {
|
||||
int len = DigitCount(val);
|
||||
int pad_len = places - len; if (pad_len < 0) return Int_.To_str(val);
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
boolean neg = val < 0;
|
||||
if (bgn) { // special logic to handle negative numbers; EX: -1 -> "-001", not "00-1"
|
||||
if (neg) {
|
||||
@ -165,7 +165,7 @@ public class Int_ implements GfoInvkAble {
|
||||
int v = m.ReadInt(GfsCore_.Arg_primitive), operand = m.ReadInt("operand");
|
||||
return ctx.Deny() ? (Object)this : v + operand;
|
||||
}
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
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);}
|
||||
|
@ -16,8 +16,10 @@ 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.primitives.*; import gplx.core.ios.*; /*IoItmFil, IoItmDir..*/
|
||||
public class Io_mgr { // exists primarily to gather all cmds under gplx namespace; otherwise need to use gplx.core.ios whenever copying/deleting file
|
||||
import gplx.core.primitives.*; import gplx.core.ios.*; /*IoItmFil, IoItmDir..*/ import gplx.core.ios.streams.*; import gplx.core.ios.loaders.*;
|
||||
public class Io_mgr implements Gfo_evt_mgr_owner { // exists primarily to gather all cmds under gplx namespace; otherwise need to use gplx.core.ios whenever copying/deleting file
|
||||
public Io_mgr() {evt_mgr = new Gfo_evt_mgr(this);}
|
||||
public Gfo_evt_mgr Evt_mgr() {return evt_mgr;} private final Gfo_evt_mgr evt_mgr;
|
||||
public boolean Exists(Io_url url) {return url.Type_dir() ? ExistsDir(url) : ExistsFil(url);}
|
||||
public boolean ExistsFil(Io_url url) {return IoEnginePool.Instance.Get_by(url.Info().EngineKey()).ExistsFil_api(url);}
|
||||
public void ExistsFilOrFail(Io_url url) {if (!ExistsFil(url)) throw Err_.new_wo_type("could not find file", "url", url);}
|
||||
@ -32,7 +34,8 @@ public class Io_mgr { // exists primarily to gather all cmds under gplx namespac
|
||||
public IoEngine_xrg_xferFil MoveFil_args(Io_url src, Io_url trg, boolean overwrite) {return IoEngine_xrg_xferFil.move_(src, trg).Overwrite_(overwrite);}
|
||||
public void CopyFil(Io_url src, Io_url trg, boolean overwrite) {IoEngine_xrg_xferFil.copy_(src, trg).Overwrite_(overwrite).Exec();}
|
||||
public IoEngine_xrg_xferFil CopyFil_args(Io_url src, Io_url trg, boolean overwrite) {return IoEngine_xrg_xferFil.copy_(src, trg).Overwrite_(overwrite);}
|
||||
public IoRecycleBin RecycleBin() {return recycleBin;} IoRecycleBin recycleBin = IoRecycleBin.Instance;
|
||||
public IoRecycleBin RecycleBin() {return recycleBin;} private IoRecycleBin recycleBin = IoRecycleBin.Instance;
|
||||
public Io_loader Loader() {return loader;} public void Loader_(Io_loader v) {this.loader = v;} private Io_loader loader;
|
||||
|
||||
public IoStream OpenStreamWrite(Io_url url) {return OpenStreamWrite_args(url).Exec();}
|
||||
public IoEngine_xrg_openWrite OpenStreamWrite_args(Io_url url) {return IoEngine_xrg_openWrite.new_(url);}
|
||||
@ -61,6 +64,7 @@ public class Io_mgr { // exists primarily to gather all cmds under gplx namespac
|
||||
public void DeleteDirDeep(Io_url url) {IoEngine_xrg_deleteDir.new_(url).Recur_().Exec();}
|
||||
public void DeleteDirDeep_ary(Io_url... urls) {for (Io_url url : urls) IoEngine_xrg_deleteDir.new_(url).Recur_().Exec();}
|
||||
public int Delete_dir_empty(Io_url url) {return Io_mgr_.Delete_dir_empty(url);}
|
||||
public boolean Truncate_fil(Io_url url, long size) {return IoEnginePool.Instance.Get_by(url.Info().EngineKey()).Truncate_fil(url, size);}
|
||||
public void MoveDirDeep(Io_url src, Io_url trg) {IoEngine_xrg_xferDir.move_(src, trg).Recur_().Exec();}
|
||||
public IoEngine_xrg_xferDir CopyDir_cmd(Io_url src, Io_url trg) {return IoEngine_xrg_xferDir.copy_(src, trg);}
|
||||
public void CopyDirSubs(Io_url src, Io_url trg) {IoEngine_xrg_xferDir.copy_(src, trg).Exec();}
|
||||
@ -78,23 +82,30 @@ public class Io_mgr { // exists primarily to gather all cmds under gplx namespac
|
||||
public IoEngine_xrg_loadFilStr LoadFilStr_args(Io_url url) {return IoEngine_xrg_loadFilStr.new_(url);}
|
||||
public byte[] LoadFilBryOrNull(Io_url url) {return LoadFilBryOr(url, null);}
|
||||
public byte[] LoadFilBryOr(Io_url url, byte[] or) {return ExistsFil(url) ? LoadFilBry(url) : or;}
|
||||
public byte[] LoadFilBry(String url) {return LoadFilBry_reuse(Io_url_.new_fil_(url), Bry_.Empty, Int_obj_ref.zero_());}
|
||||
public byte[] LoadFilBry(Io_url url) {return LoadFilBry_reuse(url, Bry_.Empty, Int_obj_ref.zero_());}
|
||||
public byte[] LoadFilBry(String url) {return LoadFilBry_reuse(Io_url_.new_fil_(url), Bry_.Empty, Int_obj_ref.New_zero());}
|
||||
public byte[] LoadFilBry(Io_url url) {return LoadFilBry_reuse(url, Bry_.Empty, Int_obj_ref.New_zero());}
|
||||
public void LoadFilBryByBfr(Io_url url, Bry_bfr bfr) {
|
||||
Int_obj_ref len = Int_obj_ref.zero_();
|
||||
Int_obj_ref len = Int_obj_ref.New_zero();
|
||||
byte[] bry = LoadFilBry_reuse(url, Bry_.Empty, len);
|
||||
bfr.Bfr_init(bry, len.Val());
|
||||
}
|
||||
public static final byte[] LoadFilBry_fail = Bry_.Empty;
|
||||
public byte[] LoadFilBry_reuse(Io_url url, byte[] ary, Int_obj_ref aryLen) {
|
||||
if (!ExistsFil(url)) {aryLen.Val_(0); return LoadFilBry_fail;}
|
||||
public byte[] LoadFilBry_reuse(Io_url url, byte[] ary, Int_obj_ref ary_len) {
|
||||
if (loader != null) {
|
||||
byte[] rv = loader.Load_fil_as_bry(url);
|
||||
if (rv != null) return rv;
|
||||
}
|
||||
if (!ExistsFil(url)) {
|
||||
ary_len.Val_(0);
|
||||
return LoadFilBry_fail;
|
||||
}
|
||||
IoStream stream = IoStream_.Null;
|
||||
try {
|
||||
stream = OpenStreamRead(url);
|
||||
int streamLen = (int)stream.Len();
|
||||
aryLen.Val_(streamLen);
|
||||
if (streamLen > ary.length)
|
||||
ary = new byte[streamLen];
|
||||
int stream_len = (int)stream.Len();
|
||||
ary_len.Val_(stream_len);
|
||||
if (stream_len > ary.length)
|
||||
ary = new byte[stream_len];
|
||||
stream.ReadAry(ary);
|
||||
return ary;
|
||||
}
|
||||
@ -138,10 +149,11 @@ public class Io_mgr { // exists primarily to gather all cmds under gplx namespac
|
||||
}
|
||||
public boolean DownloadFil(String src, Io_url trg) {return IoEngine_xrg_downloadFil.new_(src, trg).Exec();}
|
||||
public IoEngine_xrg_downloadFil DownloadFil_args(String src, Io_url trg) {return IoEngine_xrg_downloadFil.new_(src, trg);}
|
||||
public static final Io_mgr Instance = new Io_mgr(); public Io_mgr() {}
|
||||
public static final Io_mgr Instance = new Io_mgr();
|
||||
public static final int Len_kb = 1024, Len_mb = 1048576, Len_gb = 1073741824, Len_gb_2 = 2147483647;
|
||||
public static final long Len_mb_long = Len_mb;
|
||||
public static final long Len_null = -1;
|
||||
public static final String Evt__fil_created = "fil_created";
|
||||
}
|
||||
class Io_mgr_ {
|
||||
public static int Delete_dir_empty(Io_url url) {
|
||||
|
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.core.strings.*; import gplx.core.ios.*; /*IoUrlInfo*/ import gplx.core.envs.*; import gplx.langs.htmls.*; import gplx.core.interfaces.*;
|
||||
public class Io_url implements CompareAble, ParseAble, GfoInvkAble { //_20101005 URL:doc/Io_url.txt
|
||||
public class Io_url implements CompareAble, ParseAble, Gfo_invk { //_20101005 URL:doc/Io_url.txt
|
||||
public IoUrlInfo Info() {return info;} IoUrlInfo info;
|
||||
public String Raw() {return raw;} final String raw;
|
||||
public byte[] RawBry() {return Bry_.new_u8(raw);}
|
||||
@ -55,7 +55,7 @@ public class Io_url implements CompareAble, ParseAble, GfoInvkAble { //_20101005
|
||||
: String_.Empty;
|
||||
}
|
||||
public List_adp XtoNames() {
|
||||
List_adp list = List_adp_.new_();
|
||||
List_adp list = List_adp_.New();
|
||||
Io_url cur = this;
|
||||
while (!cur.EqNull()) {
|
||||
list.Add(cur.NameAndExt_noDirSpr());
|
||||
@ -86,6 +86,6 @@ public class Io_url implements CompareAble, ParseAble, GfoInvkAble { //_20101005
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_to_http_file)) return To_http_file_str();
|
||||
else if (ctx.Match(k, Invk_gen_sub_path_for_os)) return Gen_sub_path_for_os(m.ReadStr("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
} static final String Invk_to_http_file = "to_http_file", Invk_gen_sub_path_for_os = "gen_sub_path_for_os";
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ public class Keyval_ {
|
||||
return null;
|
||||
}
|
||||
public static String Ary__to_str__nest(Keyval... ary) {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
Ary__to_str__nest(bfr, 0, ary);
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
|
@ -17,13 +17,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
public class Keyval_list {
|
||||
public int Count() {return list.Count();} private final List_adp list = List_adp_.new_();
|
||||
public int Count() {return list.Count();} private final List_adp list = List_adp_.New();
|
||||
public void Clear() {list.Clear();}
|
||||
public Keyval Get_at(int i) {return (Keyval)list.Get_at(i);}
|
||||
public Keyval_list Add(String key, Object val) {list.Add(Keyval_.new_(key, val)); return this;}
|
||||
public Keyval[] To_ary() {return (Keyval[])list.To_ary(Keyval.class);}
|
||||
public String To_str() {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
int len = list.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Keyval kv = (Keyval)list.Get_at(i);
|
||||
|
@ -60,7 +60,7 @@ class List_adp_noop implements List_adp {
|
||||
public void Del_range(int bgn, int end) {}
|
||||
public void Clear() {}
|
||||
public int Idx_last() {return -1;}
|
||||
public int Idx_of(Object o) {return List_adp_.NotFound;}
|
||||
public int Idx_of(Object o) {return List_adp_.Not_found;}
|
||||
public void Move_to(int elemPos, int newPos) {}
|
||||
public void Resize_bounds(int i) {}
|
||||
public Object To_ary(Class<?> memberType) {return Object_.Ary_empty;}
|
||||
|
@ -16,23 +16,17 @@ 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.*; /*EnumerAble,ComparerAble*/
|
||||
import gplx.core.lists.*;
|
||||
public class List_adp_ {
|
||||
public static final List_adp Noop = new List_adp_noop();
|
||||
public static List_adp as_(Object obj) {return obj instanceof List_adp ? (List_adp)obj : null;}
|
||||
public static List_adp new_() {return new List_adp_obj();}
|
||||
public static List_adp size_(int v) {return new List_adp_obj(v);}
|
||||
public static List_adp many_(Object... ary) {
|
||||
public static List_adp New() {return new List_adp_obj();}
|
||||
public static List_adp New_w_size(int v) {return new List_adp_obj(v);}
|
||||
public static List_adp New_by_many(Object... ary) {
|
||||
List_adp rv = new List_adp_obj();
|
||||
rv.Add_many(ary);
|
||||
return rv;
|
||||
}
|
||||
public static void Add_list(List_adp rv, List_adp add) {
|
||||
int len = add.Count();
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv.Add(add.Get_at(i));
|
||||
}
|
||||
public static void DelAt_last(List_adp list) {list.Del_at(list.Count() - 1);}
|
||||
public static void Del_at_last(List_adp list) {list.Del_at(list.Count() - 1);}
|
||||
public static Object Pop(List_adp list) {
|
||||
int lastIdx = list.Count() - 1;
|
||||
Object rv = list.Get_at(lastIdx);
|
||||
@ -57,17 +51,5 @@ public class List_adp_ {
|
||||
list.Del_at(last_idx);
|
||||
return rv;
|
||||
}
|
||||
public static void DisposeAll(List_adp list) {
|
||||
for (int i = 0; i < list.Count(); i++)
|
||||
((Rls_able)list.Get_at(i)).Rls();
|
||||
}
|
||||
public static List_adp new_ary_(Object ary) {
|
||||
int ary_len = Array_.Len(ary);
|
||||
List_adp rv = size_(ary_len);
|
||||
for (int i = 0; i < ary_len; i++)
|
||||
rv.Add(Array_.Get_at(ary, i));
|
||||
return rv;
|
||||
}
|
||||
public static final int Capacity_initial = 8;
|
||||
public static final int NotFound = -1, Base1 = 1, LastIdxOffset = 1, CountToPos = 1;
|
||||
public static final int Not_found = -1, Base1 = 1;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
import gplx.core.strings.*; import gplx.core.lists.*;
|
||||
public abstract class List_adp_base implements List_adp, GfoInvkAble {
|
||||
public abstract class List_adp_base implements List_adp, Gfo_invk {
|
||||
private Object[] list; private int count;
|
||||
public List_adp_base(int capacity) {
|
||||
this.list = new Object[capacity];
|
||||
@ -41,7 +41,7 @@ public abstract class List_adp_base implements List_adp, GfoInvkAble {
|
||||
count++;
|
||||
}
|
||||
protected int Del_base(Object o) {
|
||||
int index = IndexOf_base(o); if (index == List_adp_.NotFound) return List_adp_.NotFound;
|
||||
int index = IndexOf_base(o); if (index == List_adp_.Not_found) return List_adp_.Not_found;
|
||||
this.Del_at(index);
|
||||
return index;
|
||||
}
|
||||
@ -64,7 +64,7 @@ public abstract class List_adp_base implements List_adp, GfoInvkAble {
|
||||
protected int IndexOf_base(Object o) {
|
||||
for (int i = 0; i < count; i++)
|
||||
if (Object_.Eq(list[i], o)) return i;
|
||||
return List_adp_.NotFound;
|
||||
return List_adp_.Not_found;
|
||||
}
|
||||
@gplx.Virtual public void Clear() {
|
||||
for (int i = 0; i < count; i++)
|
||||
@ -120,8 +120,9 @@ public abstract class List_adp_base implements List_adp, GfoInvkAble {
|
||||
public void Del(Object item) {Del_base(item);}
|
||||
public int Idx_of(Object o) {return IndexOf_base(o);}
|
||||
public List_adp_base() {
|
||||
list = new Object[List_adp_.Capacity_initial];
|
||||
list = new Object[Len_initial];
|
||||
}
|
||||
private static final int Len_initial = 8;
|
||||
public Object To_ary_and_clear(Class<?> memberType) {Object rv = To_ary(memberType); this.Clear(); return rv;}
|
||||
public Object To_ary(Class<?> memberType) {
|
||||
Object rv = Array_.Create(memberType, count);
|
||||
@ -138,7 +139,7 @@ public abstract class List_adp_base implements List_adp, GfoInvkAble {
|
||||
return rv;
|
||||
}
|
||||
public String To_str() {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
for (int i = 0; i < count; ++i)
|
||||
bfr.Add_str_u8(Object_.Xto_str_strict_or_null_mark(list[i])).Add_byte_nl();
|
||||
return bfr.To_str_and_clear();
|
||||
@ -168,7 +169,7 @@ public abstract class List_adp_base implements List_adp, GfoInvkAble {
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_len)) return count;
|
||||
else if (ctx.Match(k, Invk_get_at)) return Get_at(m.ReadInt("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
// return this;
|
||||
} private static final String Invk_len = "len", Invk_get_at = "get_at";
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ package gplx;
|
||||
import org.junit.*;
|
||||
public class List_adp_tst {
|
||||
@Before public void setup() {
|
||||
list = List_adp_.new_();
|
||||
list = List_adp_.New();
|
||||
listBase = (List_adp_base)list;
|
||||
} List_adp list; List_adp_base listBase;
|
||||
@Test public void Add() {
|
||||
@ -29,7 +29,7 @@ public class List_adp_tst {
|
||||
Tfds.Eq(1, list.Count());
|
||||
}
|
||||
@Test public void Add_changeCapacity() {
|
||||
int capacity = List_adp_.Capacity_initial;
|
||||
int capacity = 8;
|
||||
for (int i = 0; i < capacity; i++)
|
||||
list.Add("0");
|
||||
Tfds.Eq(capacity, list.Count());
|
||||
@ -116,7 +116,7 @@ public class List_adp_tst {
|
||||
}
|
||||
}
|
||||
@Test public void Clear() {
|
||||
int capacity = List_adp_.Capacity_initial;
|
||||
int capacity = 8;
|
||||
for (int i = 0; i < capacity + 1; i++)
|
||||
list.Add("0");
|
||||
Tfds.Eq(capacity * 2, listBase.Capacity());
|
||||
|
@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx;
|
||||
import gplx.core.strings.*; import gplx.core.envs.*;
|
||||
import gplx.core.lists.*; /*EnumerAble,ComparerAble*/
|
||||
public class Ordered_hash_base extends Hash_adp_base implements Ordered_hash, GfoInvkAble {
|
||||
private final List_adp ordered = List_adp_.new_();
|
||||
public class Ordered_hash_base extends Hash_adp_base implements Ordered_hash, Gfo_invk {
|
||||
private final List_adp ordered = List_adp_.New();
|
||||
@Override protected void Add_base(Object key, Object val) {
|
||||
super.Add_base(key, val);
|
||||
ordered.Add(val);
|
||||
@ -86,7 +86,7 @@ public class Ordered_hash_base extends Hash_adp_base implements Ordered_hash, Gf
|
||||
if (ctx.Deny()) return this;
|
||||
return To_str_ui();
|
||||
}
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} static final String Invk_SetKeyOnly = "SetKeyOnly", Invk_Print = "Print";
|
||||
public int Len() {return ordered.Count();}
|
||||
|
@ -29,7 +29,7 @@ public class Ordered_hash_tst {
|
||||
hash.Add("key2", "val2");
|
||||
hash.Add("key1", "val1");
|
||||
|
||||
List_adp list = List_adp_.new_();
|
||||
List_adp list = List_adp_.New();
|
||||
for (Object val : hash)
|
||||
list.Add(val);
|
||||
Tfds.Eq("val2", list.Get_at(0));
|
||||
|
@ -17,14 +17,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx;
|
||||
import java.util.*;
|
||||
public class RandomAdp_ implements GfoInvkAble {
|
||||
public class RandomAdp_ implements Gfo_invk {
|
||||
public static RandomAdp new_() {
|
||||
Random random = new Random(System.currentTimeMillis());
|
||||
return new RandomAdp(random);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_Next)) return RandomAdp_.new_().Next(m.ReadInt("max"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
} static final String Invk_Next = "Next";
|
||||
public static final RandomAdp_ Gfs = new RandomAdp_();
|
||||
}
|
||||
|
@ -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 GfoInvkAble {
|
||||
public class String_ implements Gfo_invk {
|
||||
public static final Class<?> Cls_ref_type = String.class;
|
||||
public static final String Cls_val_name = "str" + "ing";
|
||||
public static final int Find_none = -1, Pos_neg1 = -1;
|
||||
@ -339,7 +339,7 @@ public class String_ implements GfoInvkAble {
|
||||
|
||||
public static String[] Ary(String... ary) {return ary;}
|
||||
public static String[] Ary_wo_null(String... ary) {
|
||||
List_adp list = List_adp_.new_();
|
||||
List_adp list = List_adp_.New();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String itm = ary[i];
|
||||
@ -357,7 +357,7 @@ public class String_ implements GfoInvkAble {
|
||||
public static final String[] Ary_empty = new String[0];
|
||||
public static String[] Split(String raw, char dlm) {return Split(raw, dlm, false);}
|
||||
public static String[] Split(String raw, char dlm, boolean addEmptyIfDlmIsLast) {
|
||||
List_adp list = List_adp_.new_(); String_bldr sb = String_bldr_.new_();
|
||||
List_adp list = List_adp_.New(); String_bldr sb = String_bldr_.new_();
|
||||
int rawLen = String_.Len(raw); char c = '\0';
|
||||
for (int i = 0; i < rawLen; i++) {
|
||||
c = String_.CharAt(raw, i);
|
||||
@ -433,7 +433,7 @@ public class String_ implements GfoInvkAble {
|
||||
if (String_.Eq(s, "") // "".Split('a') return array with one member: ""
|
||||
|| String_.Eq(spr, "")) // "a".Split('\0') returns array with one member: "a"
|
||||
return new String[] {s};
|
||||
List_adp list = List_adp_.new_(); String_bldr sb = String_bldr_.new_();
|
||||
List_adp list = List_adp_.New(); String_bldr sb = String_bldr_.new_();
|
||||
int i = 0, sprPos = 0; boolean sprMatched = false; char spr0 = CharAt(spr, 0);
|
||||
int textLength = Len(s); int sprLength = Len(spr);
|
||||
while (true) {
|
||||
@ -485,7 +485,7 @@ public class String_ implements GfoInvkAble {
|
||||
if (ctx.Deny()) return this;
|
||||
return PadBgn(s, totalLen, pad);
|
||||
}
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
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) {
|
||||
@ -510,13 +510,13 @@ public class String_ implements GfoInvkAble {
|
||||
return rv;
|
||||
}
|
||||
public static String [] Ary_filter(String[] src, String[] filter) {
|
||||
Hash_adp hash = Hash_adp_.new_();
|
||||
Hash_adp hash = Hash_adp_.New();
|
||||
int len = filter.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
String itm = filter[i];
|
||||
hash.Add_if_dupe_use_nth(itm, itm);
|
||||
}
|
||||
List_adp rv = List_adp_.new_();
|
||||
List_adp rv = List_adp_.New();
|
||||
len = src.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
String itm = src[i];
|
||||
@ -551,7 +551,7 @@ public class String_ implements GfoInvkAble {
|
||||
}
|
||||
public static String To_str__as_kv_ary(String... ary) {
|
||||
int len = ary.length;
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
for (int i = 0; i < len; i+=2) {
|
||||
bfr.Add_str_u8(ary[i]).Add_byte_eq();
|
||||
String val = i + 1 < len ? ary[i + 1] : null;
|
||||
|
@ -80,7 +80,7 @@ public class Tfds { // URL:doc/gplx.tfds/Tfds.txt
|
||||
throw Err_.new_wo_type(msg);
|
||||
}
|
||||
static void Eq_ary_wkr(Object lhsAry, Object rhsAry, boolean compareUsingEquals, String customMsg) {
|
||||
List_adp list = List_adp_.new_(); boolean pass = true;
|
||||
List_adp list = List_adp_.New(); boolean pass = true;
|
||||
int lhsLen = Array_.Len(lhsAry), rhsLen = Array_.Len(rhsAry);
|
||||
for (int i = 0; i < lhsLen; i++) {
|
||||
Object lhs = Array_.Get_at(lhsAry, i);
|
||||
@ -103,7 +103,7 @@ public class Tfds { // URL:doc/gplx.tfds/Tfds.txt
|
||||
throw Err_.new_wo_type(msg);
|
||||
}
|
||||
static void Eq_list_wkr(List_adp lhsList, List_adp rhsList, TfdsEqListItmStr xtoStr, String customMsg) {
|
||||
List_adp list = List_adp_.new_(); boolean pass = true;
|
||||
List_adp list = List_adp_.New(); boolean pass = true;
|
||||
int lhsLen = lhsList.Count(), rhsLen = rhsList.Count();
|
||||
for (int i = 0; i < lhsLen; i++) {
|
||||
Object lhs = lhsList.Get_at(i);
|
||||
|
@ -66,7 +66,7 @@ public class TfdsTstr_fxt {
|
||||
sb.Add(String_.Repeat("_", 80));
|
||||
throw Err_.new_wo_type(sb.To_str());
|
||||
}
|
||||
List_adp list = List_adp_.new_();
|
||||
List_adp list = List_adp_.New();
|
||||
public static TfdsTstr_fxt new_() {return new TfdsTstr_fxt();} TfdsTstr_fxt() {}
|
||||
}
|
||||
class TfdsTstrItm {
|
||||
|
@ -25,6 +25,9 @@ public class Time_span implements CompareAble { // NOTE: gplx.Time_span b/c Syst
|
||||
public Decimal_adp Total_days() {
|
||||
return Decimal_adp_.divide_(fracs, Time_span_.Divisors[Time_span_.Idx_Hour] * 24);
|
||||
}
|
||||
public Decimal_adp Total_hours() {
|
||||
return Decimal_adp_.divide_(fracs, Time_span_.Divisors[Time_span_.Idx_Hour]);
|
||||
}
|
||||
public int[] Units() {return Time_span_.Split_long(fracs, Time_span_.Divisors);}
|
||||
public int Units_fracs() {
|
||||
int[] ary = Time_span_.Split_long(fracs, Time_span_.Divisors);
|
||||
|
@ -59,10 +59,10 @@ public class UsrMsg {
|
||||
rv.hdr = hdr;
|
||||
return rv;
|
||||
}
|
||||
public static UsrMsg invk_(GfoInvkAble invk, String cmd) {
|
||||
public static UsrMsg invk_(Gfo_invk invk, String cmd) {
|
||||
UsrMsg rv = new UsrMsg();
|
||||
rv.invk = invk;
|
||||
rv.cmd = cmd;
|
||||
return rv;
|
||||
} GfoInvkAble invk; String cmd;
|
||||
} Gfo_invk invk; String cmd;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class UsrMsgWkrList {
|
||||
wkr = v;
|
||||
else {
|
||||
if (list == null) {
|
||||
list = List_adp_.new_();
|
||||
list = List_adp_.New();
|
||||
list.Add(wkr);
|
||||
wkr = null;
|
||||
}
|
||||
|
@ -34,5 +34,5 @@ public class UsrMsgWkr_test implements UsrMsgWkr {
|
||||
dlg.Reg(UsrMsgWkr_.Type_Warn, wkr);
|
||||
return wkr;
|
||||
}
|
||||
List_adp msgs = List_adp_.new_();
|
||||
List_adp msgs = List_adp_.New();
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public class Bry_bfr_mkr_mgr {
|
||||
rv_idx = used_len++;
|
||||
rv = used[rv_idx];
|
||||
if (rv == null) {
|
||||
rv = Bry_bfr.reset_(reset);
|
||||
rv = Bry_bfr_.Reset(reset);
|
||||
used[rv_idx] = rv;
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.core.brys; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.errs.*; import gplx.core.btries.*;
|
||||
public class Bry_rdr {
|
||||
private final gplx.core.primitives.Int_obj_ref pos_ref = gplx.core.primitives.Int_obj_ref.neg1_();
|
||||
private final gplx.core.primitives.Int_obj_ref pos_ref = gplx.core.primitives.Int_obj_ref.New_neg1();
|
||||
public byte[] Src() {return src;} protected byte[] src;
|
||||
public int Src_end() {return src_end;} protected int src_end;
|
||||
public int Pos() {return pos;} protected int pos;
|
||||
|
@ -34,7 +34,7 @@ class Time_fmtr_arg_fxt {
|
||||
return this;
|
||||
} Bfr_arg__time arg;
|
||||
public void XferAry(int seconds, String expd) {
|
||||
Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
Bry_bfr bfr = Bry_bfr_.Reset(255);
|
||||
arg.Seconds_(seconds);
|
||||
arg.Bfr_arg__add(bfr);
|
||||
Tfds.Eq(expd, bfr.To_str());
|
||||
|
@ -23,7 +23,7 @@ public class Bry_fmtr {
|
||||
public Bry_fmtr_eval_mgr Eval_mgr() {return eval_mgr;} public Bry_fmtr Eval_mgr_(Bry_fmtr_eval_mgr v) {eval_mgr = v; return this;} Bry_fmtr_eval_mgr eval_mgr = Bry_fmtr_eval_mgr_gfs.Instance;
|
||||
public Bry_fmtr Fmt_(byte[] v) {fmt = v; dirty = true; return this;} public Bry_fmtr Fmt_(String v) {return Fmt_(Bry_.new_u8(v));}
|
||||
public Bry_fmtr Keys_(String... ary) {
|
||||
if (keys == null) keys = Hash_adp_.new_();
|
||||
if (keys == null) keys = Hash_adp_.New();
|
||||
else keys.Clear();
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++)
|
||||
@ -121,12 +121,12 @@ public class Bry_fmtr {
|
||||
public boolean Fail_when_invalid_escapes() {return fail_when_invalid_escapes;} public Bry_fmtr Fail_when_invalid_escapes_(boolean v) {fail_when_invalid_escapes = v; return this;} private boolean fail_when_invalid_escapes = true;
|
||||
public Bry_fmtr Compile() {
|
||||
synchronized (this) { // THREAD: DATE:2015-04-29
|
||||
Bry_bfr lkp_bfr = Bry_bfr.new_(16);
|
||||
Bry_bfr lkp_bfr = Bry_bfr_.New_w_size(16);
|
||||
int fmt_len = fmt.length; int fmt_end = fmt_len - 1; int fmt_pos = 0;
|
||||
byte[] trg_bry = new byte[fmt_len]; int trg_pos = 0;
|
||||
boolean lkp_is_active = false, lkp_is_numeric = true;
|
||||
byte nxt_byte, tmp_byte;
|
||||
List_adp list = List_adp_.new_();
|
||||
List_adp list = List_adp_.New();
|
||||
fmt_args_exist = false;
|
||||
while (true) {
|
||||
if (fmt_pos > fmt_end) break;
|
||||
@ -255,9 +255,9 @@ public class Bry_fmtr {
|
||||
tmp_bfr.Add_byte(Byte_ascii.Apos);
|
||||
}
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
} static Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
} static Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
|
||||
public void Bld_bfr_many_and_set_fmt(Object... args) {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
this.Bld_bfr_many(bfr, args);
|
||||
byte[] bry = bfr.To_bry_and_clear();
|
||||
this.Fmt_(bry).Compile();
|
||||
|
@ -19,7 +19,7 @@ package gplx.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.cor
|
||||
public class Bry_fmtr_eval_mgr_ {
|
||||
public static Io_url Eval_url(Bry_fmtr_eval_mgr eval_mgr, byte[] fmt) {
|
||||
if (eval_mgr == null) return Io_url_.new_any_(String_.new_u8(fmt));
|
||||
Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
Bry_bfr bfr = Bry_bfr_.Reset(255);
|
||||
Bry_fmtr fmtr = Bry_fmtr.tmp_();
|
||||
fmtr.Eval_mgr_(eval_mgr).Fmt_(fmt).Bld_bfr_none(bfr);
|
||||
return Io_url_.new_any_(bfr.To_str_and_clear());
|
||||
|
@ -56,7 +56,7 @@ class Bry_fmtr_tst_mok implements Bry_fmtr_eval_mgr {
|
||||
}
|
||||
class Bry_fmtr_fxt {
|
||||
private final Bry_fmtr fmtr = Bry_fmtr.new_();
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
private Object[] args;
|
||||
public Bry_fmtr_fxt Clear() {fmtr.Fmt_(String_.Empty).Keys_(String_.Empty); args = Object_.Ary_empty; return this;}
|
||||
public Bry_fmtr_fxt Fmt (String fmt) {fmtr.Fmt_(fmt); return this;}
|
||||
|
@ -23,7 +23,7 @@ public class Bry_fmt_parser_ {
|
||||
int txt_bgn = -1;
|
||||
int key_idx = -1;
|
||||
Hash_adp_bry keys_hash = Hash_adp_bry.cs();
|
||||
List_adp list = List_adp_.new_();
|
||||
List_adp list = List_adp_.New();
|
||||
while (true) {
|
||||
boolean is_last = pos == src_len;
|
||||
byte b = is_last ? escape : src[pos];
|
||||
|
@ -38,7 +38,7 @@ class Bfr_fmt_arg_mok implements Bfr_arg {
|
||||
}
|
||||
class Bry_fmt_fxt {
|
||||
private final Bry_fmt fmt = new Bry_fmt(Bry_.Empty, Bry_.Ary_empty, Bfr_fmt_arg.Ary_empty);
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
private Object[] vals;
|
||||
public Bry_fmt_fxt Clear() {vals = Object_.Ary_empty; return this;}
|
||||
public Bry_fmt_fxt Fmt(String s) {fmt.Fmt_(s); return this;}
|
||||
|
@ -17,8 +17,8 @@ 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_();
|
||||
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) {}
|
||||
|
@ -30,9 +30,9 @@ public class Criteria_fld implements Criteria {
|
||||
crt.Val_as_obj_(o);
|
||||
}
|
||||
public boolean Matches(Object invkObj) {
|
||||
GfoInvkAble invk = (GfoInvkAble)invkObj;
|
||||
Gfo_invk invk = (Gfo_invk)invkObj;
|
||||
if (key == Criteria_fld.Key_null) return crt.Matches(invkObj);
|
||||
Object comp = GfoInvkAble_.InvkCmd(invk, this.Pre_w_key());
|
||||
Object comp = Gfo_invk_.Invk_by_key(invk, this.Pre_w_key());
|
||||
return crt.Matches(comp);
|
||||
}
|
||||
public String To_str() {return String_.Concat(key, " ", crt.To_str());}
|
||||
|
@ -96,8 +96,4 @@ public class Env_ {
|
||||
Env_prop_key__user_language = "user.language"
|
||||
, Env_prop_key__java_version = "java.version"
|
||||
;
|
||||
public static void Term_add(GfoInvkAble invk, String cmd) {
|
||||
Thread_adp thread = Thread_adp_.invk_(invk, cmd);
|
||||
Runtime.getRuntime().addShutdownHook(thread.Under_thread());
|
||||
}
|
||||
}
|
||||
|
@ -19,10 +19,11 @@ package gplx.core.envs; import gplx.*; import gplx.core.*;
|
||||
import gplx.Bool_;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Err_;
|
||||
import gplx.GfoInvkAble;
|
||||
import gplx.GfoInvkAbleCmd;
|
||||
import gplx.GfoInvkAble_;
|
||||
import gplx.Gfo_invk;
|
||||
import gplx.Gfo_invk_cmd;
|
||||
import gplx.Gfo_invk_;
|
||||
import gplx.GfoMsg;
|
||||
import gplx.Gfo_usr_dlg;
|
||||
import gplx.Gfo_usr_dlg_;
|
||||
@ -45,7 +46,7 @@ import java.io.InputStreamReader;
|
||||
import javax.management.RuntimeErrorException;
|
||||
import gplx.core.brys.fmtrs.*; import gplx.core.strings.*;
|
||||
import gplx.langs.gfs.*;
|
||||
public class Process_adp implements GfoInvkAble, Rls_able {
|
||||
public class Process_adp implements Gfo_invk, Rls_able {
|
||||
public boolean Enabled() {return enabled;} public Process_adp Enabled_(boolean v) {enabled = v; return this;} private boolean enabled = true;
|
||||
public byte Exe_exists() {return exe_exists;} public Process_adp Exe_exists_(byte v) {exe_exists = v; return this;} private byte exe_exists = Bool_.__byte;
|
||||
public Io_url Exe_url() {return exe_url;} public Process_adp Exe_url_(Io_url val) {exe_url = val; exe_exists = Bool_.__byte; return this;} Io_url exe_url;
|
||||
@ -58,28 +59,28 @@ public class Process_adp implements GfoInvkAble, Rls_able {
|
||||
public String Rslt_out() {return rslt_out;} private String rslt_out;
|
||||
public Io_url Working_dir() {return working_dir;} public Process_adp Working_dir_(Io_url v) {working_dir = v; return this;} Io_url working_dir;
|
||||
public Process_adp Cmd_args(String cmd, String args) {this.Exe_url_(Io_url_.new_fil_(cmd)); this.args_fmtr.Fmt_(args); return this;}
|
||||
public Process_adp WhenBgn_add(GfoInvkAbleCmd cmd) {whenBgnList.Add(cmd); return this;}
|
||||
public Process_adp WhenBgn_del(GfoInvkAbleCmd cmd) {whenBgnList.Del(cmd); return this;}
|
||||
public Process_adp WhenBgn_add(Gfo_invk_cmd cmd) {whenBgnList.Add(cmd); return this;}
|
||||
public Process_adp WhenBgn_del(Gfo_invk_cmd cmd) {whenBgnList.Del(cmd); return this;}
|
||||
public int Thread_timeout() {return thread_timeout;} public Process_adp Thread_timeout_seconds_(int v) {thread_timeout = v * 1000; return this;} int thread_timeout = 0;
|
||||
public int Thread_interval() {return thread_interval;} public Process_adp Thread_interval_(int v) {thread_interval = v; return this;} int thread_interval = 20;
|
||||
public String Thread_kill_name() {return thread_kill_name;} public Process_adp Thread_kill_name_(String v) {thread_kill_name = v; return this;} private String thread_kill_name = "";
|
||||
public Io_url Tmp_dir() {return tmp_dir;} @gplx.Virtual public Process_adp Tmp_dir_(Io_url v) {tmp_dir = v; return this;} Io_url tmp_dir;
|
||||
private Process_adp WhenBgn_run() {return Invk_cmds(whenBgnList);} List_adp whenBgnList = List_adp_.new_();
|
||||
public Process_adp WhenEnd_add(GfoInvkAbleCmd cmd) {whenEndList.Add(cmd); return this;}
|
||||
public Process_adp WhenEnd_del(GfoInvkAbleCmd cmd) {whenEndList.Del(cmd); return this;}
|
||||
private Process_adp WhenBgn_run() {return Invk_cmds(whenBgnList);} List_adp whenBgnList = List_adp_.New();
|
||||
public Process_adp WhenEnd_add(Gfo_invk_cmd cmd) {whenEndList.Add(cmd); return this;}
|
||||
public Process_adp WhenEnd_del(Gfo_invk_cmd cmd) {whenEndList.Del(cmd); return this;}
|
||||
public Gfo_usr_dlg Prog_dlg() {return prog_dlg;} public Process_adp Prog_dlg_(Gfo_usr_dlg v) {prog_dlg = v; return this;} Gfo_usr_dlg prog_dlg;
|
||||
public String Prog_fmt() {return prog_fmt;} public Process_adp Prog_fmt_(String v) {prog_fmt = v; return this;} private String prog_fmt = ""; // NOTE: set to "", else cmds that do not set prog_fmt will fail on fmtr.Fmt(null)
|
||||
private GfoInvkAble owner;
|
||||
private Process_adp WhenEnd_run() {return Invk_cmds(whenEndList);} List_adp whenEndList = List_adp_.new_();
|
||||
private Gfo_invk owner;
|
||||
private Process_adp WhenEnd_run() {return Invk_cmds(whenEndList);} List_adp whenEndList = List_adp_.New();
|
||||
private Process_adp Invk_cmds(List_adp list) {
|
||||
for (Object o : list)
|
||||
((GfoInvkAbleCmd)o).Invk();
|
||||
((Gfo_invk_cmd)o).Exec();
|
||||
return this;
|
||||
}
|
||||
public Process_adp Run(Object... args) {
|
||||
if (String_.Len_eq_0(exe_url.Raw())) return this; // noop if exe_url is "";
|
||||
if (!args_fmtr.Fmt_null()) {
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
args_fmtr.Bld_bfr_many(tmp_bfr, args);
|
||||
args_str = tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
@ -108,12 +109,12 @@ public class Process_adp implements GfoInvkAble, Rls_able {
|
||||
else if (ctx.Match(k, Invk_timeout_)) thread_timeout = m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_tmp_dir_)) tmp_dir = m.ReadIoUrl("v");
|
||||
else if (ctx.Match(k, Invk_owner)) return owner;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
static final String Invk_cmd = "cmd", Invk_cmd_ = "cmd_", Invk_args = "args", Invk_args_ = "args_", Invk_cmd_args_ = "cmd_args_", Invk_enabled = "enabled", Invk_enabled_ = "enabled_", Invk_mode_ = "mode_", Invk_timeout_ = "timeout_", Invk_tmp_dir_ = "tmp_dir_", Invk_owner = "owner";
|
||||
Bry_fmtr_eval_mgr cmd_url_eval;
|
||||
public static Process_adp ini_(GfoInvkAble owner, Gfo_usr_dlg usr_dlg, Process_adp process, Bry_fmtr_eval_mgr cmd_url_eval, byte run_mode, int timeout, String cmd_url_fmt, String args_fmt, String... args_keys) {
|
||||
public static Process_adp ini_(Gfo_invk owner, Gfo_usr_dlg usr_dlg, Process_adp process, Bry_fmtr_eval_mgr cmd_url_eval, byte run_mode, int timeout, String cmd_url_fmt, String args_fmt, String... args_keys) {
|
||||
process.Run_mode_(run_mode).Thread_timeout_seconds_(timeout);
|
||||
process.cmd_url_eval = cmd_url_eval;
|
||||
Io_url cmd_url = Bry_fmtr_eval_mgr_.Eval_url(cmd_url_eval, Bry_.new_u8(cmd_url_fmt));
|
||||
@ -130,7 +131,7 @@ public class Process_adp implements GfoInvkAble, Rls_able {
|
||||
: exe_args
|
||||
;
|
||||
}
|
||||
private Bry_fmtr notify_fmtr = Bry_fmtr.new_("", "process_exe_name", "process_exe_args", "process_seconds"); Bry_bfr notify_bfr = Bry_bfr.reset_(255);
|
||||
private Bry_fmtr notify_fmtr = Bry_fmtr.new_("", "process_exe_name", "process_exe_args", "process_seconds"); Bry_bfr notify_bfr = Bry_bfr_.Reset(255);
|
||||
public Process UnderProcess() {return process;} Process process;
|
||||
public void Rls() {if (process != null) process.destroy();}
|
||||
public Process_adp Run_wait_sync() {
|
||||
@ -276,7 +277,7 @@ public class Process_adp implements GfoInvkAble, Rls_able {
|
||||
process.Process_run_and_end();
|
||||
return;
|
||||
}
|
||||
public static final List_adp Test_runs = List_adp_.new_();
|
||||
public static final List_adp Test_runs = List_adp_.New();
|
||||
private Process_adp Test_runs_add() {Test_runs.Add(exe_url.Raw() + " " + args_str); exit_code = Exit_pass; return this;}
|
||||
public static int run_wait_arg_(Io_url url, String arg) {
|
||||
Process_adp process = new Process_adp();
|
||||
@ -286,7 +287,7 @@ public class Process_adp implements GfoInvkAble, Rls_able {
|
||||
private static final String GRP_KEY = "gplx.process";
|
||||
public static final int Exit_pass = 0, Exit_init = -1;
|
||||
public static String[] Xto_process_bldr_args_utl(Io_url exe_url, String args_str) {
|
||||
List_adp list = List_adp_.new_();
|
||||
List_adp list = List_adp_.New();
|
||||
list.Add(exe_url.Xto_api());
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
int len = String_.Len(args_str);
|
||||
|
@ -32,7 +32,7 @@ class GfoFldList_base implements GfoFldList {
|
||||
public boolean Has(String key) {return hash.Has(key);}
|
||||
public int Idx_of(String key) {
|
||||
Object rv = idxs.Get_by(key);
|
||||
return rv == null ? List_adp_.NotFound : Int_.cast(rv);
|
||||
return rv == null ? List_adp_.Not_found : Int_.cast(rv);
|
||||
}
|
||||
public GfoFld Get_at(int i) {return (GfoFld)hash.Get_at(i);}
|
||||
public GfoFld FetchOrNull(String key) {return (GfoFld)hash.Get_by(key);}
|
||||
@ -50,12 +50,12 @@ class GfoFldList_base implements GfoFldList {
|
||||
}
|
||||
return sb.To_str();
|
||||
}
|
||||
Ordered_hash hash = Ordered_hash_.New(); Hash_adp idxs = Hash_adp_.new_(); // PERF: idxs used for Idx_of; need to recalc if Del ever added
|
||||
Ordered_hash hash = Ordered_hash_.New(); Hash_adp idxs = Hash_adp_.New(); // PERF: idxs used for Idx_of; need to recalc if Del ever added
|
||||
}
|
||||
class GfoFldList_null implements GfoFldList {
|
||||
public int Count() {return 0;}
|
||||
public boolean Has(String key) {return false;}
|
||||
public int Idx_of(String key) {return List_adp_.NotFound;}
|
||||
public int Idx_of(String key) {return List_adp_.Not_found;}
|
||||
public GfoFld Get_at(int i) {return GfoFld.Null;}
|
||||
public GfoFld FetchOrNull(String key) {return null;}
|
||||
public GfoFldList Add(String key, ClassXtn typx) {return this;}
|
||||
|
@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.gfo_ndes; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.strings.*; import gplx.core.stores.*;
|
||||
public class GfoNde implements GfoInvkAble {
|
||||
public class GfoNde implements Gfo_invk {
|
||||
public GfoFldList Flds() {return flds;} GfoFldList flds;
|
||||
public Hash_adp EnvVars() {return envVars;} Hash_adp envVars = Hash_adp_.new_();
|
||||
public Hash_adp EnvVars() {return envVars;} Hash_adp envVars = Hash_adp_.New();
|
||||
public String Name() {return name;} public GfoNde Name_(String v) {name = v; return this;} private String name;
|
||||
public Object ReadAt(int i) {ChkIdx(i); return ary[i];}
|
||||
public void WriteAt(int i, Object val) {ChkIdx(i); ary[i] = val;}
|
||||
|
@ -28,7 +28,7 @@ class GfoNdeList_base implements GfoNdeList {
|
||||
public void Del(GfoNde rcd) {list.Del(rcd);}
|
||||
public void Clear() {list.Clear();}
|
||||
public void Sort_by(ComparerAble comparer) {list.Sort_by(comparer);}
|
||||
List_adp list = List_adp_.new_();
|
||||
List_adp list = List_adp_.New();
|
||||
}
|
||||
class GfoNdeList_null implements GfoNdeList {
|
||||
public int Count() {return 0;}
|
||||
|
@ -28,7 +28,7 @@ public class GfoNde_ {
|
||||
public static GfoNde nde_(String name, Object[] ary, GfoNde... subs) {return new GfoNde(GfoNde_.Type_Node, name, GfoFldList_.Null, ary, GfoFldList_.Null, subs);}
|
||||
public static GfoNde rdr_(DataRdr rdr) {
|
||||
try {
|
||||
List_adp rows = List_adp_.new_();
|
||||
List_adp rows = List_adp_.New();
|
||||
GfoFldList flds = GfoFldList_.new_();
|
||||
int fldLen = rdr.FieldCount();
|
||||
for (int i = 0; i < fldLen; i++)
|
||||
|
@ -17,9 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.gfo_regys; import gplx.*; import gplx.core.*;
|
||||
import gplx.langs.gfs.*; import gplx.core.type_xtns.*; import gplx.core.interfaces.*;
|
||||
public class GfoRegy implements GfoInvkAble {
|
||||
public class GfoRegy implements Gfo_invk {
|
||||
public int Count() {return hash.Count();}
|
||||
public Hash_adp Parsers() {return parsers;} Hash_adp parsers = Hash_adp_.new_();
|
||||
public Hash_adp Parsers() {return parsers;} Hash_adp parsers = Hash_adp_.New();
|
||||
public GfoRegyItm FetchOrNull(String key) {return (GfoRegyItm)hash.Get_by(key);}
|
||||
public Object FetchValOrFail(String key) {
|
||||
GfoRegyItm rv = (GfoRegyItm)hash.Get_by(key); if (rv == null) throw Err_.new_wo_type("regy does not have key", "key", key);
|
||||
@ -82,13 +82,13 @@ public class GfoRegy implements GfoInvkAble {
|
||||
if (ctx.Deny()) return this;
|
||||
RegObjByType(key, val, type);
|
||||
}
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} public static final String Invk_RegDir = "RegDir", Invk_RegObj = "RegObj";
|
||||
void RegItm(String key, Object val, int valType, Io_url url) {
|
||||
hash.Add_if_dupe_use_nth(key, new GfoRegyItm(key, val, valType, url));
|
||||
}
|
||||
Hash_adp hash = Hash_adp_.new_();
|
||||
Hash_adp hash = Hash_adp_.New();
|
||||
public static final String Err_ChopBgn = "chopBgn results in null key", Err_ChopEnd = "chopEnd results in null key", Err_Dupe = "key already registered";
|
||||
public static final GfoRegy Instance = new GfoRegy(); GfoRegy() {}
|
||||
@gplx.Internal protected static GfoRegy new_() {return new GfoRegy();}
|
||||
|
@ -36,7 +36,7 @@ public class Utf16__tst {
|
||||
}
|
||||
}
|
||||
class Utf16__fxt {
|
||||
private Int_obj_ref hi_ref = Int_obj_ref.neg1_(), lo_ref = Int_obj_ref.neg1_();
|
||||
private Int_obj_ref hi_ref = Int_obj_ref.New_neg1(), lo_ref = Int_obj_ref.New_neg1();
|
||||
public void Test_encode_decode(int expd_c_int, int... expd_int) {
|
||||
byte[] expd = Bry_.New_by_ints(expd_int);
|
||||
byte[] bfr = new byte[10];
|
||||
|
@ -33,7 +33,7 @@ public class Utf8__tst {
|
||||
fxt.Test_Increment_char_at_last_pos("€", "₭"); // len=3
|
||||
}
|
||||
// @Test public void Increment_char_at_last_pos_exhaustive_check() { // check all values; commented for perf
|
||||
// Bry_bfr bfr = Bry_bfr.new_();
|
||||
// Bry_bfr bfr = Bry_bfr_.New();
|
||||
// int bgn = 32;
|
||||
// while (true) {
|
||||
// byte[] bgn_bry = Utf16_.Encode_int_to_bry(bgn);
|
||||
|
@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.consoles.*; import gplx.core.criterias.*;
|
||||
import gplx.core.ios.streams.*;
|
||||
public interface IoEngine {
|
||||
String Key();
|
||||
boolean ExistsFil_api(Io_url url);
|
||||
@ -32,6 +33,7 @@ public interface IoEngine {
|
||||
IoStream OpenStreamWrite(IoEngine_xrg_openWrite args);
|
||||
void XferFil(IoEngine_xrg_xferFil args);
|
||||
void RecycleFil(IoEngine_xrg_recycleFil xrg);
|
||||
boolean Truncate_fil(Io_url url, long size);
|
||||
|
||||
boolean ExistsDir(Io_url url);
|
||||
void CreateDir(Io_url url); // creates all folder levels (EX: C:\a\b\c\ will create C:\a\ and C:\a\b\). will not fail if called on already existing folders.
|
||||
|
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*; import gplx.core.*;
|
||||
public class IoEnginePool {
|
||||
private final Hash_adp hash = Hash_adp_.new_();
|
||||
private final Hash_adp hash = Hash_adp_.New();
|
||||
public void Add_if_dupe_use_nth(IoEngine engine) {
|
||||
hash.Del(engine.Key());
|
||||
hash.Add(engine.Key(), engine);
|
||||
|
@ -16,6 +16,7 @@ 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.ios; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.ios.streams.*;
|
||||
public abstract class IoEngine_base implements IoEngine {
|
||||
public abstract String Key();
|
||||
public abstract boolean ExistsFil_api(Io_url url);
|
||||
@ -30,6 +31,7 @@ public abstract class IoEngine_base implements IoEngine {
|
||||
public abstract IoStream OpenStreamRead(Io_url url);
|
||||
public abstract IoStream OpenStreamWrite(IoEngine_xrg_openWrite args);
|
||||
public abstract void XferFil(IoEngine_xrg_xferFil args);
|
||||
public abstract boolean Truncate_fil(Io_url url, long size);
|
||||
|
||||
public abstract boolean ExistsDir(Io_url url);
|
||||
public abstract void CreateDir(Io_url url); // creates all folder levels (EX: C:\a\b\c\ will create C:\a\ and C:\a\b\). will not fail if called on already existing folders.
|
||||
|
@ -16,6 +16,7 @@ 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.ios; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.ios.streams.*;
|
||||
public class IoEngine_memory extends IoEngine_base {
|
||||
@Override public String Key() {return key;} private String key = IoEngine_.MemKey;
|
||||
@Override public boolean ExistsFil_api(Io_url url) {return FetchFil(url) != IoItmFil_mem.Null;}
|
||||
@ -62,6 +63,7 @@ public class IoEngine_memory extends IoEngine_base {
|
||||
else
|
||||
SaveFilStr(args.Url(), args.Text());
|
||||
}
|
||||
@Override public boolean Truncate_fil(Io_url url, long size) {throw Err_.new_unimplemented();}
|
||||
@Override public String LoadFilStr(IoEngine_xrg_loadFilStr args) {
|
||||
return FetchFil(args.Url()).Text();
|
||||
}
|
||||
@ -190,6 +192,7 @@ public class IoEngine_memory extends IoEngine_base {
|
||||
byte[] bry = Bry_.new_u8(FetchFil(Io_url_.mem_fil_(xrg.Src())).Text());
|
||||
return Io_stream_rdr_.mem_(bry);
|
||||
}
|
||||
|
||||
IoItmHash dirs = IoItmHash.new_();
|
||||
IoEngineUtl utl = IoEngineUtl.new_();
|
||||
@gplx.Internal protected static IoEngine_memory new_(String key) {
|
||||
|
@ -28,6 +28,8 @@ import java.util.Date;
|
||||
import javax.print.FlavorException;
|
||||
import javax.tools.JavaCompiler;
|
||||
import gplx.core.criterias.*; import gplx.core.bits.*; import gplx.core.envs.*;
|
||||
import gplx.core.ios.streams.*;
|
||||
import gplx.core.progs.*;
|
||||
public class IoEngine_system extends IoEngine_base {
|
||||
@Override public String Key() {return IoEngine_.SysKey;}
|
||||
@Override public void DeleteDirDeep(IoEngine_xrg_deleteDir args) {utl.DeleteDirDeep(this, args.Url(), args);}
|
||||
@ -248,8 +250,7 @@ public class IoEngine_system extends IoEngine_base {
|
||||
MarkFileWritable(trgFil, trgUrl, args.ReadOnlyFails(), "copy");
|
||||
}
|
||||
else { // trgFil doesn't exist; must create file first else fileNotFound exception thrown
|
||||
// if (overwrite) throw Err_
|
||||
boolean rv = true; //Exception exc = null;
|
||||
boolean rv = true;
|
||||
if (!ExistsDir(trgUrl.OwnerDir())) CreateDir(trgUrl.OwnerDir());
|
||||
try {
|
||||
trgFil.createNewFile();
|
||||
@ -257,7 +258,6 @@ public class IoEngine_system extends IoEngine_base {
|
||||
IoEngine_system_xtn.SetExecutable(trgFil, true);
|
||||
}
|
||||
catch (IOException e) {
|
||||
// exc = e;
|
||||
rv = false;
|
||||
}
|
||||
if (!rv)
|
||||
@ -310,6 +310,75 @@ public class IoEngine_system extends IoEngine_base {
|
||||
}
|
||||
UpdateFilModifiedTime(trgUrl, QueryFil(srcUrl).ModifiedTime()); // must happen after file is closed
|
||||
}
|
||||
public void CopyFil(gplx.core.progs.Gfo_prog_ui prog_ui, Io_url src_url, Io_url trg_url, boolean overwrite, boolean readonly_fails) {
|
||||
// TODO:JAVA6 hidden property ignored; 1.6 does not allow OS-independent way of setting isHidden (wnt only possible through jni)
|
||||
File src_fil = new File(src_url.Xto_api()), trg_fil = new File(trg_url.Xto_api());
|
||||
if (trg_fil.isFile()) { // trg_fil exists; check if overwrite set and trg_fil is writable
|
||||
Chk_TrgFil_Overwrite(overwrite, trg_url);
|
||||
MarkFileWritable(trg_fil, trg_url, readonly_fails, "copy");
|
||||
}
|
||||
else { // trg_fil doesn't exist; must create file first else fileNotFound exception thrown
|
||||
boolean rv = true;
|
||||
if (!ExistsDir(trg_url.OwnerDir())) CreateDir(trg_url.OwnerDir());
|
||||
try {
|
||||
trg_fil.createNewFile();
|
||||
if (!Op_sys.Cur().Tid_is_drd())
|
||||
IoEngine_system_xtn.SetExecutable(trg_fil, true);
|
||||
}
|
||||
catch (IOException e) {
|
||||
rv = false;
|
||||
}
|
||||
if (!rv)
|
||||
throw Err_.new_wo_type("create file failed", "trg", trg_url.Xto_api());
|
||||
}
|
||||
FileInputStream src_stream = null; FileOutputStream trg_stream = null;
|
||||
FileChannel src_channel = null, trg_channel = null;
|
||||
try {
|
||||
// make objects
|
||||
try {src_stream = new FileInputStream(src_fil);}
|
||||
catch (FileNotFoundException e) {throw IoErr.FileNotFound("copy", src_url);}
|
||||
try {trg_stream = new FileOutputStream(trg_fil);}
|
||||
catch (FileNotFoundException e) {
|
||||
trg_stream = TryToUnHideFile(trg_fil, trg_url);
|
||||
if (trg_stream == null)
|
||||
throw IoErr.FileNotFound("copy", trg_url);
|
||||
// else
|
||||
// wasHidden = true;
|
||||
}
|
||||
src_channel = src_stream.getChannel();
|
||||
trg_channel = trg_stream.getChannel();
|
||||
|
||||
// transfer data
|
||||
long pos = 0, count = 0, read = 0;
|
||||
try {count = src_channel.size();}
|
||||
catch (IOException e) {throw Err_.new_exc(e, "io", "size failed", "src", src_url.Xto_api());}
|
||||
int buffer_size = IoEngineArgs.Instance.LoadFilStr_BufferSize;
|
||||
long transfer_size = (count > buffer_size) ? buffer_size : count; // transfer as much as fileSize, but limit to LoadFilStr_BufferSize
|
||||
while (pos < count) {
|
||||
try {read = trg_channel.transferFrom(src_channel, pos, transfer_size);}
|
||||
catch (IOException e) {
|
||||
Closeable_close(src_channel, src_url, false);
|
||||
Closeable_close(trg_channel, trg_url, false);
|
||||
Closeable_close(src_stream, src_url, false);
|
||||
Closeable_close(trg_stream, src_url, false);
|
||||
throw Err_.new_exc(e, "io", "transfer data failed", "src", src_url.Xto_api(), "trg", trg_url.Xto_api());
|
||||
}
|
||||
if (read == -1) break;
|
||||
if (prog_ui.Prog_notify_and_chk_if_suspended(pos, count)) return;
|
||||
pos += read;
|
||||
}
|
||||
// if (wasHidden)
|
||||
//
|
||||
}
|
||||
finally {
|
||||
// cleanup
|
||||
Closeable_close(src_channel, src_url, false);
|
||||
Closeable_close(trg_channel, trg_url, false);
|
||||
Closeable_close(src_stream, src_url, false);
|
||||
Closeable_close(trg_stream, src_url, false);
|
||||
}
|
||||
UpdateFilModifiedTime(trg_url, QueryFil(src_url).ModifiedTime()); // must happen after file is closed
|
||||
}
|
||||
FileOutputStream TryToUnHideFile(File trgFil, Io_url trgUrl) {
|
||||
FileOutputStream trgStream = null;
|
||||
if (trgFil.exists()) { // WORKAROUND: java fails when writing to hidden files; unmark hidden and try again
|
||||
@ -373,8 +442,8 @@ public class IoEngine_system extends IoEngine_base {
|
||||
XferDir(IoEngine_xrg_xferDir.copy_(src, trg));
|
||||
}
|
||||
}
|
||||
protected static void Closeable_close(Closeable closeable, Io_url url, boolean throwErr) {Closeable_close(closeable, url.Xto_api(), throwErr);}
|
||||
protected static void Closeable_close(Closeable closeable, String url_str, boolean throwErr) {
|
||||
public static void Closeable_close(Closeable closeable, Io_url url, boolean throwErr) {Closeable_close(closeable, url.Xto_api(), throwErr);}
|
||||
public static void Closeable_close(Closeable closeable, String url_str, boolean throwErr) {
|
||||
if (closeable == null) return;
|
||||
try {closeable.close();}
|
||||
catch (IOException e) {
|
||||
@ -484,6 +553,21 @@ public class IoEngine_system extends IoEngine_base {
|
||||
if (trg_stream != null) trg_stream.Rls();
|
||||
}
|
||||
} Io_url session_fil; Bry_bfr prog_fmt_bfr;
|
||||
@Override public boolean Truncate_fil(Io_url url, long size) {
|
||||
FileOutputStream stream = null;
|
||||
FileChannel channel = null;
|
||||
try {stream = new FileOutputStream(url.Xto_api(), true);}
|
||||
catch (FileNotFoundException e) {throw Err_.new_("io", "truncate: open failed", "url", url.Xto_api(), "err", Err_.Message_gplx_log(e));}
|
||||
channel = stream.getChannel();
|
||||
try {channel.truncate(size); return true;}
|
||||
catch (IOException e) {return false;}
|
||||
finally {
|
||||
try {
|
||||
if (stream != null) stream.close();
|
||||
if (channel != null) channel.close();
|
||||
} catch (IOException e) {return false;}
|
||||
}
|
||||
}
|
||||
byte[] download_bfr; static final int Download_bfr_len = Io_mgr.Len_kb * 128;
|
||||
public static Err Err_Fil_NotFound(Io_url url) {
|
||||
return Err_.new_(IoEngineArgs.Instance.Err_FileNotFound, "file not found", "url", url.Xto_api()).Trace_ignore_add_1_();
|
||||
|
@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.core.ios.streams.*;
|
||||
public class IoEngine_xrg_downloadFil {
|
||||
public String Src() {return src;} public IoEngine_xrg_downloadFil Src_(String v) {src = v; return this;} private String src;
|
||||
public Io_url Trg() {return trg;} public IoEngine_xrg_downloadFil Trg_(Io_url v) {trg = v; return this;} private Io_url trg;
|
||||
|
@ -16,6 +16,7 @@ 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.ios; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.ios.streams.*;
|
||||
public class IoEngine_xrg_openRead {
|
||||
public Io_url Url() {return url;} Io_url url;
|
||||
public String ErrMsg() {return errMsg;} private String errMsg;
|
||||
|
@ -16,6 +16,7 @@ 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.ios; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.ios.streams.*;
|
||||
public class IoEngine_xrg_openWrite {
|
||||
public Io_url Url() {return url;} public IoEngine_xrg_openWrite Url_(Io_url val) {url = val; return this;} Io_url url;
|
||||
public boolean ReadOnlyIgnored() {return readOnlyIgnored;} public IoEngine_xrg_openWrite ReadOnlyIgnored_() {return ReadOnlyIgnored_(true);} public IoEngine_xrg_openWrite ReadOnlyIgnored_(boolean v) {readOnlyIgnored = v; return this;} private boolean readOnlyIgnored = false;
|
||||
|
@ -49,8 +49,8 @@ public class IoEngine_xrg_recycleFil extends IoEngine_xrg_fil_affects1_base {
|
||||
public IoEngine_xrg_recycleFil(int v) {
|
||||
mode = v;
|
||||
time = DateAdp_.Now();
|
||||
uuid = Guid_adp_.new_();
|
||||
rootDirNames = List_adp_.new_(); rootDirNames.Add("z_trash");
|
||||
uuid = Guid_adp_.New();
|
||||
rootDirNames = List_adp_.New(); rootDirNames.Add("z_trash");
|
||||
}
|
||||
public static IoEngine_xrg_recycleFil sysm_(Io_url url) {return new IoEngine_xrg_recycleFil(SysmConst);}
|
||||
public static IoEngine_xrg_recycleFil gplx_(Io_url url) {IoEngine_xrg_recycleFil rv = new IoEngine_xrg_recycleFil(GplxConst); rv.Url_set(url); return rv;}
|
||||
|
@ -31,7 +31,7 @@ public class IoItmDir_ {
|
||||
return rv;
|
||||
}
|
||||
static IoItmDir null_() {
|
||||
IoItmDir rv = new IoItmDir(true); // TODO: NULL should be removed
|
||||
IoItmDir rv = new IoItmDir(true); // TODO_OLD: NULL should be removed
|
||||
rv.ctor_IoItmBase_url(Io_url_.Empty);
|
||||
rv.Exists_set(false);
|
||||
return rv;
|
||||
|
@ -16,7 +16,7 @@ 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.ios; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.ios.*; /*IoStream_mem*/ import gplx.core.texts.*; /*Encoding_*/
|
||||
import gplx.core.ios.streams.*; /*IoStream_mem*/ import gplx.core.texts.*; /*Encoding_*/
|
||||
class IoItmFil_mem extends IoItmFil { public static IoItmFil_mem as_(Object obj) {return obj instanceof IoItmFil_mem ? (IoItmFil_mem)obj : null;}
|
||||
@gplx.Internal protected IoStream_mem Stream() {return stream;} IoStream_mem stream; // NOTE: using stream instead of Text, b/c no events for IoStream.Dispose; ex: stream.OpenStreamWrite; stream.Write("hi"); stream.Dispose(); "hi" would not be saved if Text is member variable
|
||||
@Override public long Size() {return (int)stream.Len();}
|
||||
|
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*; import gplx.core.*;
|
||||
import gplx.langs.gfs.*;
|
||||
public abstract class IoItm_base implements GfoInvkAble, CompareAble {
|
||||
public abstract class IoItm_base implements Gfo_invk, CompareAble {
|
||||
public abstract int TypeId(); public abstract boolean Type_dir(); public abstract boolean Type_fil();
|
||||
public Io_url Url() {return ownerDir == null ? url : ownerDir.Url().GenSubFil(name); /*NOTE: must call .Url*/} Io_url url;
|
||||
public IoItmDir OwnerDir() {return ownerDir;} IoItmDir ownerDir;
|
||||
@ -35,19 +35,19 @@ public abstract class IoItm_base implements GfoInvkAble, CompareAble {
|
||||
}
|
||||
public Object XtnProps_get(String key) {return props.Get_by(key);} Hash_adp props = Hash_adp_.Noop;
|
||||
public IoItm_base XtnProps_set(String key, Object val) {
|
||||
if (props == Hash_adp_.Noop) props = Hash_adp_.new_();
|
||||
if (props == Hash_adp_.Noop) props = Hash_adp_.New();
|
||||
props.Del(key);
|
||||
props.Add(key, val);
|
||||
return this;
|
||||
}
|
||||
public int compareTo(Object comp) {return url.compareTo(((IoItm_base)comp).url);} // NOTE: needed for comic importer (sort done on IoItmHash which contains IoItm_base)
|
||||
// public Object Data_get(String name) {return GfoInvkAble_.InvkCmd(this, name);}
|
||||
// public Object Data_get(String name) {return Gfo_invk_.Invk_by_key(this, name);}
|
||||
@gplx.Virtual public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, IoItm_base_.Prop_Type)) return this.TypeId();
|
||||
else if (ctx.Match(k, IoItm_base_.Prop_Path)) return this.Url();
|
||||
else if (ctx.Match(k, IoItm_base_.Prop_Title)) return this.Url().NameOnly(); // needed for gfio script criteria;
|
||||
else if (ctx.Match(k, IoItm_base_.Prop_Ext)) return this.Url().Ext(); // needed for gfio script criteria; EX: where "ext LIKE '.java'"
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
}
|
||||
@gplx.Internal protected void ctor_IoItmBase_url(Io_url url) {this.url = url; this.name = url.NameAndExt();}
|
||||
@gplx.Internal protected void ctor_IoItmBase_name(String name) {this.name = name;}
|
||||
|
@ -35,7 +35,7 @@ public class IoRecycleBin {
|
||||
IoEngine_xrg_saveFilStr.new_(regyUrl, text).Append_().Exec();
|
||||
}
|
||||
public List_adp Regy_search(Io_url url, String_bldr sb) {
|
||||
List_adp list = List_adp_.new_();
|
||||
List_adp list = List_adp_.New();
|
||||
Io_url regyUrl = FetchRegistryUrl(url);
|
||||
String[] lines = IoEngine_xrg_loadFilStr.new_(regyUrl).ExecAsStrAry();
|
||||
int linesLen = Array_.Len(lines);
|
||||
|
@ -119,7 +119,7 @@ abstract class IoUrlInfo_base implements IoUrlInfo {
|
||||
}
|
||||
}
|
||||
static final int
|
||||
OwnerDirPos_hasNoOwner = -1 // List_adp_.NotFound
|
||||
OwnerDirPos_hasNoOwner = -1 // List_adp_.Not_found
|
||||
, OwnerDirPos_isNull = -2
|
||||
, OwnerDirPos_isRoot = -3;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.core.ios; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.envs.*;
|
||||
import gplx.langs.gfs.*;
|
||||
public class IoUrlInfoRegy implements GfoInvkAble {
|
||||
public class IoUrlInfoRegy implements Gfo_invk {
|
||||
public void Reg(IoUrlInfo info) {hash.Add_if_dupe_use_nth(info.Key(), info);}
|
||||
public IoUrlInfo Match(String raw) {
|
||||
if (String_.Len(raw) == 0) return IoUrlInfo_.Nil;
|
||||
|
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.core.ios; import gplx.*; import gplx.core.*;
|
||||
import gplx.core.strings.*; import gplx.langs.gfs.*;
|
||||
public class IoUrlTypeRegy implements GfoInvkAble {
|
||||
public class IoUrlTypeRegy implements Gfo_invk {
|
||||
public String[] FetchAryOr(String key, String... or) {
|
||||
IoUrlTypeGrp itm = (IoUrlTypeGrp)hash.Get_by(key);
|
||||
return itm == null ? or : itm.AsAry();
|
||||
@ -33,13 +33,13 @@ public class IoUrlTypeRegy implements GfoInvkAble {
|
||||
}
|
||||
return itm;
|
||||
}
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
// return this;
|
||||
} public static final String Invk_Get = "Get";
|
||||
Ordered_hash hash = Ordered_hash_.New();
|
||||
public static final IoUrlTypeRegy Instance = new IoUrlTypeRegy(); IoUrlTypeRegy() {}
|
||||
}
|
||||
class IoUrlTypeGrp implements GfoInvkAble {
|
||||
class IoUrlTypeGrp implements Gfo_invk {
|
||||
public String[] AsAry() {
|
||||
String[] rv = new String[list.Count()];
|
||||
for (int i = 0; i < list.Count(); i++)
|
||||
@ -70,7 +70,7 @@ class IoUrlTypeGrp implements GfoInvkAble {
|
||||
return sb.To_str();
|
||||
}
|
||||
else if (ctx.Match(k, Invk_Clear)) {if (ctx.Deny()) return this; list.Clear();}
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} public static final String Invk_AddMany = "Add_many", Invk_Clear = "Clear", Invk_Print = "Print";
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public class Io_download_fmt {
|
||||
public Io_download_fmt() {
|
||||
this.src_name = prog_msg_hdr = ""; // NOTE: set to "" else prog_mgr will fail with null ref
|
||||
}
|
||||
private final Bry_bfr prog_bfr = Bry_bfr.new_(); Bry_fmtr prog_fmtr = Bry_fmtr.new_().Fail_when_invalid_escapes_(false); // NOTE: prog_fmtr can be passed file_names with ~ which are not easy to escape; DATE:2013-02-19
|
||||
private final Bry_bfr prog_bfr = Bry_bfr_.New(); Bry_fmtr prog_fmtr = Bry_fmtr.new_().Fail_when_invalid_escapes_(false); // NOTE: prog_fmtr can be passed file_names with ~ which are not easy to escape; DATE:2013-02-19
|
||||
public long Time_bgn() {return time_bgn;} private long time_bgn;
|
||||
public long Time_now() {return time_now;} private long time_now;
|
||||
public long Time_dif() {return time_dif;} private long time_dif;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user