mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Refactor: Refactor baselib; merge Array_ and Bool_
This commit is contained in:
@@ -1,20 +1,21 @@
|
||||
/*
|
||||
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.*;
|
||||
class IntObjHash_base {
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
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) {
|
||||
@@ -55,7 +56,7 @@ class IntObjHash_base {
|
||||
void ExpandRootAry(int key) {
|
||||
int newRootAryBound = (key / subAryLength) + 1;
|
||||
Object[] newRootAry = new Object[newRootAryBound];
|
||||
Array_.Copy(rootAry, newRootAry);
|
||||
ArrayUtl.Copy(rootAry, newRootAry);
|
||||
rootAry = newRootAry;
|
||||
maxKey = (rootAry.length * subAryLength) - 1;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
/*
|
||||
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.*;
|
||||
import gplx.core.strings.*;
|
||||
public class GfmlDocPos implements CompareAble {
|
||||
import gplx.objects.lists.CompareAble;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
public class GfmlDocPos implements CompareAble {
|
||||
public String Path() {if (path == null) MakePath(); return path;} private String path;
|
||||
public int compareTo(Object obj) {
|
||||
/* Same: same coord (ex: 0_1 = 0_1)
|
||||
@@ -23,14 +25,14 @@ public class GfmlDocPos implements CompareAble {
|
||||
Less: lower level (ex: 0_1 < 0) or lower idx (ex: 0_1 < 0_0) */
|
||||
GfmlDocPos comp = (GfmlDocPos)obj;
|
||||
for (int i = 0; i < ary.length; i++) {
|
||||
if (i >= comp.ary.length) return CompareAble_.More; // more ary than comp and whatever ary they share are equal; must be more;
|
||||
if (i >= comp.ary.length) return CompareAbleUtl.More; // more ary than comp and whatever ary they share are equal; must be more;
|
||||
int origVal = ary[i];
|
||||
int compVal = comp.ary[i];
|
||||
if (origVal == compVal) continue; // indexes are equal; continue to next
|
||||
else if (origVal < compVal) return CompareAble_.Less;
|
||||
else if (origVal > compVal) return CompareAble_.More;
|
||||
else if (origVal < compVal) return CompareAbleUtl.Less;
|
||||
else if (origVal > compVal) return CompareAbleUtl.More;
|
||||
}
|
||||
if (ary.length < comp.ary.length) return CompareAble_.Less; // less ary than comp, and whatever ary they share are equal; must be less
|
||||
if (ary.length < comp.ary.length) return CompareAbleUtl.Less; // less ary than comp, and whatever ary they share are equal; must be less
|
||||
return Int_.Compare(idx, comp.idx); // compare idx
|
||||
}
|
||||
public GfmlDocPos NewClone() {return new GfmlDocPos(ary, idx);}
|
||||
|
||||
@@ -14,6 +14,7 @@ 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.lists.CompareAbleUtl;
|
||||
interface GfmlScopeItm {
|
||||
String Key();
|
||||
GfmlDocPos DocPos();
|
||||
@@ -57,7 +58,7 @@ class GfmlScopeList {
|
||||
GfmlScopeItm rv = null;
|
||||
for (Object itemObj : list) {
|
||||
GfmlScopeItm itm = (GfmlScopeItm)itemObj;
|
||||
if (CompareAble_.Is(CompareAble_.More_or_same, pos, itm.DocPos()))
|
||||
if (CompareAbleUtl.Is(CompareAbleUtl.More_or_same, pos, itm.DocPos()))
|
||||
rv = itm;
|
||||
else
|
||||
break; // ASSUME: insertion is done in order; first lessThan means rest will also be lessThan
|
||||
|
||||
@@ -14,6 +14,7 @@ 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.lists.CompareAbleUtl;
|
||||
import org.junit.*;
|
||||
public class z015_GfmlDocPos_tst {
|
||||
GfmlDocPos root = GfmlDocPos_.Root;
|
||||
@@ -31,19 +32,19 @@ public class z015_GfmlDocPos_tst {
|
||||
@Test public void CompareTo_same() {
|
||||
GfmlDocPos lhs = root.NewDown(0);
|
||||
GfmlDocPos rhs = root.NewDown(0);
|
||||
tst_CompareTo(lhs, rhs, CompareAble_.Same);
|
||||
tst_CompareTo(lhs, rhs, CompareAbleUtl.Same);
|
||||
}
|
||||
@Test public void CompareTo_diffIndex() {
|
||||
GfmlDocPos lhs = root.NewDown(0);
|
||||
GfmlDocPos rhs = root.NewDown(1);
|
||||
tst_CompareTo(lhs, rhs, CompareAble_.Less);
|
||||
tst_CompareTo(rhs, lhs, CompareAble_.More);
|
||||
tst_CompareTo(lhs, rhs, CompareAbleUtl.Less);
|
||||
tst_CompareTo(rhs, lhs, CompareAbleUtl.More);
|
||||
}
|
||||
@Test public void CompareTo_diffLevel() {
|
||||
GfmlDocPos lhs = root;
|
||||
GfmlDocPos rhs = root.NewDown(0);
|
||||
tst_CompareTo(lhs, rhs, CompareAble_.Less);
|
||||
tst_CompareTo(rhs, lhs, CompareAble_.More);
|
||||
tst_CompareTo(lhs, rhs, CompareAbleUtl.Less);
|
||||
tst_CompareTo(rhs, lhs, CompareAbleUtl.More);
|
||||
}
|
||||
void tst_Path(GfmlDocPos pos, String expdPath) {Tfds.Eq(expdPath, pos.Path());}
|
||||
void tst_CompareTo(GfmlDocPos lhs, GfmlDocPos rhs, int expd) {Tfds.Eq(expd, lhs.compareTo(rhs));}
|
||||
|
||||
@@ -14,6 +14,7 @@ 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;
|
||||
import org.junit.*;
|
||||
public class z016_GfmlScopeList_tst {
|
||||
@Before public void setup() {
|
||||
@@ -38,7 +39,7 @@ public class z016_GfmlScopeList_tst {
|
||||
GfmlDocPos docPos_(int... ary) {
|
||||
int last = ary.length - 1;
|
||||
int idx = ary[last];
|
||||
int[] levels = (int[])Array_.Resize(ary, last);
|
||||
int[] levels = (int[])ArrayUtl.Resize(ary, last);
|
||||
return new GfmlDocPos(levels, idx);
|
||||
}
|
||||
void run_Add(GfmlScopeList list, GfmlScopeItm... ary) {
|
||||
|
||||
Reference in New Issue
Block a user