mirror of https://github.com/gnosygnu/xowa
parent
9509363f46
commit
096045614c
@ -0,0 +1,31 @@
|
||||
/*
|
||||
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 org.junit.*;
|
||||
public class Bool__tst {
|
||||
private final Bool__fxt fxt = new Bool__fxt();
|
||||
@Test public void Compare() {
|
||||
fxt.Test__compare(Bool_.Y, Bool_.Y, CompareAble_.Same);
|
||||
fxt.Test__compare(Bool_.N, Bool_.N, CompareAble_.Same);
|
||||
fxt.Test__compare(Bool_.N, Bool_.Y, CompareAble_.Less);
|
||||
fxt.Test__compare(Bool_.Y, Bool_.N, CompareAble_.More);
|
||||
}
|
||||
}
|
||||
class Bool__fxt {
|
||||
public void Test__compare(boolean lhs, boolean rhs, int expd) {Tfds.Eq(expd, Bool_.Compare(lhs, rhs));}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
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.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
public class Bfr_fmt_arg {
|
||||
public Bfr_fmt_arg(byte[] key, Bfr_arg arg) {this.Key = key; this.Arg = arg;}
|
||||
public byte[] Key;
|
||||
public Bfr_arg Arg;
|
||||
public static final Bfr_fmt_arg[] Ary_empty = new Bfr_fmt_arg[0];
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
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.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
public class Bry_fmt {
|
||||
private byte[] src;
|
||||
private Bry_fmt_itm[] itms; private int itms_len;
|
||||
private Bfr_fmt_arg[] args = Bfr_fmt_arg.Ary_empty;
|
||||
private byte[][] keys = Bry_.Ary_empty;
|
||||
private boolean dirty;
|
||||
public Bry_fmt(byte[] src, byte[][] keys, Bfr_fmt_arg[] args) {
|
||||
dirty = true;
|
||||
this.src = src; this.keys = keys; this.args = args;
|
||||
}
|
||||
public Bry_fmt Fmt_(String v) {dirty = true; src = Bry_.new_u8(v); return this;}
|
||||
public Bry_fmt Args_(Bfr_fmt_arg... v) {dirty = true; args = v; return this;}
|
||||
public Bry_fmt Keys_(byte[]... v) {dirty = true; keys = v; return this;}
|
||||
public void Bld_bfr_many(Bry_bfr bfr, Object... vals) {
|
||||
if (dirty) Compile();
|
||||
int vals_len = vals.length;
|
||||
for (int i = 0; i < itms_len; ++i) {
|
||||
Bry_fmt_itm itm = itms[i];
|
||||
switch (itm.Tid) {
|
||||
case Bry_fmt_itm.Tid__txt: bfr.Add_mid(src, itm.Src_bgn, itm.Src_end); break;
|
||||
case Bry_fmt_itm.Tid__arg: itm.Arg.Bfr_arg__add(bfr);break;
|
||||
case Bry_fmt_itm.Tid__key:
|
||||
int idx = itm.Key_idx;
|
||||
if (idx > -1 && idx < vals_len)
|
||||
bfr.Add_obj(vals[idx]);
|
||||
else
|
||||
bfr.Add_mid(src, itm.Src_bgn, itm.Src_end);
|
||||
break;
|
||||
default: throw Err_.new_unhandled(itm.Tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Compile() {
|
||||
dirty = false;
|
||||
this.itms = Bry_fmt_parser_.Parse(Byte_ascii.Tilde, Byte_ascii.Curly_bgn, Byte_ascii.Curly_end, args, keys, src);
|
||||
this.itms_len = itms.length;
|
||||
}
|
||||
public static Bry_fmt New(String fmt, String... keys) {return new Bry_fmt(Bry_.new_u8(fmt), Bry_.Ary(keys), Bfr_fmt_arg.Ary_empty);}
|
||||
}
|
||||
class Bry_fmt_itm {
|
||||
public Bry_fmt_itm(int tid, int src_bgn, int src_end) {
|
||||
this.Tid = tid;
|
||||
this.Src_bgn = src_bgn;
|
||||
this.Src_end = src_end;
|
||||
}
|
||||
public int Tid;
|
||||
public int Src_bgn;
|
||||
public int Src_end;
|
||||
public int Key_idx;
|
||||
public Bfr_arg Arg;
|
||||
|
||||
public static final int Tid__txt = 0, Tid__key = 1, Tid__arg = 2;
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
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.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
class Bry_fmt_parser_ {
|
||||
public static Bry_fmt_itm[] Parse(byte escape, byte grp_bgn, byte grp_end, Bfr_fmt_arg[] args, byte[][] keys, byte[] src) {
|
||||
int src_len = src.length;
|
||||
int pos = 0;
|
||||
int txt_bgn = -1;
|
||||
int key_idx = -1;
|
||||
Hash_adp_bry keys_hash = Hash_adp_bry.cs();
|
||||
List_adp list = List_adp_.new_();
|
||||
while (true) {
|
||||
boolean is_last = pos == src_len;
|
||||
byte b = is_last ? escape : src[pos];
|
||||
if (b == escape) {
|
||||
if (txt_bgn != -1) list.Add(new Bry_fmt_itm(Bry_fmt_itm.Tid__txt, txt_bgn, pos));
|
||||
if (is_last) break;
|
||||
++pos;
|
||||
if (pos == src_len) throw Err_.new_("bry_fmtr", "fmt cannot end with escape", "escape", Byte_ascii.To_str(escape), "raw", src);
|
||||
b = src[pos];
|
||||
if (b == escape) {
|
||||
list.Add(new Bry_fmt_itm(Bry_fmt_itm.Tid__txt, pos, pos + 1));
|
||||
++pos;
|
||||
}
|
||||
else if (b == grp_bgn) {
|
||||
++pos;
|
||||
int grp_end_pos = Bry_find_.Find_fwd(src, grp_end, pos); if (grp_end_pos == Bry_find_.Not_found) throw Err_.new_("bry_fmtr", "grp_end missing", "grp_bgn", Byte_ascii.To_str(grp_bgn), "grp_end", Byte_ascii.To_str(grp_end), "raw", src);
|
||||
byte[] key_bry = Bry_.Mid(src, pos, grp_end_pos);
|
||||
Bry_fmt_itm key_itm = (Bry_fmt_itm)keys_hash.Get_by_bry(key_bry);
|
||||
if (key_itm == null) {
|
||||
key_itm = new Bry_fmt_itm(Bry_fmt_itm.Tid__key, pos - 2, grp_end_pos + 1); // -2 to get "~{"; +1 to get "}"
|
||||
key_itm.Key_idx = ++key_idx;
|
||||
keys_hash.Add(key_bry, key_itm);
|
||||
}
|
||||
list.Add(key_itm);
|
||||
pos = grp_end_pos + 1;
|
||||
}
|
||||
else throw Err_.new_("bry_fmtr", "escape must be followed by escape or group_bgn", "escape", Byte_ascii.To_str(escape), "group_bgn", Byte_ascii.To_str(escape), "raw", src);
|
||||
txt_bgn = -1;
|
||||
}
|
||||
else {
|
||||
if (txt_bgn == -1) txt_bgn = pos;
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
Bry_fmt_itm[] rv = (Bry_fmt_itm[])list.To_ary_and_clear(Bry_fmt_itm.class);
|
||||
int len = args.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Bfr_fmt_arg arg = args[i];
|
||||
Bry_fmt_itm key_itm = (Bry_fmt_itm)keys_hash.Get_by(arg.Key); if (key_itm == null) continue;
|
||||
key_itm.Tid = Bry_fmt_itm.Tid__arg;
|
||||
key_itm.Arg = arg.Arg;
|
||||
}
|
||||
len = keys.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
byte[] key = keys[i];
|
||||
Bry_fmt_itm key_itm = (Bry_fmt_itm)keys_hash.Get_by(key); if (key_itm == null) throw Err_.new_("bry_fmtr", "could not find key", "key", key);
|
||||
key_itm.Key_idx = i;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
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.core.brys.fmtrs; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
|
||||
import org.junit.*;
|
||||
public class Bry_fmt_tst {
|
||||
private final Bry_fmt_fxt fxt = new Bry_fmt_fxt();
|
||||
@Test public void Text() {fxt.Clear().Fmt("a").Test("a");}
|
||||
@Test public void Key__basic() {fxt.Clear().Fmt("~{key}").Vals("a").Test("a");}
|
||||
@Test public void Key__mult() {fxt.Clear().Fmt("~{key1}~{key2}").Vals("a", "b").Test("ab");}
|
||||
@Test public void Key__repeat() {fxt.Clear().Fmt("~{key1}~{key1}").Vals("a").Test("aa");}
|
||||
@Test public void Key__missing() {fxt.Clear().Fmt("~{key}").Test("~{key}");}
|
||||
@Test public void Tilde() {fxt.Clear().Fmt("~~~~").Test("~~");}
|
||||
@Test public void Simple() {fxt.Clear().Fmt("0~{key1}1~{key2}2").Vals(".", ",").Test("0.1,2");}
|
||||
@Test public void Arg() {fxt.Clear().Fmt("~{custom}").Args("custom", new Bfr_fmt_arg_mok(123)).Test("123");}
|
||||
@Test public void Keys() {fxt.Clear().Fmt("~{b}~{c}~{a}").Keys("a", "b", "c").Vals("a", "b", "c").Test("bca");}
|
||||
}
|
||||
class Bfr_fmt_arg_mok implements Bfr_arg {
|
||||
private int num;
|
||||
public Bfr_fmt_arg_mok(int num) {this.num = num;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
bfr.Add_int_variable(num);
|
||||
}
|
||||
}
|
||||
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 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;}
|
||||
public Bry_fmt_fxt Vals(Object... vals) {this.vals = vals; return this;}
|
||||
public Bry_fmt_fxt Args(String key, Bfr_arg arg) {fmt.Args_(new Bfr_fmt_arg(Bry_.new_u8(key), arg)); return this;}
|
||||
public Bry_fmt_fxt Keys(String... keys) {fmt.Keys_(Bry_.Ary(keys)); return this;}
|
||||
public void Test(String expd) {
|
||||
fmt.Bld_bfr_many(bfr, vals);
|
||||
Tfds.Eq(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
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.core.brys; import gplx.*; import gplx.core.*;
|
||||
import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Bit_heap_rdr {
|
||||
private final byte[] hzip_int_bry = new byte[5];
|
||||
public int Cur_val() {return cur_val;} private int cur_val;
|
||||
public int Cur_bits() {return cur_bits;} private int cur_bits;
|
||||
public int Cur_pos() {return cur_pos;} private int cur_pos;
|
||||
public byte[] Src() {return src;} private byte[] src;
|
||||
public int Src_end() {return src_end;} private int src_end;
|
||||
public void Load(byte[] src, int src_bgn, int src_end) {
|
||||
this.src = src; this.cur_pos = src_bgn; this.src_end = src_end;
|
||||
this.cur_val = 0; this.cur_bits = 0;
|
||||
}
|
||||
public boolean Get_bool() {
|
||||
Get_bgn(cur_bits);
|
||||
int old_val = cur_val;
|
||||
this.cur_val = cur_val >> 1;
|
||||
int comp_val = cur_val << 1;
|
||||
boolean rv = (old_val - comp_val) == 1;
|
||||
Get_end(1);
|
||||
return rv;
|
||||
}
|
||||
public byte Get_byte(int bits) {
|
||||
int old_bits = bits;
|
||||
int new_bits = cur_bits + bits;
|
||||
boolean again = false;
|
||||
if (new_bits > 7 && cur_bits > 0) {
|
||||
old_bits = 8 - cur_bits;
|
||||
again = true;
|
||||
new_bits -= 8;
|
||||
}
|
||||
int rv = Get_byte_private(old_bits, cur_bits);
|
||||
if (again) {
|
||||
Get_end(old_bits);
|
||||
int new_val = Get_byte_private(new_bits, 0);
|
||||
rv += new_val << old_bits;
|
||||
}
|
||||
Get_end(new_bits);
|
||||
return (byte)rv;
|
||||
}
|
||||
public int Get_int_hzip(int reqd_len) {
|
||||
int full_len = reqd_len; int bgn_idx = 0;
|
||||
byte b0 = Get_byte(8);
|
||||
switch (b0) {
|
||||
case Xoh_hzip_int.prefix__b256__2: full_len = 2; bgn_idx = 1; break;
|
||||
case Xoh_hzip_int.prefix__b256__3: full_len = 3; bgn_idx = 1; break;
|
||||
case Xoh_hzip_int.prefix__b256__4: full_len = 4; bgn_idx = 1; break;
|
||||
case Xoh_hzip_int.prefix__b256__5: full_len = 5; bgn_idx = 1; break;
|
||||
}
|
||||
hzip_int_bry[0] = b0;
|
||||
for (int i = 1; i < full_len; ++i)
|
||||
hzip_int_bry[i] = Get_byte(8);
|
||||
return Xoh_hzip_int.To_int_by_bry(hzip_int_bry, bgn_idx, full_len, Byte_.Zero, 256);
|
||||
}
|
||||
private byte Get_byte_private(int bits, int chk_bits) {
|
||||
Get_bgn(chk_bits);
|
||||
int old_val = cur_val;
|
||||
this.cur_val = cur_val >> bits;
|
||||
int comp_val = cur_val << bits;
|
||||
byte rv = (byte)(old_val - comp_val);
|
||||
return rv;
|
||||
}
|
||||
private void Get_bgn(int chk_bits) {
|
||||
if (chk_bits == 0) cur_val = src[cur_pos] & 0xFF; // PATCH.JAVA:need to convert to unsigned byte
|
||||
}
|
||||
private void Get_end(int bits) {
|
||||
int new_bits = cur_bits + bits;
|
||||
if (new_bits == 8) {
|
||||
cur_bits = 0;
|
||||
cur_pos += 1;
|
||||
}
|
||||
else
|
||||
cur_bits = new_bits;
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
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.core.brys; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
public class Bit_heap_rdr_tst {
|
||||
private final Bit_heap_rdr_fxt fxt = new Bit_heap_rdr_fxt();
|
||||
@Test public void Get_bool() {
|
||||
fxt.Load(255);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur(127, 1, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 63, 2, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 31, 3, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 15, 4, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 7, 5, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 3, 6, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 1, 7, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 0, 0, 1);
|
||||
|
||||
fxt.Load(0);
|
||||
fxt.Test__get_bool(Bool_.N).Test__cur( 0, 1, 0);
|
||||
|
||||
fxt.Load(6);
|
||||
fxt.Test__get_bool(Bool_.N).Test__cur( 3, 1, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 1, 2, 0);
|
||||
fxt.Test__get_bool(Bool_.Y).Test__cur( 0, 3, 0);
|
||||
}
|
||||
@Test public void Get_byte() {
|
||||
fxt.Load(255).Test__get_byte(2, 3).Test__cur(63, 2, 0);
|
||||
|
||||
fxt.Load(255, 3);
|
||||
fxt.Test__get_byte(7, 127);
|
||||
fxt.Test__get_byte(3, 7);
|
||||
|
||||
fxt.Load(10);
|
||||
fxt.Test__get_bool(false);
|
||||
fxt.Test__get_byte(3, 5);
|
||||
}
|
||||
@Test public void Get_int_hzip() {
|
||||
fxt.Load(100).Test__get_int_hzip(1, 100).Test__cur(0, 0, 1);
|
||||
fxt.Load(253, 1, 44).Test__get_int_hzip(1, 300).Test__cur(0, 0, 3);
|
||||
fxt.Load(0, 100).Test__get_int_hzip(2, 100).Test__cur(0, 0, 2);
|
||||
fxt.Load(250, 3, 88, 0).Test__get_bool(Bool_.N).Test__get_int_hzip(1, 300).Test__cur(0, 1, 3);
|
||||
}
|
||||
}
|
||||
class Bit_heap_rdr_fxt {
|
||||
private final Bit_heap_rdr heap = new Bit_heap_rdr();
|
||||
public Bit_heap_rdr_fxt Load(int... src) {
|
||||
byte[] bry = Bry_.New_by_ints(src);
|
||||
heap.Load(bry, 0, bry.length);
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_rdr_fxt Test__get_bool(boolean expd) {
|
||||
Tfds.Eq_bool(expd, heap.Get_bool());
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_rdr_fxt Test__get_byte(int bits, int expd) {
|
||||
Tfds.Eq_byte((byte)expd, heap.Get_byte(bits));
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_rdr_fxt Test__get_int_hzip(int reqd, int expd) {
|
||||
Tfds.Eq_int(expd, heap.Get_int_hzip(reqd));
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_rdr_fxt Test__cur(int cur_val, int cur_bits, int cur_pos) {
|
||||
Tfds.Eq_int(cur_val, heap.Cur_val(), "val");
|
||||
Tfds.Eq_int(cur_bits, heap.Cur_bits(), "bits");
|
||||
Tfds.Eq_int(cur_pos, heap.Cur_pos(), "pos");
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
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.core.brys; import gplx.*; import gplx.core.*;
|
||||
public class Bit_heap_wtr {
|
||||
private final gplx.xowa.htmls.core.hzips.Xoh_hzip_int hzip_int = new gplx.xowa.htmls.core.hzips.Xoh_hzip_int().Mode_is_b256_(true);
|
||||
private final Bry_bfr hzip_int_bfr = Bry_bfr.reset_(5);
|
||||
public int Cur() {return cur;} private int cur;
|
||||
public int Cur_bits() {return cur_bits;} private int cur_bits;
|
||||
public Bry_bfr Heap() {return heap;} private final Bry_bfr heap = Bry_bfr.new_();
|
||||
public void Clear() {heap.Clear(); cur = 0; cur_bits = 0;}
|
||||
public void Add_bool(boolean v) {
|
||||
if (v)
|
||||
cur += Pow_ary[cur_bits];
|
||||
if (cur_bits == 7) {
|
||||
heap.Add_byte((byte)cur);
|
||||
cur = 0;
|
||||
cur_bits = 0;
|
||||
}
|
||||
else
|
||||
++cur_bits;
|
||||
}
|
||||
public void Add_byte(byte val_byte) {
|
||||
int val_int = val_byte & 0xFF; // PATCH.JAVA:need to convert to unsigned byte
|
||||
if (cur_bits == 0)
|
||||
heap.Add_byte(val_byte);
|
||||
else {
|
||||
heap.Add_byte((byte)(cur + (val_int << cur_bits)));
|
||||
this.cur = val_int >> cur_bits;
|
||||
}
|
||||
}
|
||||
public void Add_byte(int val_bits, int val) {
|
||||
int total_bits = cur_bits + val_bits;
|
||||
int new_val = cur + (val << cur_bits);
|
||||
if (total_bits < 8) {
|
||||
this.cur_bits = total_bits;
|
||||
this.cur = new_val;
|
||||
}
|
||||
else {
|
||||
heap.Add_byte((byte)new_val);
|
||||
this.cur = val >> (8 - cur_bits);
|
||||
this.cur_bits = total_bits - 8;
|
||||
}
|
||||
}
|
||||
public void Add_int_hzip(int reqd_len, int val) {
|
||||
hzip_int.Encode(reqd_len, hzip_int_bfr, val);
|
||||
int len = hzip_int_bfr.Len();
|
||||
byte[] hzip_bry = hzip_int_bfr.Bfr();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
byte b = hzip_bry[i];
|
||||
Add_byte(8, b & 0xFF); // PATCH.JAVA:need to convert to unsigned byte
|
||||
}
|
||||
hzip_int_bfr.Clear();
|
||||
}
|
||||
public void Save(Bry_bfr bfr) {}
|
||||
public static final int[] Pow_ary = new int[] {1, 2, 4, 8, 16, 32, 64, 128, 256};
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
/*
|
||||
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.core.brys; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
public class Bit_heap_wtr_tst {
|
||||
private final Bit_heap_wtr_fxt fxt = new Bit_heap_wtr_fxt();
|
||||
@Test public void Add_bool() {
|
||||
fxt.Clear().Add_bool(Bool_.Y).Test__vals(1, 1);
|
||||
fxt.Clear().Add_bool(Bool_.N).Test__vals(1, 0);
|
||||
fxt.Clear().Add_bool(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y).Test__vals(4, 15);
|
||||
fxt.Clear().Add_bool(Bool_.Y, Bool_.N, Bool_.N, Bool_.Y).Test__vals(4, 9);
|
||||
fxt.Clear().Add_bool(8, Bool_.Y).Test__vals(0, 0, 255);
|
||||
}
|
||||
@Test public void Add_byte() {
|
||||
fxt.Clear().Add_byte(255).Test__vals(0, 0, 255);
|
||||
}
|
||||
@Test public void Add_bool_byte() {
|
||||
fxt.Clear().Add_bool(Bool_.N).Add_byte(255).Test__vals(1, 127, 254);
|
||||
fxt.Clear().Add_bool(Bool_.Y).Add_byte(255).Test__vals(1, 127, 255);
|
||||
fxt.Clear().Add_bool(Bool_.Y, Bool_.Y, Bool_.Y, Bool_.Y).Add_byte(255).Test__vals(4, 15, 255);
|
||||
}
|
||||
@Test public void Add_byte_digits() {
|
||||
fxt.Clear().Add_byte(4, 15).Test__vals(4, 15);
|
||||
fxt.Clear().Add_byte(7, 127).Add_byte(2, 3).Test__vals(1, 1, 255);
|
||||
|
||||
fxt.Clear().Add_byte(3, 7).Add_byte(3, 7).Test__vals(6, 63);
|
||||
fxt.Clear().Add_byte(6, 63).Add_byte(3, 7).Test__vals(1, 1, 255);
|
||||
|
||||
fxt.Clear().Add_byte(3, 6).Add_byte(3, 6).Test__vals(6, 54);
|
||||
}
|
||||
@Test public void Add_int_hzip() {
|
||||
fxt.Clear().Add_int_hzip(1, 100).Test__vals(0, 0, 100);
|
||||
fxt.Clear().Add_int_hzip(1, 300).Test__vals(0, 0, 253, 1, 44);
|
||||
fxt.Clear().Add_int_hzip(2, 100).Test__vals(0, 0, 0, 100);
|
||||
fxt.Clear().Add_bool(Bool_.N).Add_int_hzip(1, 300).Test__vals(1, 0, 250, 3, 88);
|
||||
}
|
||||
}
|
||||
class Bit_heap_wtr_fxt {
|
||||
private final Bit_heap_wtr heap = new Bit_heap_wtr();
|
||||
public Bit_heap_wtr_fxt Clear() {heap.Clear(); return this;}
|
||||
public Bit_heap_wtr_fxt Add_bool(int len, boolean v) {
|
||||
boolean[] ary = new boolean[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
ary[i] = v;
|
||||
Add_bool(ary);
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_wtr_fxt Add_bool(boolean... v) {
|
||||
int len = v.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
heap.Add_bool(v[i]);
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_wtr_fxt Add_byte(int... v) {
|
||||
int len = v.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
heap.Add_byte((byte)v[i]);
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_wtr_fxt Add_byte(int bits, int val) {
|
||||
heap.Add_byte(bits, (byte)val);
|
||||
return this;
|
||||
}
|
||||
public Bit_heap_wtr_fxt Add_int_hzip(int reqd, int val) {
|
||||
heap.Add_int_hzip(reqd, val);
|
||||
return this;
|
||||
}
|
||||
public void Test__vals(int expd_cur_bits, int expd_cur, int... expd_ary) {
|
||||
Tfds.Eq_int (expd_cur_bits , heap.Cur_bits() , "cur_bits");
|
||||
Tfds.Eq_int (expd_cur , heap.Cur() , "cur");
|
||||
Tfds.Eq_ary (Bry_.New_by_ints(expd_ary) , heap.Heap().To_bry() , "heap");
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
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.dbs.diffs; import gplx.*; import gplx.dbs.*;
|
||||
public class Gfdb_diff_db_ {
|
||||
public static final String
|
||||
Fld__diff_site = "diff_site" // -1 for single-site merge; 0+ for multiple-site merges where 0+ is defined in a registry
|
||||
, Fld__diff_time = "diff_time" // -1 for single-time merge; 0+ for multiple-time merges where 0+ is defined in a registry
|
||||
, Fld__diff_db_trg = "diff_db_trg" // -1 for single-db tables; 0+ for multiple-db tables
|
||||
, Fld__diff_db_src = "diff_db_src" // -1 for I,U,D; 0+ for M
|
||||
, Fld__diff_type = "diff_type" // I,U,D,M
|
||||
, Fld__diff_uid = "diff_uid" // 0+
|
||||
;
|
||||
public static final byte
|
||||
Tid__insert = 0
|
||||
, Tid__update = 1
|
||||
, Tid__delete = 2
|
||||
, Tid__move = 3
|
||||
;
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
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.dbs.diffs; import gplx.*; import gplx.dbs.*;
|
||||
public class Gfdb_diff_tbl {
|
||||
public Gfdb_diff_tbl(String name, Db_meta_fld[] keys, Db_meta_fld[] vals, Db_rdr rdr) {
|
||||
this.name = name; this.keys = keys; this.vals = vals; this.rdr = rdr;
|
||||
int keys_len = keys.length; int vals_len = vals.length;
|
||||
this.flds = new Db_meta_fld[keys_len + vals_len];
|
||||
for (int i = 0; i < keys_len; ++i)
|
||||
flds[i] = keys[i];
|
||||
for (int i = 0; i < vals_len; ++i)
|
||||
flds[i + keys_len] = vals[i];
|
||||
}
|
||||
public String Name() {return name;} private final String name;
|
||||
public Db_meta_fld[] Flds() {return flds;} private final Db_meta_fld[] flds;
|
||||
public Db_meta_fld[] Keys() {return keys;} private final Db_meta_fld[] keys;
|
||||
public Db_meta_fld[] Vals() {return vals;} private final Db_meta_fld[] vals;
|
||||
public Db_rdr Rdr() {return rdr;} private final Db_rdr rdr;
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
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.dbs.diffs; import gplx.*; import gplx.dbs.*;
|
||||
public class Gfdb_rdr_utl_ {
|
||||
public static int Compare(Db_meta_fld[] flds, int len, Db_rdr lhs_rdr, Db_rdr rhs_rdr) {
|
||||
int comp = CompareAble_.Same;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Db_meta_fld fld = flds[i];
|
||||
String fld_name = fld.Name();
|
||||
switch (fld.Tid()) {
|
||||
case Db_meta_fld.Tid_bool: comp = Bool_.Compare (lhs_rdr.Read_bool_by_byte(fld_name), rhs_rdr.Read_bool_by_byte(fld_name)); break;
|
||||
case Db_meta_fld.Tid_int: comp = Int_.Compare (lhs_rdr.Read_int(fld_name) , rhs_rdr.Read_int(fld_name)); break;
|
||||
case Db_meta_fld.Tid_long: comp = Long_.Compare (lhs_rdr.Read_long(fld_name) , rhs_rdr.Read_long(fld_name)); break;
|
||||
case Db_meta_fld.Tid_float: comp = Float_.Compare (lhs_rdr.Read_float(fld_name) , rhs_rdr.Read_float(fld_name)); break;
|
||||
case Db_meta_fld.Tid_double: comp = Double_.Compare (lhs_rdr.Read_double(fld_name) , rhs_rdr.Read_double(fld_name)); break;
|
||||
case Db_meta_fld.Tid_str: comp = String_.Compare (lhs_rdr.Read_str(fld_name) , rhs_rdr.Read_str(fld_name)); break;
|
||||
case Db_meta_fld.Tid_bry: comp = Bry_.Compare (lhs_rdr.Read_bry(fld_name) , rhs_rdr.Read_bry(fld_name)); break;
|
||||
default: throw Err_.new_unhandled(fld.Tid());
|
||||
}
|
||||
if (comp != CompareAble_.Same) return comp;
|
||||
}
|
||||
return CompareAble_.Same;
|
||||
}
|
||||
public static void Stmt_args(Db_stmt stmt, Db_meta_fld[] flds, int len, Db_rdr rdr) {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Db_meta_fld fld = flds[i];
|
||||
String fld_name = fld.Name();
|
||||
switch (fld.Tid()) {
|
||||
case Db_meta_fld.Tid_bool: stmt.Val_bool_as_byte (fld_name, rdr.Read_bool_by_byte(fld_name)); break;
|
||||
case Db_meta_fld.Tid_byte: stmt.Val_byte (fld_name, rdr.Read_byte(fld_name)); break;
|
||||
case Db_meta_fld.Tid_int: stmt.Val_int (fld_name, rdr.Read_int(fld_name)); break;
|
||||
case Db_meta_fld.Tid_long: stmt.Val_long (fld_name, rdr.Read_long(fld_name)); break;
|
||||
case Db_meta_fld.Tid_float: stmt.Val_float (fld_name, rdr.Read_float(fld_name)); break;
|
||||
case Db_meta_fld.Tid_double: stmt.Val_double (fld_name, rdr.Read_double(fld_name)); break;
|
||||
case Db_meta_fld.Tid_str: stmt.Val_str (fld_name, rdr.Read_str(fld_name)); break;
|
||||
case Db_meta_fld.Tid_bry: stmt.Val_bry (fld_name, rdr.Read_bry(fld_name)); break;
|
||||
default: throw Err_.new_unhandled(fld.Tid());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
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.dbs.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import gplx.dbs.*;
|
||||
public class Gfdb_diff_bldr {
|
||||
private Gfdb_diff_rdr_comparer rdr_comparer = new Gfdb_diff_rdr_comparer();
|
||||
private Gfdb_diff_wkr diff_wkr;
|
||||
public void Init(Gfdb_diff_wkr diff_wkr) {this.diff_wkr = diff_wkr;}
|
||||
public void Compare(Gfdb_diff_tbl lhs_tbl, Gfdb_diff_tbl rhs_tbl) {
|
||||
rdr_comparer.Init(lhs_tbl, rhs_tbl);
|
||||
diff_wkr.Init_tbls(lhs_tbl, rhs_tbl);
|
||||
boolean loop = true;
|
||||
while (loop) {
|
||||
int rslt = rdr_comparer.Compare();
|
||||
switch (rslt) {
|
||||
case Gfdb_diff_rdr_comparer.Rslt__same: diff_wkr.Handle_same(); break;
|
||||
case Gfdb_diff_rdr_comparer.Rslt__lhs_missing: diff_wkr.Handle_lhs_missing(); break;
|
||||
case Gfdb_diff_rdr_comparer.Rslt__rhs_missing: diff_wkr.Handle_rhs_missing(); break;
|
||||
case Gfdb_diff_rdr_comparer.Rslt__done: loop = false; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
/*
|
||||
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.dbs.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import org.junit.*;
|
||||
import gplx.dbs.*; import gplx.dbs.engines.mems.*;
|
||||
public class Gfdb_diff_bldr_tst {
|
||||
private final Gfdb_diff_bldr_fxt fxt = new Gfdb_diff_bldr_fxt();
|
||||
@Test public void Same() {
|
||||
fxt.Init__tbl__lhs(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Init__tbl__rhs(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Test__bld();
|
||||
}
|
||||
@Test public void Update() {
|
||||
fxt.Init__tbl__lhs(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Init__tbl__rhs(Object_.Ary(1, "A1") , Object_.Ary(2, "B1"));
|
||||
fxt.Test__bld("U|1|A1", "U|2|B1");
|
||||
}
|
||||
@Test public void Insert() {
|
||||
fxt.Init__tbl__lhs(Object_.Ary(1, "A"));
|
||||
fxt.Init__tbl__rhs(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Test__bld("I|2|B");
|
||||
}
|
||||
@Test public void Delete() {
|
||||
fxt.Init__tbl__lhs(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Init__tbl__rhs(Object_.Ary(1, "A"));
|
||||
fxt.Test__bld("D|2");
|
||||
}
|
||||
@Test public void Basic() {
|
||||
fxt.Init__tbl__lhs
|
||||
( Object_.Ary(1, "A")
|
||||
, Object_.Ary(2, "B")
|
||||
, Object_.Ary(3, "C")
|
||||
);
|
||||
fxt.Init__tbl__rhs
|
||||
( Object_.Ary(1, "A")
|
||||
, Object_.Ary(2, "B1")
|
||||
, Object_.Ary(4, "D")
|
||||
);
|
||||
fxt.Test__bld("U|2|B1", "D|3", "I|4|D");
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_bldr_fxt {
|
||||
private final Gfdb_diff_bldr bldr = new Gfdb_diff_bldr();
|
||||
private final Gfdb_diff_wkr__test wkr = new Gfdb_diff_wkr__test();
|
||||
private final Db_meta_fld[] key_flds, val_flds;
|
||||
private Gfdb_diff_tbl lhs_tbl, rhs_tbl;
|
||||
public Gfdb_diff_bldr_fxt() {
|
||||
Db_meta_fld_list fld_list = new Db_meta_fld_list();
|
||||
fld_list.Add_int("id");
|
||||
key_flds = fld_list.To_fld_ary();
|
||||
fld_list.Clear();
|
||||
fld_list.Add_str("val", 255);
|
||||
val_flds = fld_list.To_fld_ary();
|
||||
bldr.Init(wkr);
|
||||
}
|
||||
public void Init__tbl__lhs(Object[]... rows) {this.lhs_tbl = Make__tbl(key_flds, val_flds, rows);}
|
||||
public void Init__tbl__rhs(Object[]... rows) {this.rhs_tbl = Make__tbl(key_flds, val_flds, rows);}
|
||||
public void Test__bld(String... expd) {
|
||||
bldr.Compare(lhs_tbl, rhs_tbl);
|
||||
Tfds.Eq_ary_str(expd, wkr.To_str_ary());
|
||||
}
|
||||
private static Gfdb_diff_tbl Make__tbl(Db_meta_fld[] keys, Db_meta_fld[] vals, Object[][] rows) {
|
||||
int keys_len = keys.length; int vals_len = vals.length;
|
||||
int cols_len = keys_len + vals_len;
|
||||
String[] cols = new String[cols_len];
|
||||
for (int i = 0; i < keys_len; ++i)
|
||||
cols[i] = keys[i].Name();
|
||||
for (int i = 0; i < vals_len; ++i)
|
||||
cols[i + keys_len] = vals[i].Name();
|
||||
|
||||
int rows_len = rows.length;
|
||||
Mem_row[] mem_rows = new Mem_row[rows_len];
|
||||
for (int i = 0; i < rows_len; ++i) {
|
||||
Object[] row = rows[i];
|
||||
Mem_row mem_row = new Mem_row();
|
||||
mem_rows[i] = mem_row;
|
||||
for (int j = 0; j < cols_len; ++j) {
|
||||
Object cell = row[j];
|
||||
mem_row.Add(cols[j], cell);
|
||||
}
|
||||
}
|
||||
Db_rdr rdr = new Db_rdr__mem(cols, mem_rows);
|
||||
return new Gfdb_diff_tbl("tbl1", keys, vals, rdr);
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_wkr__test implements Gfdb_diff_wkr {
|
||||
private final List_adp list = List_adp_.new_();
|
||||
private final Bry_bfr bfr = Bry_bfr.new_();
|
||||
private Db_rdr lhs_rdr, rhs_rdr;
|
||||
public void Init_tbls(Gfdb_diff_tbl lhs_tbl, Gfdb_diff_tbl rhs_tbl) {
|
||||
this.lhs_rdr = lhs_tbl.Rdr(); this.rhs_rdr = rhs_tbl.Rdr();
|
||||
}
|
||||
public void Term_tbls() {}
|
||||
public void Handle_same() {
|
||||
String lhs_val = lhs_rdr.Read_str("val");
|
||||
String rhs_val = rhs_rdr.Read_str("val");
|
||||
if (!String_.Eq(lhs_val, rhs_val))
|
||||
list.Add(bfr.Add_str_a7("U").Add_byte_pipe().Add_obj(lhs_rdr.Read_obj("id")).Add_byte_pipe().Add_str_a7(rhs_val).To_str_and_clear());
|
||||
}
|
||||
public void Handle_lhs_missing() {
|
||||
String rhs_val = rhs_rdr.Read_str("val");
|
||||
list.Add(bfr.Add_str_a7("I").Add_byte_pipe().Add_obj(rhs_rdr.Read_obj("id")).Add_byte_pipe().Add_str_a7(rhs_val).To_str_and_clear());
|
||||
}
|
||||
public void Handle_rhs_missing() {
|
||||
list.Add(bfr.Add_str_a7("D").Add_byte_pipe().Add_obj(lhs_rdr.Read_obj("id")).To_str_and_clear());
|
||||
}
|
||||
public String[] To_str_ary() {return list.To_str_ary_and_clear();}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
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.dbs.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
class Gfdb_diff_rdr_comparer {
|
||||
private Db_rdr lhs_rdr, rhs_rdr;
|
||||
private boolean lhs_rdr_move, rhs_rdr_move;
|
||||
private boolean lhs_rdr_done, rhs_rdr_done;
|
||||
private Db_meta_fld[] key_flds; private int key_flds_len;
|
||||
public void Init(Gfdb_diff_tbl lhs_tbl, Gfdb_diff_tbl rhs_tbl) {
|
||||
this.lhs_rdr = lhs_tbl.Rdr(); this.rhs_rdr = rhs_tbl.Rdr();
|
||||
this.lhs_rdr_move = rhs_rdr_move = Bool_.Y;
|
||||
this.lhs_rdr_done = rhs_rdr_done = Bool_.N;
|
||||
this.key_flds = rhs_tbl.Keys(); key_flds_len = key_flds.length;
|
||||
}
|
||||
public int Compare() {
|
||||
if (lhs_rdr_move) {
|
||||
lhs_rdr_move = lhs_rdr.Move_next();
|
||||
if (!lhs_rdr_move) lhs_rdr_done = true;
|
||||
}
|
||||
if (rhs_rdr_move) {
|
||||
rhs_rdr_move = rhs_rdr.Move_next();
|
||||
if (!rhs_rdr_move) rhs_rdr_done = true;
|
||||
}
|
||||
if (lhs_rdr_done && rhs_rdr_done) return Gfdb_diff_rdr_comparer.Rslt__done;
|
||||
else if (lhs_rdr_done) {rhs_rdr_move = true; return Gfdb_diff_rdr_comparer.Rslt__lhs_missing;}
|
||||
else if (rhs_rdr_done) {lhs_rdr_move = true; return Gfdb_diff_rdr_comparer.Rslt__rhs_missing;}
|
||||
else {
|
||||
int comp = Gfdb_rdr_utl_.Compare(key_flds, key_flds_len, lhs_rdr, rhs_rdr);
|
||||
switch (comp) {
|
||||
case CompareAble_.Same: // lhs == rhs; move both
|
||||
lhs_rdr_move = rhs_rdr_move = true;
|
||||
return Gfdb_diff_rdr_comparer.Rslt__same;
|
||||
case CompareAble_.Less: // lhs < rhs; EX: lhs == 2; rhs == 3
|
||||
lhs_rdr_move = true;
|
||||
rhs_rdr_move = false;
|
||||
return Gfdb_diff_rdr_comparer.Rslt__rhs_missing;
|
||||
case CompareAble_.More: // lhs > rhs; EX: lhs == 4; rhs == 3
|
||||
lhs_rdr_move = false;
|
||||
rhs_rdr_move = true;
|
||||
return Gfdb_diff_rdr_comparer.Rslt__lhs_missing;
|
||||
default: throw Err_.new_unhandled(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static final int
|
||||
Rslt__same = 0
|
||||
, Rslt__lhs_missing = 1
|
||||
, Rslt__rhs_missing = 2
|
||||
, Rslt__done = 3
|
||||
;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue