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

Refactor: Refactor Dbmeta classes; Rename methods of list and hash classes

This commit is contained in:
gnosygnu
2021-12-01 07:49:25 -05:00
parent 231e10bc19
commit 197e0aa863
846 changed files with 8560 additions and 8513 deletions

View File

@@ -1,26 +1,26 @@
/*
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
*/
/*
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.*;
public class GfmlAtr implements GfmlItm {
public class GfmlAtr implements GfmlItm {
public int ObjType() {return GfmlObj_.Type_atr;}
public GfmlTkn KeyTkn() {return keyTkn;} GfmlTkn keyTkn; public String Key() {return keyTkn.Val();}
public GfmlTkn DatTkn() {return datTkn;} GfmlTkn datTkn;
public GfmlType Type() {return type;} GfmlType type;
public boolean KeyedSubObj() {return true;}
public int SubObjs_Count() {return subObjs.Count();}
public int SubObjs_Count() {return subObjs.Len();}
public GfmlObj SubObjs_GetAt(int i) {return (GfmlObj)subObjs.Get_at(i);} GfmlObjList subObjs = GfmlObjList.new_(); // PERF?: make capacity 3 instead of 8
public void SubObjs_Add(GfmlObj o) {subObjs.Add(o);}
public String To_str() {return String_.Concat(this.Key(), "=", this.DatTkn().Val());}
@@ -41,13 +41,13 @@ public class GfmlAtr implements GfmlItm {
int idx = GetTknIdx(oldTkn);
GfmlTkn tkn = MakeTkn(oldTkn, s);
if (idx != -1)
subObjs.Del_at(idx);
subObjs.DelAt(idx);
if (idx == -1) idx = 0;
subObjs.Add_at(tkn, idx);
return tkn;
}
int GetTknIdx(GfmlTkn t) {
for (int i = 0; i < subObjs.Count(); i++) {
for (int i = 0; i < subObjs.Len(); i++) {
GfmlObj obj = (GfmlObj)subObjs.Get_at(i);
if (obj == t) return i;
}

View File

@@ -1,18 +1,18 @@
/*
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
*/
/*
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.*;
public class GfmlDoc_ {
public static GfmlDoc parse_any_eol_(String raw) {return parse(String_.Replace(raw, String_.CrLf, String_.Lf));}
@@ -35,7 +35,7 @@ class GfmlUsrMsgs {
}
public static Err gfmlParseError(GfmlBldr bldr) {
Err rv = Err_.new_wo_type("gfml parse error");
for (int i = 0; i < bldr.Doc().UsrMsgs().Count(); i++) {
for (int i = 0; i < bldr.Doc().UsrMsgs().Len(); i++) {
UsrMsg um = (UsrMsg)bldr.Doc().UsrMsgs().Get_at(i);
rv.Args_add("err" + Int_.To_str(i), um.To_str());
}

View File

@@ -13,10 +13,10 @@ 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.*;
public class GfmlItmHnds {
public int Count() {return list.Count();} List_adp list = List_adp_.New();
public GfmlNde Get_at(int idx) {return (GfmlNde)list.Get_at(idx);}
public void Add(GfmlNde nde) {list.Add(nde);}
public static GfmlItmHnds new_() {return new GfmlItmHnds();} GfmlItmHnds() {}
}
public int Count() {return list.Len();} List_adp list = List_adp_.New();
public GfmlNde Get_at(int idx) {return (GfmlNde)list.Get_at(idx);}
public void Add(GfmlNde nde) {list.Add(nde);}
public static GfmlItmHnds new_() {return new GfmlItmHnds();} GfmlItmHnds() {}
}

View File

@@ -15,10 +15,10 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfml; import gplx.*;
public class GfmlItmKeys {
public int Count() {return list.Count();}
public int Count() {return list.Len();}
public boolean Has(String key) {return hash.Has(key);}
public GfmlItm Get_at(int i) {return (GfmlItm)list.Get_at(i);}
public GfmlItm Get_by(String key) {return (GfmlItm)hash.Get_by(key);}
public GfmlItm Get_by(String key) {return (GfmlItm)hash.GetByOrNull(key);}
public String FetchDataOr(String key, String or) {
GfmlAtr atr = FetchAtr(key);
return (atr == null) ? or : atr.DatTkn().Val();
@@ -52,7 +52,7 @@ public class GfmlItmKeys {
}
if (toDel != null) list.Del(toDel);
}
GfmlAtr FetchAtr(String key) {return GfmlAtr.as_(hash.Get_by(key));}
GfmlAtr FetchAtr(String key) {return GfmlAtr.as_(hash.GetByOrNull(key));}
List_adp list = List_adp_.New(); Hash_adp hash = Hash_adp_.New();
public static GfmlItmKeys new_() {return new GfmlItmKeys();} GfmlItmKeys() {}
@gplx.Internal protected static final String NullKey = "";

View File

@@ -1,27 +1,27 @@
/*
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
*/
/*
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.*;
public class GfmlNde implements GfmlItm {
public class GfmlNde implements GfmlItm {
public static final int OBJ_TYPE = GfmlObj_.Type_nde;
public int ObjType() {return objType;} int objType = GfmlObj_.Type_nde;
public GfmlTkn KeyTkn() {return keyTkn;} public String Key() {return keyTkn.Val();} GfmlTkn keyTkn = GfmlTkn_.Null;
public GfmlType Type() {return type;} GfmlType type;
public boolean KeyedSubObj() {return keyedSubObj;} public GfmlNde KeyedSubObj_(boolean v) {keyedSubObj = v; return this;} private boolean keyedSubObj;
public int ChainId() {return chainId;} public GfmlNde ChainId_(int v) {chainId = v; return this;} int chainId; // can use boolean chainHead, but this is easier for debugging
public int SubObjs_Count() {return subObjs.Count();} GfmlObjList subObjs = GfmlObjList.new_();
public int SubObjs_Count() {return subObjs.Len();} GfmlObjList subObjs = GfmlObjList.new_();
public GfmlObj SubObjs_GetAt(int i) {return (GfmlObj)subObjs.Get_at(i);}
public void SubObjs_Add(GfmlObj gobj) {
subObjs.Add(gobj);
@@ -61,8 +61,8 @@ public class GfmlNde implements GfmlItm {
// a:{} -> a:{b:{}}
}
int PosOf(boolean fwd, String... find) {
int bgn = fwd ? 0 : subObjs.Count() - 1;
int end = fwd ? subObjs.Count() : 0;
int bgn = fwd ? 0 : subObjs.Len() - 1;
int end = fwd ? subObjs.Len() : 0;
int dif = fwd ? 1 : -1;
for (int i = bgn; i != end; i+=dif) {
GfmlObj subObj = (GfmlObj)subObjs.Get_at(i);

View File

@@ -1,26 +1,26 @@
/*
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
*/
/*
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.*;
interface GfmlScopeItm {
interface GfmlScopeItm {
String Key();
GfmlDocPos DocPos();
}
class GfmlScopeRegy {
public boolean Has(String key) {
GfmlScopeList list = (GfmlScopeList)hash.Get_by(key); if (list == null) return false;
GfmlScopeList list = (GfmlScopeList)hash.GetByOrNull(key); if (list == null) return false;
return list.Count() > 0;
}
public void Add(GfmlScopeItm itm) {
@@ -28,16 +28,16 @@ class GfmlScopeRegy {
list.Add(itm);
}
public void Del(GfmlScopeItm itm) {
GfmlScopeList list = (GfmlScopeList)hash.Get_by(itm.Key()); if (list == null) return;
GfmlScopeList list = (GfmlScopeList)hash.GetByOrNull(itm.Key()); if (list == null) return;
list.Del(itm);
if (list.Count() == 0) hash.Del(itm.Key());
}
public GfmlScopeItm Get_by(String key, GfmlDocPos pos) {
GfmlScopeList list = (GfmlScopeList)hash.Get_by(key); if (list == null) return null;
GfmlScopeList list = (GfmlScopeList)hash.GetByOrNull(key); if (list == null) return null;
return list.Get_by(pos);
}
GfmlScopeList ItmOrNew(String key) {
GfmlScopeList rv = (GfmlScopeList)hash.Get_by(key);
GfmlScopeList rv = (GfmlScopeList)hash.GetByOrNull(key);
if (rv == null) {
rv = GfmlScopeList.new_(key);
hash.Add(key, rv);
@@ -49,11 +49,11 @@ class GfmlScopeRegy {
}
class GfmlScopeList {
public String Key() {return key;} private String key;
public int Count() {return list.Count();}
public int Count() {return list.Len();}
public void Add(GfmlScopeItm itm) {list.Add(itm);}
public void Del(GfmlScopeItm itm) {list.Del(itm);}
public GfmlScopeItm Get_by(GfmlDocPos pos) {
if (list.Count() == 0) return null;
if (list.Len() == 0) return null;
GfmlScopeItm rv = null;
for (Object itemObj : list) {
GfmlScopeItm itm = (GfmlScopeItm)itemObj;