v3.3.4 v3.1.1.1
gnosygnu 9 years ago
parent 9509363f46
commit 096045614c

@ -1,10 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src_311_gfoObj"/>
<classpathentry kind="src" path="src_420_usrMsg"/>
<classpathentry kind="src" path="tst"/>
<classpathentry kind="src" path="xtn"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="lib/commons-compress-1.5.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>

@ -39,6 +39,11 @@ public class Bool_ implements GfoInvkAble {
return false;
throw Err_.new_parse_type(boolean.class, raw);
}
public static int Compare(boolean lhs, boolean rhs) {
if ( lhs == rhs) return CompareAble_.Same;
else if (!lhs && rhs) return CompareAble_.Less;
else /*lhs && !rhs*/ return CompareAble_.More;
}
public static boolean By_int(int v) {return v == Y_int;}
public static int To_int(boolean v) {return v ? Y_int : N_int;}
public static byte To_byte(boolean v) {return v ? Y_byte : N_byte;}

@ -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));}
}

@ -23,14 +23,26 @@ public class Bry_ {
public static final byte[] Empty = new byte[0];
public static final byte[][] Ary_empty = new byte[0][];
public static final Class<?> Cls_ref_type = byte[].class;
public static byte[] new_bytes(byte... ary) {return ary;}
public static byte[] new_ints(int... ary) {
public static byte[] New_by_byte(byte b) {return new byte[] {b};}
public static byte[] New_by_ints(int... ary) {
int len = ary.length;
byte[] rv = new byte[len];
for (int i = 0; i < len; i++)
rv[i] = (byte)ary[i];
return rv;
}
public static byte[] New_by_objs(Bry_bfr bfr, Object... ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
Object itm = ary[i];
Class<?> type = Type_adp_.ClassOf_obj(itm);
if (Type_adp_.Eq(type, int.class)) bfr.Add_byte((byte)Int_.cast(itm));
else if (Type_adp_.Eq(type, String.class)) bfr.Add_str_u8((String)itm);
else if (Type_adp_.Eq(type, byte[].class)) bfr.Add((byte[])itm);
else throw Err_.new_unhandled(Type_adp_.FullNameOf_type(type));
}
return bfr.To_bry_and_clear();
}
public static byte[] Coalesce_to_empty(byte[] v) {return v == null ? Bry_.Empty : v;}
public static byte[] Coalesce(byte[] v, byte[] or) {return v == null ? or : v;}
public static byte[] new_a7(String str) {
@ -210,6 +222,8 @@ public class Bry_ {
if (src[i] == lkp) return true;
return false;
}
public static boolean Has_at_bgn(byte[] src, byte lkp) {return Has_at_bgn(src, lkp, 0);}
public static boolean Has_at_bgn(byte[] src, byte lkp, int src_bgn) {return src_bgn < src.length ? src[src_bgn] == lkp : false;}
public static boolean Has_at_bgn(byte[] src, byte[] lkp) {return Has_at_bgn(src, lkp, 0, src.length);}
public static boolean Has_at_bgn(byte[] src, byte[] lkp, int src_bgn, int src_end) {
int lkp_len = lkp.length;
@ -229,7 +243,6 @@ public class Bry_ {
}
return true;
}
public static boolean Has_at_bgn(byte[] src, byte lkp, int src_bgn) {return src_bgn < src.length ? src[src_bgn] == lkp : false;}
public static void Set(byte[] src, int bgn, int end, byte[] repl) {
int repl_len = repl.length;
for (int i = 0; i < repl_len; i++)

@ -20,17 +20,17 @@ import org.junit.*; import gplx.core.primitives.*; import gplx.core.brys.*;
public class Bry__tst {
private final Bry__fxt fxt = new Bry__fxt();
@Test public void new_ascii_() {
fxt.Test_new_a7("a" , Bry_.new_ints(97)); // one
fxt.Test_new_a7("abc" , Bry_.new_ints(97, 98, 99)); // many
fxt.Test_new_a7("a" , Bry_.New_by_ints(97)); // one
fxt.Test_new_a7("abc" , Bry_.New_by_ints(97, 98, 99)); // many
fxt.Test_new_a7("" , Bry_.Empty); // none
fxt.Test_new_a7("¢€𤭢" , Bry_.new_ints(63, 63, 63, 63)); // non-ascii -> ?
fxt.Test_new_a7("¢€𤭢" , Bry_.New_by_ints(63, 63, 63, 63)); // non-ascii -> ?
}
@Test public void new_u8() {
fxt.Test_new_u8("a" , Bry_.new_ints(97)); // one
fxt.Test_new_u8("abc" , Bry_.new_ints(97, 98, 99)); // many
fxt.Test_new_u8("¢" , Bry_.new_ints(194, 162)); // bry_len=2; cent
fxt.Test_new_u8("€" , Bry_.new_ints(226, 130, 172)); // bry_len=3; euro
fxt.Test_new_u8("𤭢" , Bry_.new_ints(240, 164, 173, 162)); // bry_len=3; example from en.w:UTF-8
fxt.Test_new_u8("a" , Bry_.New_by_ints(97)); // one
fxt.Test_new_u8("abc" , Bry_.New_by_ints(97, 98, 99)); // many
fxt.Test_new_u8("¢" , Bry_.New_by_ints(194, 162)); // bry_len=2; cent
fxt.Test_new_u8("€" , Bry_.New_by_ints(226, 130, 172)); // bry_len=3; euro
fxt.Test_new_u8("𤭢" , Bry_.New_by_ints(240, 164, 173, 162)); // bry_len=3; example from en.w:UTF-8
}
@Test public void Add__bry_plus_byte() {
fxt.Test_add("a" , Byte_ascii.Pipe , "a|"); // basic

@ -25,6 +25,10 @@ public class Bry_find_ {
if (src[i] == lkp) return i;
return Bry_find_.Not_found;
}
public static int Find_fwd_or(byte[] src, byte lkp, int cur, int end, int or) {
int rv = Find_fwd(src, lkp, cur, end);
return rv == Bry_find_.Not_found ? or : rv;
}
public static int Find_bwd(byte[] src, byte lkp) {return Find_bwd(src, lkp, src.length, 0);}
public static int Find_bwd(byte[] src, byte lkp, int cur) {return Find_bwd(src, lkp, cur , 0);}
public static int Find_bwd(byte[] src, byte lkp, int cur, int end) {
@ -177,6 +181,16 @@ public class Bry_find_ {
}
return bgn;
}
public static int Find_bwd__skip(byte[] src, int end, int bgn, byte skip) {
int src_len = src.length; if (end == src_len) return end;
if (end > src_len || end < 0) return Bry_find_.Not_found;
int pos = end - 1; // start from end - 1; handles situations where len is passed in
for (int i = pos; i >= bgn; --i) {
if (src[i] != skip)
return i + 1;
}
return bgn;
}
public static int Find_bwd_while(byte[] src, int cur, int end, byte while_byte) {
--cur;
while (true) {

@ -23,6 +23,8 @@ public class Byte_ {
Zero = 0
, Min_value = Byte.MIN_VALUE
, Max_value_127 = 127
, Val_128 = -128
, Val_255 = -1
;
public static byte cast(Object o) {try {return (Byte)o;} catch (Exception e) {throw Err_.new_type_mismatch_w_exc(e, byte.class, o);}}
public static byte parse(String raw) {return Byte.parseByte(raw);}

@ -108,10 +108,12 @@ public class Byte_ascii {
, Angle_end_bry = new byte[] {Byte_ascii.Angle_end}
, Comma_bry = new byte[] {Byte_ascii.Comma}
, Colon_bry = new byte[] {Byte_ascii.Colon}
, Semic_bry = new byte[] {Byte_ascii.Semic}
, Eq_bry = new byte[] {Byte_ascii.Eq}
, Amp_bry = new byte[] {Byte_ascii.Amp}
, Lt_bry = new byte[] {Byte_ascii.Lt}
, Gt_bry = new byte[] {Byte_ascii.Gt}
, Question_bry = new byte[] {Byte_ascii.Question}
, Brack_bgn_bry = new byte[] {Byte_ascii.Brack_bgn}
, Brack_end_bry = new byte[] {Byte_ascii.Brack_end}
, Apos_bry = new byte[] {Byte_ascii.Apos}

@ -18,9 +18,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
public class Cancelable_ {
public static final Cancelable Never = new Cancelable_never();
public static Cancelable New_proxy() {return new Cancelable_proxy();}
}
class Cancelable_never implements Cancelable {
public boolean Canceled() {return false;}
public void Cancel() {}
public void Cancel_reset() {}
}
class Cancelable_proxy implements Cancelable {
private boolean canceled = false;
public boolean Canceled() {return canceled;}
public void Cancel() {canceled = true;}
public void Cancel_reset() {canceled = false;}
}

@ -69,6 +69,7 @@ public class DateAdp implements CompareAble, GfoInvkAble {
public String XtoStr_fmt_yyyy_MM_dd_HH_mm() {return XtoStr_fmt("yyyy-MM-dd HH:mm");}
public String XtoStr_fmt_yyyy_MM_dd_HH_mm_ss() {return XtoStr_fmt("yyyy-MM-dd HH:mm:ss");}
public String XtoStr_fmt_iso_8561() {return XtoStr_fmt("yyyy-MM-dd HH:mm:ss");}
public String XtoStr_fmt_iso_8561_w_tz() {return XtoStr_fmt("yyyy-MM-dd'T'HH:mm:ss'Z'");}
public static int Timezone_offset_test = Int_.Min_value;
public Calendar UnderDateTime() {return under;} Calendar under;
public int Year() {return under.get(Calendar.YEAR);}

@ -58,7 +58,7 @@ public class Err extends RuntimeException {
String nl_str = called_by_log ? "\t" : "\n";
String rv = ""; //nl_str + "----------------------------------------------------------------------" + nl_str;
for (int i = 0; i < msgs_idx; ++i) {
rv += "[err " + Int_.To_str(i) + "] " + msgs_ary[i].To_str() + nl_str;
rv += "[err " + Int_.To_str(i) + "] " + String_.Replace(msgs_ary[i].To_str(), "\n", nl_str) + nl_str;
}
if (include_trace)
rv += "[trace]:" + Trace_to_str(is_gplx, called_by_log, trace_ignore, trace == null ? Err_.Trace_lang(this) : trace);

@ -23,6 +23,11 @@ public class Float_ {
public static boolean IsNaN(float v) {return Float.isNaN(v);}
public static float cast(Object obj) {try {return (Float)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, float.class, obj);}}
public static float parse(String raw) {try {return Float.parseFloat(raw);} catch(Exception exc) {throw Err_.new_parse_exc(exc, float.class, raw);}}
public static int Compare(float lhs, float rhs) {
if ( lhs == rhs) return CompareAble_.Same;
else if ( lhs < rhs) return CompareAble_.Less;
else /*lhs > rhs*/ return CompareAble_.More;
}
public static String To_str(float v) {
int v_int = (int)v;
return v - v_int == 0 ? Int_.To_str(v_int) : Float.toString(v);

@ -43,7 +43,7 @@ public class Hash_adp_bry extends gplx.core.lists.Hash_adp_base implements Hash_
}
public Object Get_by_bry(byte[] src) {return super.Fetch_base(key_ref.Init(src));}
public Object Get_by_mid(byte[] src, int bgn, int end) {return super.Fetch_base(key_ref.Init(src, bgn, end));}
public Hash_adp_bry Add_byte_int(byte key, int val) {this.Add_base(Bry_.new_bytes(key), Int_obj_val.new_(val)); return this;}
public Hash_adp_bry Add_byte_int(byte key, int val) {this.Add_base(new byte[]{key}, Int_obj_val.new_(val)); return this;}
public Hash_adp_bry Add_bry_byte(byte[] key, byte val) {this.Add_base(key, Byte_obj_val.new_(val)); return this;}
public Hash_adp_bry Add_bry_int(byte[] key, int val) {this.Add_base(key, Int_obj_val.new_(val)); return this;}
public Hash_adp_bry Add_bry_bry(byte[] key) {this.Add_base(key, key); return this;}

@ -16,5 +16,4 @@ 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;
public @interface Internal {}
public @interface Internal {}

@ -16,5 +16,4 @@ 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;
public @interface New {}
public @interface New {}

@ -16,5 +16,4 @@ 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;
public @interface Virtual {}
public @interface Virtual {}

@ -17,7 +17,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys; import gplx.*; import gplx.core.*;
public interface Bfr_arg {
void Bfr_arg__clear();
boolean Bfr_arg__exists();
void Bfr_arg__add(Bry_bfr bfr);
}

@ -20,18 +20,16 @@ import gplx.core.brys.args.*; import gplx.core.brys.fmtrs.*;
public class Bfr_arg_ {
public static Bfr_arg__int New_int(int v) {return new Bfr_arg__int(v);}
public static Bfr_arg__byte New_byte(byte v) {return new Bfr_arg__byte(v);}
public static Bfr_arg__bry New_bry(String v) {return new Bfr_arg__bry(Bry_.new_u8(v));}
public static Bfr_arg__bry New_bry(byte[] v) {return new Bfr_arg__bry(v);}
public static Bfr_arg__bry New_bry(String v) {return Bfr_arg__bry.New(Bry_.new_u8(v));}
public static Bfr_arg__bry New_bry(byte[] v) {return Bfr_arg__bry.New(v);}
public static Bfr_arg__bry_fmtr New_bry_fmtr__null() {return new Bfr_arg__bry_fmtr(null, null);}
public static Bfr_arg__bry_fmtr New_bry_fmtr(Bry_fmtr v, Bfr_arg... arg_ary) {return new Bfr_arg__bry_fmtr(v, arg_ary);}
public static final Bfr_arg Noop = new Bfr_arg___noop();
public static void Clear(Bfr_arg... ary) {
for (Bfr_arg arg : ary)
public static void Clear(Bfr_arg_clearable... ary) {
for (Bfr_arg_clearable arg : ary)
arg.Bfr_arg__clear();
}
}
class Bfr_arg___noop implements gplx.core.brys.Bfr_arg {
public void Bfr_arg__clear() {}
public boolean Bfr_arg__exists() {return false;}
public void Bfr_arg__add(Bry_bfr bfr) {}
}

@ -16,6 +16,7 @@ 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 interface Clear_able {
void Clear();
public interface Bfr_arg_clearable extends Bfr_arg {
void Bfr_arg__clear();
boolean Bfr_arg__missing();
}

@ -16,9 +16,28 @@ 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.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
public class Bfr_arg__bry extends gplx.core.brys.Bfr_arg_base {
private byte[] bry;
public Bfr_arg__bry(byte[] v) {this.bry = v;}
public void Set(byte[] v) {this.bry = v;}
@Override public void Bfr_arg__add(Bry_bfr bfr) {bfr.Add(bry);}
public class Bfr_arg__bry implements Bfr_arg_clearable {
private int tid;
private byte[] src; private int src_bgn, src_end;
private Bfr_arg arg;
public void Set_by_mid(byte[] src, int bgn, int end) {this.tid = Tid_mid; this.src = src; this.src_bgn = bgn; this.src_end = end;}
public void Set_by_val(byte[] src) {this.tid = Tid_val; this.src = src;}
public void Set_by_arg(Bfr_arg arg) {this.tid = Tid_arg; this.arg = arg;}
public void Bfr_arg__clear() {
tid = Tid_nil;
src = null; src_bgn = src_end = -1;
arg = null;
}
public boolean Bfr_arg__missing() {return tid == Tid_nil;}
public void Bfr_arg__add(Bry_bfr bfr) {
switch (tid) {
case Tid_val: bfr.Add(src); break;
case Tid_mid: bfr.Add_mid(src, src_bgn, src_end); break;
case Tid_arg: arg.Bfr_arg__add(bfr); break;
case Tid_nil: break;
}
}
public static Bfr_arg__bry New_empty() {return new Bfr_arg__bry();}
public static Bfr_arg__bry New(byte[] v) {Bfr_arg__bry rv = new Bfr_arg__bry(); rv.Set_by_val(v); return rv;}
private static final int Tid_nil = 0, Tid_val = 1, Tid_mid = 2, Tid_arg = 3;
}

@ -16,10 +16,10 @@ 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.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
public class Bfr_arg__bry_ary extends gplx.core.brys.Bfr_arg_base {
public class Bfr_arg__bry_ary implements Bfr_arg {
private byte[][] bry_ary;
public Bfr_arg__bry_ary Set(byte[][] v) {this.bry_ary = v; return this;}
@Override public void Bfr_arg__add(Bry_bfr bfr) {
public Bfr_arg__bry_ary Set(byte[]... v) {this.bry_ary = v; return this;}
public void Bfr_arg__add(Bry_bfr bfr) {
for (byte[] bry : bry_ary)
bfr.Add(bry);
}

@ -17,12 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.brys.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
import gplx.core.brys.fmtrs.*;
public class Bfr_arg__bry_fmtr extends gplx.core.brys.Bfr_arg_base {
public class Bfr_arg__bry_fmtr implements Bfr_arg {
private Bry_fmtr fmtr; private Object[] arg_ary;
public Bfr_arg__bry_fmtr(Bry_fmtr fmtr, Object[] arg_ary) {Set(fmtr, arg_ary);}
public Bfr_arg__bry_fmtr Set(Bry_fmtr fmtr, Object... arg_ary) {
this.fmtr = fmtr; this.arg_ary = arg_ary;
return this;
}
@Override public void Bfr_arg__add(Bry_bfr bfr) {fmtr.Bld_bfr_many(bfr, arg_ary);}
public void Bfr_arg__add(Bry_bfr bfr) {fmtr.Bld_bfr_many(bfr, arg_ary);}
}

@ -16,8 +16,8 @@ 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.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
public class Bfr_arg__byte extends gplx.core.brys.Bfr_arg_base {
public class Bfr_arg__byte implements Bfr_arg {
private final byte byt;
public Bfr_arg__byte(byte byt) {this.byt = byt;}
@Override public void Bfr_arg__add(Bry_bfr bfr) {bfr.Add_byte(byt);}
public void Bfr_arg__add(Bry_bfr bfr) {bfr.Add_byte(byt);}
}

@ -16,10 +16,10 @@ 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.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
public class Bfr_arg__decimal_int extends gplx.core.brys.Bfr_arg_base {
public class Bfr_arg__decimal_int implements Bfr_arg {
public int Val() {return val;} public Bfr_arg__decimal_int Val_(int v) {val = v; return this;} int val;
public Bfr_arg__decimal_int Places_(int v) {places = v; multiple = (int)Math_.Pow(10, v); return this;} int multiple = 1000, places = 3;
@Override public void Bfr_arg__add(Bry_bfr bfr) {
public void Bfr_arg__add(Bry_bfr bfr) {
bfr.Add_int_variable(val / multiple).Add_byte(Byte_ascii.Dot).Add_int_fixed(val % multiple, places);
}
}

@ -16,7 +16,7 @@ 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.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
public class Bfr_arg__int extends gplx.core.brys.Bfr_arg_base {
public class Bfr_arg__int implements Bfr_arg {
private int val, val_digits;
public Bfr_arg__int(int v) {Set(v);}
public Bfr_arg__int Set(int v) {
@ -24,5 +24,5 @@ public class Bfr_arg__int extends gplx.core.brys.Bfr_arg_base {
this.val_digits = Int_.DigitCount(val);
return this;
}
@Override public void Bfr_arg__add(Bry_bfr bfr) {bfr.Add_int_digits(val_digits, val);}
public void Bfr_arg__add(Bry_bfr bfr) {bfr.Add_int_digits(val_digits, val);}
}

@ -16,7 +16,7 @@ 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.args; import gplx.*; import gplx.core.*; import gplx.core.brys.*;
public class Bfr_arg__time extends gplx.core.brys.Bfr_arg_base {
public class Bfr_arg__time implements Bfr_arg {
public Bfr_arg__time() {
units_len = units.length;
}
@ -30,7 +30,7 @@ public class Bfr_arg__time extends gplx.core.brys.Bfr_arg_base {
int[] units = new int[] {86400, 3600, 60, 1};
int units_len;
byte[] spr = new byte[] {Byte_ascii.Space};
@Override public void Bfr_arg__add(Bry_bfr bfr) {
public void Bfr_arg__add(Bry_bfr bfr) {
if (seconds == 0) { // handle 0 separately (since it will always be < than units[*]
bfr.Add_int_fixed(0, 2).Add(segs[units_len - 1]);
return;

@ -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());
}
}

@ -17,6 +17,9 @@ 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_fmtr_itm {
Bry_fmtr_itm(boolean arg, int argIdx, byte[] dat) {
this.Arg = arg; this.ArgIdx = argIdx; this.Dat = dat;
}
public boolean Arg;
public int ArgIdx;
public byte[] Dat;
@ -27,7 +30,4 @@ public class Bry_fmtr_itm {
public static Bry_fmtr_itm arg_(int idx) {return new Bry_fmtr_itm(true, idx, Bry_.Empty);}
public static Bry_fmtr_itm dat_(byte[] dat, int len) {return new Bry_fmtr_itm(false, -1, Bry_.Mid(dat, 0, len));}
public static Bry_fmtr_itm dat_bry_(byte[] bry) {return new Bry_fmtr_itm(false, -1, bry);}
Bry_fmtr_itm(boolean arg, int argIdx, byte[] dat) {
this.Arg = arg; this.ArgIdx = argIdx; this.Dat = dat;
}
}

@ -18,17 +18,21 @@ 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_fmtr_tst {
@Test public void Idx_text() {tst_Format("a", "a");}
@Test public void Idx_1() {tst_Format("a", "~{0}", "a");}
@Test public void Idx_3() {tst_Format("abc", "~{0}~{1}~{2}", "a", "b", "c");}
@Test public void Idx_mix() {tst_Format("abcde", "a~{0}c~{1}e", "b", "d");}
@Test public void Key_basic() {tst("~{key}" , String_.Ary("key") , ary_("a") , "a");}
@Test public void Key_mult() {tst("~{key1}~{key2}" , String_.Ary("key1", "key2") , ary_("a", "b") , "ab");}
@Test public void Key_mix() {tst("~{key1}~{1}" , String_.Ary("key1", "key2") , ary_("a", "b") , "ab");}
@Test public void Key_repeat() {tst("~{key1}~{key1}" , String_.Ary("key1") , ary_("a") , "aa");}
private final Bry_fmtr_fxt fxt = new Bry_fmtr_fxt();
@Test public void Text() {fxt.Clear().Fmt("a").Test("a");}
@Test public void Idx__1() {fxt.Clear().Fmt("~{0}").Args("a").Test("a");}
@Test public void Idx__3() {fxt.Clear().Fmt("~{0}~{1}~{2}").Args("a", "b", "c").Test("abc");}
@Test public void Idx__mix() {fxt.Clear().Fmt("a~{0}c~{1}e").Args("b", "d").Test("abcde");}
@Test public void Idx__missing() {fxt.Clear().Fmt("~{0}").Test("~{0}");}
@Test public void Key__basic() {fxt.Clear().Fmt("~{key}").Keys("key").Args("a").Test("a");}
@Test public void Key__mult() {fxt.Clear().Fmt("~{key1}~{key2}").Keys("key1", "key2").Args("a", "b").Test("ab");}
@Test public void Key__repeat() {fxt.Clear().Fmt("~{key1}~{key1}").Keys("key1").Args("a").Test("aa");}
@Test public void Mix() {fxt.Clear().Fmt("~{key1}~{1}").Keys("key1", "key2").Args("a", "b").Test("ab");}
@Test public void Simple() {
Bry_fmtr fmtr = Bry_fmtr.new_("0~{key1}1~{key2}2", "key1", "key2");
Tfds.Eq("0.1,2", fmtr.Bld_str_many(".", ","));
fxt.Clear().Fmt("0~{key1}1~{key2}2").Keys("key1", "key2").Args(".", ",").Test("0.1,2");
}
@Test public void Cmd() {
Bry_fmtr_tst_mok mok = new Bry_fmtr_tst_mok();
@ -37,20 +41,7 @@ public class Bry_fmtr_tst {
mok.Enabled_(true);
Tfds.Eq("01234", fmtr.Bld_str_many("1"));
}
@Test public void Err_missing_idx() {tst_Format("~{0}", "~{0}");}
String[] ary_(String... ary) {return ary;}
void tst(String fmt, String[] keys, String[] args, String expd) {
Bry_fmtr fmtr = new Bry_fmtr().Fmt_(Bry_.new_u8(fmt));
fmtr.Keys_(keys);
String actl = fmtr.Bld_str_many(args);
Tfds.Eq(expd, actl);
}
void tst_Format(String expd, String fmt, String... args) {
Bry_fmtr fmtr = new Bry_fmtr().Fmt_(fmt);
Tfds.Eq(expd, fmtr.Bld_str_many(args));
}
@Test public void Bld_bfr_many_and_set_fmt() {
Bry_fmtr_fxt fxt = new Bry_fmtr_fxt().Clear();
fxt.Bld_bfr_many_and_set_fmt("a~{0}c", Object_.Ary("b"), "abc");
}
@Test public void Escape_tilde() {
@ -64,12 +55,17 @@ class Bry_fmtr_tst_mok implements Bry_fmtr_eval_mgr {
}
}
class Bry_fmtr_fxt {
public Bry_fmtr_fxt Clear() {
if (fmtr == null) {
fmtr = Bry_fmtr.new_();
}
return this;
} private Bry_fmtr fmtr;
private final Bry_fmtr fmtr = Bry_fmtr.new_();
private final Bry_bfr bfr = Bry_bfr.new_();
private Object[] args;
public Bry_fmtr_fxt Clear() {fmtr.Fmt_(String_.Empty).Keys_(String_.Empty); args = Object_.Ary_empty; return this;}
public Bry_fmtr_fxt Fmt (String fmt) {fmtr.Fmt_(fmt); return this;}
public Bry_fmtr_fxt Keys(String... args) {fmtr.Keys_(args); return this;}
public Bry_fmtr_fxt Args(Object... args) {this.args = args; return this;}
public void Test(String expd) {
fmtr.Bld_bfr_many(bfr, args);
Tfds.Eq(expd, bfr.To_str_and_clear());
}
public void Bld_bfr_many_and_set_fmt(String fmt, Object[] args, String expd) {
fmtr.Fmt_(fmt);
fmtr.Bld_bfr_many_and_set_fmt(args);

@ -17,11 +17,11 @@ 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 gplx.core.brys.*;
public class Bry_fmtr_vals extends gplx.core.brys.Bfr_arg_base {
public class Bry_fmtr_vals implements Bfr_arg {
private final Bry_fmtr fmtr; private Object[] vals;
Bry_fmtr_vals(Bry_fmtr fmtr) {this.fmtr = fmtr;}
public Bry_fmtr_vals Vals_(Object... v) {this.vals = v; return this;}
@Override public void Bfr_arg__add(Bry_bfr bfr) {
public void Bfr_arg__add(Bry_bfr bfr) {
fmtr.Bld_bfr_ary(bfr, vals);
}
public static Bry_fmtr_vals new_fmt(String fmt, String... keys) {

@ -41,6 +41,10 @@ public class Btrie_slim_mgr implements Btrie_mgr {
cur = nxt;
}
}
public byte Match_byte_or(byte[] src, int bgn, int end, byte or) {
Object rv_obj = Match_bgn(src, bgn, end);
return rv_obj == null ? or : ((Byte_obj_val)rv_obj).Val();
}
public Btrie_slim_mgr Add_bry_tid(byte[] bry, byte tid) {return (Btrie_slim_mgr)Add_obj(bry, Byte_obj_val.new_(tid));}
public Btrie_slim_mgr Add_bry_int(byte[] key, int val) {return (Btrie_slim_mgr)Add_obj(key, Int_obj_val.new_(val));}
public Btrie_slim_mgr Add_str_byte(String key, byte val) {return (Btrie_slim_mgr)Add_obj(Bry_.new_u8(key), Byte_obj_val.new_(val));}

@ -59,7 +59,8 @@ public class Base85_ {
throw Err_.new_wo_type("neg number not allowed", "v", v);
}
public static final int Len_int = 5;
private static final int Pow85_last = 4, Radix = 85; private static final byte A7_offset = 33;
private static final int Pow85_last = 4, Radix = 85;
public static final byte A7_offset = 33;
public static final int Pow85_0 = 1, Pow85_1 = 85, Pow85_2 = 7225, Pow85_3 = 614125, Pow85_4 = 52200625;
public static int[] Pow85 = new int[]{Pow85_0, Pow85_1, Pow85_2, Pow85_3, Pow85_4}; // NOTE: ary constructed to match index to exponent; Pow85[1] = 85^1
}

@ -38,7 +38,7 @@ public class Utf16__tst {
class Utf16__fxt {
private Int_obj_ref hi_ref = Int_obj_ref.neg1_(), lo_ref = Int_obj_ref.neg1_();
public void Test_encode_decode(int expd_c_int, int... expd_int) {
byte[] expd = Bry_.new_ints(expd_int);
byte[] expd = Bry_.New_by_ints(expd_int);
byte[] bfr = new byte[10];
int bfr_len = Utf16_.Encode_int(expd_c_int, bfr, 0);
byte[] actl = Bry_.Mid_by_len(bfr, 0, bfr_len);

@ -129,6 +129,20 @@ public class IoEngine_system extends IoEngine_base {
Closeable_close(reader, url_str, false);
return sw.toString();
}
@SuppressWarnings("resource") public static byte[] Load_from_stream_as_bry(InputStream stream, String url_str) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
byte[] data = new byte[4096];
int read = 0;
try {
while ((read = stream.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, read);
}
buffer.flush();
} catch (IOException e) {
e.printStackTrace();
}
return buffer.toByteArray();
}
@Override public boolean ExistsDir(Io_url url) {return new File(url.Xto_api()).exists();}
@Override public void CreateDir(Io_url url) {new File(url.Xto_api()).mkdirs();}
@Override public void DeleteDir(Io_url url) {

@ -20,7 +20,7 @@ import org.junit.*; //using System.IO; /*Stream*/
public class IoStream_mem_tst {
@Test public void Write() { // confirm that changes written to Stream acquired via .AdpObj are written to IoStream_mem.Buffer
IoStream_mem stream = IoStream_mem.wtr_data_(Io_url_.Empty, 0);
byte[] data = Bry_.new_ints(1);
byte[] data = Bry_.New_by_ints(1);
stream.Write(data, 0, Array_.Len(data));
Tfds.Eq(1L , stream.Len());

@ -99,10 +99,10 @@ public class Io_size_ {
return val == Int_.Min_value ? cur : (val * Io_mgr.Len_mb_long);
}
}
class Io_size_fmtr_arg extends gplx.core.brys.Bfr_arg_base {
class Io_size_fmtr_arg implements Bfr_arg {
public long Val() {return val;} public Io_size_fmtr_arg Val_(long v) {val = v; return this;} long val;
public byte[] Suffix() {return suffix;} public Io_size_fmtr_arg Suffix_(byte[] v) {suffix = v; return this;} private byte[] suffix;
@Override public void Bfr_arg__add(Bry_bfr bfr) {
public void Bfr_arg__add(Bry_bfr bfr) {
long cur = val; int pow = 0;
while (cur >= 1024) {
cur /= 1024;

@ -30,11 +30,8 @@ public class Bry_obj_ref implements gplx.core.brys.Bfr_arg {
Bry_obj_ref comp = (Bry_obj_ref)obj;
return Bry_.Match(val, val_bgn, val_end, comp.val, comp.val_bgn, comp.val_end);
}
public void Bfr_arg__clear() {val = null;}
public boolean Bfr_arg__exists() {return val != null;}
public void Bfr_arg__add(Bry_bfr bfr) {
if (Bfr_arg__exists())
bfr.Add_mid(val, val_bgn, val_end);
bfr.Add_mid(val, val_bgn, val_end);
}
public static int CalcHashCode(byte[] ary, int bgn, int end) {
int rv = 0;
@ -44,4 +41,5 @@ public class Bry_obj_ref implements gplx.core.brys.Bfr_arg {
}
public static Bry_obj_ref New_empty() {return New(Bry_.Empty);}
public static Bry_obj_ref New(byte[] val) {return new Bry_obj_ref().Val_(val);}
public static Bry_obj_ref New(String val) {return new Bry_obj_ref().Val_(Bry_.new_u8(val));}
}

@ -19,7 +19,7 @@ package gplx.dbs; import gplx.*;
public class Db_meta_fld_list {
private final Ordered_hash flds = Ordered_hash_.New();
private final List_adp keys = List_adp_.new_();
public void Clear() {flds.Clear(); keys.Clear();}
public void Clear() {flds.Clear(); keys.Clear(); str_ary = null; fld_ary = null;}
public Db_meta_fld Get_by(String name) {return (Db_meta_fld)flds.Get_by(name);}
public Db_meta_fld Get_at(int idx) {return (Db_meta_fld)flds.Get_at(idx);}
public String[] To_str_ary() {if (str_ary == null) str_ary = (String[])keys.To_ary(String.class); return str_ary;} private String[] str_ary;

@ -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");
}
}

@ -20,8 +20,8 @@ import gplx.core.errs.*;
public class Bry_rdr {
private final gplx.core.primitives.Int_obj_ref pos_ref = gplx.core.primitives.Int_obj_ref.neg1_();
public byte[] Src() {return src;} private byte[] src;
public int Pos() {return pos;} private int pos;
public int Src_end() {return src_end;} private int src_end;
public int Pos() {return pos;} private int pos;
public Bry_rdr Dflt_dlm_(byte b) {this.dflt_dlm = b; return this;} private byte dflt_dlm;
public Bry_rdr Fail_throws_err_(boolean v) {err_wkr.Fail_throws_err_(v); return this;}
public Bry_rdr Init_by_page(byte[] page, byte[] src, int src_len) {err_wkr.Init_by_page(String_.new_u8(page), src); this.pos = 0; this.src = src; this.src_end = src_len; return this;}
@ -109,12 +109,7 @@ public class Bry_rdr {
if (bgn == pos) {err_wkr.Fail("int is empty"); return Int_.Min_value;}
return rv * negative;
}
public byte Read_byte_as_a7_int() {
byte rv = Byte_ascii.To_a7_int(src[pos]);
++pos;
return rv;
}
public int Read_int_by_base85(int reqd) {
public int Read_hzip_int(int reqd) {
int rv = gplx.xowa.htmls.core.hzips.Xoh_hzip_int_.Decode(reqd, src, src_end, pos, pos_ref);
pos = pos_ref.Val();
return rv;

@ -45,9 +45,9 @@ public class Btrie_u8_mgr_tst {
}
@Test public void Uft8_asymmetric() {
fxt.Init_add(Bry_.new_u8("İ") , "1");
fxt.Test_match("İ" , "1"); // exact=y; İ = Bry_.new_ints(196,176)
fxt.Test_match("i" , "1"); // lower=y; i = Bry_.new_ints(105)
fxt.Test_match("I" , null); // upper=n; I = Bry_.new_ints( 73); see Btrie_u8_itm and rv.asymmetric_bry
fxt.Test_match("İ" , "1"); // exact=y; İ = Bry_.New_by_ints(196,176)
fxt.Test_match("i" , "1"); // lower=y; i = Bry_.New_by_ints(105)
fxt.Test_match("I" , null); // upper=n; I = Bry_.New_by_ints( 73); see Btrie_u8_itm and rv.asymmetric_bry
fxt.Clear();
fxt.Init_add(Bry_.new_u8("i") , "1");

@ -88,9 +88,6 @@ public class Io_line_rdr {
}
while (true) {
int compare = Bry_.Compare(ttl, 0, ttl.length, bfr, key_pos_bgn, key_pos_end);
// if (String_.new_u8(bfr, key_pos_bgn, key_pos_end) == "US Naval Jack.svg") {
// Tfds.Write();
// }
if (compare == CompareAble_.Same) { // eq; return true and move fwd; EX: "BA" and "BA"
return true;
}

@ -19,7 +19,7 @@ package gplx.core.ios; import gplx.*; import gplx.core.*;
public class Io_sort_split_itm_sorter implements gplx.core.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
Io_sort_split_itm lhs = (Io_sort_split_itm)lhsObj, rhs = (Io_sort_split_itm)rhsObj;
// Tfds.Write(String_.new_u8(lhs.Bfr(), lhs.Key_bgn(), lhs.Key_end()), String_.new_u8(rhs.Bfr(), rhs.Key_bgn(), rhs.Key_end()));
// Tfds.Dbg(String_.new_u8(lhs.Bfr(), lhs.Key_bgn(), lhs.Key_end()), String_.new_u8(rhs.Bfr(), rhs.Key_bgn(), rhs.Key_end()));
return Bry_.Compare(lhs.Bfr(), lhs.Key_bgn(), lhs.Key_end(), rhs.Bfr(), rhs.Key_bgn(), rhs.Key_end());
}
public static final Io_sort_split_itm_sorter Instance = new Io_sort_split_itm_sorter(); Io_sort_split_itm_sorter() {}

@ -106,6 +106,7 @@ public class Gfo_protocol_itm {
;
public static final String Str_file = "file:", Str_xcmd = "xowa-cmd:";
public static final byte[] Bry_file = Bry_.new_a7(Str_file), Bry_xcmd = Bry_.new_a7(Str_xcmd);
public static final byte[] Bry_file_with_slashes = Bry_.new_a7("file:///");
public static final int Len_xcmd = Bry_xcmd.length;
public static final byte[] Bry_relative = Bry_.new_a7("//");
public static Gfo_protocol_itm Get_or(byte tid, Gfo_protocol_itm or) {

@ -97,7 +97,7 @@ public class Gfo_url_parser {
case Byte_ascii.Question: pos = Parse_qarg_key_1st(pos, b); break;
case Byte_ascii.Amp: pos = Parse_qarg_key_nth(pos, b); break;
case Byte_ascii.Eq: pos = Parse_qarg_val(pos, b); break;
case Byte_ascii.Hash: pos = Parse_anch(pos, b); break;
case Byte_ascii.Hash: if (anch_bgn == -1) pos = Parse_anch(pos, b); else ++pos; break; // anchor begins at 1st #, not last #; EX:A#B#C has anchor of "B#C" not "C" PAGE:en.w:Grand_Central_Terminal; DATE:2015-12-31
case Byte_ascii.Percent: encoded = true; ++pos; break;
default:
++pos;

@ -89,16 +89,16 @@ public class Gfo_url_parser_tst {
tstr.Run_parse("https://site/A#B").Chk_page("A").Chk_anch("B");
}
@Test public void Anch__repeat__2() {
tstr.Run_parse("https://site/A#B#C").Chk_page("A#B").Chk_anch("C");
tstr.Run_parse("https://site/A#B#C").Chk_page("A").Chk_anch("B#C");
}
@Test public void Anch__repeat__3() {
tstr.Run_parse("https://site/A#B#C#D").Chk_page("A#B#C").Chk_anch("D");
tstr.Run_parse("https://site/A#B#C#D").Chk_page("A").Chk_anch("B#C#D");
}
@Test public void Anch__missing() {
tstr.Run_parse("https://site/A#").Chk_page("A#").Chk_anch(null);
}
@Test public void Anch__missing__eos() {
tstr.Run_parse("https://site/A#B#").Chk_page("A#B#").Chk_anch(null);
tstr.Run_parse("https://site/A#B#").Chk_page("A").Chk_anch("B#");
}
@Test public void Anch__qargs__basic() {
tstr.Run_parse("https://site/A?B=C&D=E#F").Chk_page("A").Chk_qargs("B", "C", "D", "E").Chk_anch("F");

@ -15,10 +15,10 @@ 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.xowa.drds; import gplx.*; import gplx.xowa.*;
public interface Xod_img_loader {
void Show_img(int html_uid);
package gplx.dbs.diffs; import gplx.*; import gplx.dbs.*;
public class Gfdb_diff_db {
public Gfdb_diff_db(Db_conn conn) {
this.conn = conn;
}
public Db_conn Conn() {return conn;} private final Db_conn conn;
}
/*
int uid
*/

@ -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
;
}

@ -15,9 +15,11 @@ 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 abstract class Bfr_arg_base implements Bfr_arg {
@gplx.Virtual public void Bfr_arg__clear() {}
@gplx.Virtual public boolean Bfr_arg__exists() {return true;}
public abstract void Bfr_arg__add(Bry_bfr bfr);
package gplx.dbs.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
public interface Gfdb_diff_wkr {
void Init_tbls(Gfdb_diff_tbl lhs, Gfdb_diff_tbl rhs);
void Term_tbls();
void Handle_same();
void Handle_lhs_missing();
void Handle_rhs_missing();
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save