1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-09-29 06:50:50 +00:00
gnosygnu_xowa/110_gfml/tst/gplx/gfml/ymoks_GfmlTkn_mok.java

76 lines
2.8 KiB
Java
Raw Normal View History

2017-02-07 03:14:55 +00:00
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
2017-02-07 03:14:55 +00:00
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.
2017-02-07 03:14:55 +00:00
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
2017-02-07 03:14:55 +00:00
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
2017-02-07 03:14:55 +00:00
*/
package gplx.gfml; import gplx.*;
class GfmlTkn_mok {
public String Raw() {return raw;} public GfmlTkn_mok Raw_(String v) {raw = v; return this;} private String raw;
public List_adp Subs() {return list;} List_adp list = List_adp_.New();
public GfmlTkn_mok Subs_(GfmlTkn_mok... ary) {
for (GfmlTkn_mok itm : ary)
list.Add(itm);
return this;
}
// statics
public static GfmlTkn_mok new_() {return new GfmlTkn_mok();} GfmlTkn_mok() {}
public static GfmlTkn_mok gfmlNde_(GfmlNde nde) {
GfmlTkn_mok rv = new GfmlTkn_mok();
InitItm(rv, nde);
return rv;
}
static void InitItm(GfmlTkn_mok rv, GfmlItm owner) {
for (int i = 0; i < owner.SubObjs_Count(); i++) {
GfmlObj subTkn = (GfmlObj)owner.SubObjs_GetAt(i);
GfmlTkn_mok subMok = GfmlTkn_mok.new_();
rv.Subs_(subMok);
GfmlItm subItm = GfmlItm_.as_(subTkn);
if (subItm != null)
InitItm(subMok, subItm);
else
InitTkn(subMok, (GfmlTkn)subTkn);
}
}
static void InitTkn(GfmlTkn_mok mok, GfmlTkn tkn) {
if (tkn.SubTkns().length == 0) // leafTkn; no subs; simply set
mok.Raw_(tkn.Raw());
else { // compTkn; createTkn and iterate
for (int i = 0; i < tkn.SubTkns().length; i++) {
GfmlTkn subTkn = (GfmlTkn)tkn.SubTkns()[i];
GfmlTkn_mok subMok = GfmlTkn_mok.new_();
InitTkn(subMok, subTkn);
mok.Subs_(subMok);
}
}
}
public static GfmlTkn_mok[] Xto_bry(String... ary) {
GfmlTkn_mok[] rv = new GfmlTkn_mok[ary.length];
for (int i = 0; i < rv.length; i++)
rv[i] = GfmlTkn_mok.new_().Raw_(ary[i]);
return rv;
}
public static void tst(TfdsTstr_fxt tstr, GfmlTkn_mok expd, GfmlTkn_mok actl) {
expd = NullObj(expd); actl = NullObj(actl);
if (expd.Raw() != null) tstr.Eq_str(expd.Raw(), actl.Raw(), "raw");
int max = tstr.List_Max(expd.Subs(), actl.Subs());
for (int i = 0; i < max; i++) {
GfmlTkn_mok expdSub = (GfmlTkn_mok)tstr.List_FetchAtOrNull(expd.Subs(), i);
GfmlTkn_mok actlSub = (GfmlTkn_mok)tstr.List_FetchAtOrNull(actl.Subs(), i);
tstr.SubName_push(Int_.To_str(i));
tst(tstr, expdSub, actlSub);
tstr.SubName_pop();
}
}
static GfmlTkn_mok NullObj(GfmlTkn_mok v) {return v == null ? GfmlTkn_mok.new_().Raw_(String_.Null_mark) : v;}
}