mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Refactor: Pull more classes into baselib
This commit is contained in:
@@ -13,8 +13,11 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml; import gplx.*;
|
||||
package gplx.gfml;
|
||||
import gplx.core.texts.*; /*CharStream*/
|
||||
import gplx.frameworks.evts.Gfo_evt_itm;
|
||||
import gplx.types.basics.lists.Hash_adp;
|
||||
import gplx.types.basics.lists.Hash_adp_;
|
||||
public interface GfmlLxr extends Gfo_evt_itm {
|
||||
String Key();
|
||||
String[] Hooks();
|
||||
|
||||
@@ -13,30 +13,42 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml; import gplx.*;
|
||||
import gplx.core.strings.*;
|
||||
import gplx.core.texts.*; /*CharStream*/
|
||||
package gplx.gfml;
|
||||
import gplx.types.commons.KeyVal;
|
||||
import gplx.types.errs.Err;
|
||||
import gplx.core.texts.*; /*CharStream*/
|
||||
import gplx.frameworks.invks.GfoMsg;
|
||||
import gplx.frameworks.invks.Gfo_invk;
|
||||
import gplx.frameworks.invks.Gfo_invk_;
|
||||
import gplx.frameworks.evts.Gfo_evt_itm;
|
||||
import gplx.frameworks.evts.Gfo_evt_mgr;
|
||||
import gplx.frameworks.evts.Gfo_evt_mgr_;
|
||||
import gplx.frameworks.invks.GfsCtx;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.types.commons.String_bldr;
|
||||
import gplx.types.commons.String_bldr_;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
public class GfmlLxr_ {
|
||||
public static GfmlLxr general_(String key, GfmlTkn protoTkn) {return GfmlLxr_general.new_(key, protoTkn);}
|
||||
public static GfmlLxr solo_(String key, GfmlTkn singletonTkn) {return GfmlLxr_singleton.new_(key, singletonTkn.Raw(), singletonTkn);}
|
||||
public static GfmlLxr range_(String key, String[] ary, GfmlTkn protoTkn, boolean ignoreOutput) {return GfmlLxr_group.new_(key, ary, protoTkn, ignoreOutput);}
|
||||
|
||||
@gplx.Internal protected static GfmlLxr symbol_(String key, String raw, String val, GfmlBldrCmd cmd) {
|
||||
public static GfmlLxr symbol_(String key, String raw, String val, GfmlBldrCmd cmd) {
|
||||
GfmlTkn tkn = GfmlTkn_.singleton_(key, raw, val, cmd);
|
||||
return GfmlLxr_.solo_(key, tkn);
|
||||
}
|
||||
@gplx.Internal protected static GfmlLxr frame_(String key, GfmlFrame frame, String bgn, String end) {return GfmlLxr_frame.new_(key, frame, bgn, end, GfmlBldrCmd_pendingTkns_add.Instance, GfmlBldrCmd_frameEnd.data_());}
|
||||
public static GfmlLxr frame_(String key, GfmlFrame frame, String bgn, String end) {return GfmlLxr_frame.new_(key, frame, bgn, end, GfmlBldrCmd_pendingTkns_add.Instance, GfmlBldrCmd_frameEnd.data_());}
|
||||
public static final GfmlLxr Null = new GfmlLxr_null();
|
||||
public static final String CmdTknChanged_evt = "Changed";
|
||||
public static GfmlLxr as_(Object obj) {return obj instanceof GfmlLxr ? (GfmlLxr)obj : null;}
|
||||
public static GfmlLxr cast(Object obj) {try {return (GfmlLxr)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, GfmlLxr.class, obj);}}
|
||||
public static GfmlLxr cast(Object obj) {try {return (GfmlLxr)obj;} catch(Exception exc) {throw ErrUtl.NewCast(exc, GfmlLxr.class, obj);}}
|
||||
}
|
||||
class GfmlLxr_null implements GfmlLxr {
|
||||
public String Key() {return "gfml.nullLxr";}
|
||||
public Gfo_evt_mgr Evt_mgr() {if (evt_mgr == null) evt_mgr = new Gfo_evt_mgr(this); return evt_mgr;} Gfo_evt_mgr evt_mgr;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return Gfo_invk_.Rv_unhandled;}
|
||||
public GfmlTkn CmdTkn() {return GfmlTkn_.Null;} public void CmdTkn_set(GfmlTkn val) {}
|
||||
public String[] Hooks() {return String_.Ary_empty;}
|
||||
public String[] Hooks() {return StringUtl.AryEmpty;}
|
||||
public GfmlTkn MakeTkn(CharStream stream, int hookLength) {return GfmlTkn_.Null;}
|
||||
public void SubLxr_Add(GfmlLxr... lexer) {}
|
||||
public GfmlLxr SubLxr() {return this;}
|
||||
@@ -49,8 +61,8 @@ class GfmlLxr_singleton implements GfmlLxr, Gfo_evt_itm {
|
||||
public void CmdTkn_set(GfmlTkn val) {
|
||||
String oldRaw = singletonTkn.Raw();
|
||||
singletonTkn = val;
|
||||
hooks = String_.Ary(val.Raw());
|
||||
Gfo_evt_mgr_.Pub_vals(this, GfmlLxr_.CmdTknChanged_evt, Keyval_.new_("old", oldRaw), Keyval_.new_("new", val.Raw()), Keyval_.new_("lxr", this));
|
||||
hooks = StringUtl.Ary(val.Raw());
|
||||
Gfo_evt_mgr_.Pub_vals(this, GfmlLxr_.CmdTknChanged_evt, KeyVal.NewStr("old", oldRaw), KeyVal.NewStr("new", val.Raw()), KeyVal.NewStr("lxr", this));
|
||||
}
|
||||
public String[] Hooks() {return hooks;} private String[] hooks;
|
||||
public GfmlTkn MakeTkn(CharStream stream, int hookLength) {
|
||||
@@ -64,9 +76,9 @@ class GfmlLxr_singleton implements GfmlLxr, Gfo_evt_itm {
|
||||
rv.ctor_(key, hook, singletonTkn, GfmlLxr_.Null);
|
||||
return rv;
|
||||
} protected GfmlLxr_singleton() {}
|
||||
@gplx.Internal protected void ctor_(String key, String hook, GfmlTkn singletonTkn, GfmlLxr subLxr) {
|
||||
public void ctor_(String key, String hook, GfmlTkn singletonTkn, GfmlLxr subLxr) {
|
||||
this.key = key;
|
||||
this.hooks = String_.Ary(hook);
|
||||
this.hooks = StringUtl.Ary(hook);
|
||||
this.subLxr = subLxr;
|
||||
this.singletonTkn = singletonTkn;
|
||||
}
|
||||
@@ -80,20 +92,20 @@ class GfmlLxr_group implements GfmlLxr {
|
||||
public GfmlTkn MakeTkn(CharStream stream, int hookLength) {
|
||||
while (stream.AtMid()) {
|
||||
if (!ignoreOutput)
|
||||
sb.Add_mid_len(stream.Ary(), stream.Pos(), hookLength);
|
||||
sb.AddMidLen(stream.Ary(), stream.Pos(), hookLength);
|
||||
stream.MoveNextBy(hookLength);
|
||||
|
||||
String found = String_.cast(trie.FindMatch(stream));
|
||||
String found = StringUtl.Cast(trie.FindMatch(stream));
|
||||
if (found == null) break;
|
||||
hookLength = trie.LastMatchCount;
|
||||
}
|
||||
if (ignoreOutput) return GfmlTkn_.IgnoreOutput;
|
||||
String raw = sb.To_str_and_clear();
|
||||
String raw = sb.ToStrAndClear();
|
||||
return outputTkn.MakeNew(raw, raw);
|
||||
}
|
||||
public GfmlLxr SubLxr() {throw Err_sublxr();}
|
||||
public void SubLxr_Add(GfmlLxr... lexer) {throw Err_sublxr();}
|
||||
Err Err_sublxr() {return Err_.new_unimplemented_w_msg("group lxr does not have subLxrs", "key", key, "output_tkn", outputTkn.Raw()).Trace_ignore_add_1_();}
|
||||
Err Err_sublxr() {return ErrUtl.NewUnimplemented("group lxr does not have subLxrs", "key", key, "output_tkn", outputTkn.Raw());}
|
||||
GfmlTrie trie = GfmlTrie.new_(); String_bldr sb = String_bldr_.new_(); boolean ignoreOutput;
|
||||
public static GfmlLxr_group new_(String key, String[] hooks, GfmlTkn outputTkn, boolean ignoreOutput) {
|
||||
GfmlLxr_group rv = new GfmlLxr_group();
|
||||
@@ -151,7 +163,7 @@ class GfmlLxr_general implements GfmlLxr, Gfo_invk {
|
||||
return lexer.MakeTkn(stream, length);
|
||||
}
|
||||
GfmlLxr_general_txtBfr txtBfr = new GfmlLxr_general_txtBfr(); GfmlTrie symTrie = GfmlTrie.new_(); GfmlLxr symLxr; int symTknLen;
|
||||
@gplx.Internal protected static GfmlLxr_general new_(String key, GfmlTkn txtTkn) {
|
||||
public static GfmlLxr_general new_(String key, GfmlTkn txtTkn) {
|
||||
GfmlLxr_general rv = new GfmlLxr_general();
|
||||
rv.key = key; rv.txtTkn = txtTkn;
|
||||
return rv;
|
||||
@@ -174,7 +186,7 @@ class GfmlLxr_general_txtBfr {
|
||||
Len++;
|
||||
} static final int NullPos = -1;
|
||||
public GfmlTkn MakeTkn(CharStream stream, GfmlTkn textTkn) {
|
||||
String raw = String_.new_charAry_(stream.Ary(), Bgn, Len);
|
||||
String raw = StringUtl.NewCharAry(stream.Ary(), Bgn, Len);
|
||||
Bgn = -1; Len = 0;
|
||||
return textTkn.MakeNew(raw, raw);
|
||||
}
|
||||
@@ -211,5 +223,5 @@ class GfmlLxr_frame extends GfmlLxr_singleton { GfmlFrame frame; GfmlLxr endLxr
|
||||
return rv;
|
||||
} GfmlLxr_frame() {}
|
||||
public static GfmlLxr_frame as_(Object obj) {return obj instanceof GfmlLxr_frame ? (GfmlLxr_frame)obj : null;}
|
||||
public static GfmlLxr_frame cast(Object obj) {try {return (GfmlLxr_frame)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, GfmlLxr_frame.class, obj);}}
|
||||
public static GfmlLxr_frame cast(Object obj) {try {return (GfmlLxr_frame)obj;} catch(Exception exc) {throw ErrUtl.NewCast(exc, GfmlLxr_frame.class, obj);}}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,13 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml; import gplx.*;
|
||||
package gplx.gfml;
|
||||
import gplx.frameworks.objects.New;
|
||||
import gplx.types.basics.lists.List_adp_base;
|
||||
public class GfmlObjList extends List_adp_base {
|
||||
@gplx.New public GfmlObj Get_at(int idx) {return (GfmlObj)Get_at_base(idx);}
|
||||
public void Add(GfmlObj tkn) {Add_base(tkn);}
|
||||
public void Add_at(GfmlObj tkn, int idx) {super.AddAt_base(idx, tkn);}
|
||||
public void Del(GfmlObj tkn) {Del_base(tkn);}
|
||||
public static GfmlObjList new_() {return new GfmlObjList();} GfmlObjList() {}
|
||||
}
|
||||
@New public GfmlObj GetAt(int idx) {return (GfmlObj)Get_at_base(idx);}
|
||||
public void Add(GfmlObj tkn) {Add_base(tkn);}
|
||||
public void Add_at(GfmlObj tkn, int idx) {super.AddAt_base(idx, tkn);}
|
||||
public void Del(GfmlObj tkn) {Del_base(tkn);}
|
||||
public static GfmlObjList new_() {return new GfmlObjList();} GfmlObjList() {}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml; import gplx.*;
|
||||
import gplx.core.strings.*;
|
||||
public interface GfmlTkn extends GfmlObj {
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml;
|
||||
import gplx.types.commons.String_bldr;
|
||||
import gplx.types.commons.String_bldr_;
|
||||
public interface GfmlTkn extends GfmlObj {
|
||||
String TknType();
|
||||
String Raw();
|
||||
String Val();
|
||||
@@ -23,22 +24,22 @@ public interface GfmlTkn extends GfmlObj {
|
||||
GfmlBldrCmd Cmd_of_Tkn();
|
||||
GfmlTkn MakeNew(String raw, String val);
|
||||
}
|
||||
class GfmlTknAry_ {
|
||||
class GfmlTknAry_ {
|
||||
public static final GfmlTkn[] Empty = new GfmlTkn[0];
|
||||
public static GfmlTkn[] ary_(GfmlTkn... ary) {return ary;}
|
||||
@gplx.Internal protected static String XtoRaw(GfmlTkn[] ary) {
|
||||
public static String XtoRaw(GfmlTkn[] ary) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
for (GfmlTkn tkn : ary)
|
||||
sb.Add(tkn.Raw());
|
||||
return sb.To_str();
|
||||
return sb.ToStr();
|
||||
}
|
||||
@gplx.Internal protected static String XtoVal(GfmlTkn[] ary) {return XtoVal(ary, 0, ary.length);}
|
||||
public static String XtoVal(GfmlTkn[] ary) {return XtoVal(ary, 0, ary.length);}
|
||||
static String XtoVal(GfmlTkn[] ary, int bgn, int end) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
for (int i = bgn; i < end; i++) {
|
||||
GfmlTkn tkn = ary[i];
|
||||
sb.Add(tkn.Val());
|
||||
}
|
||||
return sb.To_str();
|
||||
return sb.ToStr();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,25 +13,26 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml; import gplx.*;
|
||||
package gplx.gfml;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
public class GfmlTkn_ {
|
||||
@gplx.Internal protected static final String NullRaw = "", NullVal = ""; static final String Type_base = "gfml.baseTkn";
|
||||
@gplx.Internal protected static final GfmlTkn
|
||||
public static final String NullRaw = "", NullVal = ""; static final String Type_base = "gfml.baseTkn";
|
||||
public static final GfmlTkn
|
||||
Null = new GfmlTkn_base().ctor_GfmlTkn_base("gfml.nullTkn", NullRaw, NullVal, GfmlBldrCmd_.Null)
|
||||
, EndOfStream = GfmlTkn_.raw_("<<End Of Stream>>")
|
||||
, IgnoreOutput = GfmlTkn_.raw_("<<Ignore Output>>");
|
||||
public static GfmlTkn as_(Object obj) {return obj instanceof GfmlTkn ? (GfmlTkn)obj : null;}
|
||||
@gplx.Internal protected static GfmlTkn new_(String raw, String val) {return new GfmlTkn_base().ctor_GfmlTkn_base(Type_base, raw, val, GfmlBldrCmd_.Null);}
|
||||
public static GfmlTkn new_(String raw, String val) {return new GfmlTkn_base().ctor_GfmlTkn_base(Type_base, raw, val, GfmlBldrCmd_.Null);}
|
||||
public static GfmlTkn raw_(String raw) {return new GfmlTkn_base().ctor_GfmlTkn_base(Type_base, raw, raw, GfmlBldrCmd_.Null);}
|
||||
@gplx.Internal protected static GfmlTkn val_(String val) {return new GfmlTkn_base().ctor_GfmlTkn_base(Type_base, NullRaw, val, GfmlBldrCmd_.Null);}
|
||||
@gplx.Internal protected static GfmlTkn cmd_(String tknType, GfmlBldrCmd cmd) {return new GfmlTkn_base().ctor_GfmlTkn_base(tknType, NullRaw, NullVal, cmd);}
|
||||
@gplx.Internal protected static GfmlTkn valConst_(String tknType, String val, GfmlBldrCmd cmd) {return new GfmlTkn_valConst().ctor_GfmlTkn_base(tknType, GfmlTkn_.NullRaw, val, cmd);}
|
||||
@gplx.Internal protected static GfmlTkn singleton_(String tknType, String raw, String val, GfmlBldrCmd cmd) {return new GfmlTkn_singleton().ctor_GfmlTkn_base(tknType, raw, val, cmd);}
|
||||
@gplx.Internal protected static GfmlTkn composite_(String tknType, GfmlTkn[] ary) {return new GfmlTkn_composite(tknType, ary);}
|
||||
@gplx.Internal protected static GfmlTkn composite_list_(String tknType, GfmlObjList list) {
|
||||
public static GfmlTkn val_(String val) {return new GfmlTkn_base().ctor_GfmlTkn_base(Type_base, NullRaw, val, GfmlBldrCmd_.Null);}
|
||||
public static GfmlTkn cmd_(String tknType, GfmlBldrCmd cmd) {return new GfmlTkn_base().ctor_GfmlTkn_base(tknType, NullRaw, NullVal, cmd);}
|
||||
public static GfmlTkn valConst_(String tknType, String val, GfmlBldrCmd cmd) {return new GfmlTkn_valConst().ctor_GfmlTkn_base(tknType, GfmlTkn_.NullRaw, val, cmd);}
|
||||
public static GfmlTkn singleton_(String tknType, String raw, String val, GfmlBldrCmd cmd) {return new GfmlTkn_singleton().ctor_GfmlTkn_base(tknType, raw, val, cmd);}
|
||||
public static GfmlTkn composite_(String tknType, GfmlTkn[] ary) {return new GfmlTkn_composite(tknType, ary);}
|
||||
public static GfmlTkn composite_list_(String tknType, GfmlObjList list) {
|
||||
GfmlTkn[] ary = new GfmlTkn[list.Len()];
|
||||
for (int i = 0; i < list.Len(); i++)
|
||||
ary[i] = (GfmlTkn)list.Get_at(i);
|
||||
ary[i] = (GfmlTkn)list.GetAt(i);
|
||||
return GfmlTkn_.composite_(tknType, ary);
|
||||
}
|
||||
}
|
||||
@@ -43,7 +44,7 @@ class GfmlTkn_base implements GfmlTkn {
|
||||
public GfmlBldrCmd Cmd_of_Tkn() {return cmd;} GfmlBldrCmd cmd;
|
||||
public GfmlTkn[] SubTkns() {return GfmlTknAry_.Empty;}
|
||||
public GfmlTkn MakeNew(String rawNew, String valNew) {return new GfmlTkn_base().ctor_GfmlTkn_base(tknType, rawNew, valNew, cmd);}
|
||||
@gplx.Internal protected GfmlTkn_base ctor_GfmlTkn_base(String tknType, String raw, String val, GfmlBldrCmd cmd) {this.tknType = tknType; this.raw = raw; this.val = val; this.cmd = cmd; return this;}
|
||||
public GfmlTkn_base ctor_GfmlTkn_base(String tknType, String raw, String val, GfmlBldrCmd cmd) {this.tknType = tknType; this.raw = raw; this.val = val; this.cmd = cmd; return this;}
|
||||
}
|
||||
class GfmlTkn_valConst extends GfmlTkn_base {
|
||||
@Override public GfmlTkn MakeNew(String rawNew, String valNew) {return new GfmlTkn_base().ctor_GfmlTkn_base(this.TknType(), rawNew, this.Val(), this.Cmd_of_Tkn());}
|
||||
@@ -58,6 +59,6 @@ class GfmlTkn_composite implements GfmlTkn {
|
||||
public String Val() {return GfmlTknAry_.XtoVal(ary);}
|
||||
public GfmlBldrCmd Cmd_of_Tkn() {return GfmlBldrCmd_.Null;}
|
||||
public GfmlTkn[] SubTkns() {return ary;} GfmlTkn[] ary;
|
||||
public GfmlTkn MakeNew(String rawNew, String valNew) {throw Err_.new_unimplemented_w_msg(".MakeNew cannot be invoked on GfmlTkn_composite (raw is available, but not val)", "tknType", tknType, "rawNew", rawNew, "valNew", valNew);}
|
||||
@gplx.Internal protected GfmlTkn_composite(String tknType, GfmlTkn[] ary) {this.tknType = tknType; this.ary = ary;}
|
||||
public GfmlTkn MakeNew(String rawNew, String valNew) {throw ErrUtl.NewUnimplemented(".MakeNew cannot be invoked on GfmlTkn_composite (raw is available, but not val)", "tknType", tknType, "rawNew", rawNew, "valNew", valNew);}
|
||||
public GfmlTkn_composite(String tknType, GfmlTkn[] ary) {this.tknType = tknType; this.ary = ary;}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,17 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml; import gplx.*;
|
||||
import gplx.core.texts.*; /*CharStream*/
|
||||
package gplx.gfml;
|
||||
import gplx.types.basics.lists.Ordered_hash;
|
||||
import gplx.types.basics.lists.Ordered_hash_;
|
||||
import gplx.core.texts.CharStream;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
public class GfmlTrie {
|
||||
public String[] Symbols() {
|
||||
String[] rv = new String[symbols.Len()];
|
||||
for (int i = 0; i < rv.length; i++)
|
||||
rv[i] = String_.cast(symbols.Get_at(i));
|
||||
rv[i] = StringUtl.Cast(symbols.GetAt(i));
|
||||
return rv;
|
||||
} Ordered_hash symbols = Ordered_hash_.New();
|
||||
public int LastMatchCount; // PERF: prop is faster than method
|
||||
@@ -46,9 +50,9 @@ public class GfmlTrie {
|
||||
return result;
|
||||
}
|
||||
public void Add(String symbol, Object data) {
|
||||
if (data == null) throw Err_.new_wo_type("null objects cannot be registered", "symbol", symbol);
|
||||
if (data == null) throw ErrUtl.NewArgs("null objects cannot be registered", "symbol", symbol);
|
||||
|
||||
char[] ary = String_.XtoCharAry(symbol); int lastIndex = ary.length - 1;
|
||||
char[] ary = StringUtl.ToCharAry(symbol); int lastIndex = ary.length - 1;
|
||||
IntObjHash_base curLink = rootLink;
|
||||
for (int i = 0; i < ary.length; i++) {
|
||||
char c = ary[i];
|
||||
@@ -80,7 +84,7 @@ public class GfmlTrie {
|
||||
symbols.AddIfDupeUseNth(symbol, symbol);
|
||||
}
|
||||
public void Del(String symbol) {
|
||||
char[] ary = String_.XtoCharAry(symbol); int lastIndex = ary.length - 1;
|
||||
char[] ary = StringUtl.ToCharAry(symbol); int lastIndex = ary.length - 1;
|
||||
IntObjHash_base[] linkAry = new IntObjHash_base[ary.length]; // first, get linkAry -- one link for each symbol
|
||||
IntObjHash_base link = rootLink;
|
||||
for (int i = 0; i < ary.length; i++) {
|
||||
|
||||
@@ -13,13 +13,14 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.gfml; import gplx.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
package gplx.gfml;
|
||||
import gplx.types.basics.utls.ArrayUtl;
|
||||
import gplx.types.errs.ErrUtl;
|
||||
class IntObjHash_base {
|
||||
public int Count() {return count;} int count;
|
||||
public boolean Has(int key) {return Get_by(key) != null;}
|
||||
public Object Get_by(int key) {
|
||||
if (key < 0) throw Err_.new_wo_type("key must be >= 0", "key", key);
|
||||
if (key < 0) throw ErrUtl.NewArgs("key must be >= 0", "key", key);
|
||||
if (key > maxKey) return null;
|
||||
Object[] subAry = FetchSubAry(key);
|
||||
return subAry == null ? null : subAry[subIdx];
|
||||
@@ -39,8 +40,8 @@ class IntObjHash_base {
|
||||
maxKey = -1;
|
||||
}
|
||||
void PutObjAtKey(int key, Object obj, boolean isAdd) {
|
||||
if (key < 0) throw Err_.new_wo_type("key must be >= 0", "key", key);
|
||||
if (obj == null) throw Err_.new_wo_type("Object cannot be null; call .Del on key instead", "key", key);
|
||||
if (key < 0) throw ErrUtl.NewArgs("key must be >= 0", "key", key);
|
||||
if (obj == null) throw ErrUtl.NewArgs("Object cannot be null; call .Del on key instead", "key", key);
|
||||
if (key > maxKey) ExpandRootAry(key);
|
||||
Object[] subAry = FetchSubAry(key);
|
||||
if (subAry == null) {
|
||||
@@ -48,8 +49,8 @@ class IntObjHash_base {
|
||||
rootAry[rootIdx] = subAry;
|
||||
}
|
||||
Object curVal = subAry[subIdx];
|
||||
if ( isAdd && curVal != null) throw Err_.new_wo_type(".Add cannot be called on non-null vals; call .Set instead", "key", key, "val", curVal);
|
||||
if (!isAdd && curVal == null) throw Err_.new_wo_type(".Set cannot be called on null vals; call .Add instead", "key", key);
|
||||
if ( isAdd && curVal != null) throw ErrUtl.NewArgs(".Add cannot be called on non-null vals; call .Set instead", "key", key, "val", curVal);
|
||||
if (!isAdd && curVal == null) throw ErrUtl.NewArgs(".Set cannot be called on null vals; call .Add instead", "key", key);
|
||||
subAry[subIdx] = obj;
|
||||
if (isAdd) count++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user