mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.8.1.1'
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.xtns.wbases.claims.itms.*;
|
||||
public class Wbase_claim_grp {
|
||||
public Wbase_claim_grp(Int_obj_ref id_ref, Wbase_claim_base[] itms) {this.id_ref = id_ref; this.itms = itms;}
|
||||
public Int_obj_ref Id_ref() {return id_ref;} private final Int_obj_ref id_ref;
|
||||
public int Id() {return id_ref.Val();}
|
||||
public String Id_str() {if (id_str == null) id_str = "P" + Int_.To_str(id_ref.Val()); return id_str;} private String id_str;
|
||||
public int Len() {return itms.length;} private Wbase_claim_base[] itms;
|
||||
public Wbase_claim_base Get_at(int i) {return itms[i];}
|
||||
public static List_adp Xto_list(Ordered_hash hash) {
|
||||
int len = hash.Count();
|
||||
List_adp rv = List_adp_.New();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Wbase_claim_grp grp = (Wbase_claim_grp)hash.Get_at(i);
|
||||
int grp_len = grp.Len();
|
||||
for (int j = 0; j < grp_len; ++j)
|
||||
rv.Add(grp.Get_at(j));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -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.xowa.xtns.wbases.claims; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
public class Wbase_claim_grp_list {
|
||||
private Ordered_hash hash = Ordered_hash_.New();
|
||||
public void Add(Wbase_claim_grp itm) {hash.Add(itm.Id_ref(), itm);}
|
||||
public int Len() {return hash.Count();}
|
||||
public Wbase_claim_grp Get_at(int i) {return (Wbase_claim_grp)hash.Get_at(i);}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
import gplx.xowa.xtns.wbases.claims.itms.*;
|
||||
public interface Wbase_claim_visitor {
|
||||
void Visit_str (Wbase_claim_string itm);
|
||||
void Visit_entity (Wbase_claim_entity itm);
|
||||
void Visit_monolingualtext (Wbase_claim_monolingualtext itm);
|
||||
void Visit_quantity (Wbase_claim_quantity itm);
|
||||
void Visit_time (Wbase_claim_time itm);
|
||||
void Visit_globecoordinate (Wbase_claim_globecoordinate itm);
|
||||
void Visit_system (Wbase_claim_value itm);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
public class Wbase_references_grp {
|
||||
public Wbase_references_grp(Wbase_claim_grp_list references, int[] references_order) {this.references = references; this.references_order = references_order;}
|
||||
public Wbase_claim_grp_list References() {return references;} private Wbase_claim_grp_list references;
|
||||
public int[] References_order() {return references_order;} private int[] references_order;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
public class Wbase_claim_entity_type_ {
|
||||
public static final byte
|
||||
Tid__item = 0
|
||||
, Tid__property = 1
|
||||
;
|
||||
private static final int Ary__len = 2;
|
||||
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
|
||||
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
|
||||
public static final Wbase_claim_enum
|
||||
Itm__item = New(Tid__item , "item")
|
||||
, Itm__property = New(Tid__property , "property")
|
||||
;
|
||||
private static Wbase_claim_enum New(byte tid, String key) {
|
||||
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
|
||||
hash_by_bry.Add(rv.Key_bry(), rv);
|
||||
Ary[tid] = rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static String To_str_or_fail(byte tid) {return Ary[tid].Key_str();}
|
||||
public static byte[] To_bry_or_fail(byte tid) {return Ary[tid].Key_bry();}
|
||||
public static byte To_tid_or_fail(byte[] bry) {return ((Wbase_claim_enum)hash_by_bry.Get_by_or_fail(bry)).Tid();}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
public class Wbase_claim_enum {
|
||||
public Wbase_claim_enum(byte tid, String key_str) {
|
||||
this.tid = tid;
|
||||
this.key_str = key_str;
|
||||
this.key_bry = Bry_.new_u8(key_str);
|
||||
}
|
||||
public byte Tid() {return tid;} private final byte tid;
|
||||
public String Key_str() {return key_str;} private final String key_str;
|
||||
public byte[] Key_bry() {return key_bry;} private final byte[] key_bry;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
public class Wbase_claim_enum_ {
|
||||
public static byte To_tid_or_invalid(Hash_adp hash, byte[] url, String key) {
|
||||
Object rv_obj = hash.Get_by(key);
|
||||
if (rv_obj == null) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown enum key for wikibase; url=~{0} key=~{1}", url, key);
|
||||
return Tid__invalid;
|
||||
}
|
||||
return ((Wbase_claim_enum)rv_obj).Tid();
|
||||
}
|
||||
public static byte To_tid_or_invalid(Hash_adp_bry hash, byte[] url, byte[] key) {
|
||||
Object rv_obj = hash.Get_by_bry(key);
|
||||
if (rv_obj == null) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown enum key for wikibase; url=~{0} key=~{1}", url, key);
|
||||
return Tid__invalid;
|
||||
}
|
||||
return ((Wbase_claim_enum)rv_obj).Tid();
|
||||
}
|
||||
public static final byte Tid__invalid = Byte_.Max_value_127;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
public class Wbase_claim_rank_ {
|
||||
public static final byte // SERIALIZED.MW
|
||||
Tid__preferred = 2
|
||||
, Tid__normal = 1
|
||||
, Tid__deprecated = 0
|
||||
, Tid__unknown = 3
|
||||
;
|
||||
private static final int Ary__len = 4;
|
||||
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
|
||||
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
|
||||
public static final Wbase_claim_enum
|
||||
Itm__preferred = New(Tid__preferred , "preferred")
|
||||
, Itm__normal = New(Tid__normal , "normal")
|
||||
, Itm__deprecated = New(Tid__deprecated , "deprecated")
|
||||
, Itm__unknown = New(Tid__unknown , "unknown")
|
||||
;
|
||||
private static Wbase_claim_enum New(byte tid, String key) {
|
||||
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
|
||||
hash_by_bry.Add(rv.Key_bry(), rv);
|
||||
Ary[tid] = rv;
|
||||
return rv;
|
||||
}
|
||||
public static byte To_tid_or_unknown(byte[] src) {
|
||||
Object obj = hash_by_bry.Get_by_bry(src);
|
||||
return obj == null ? Tid__unknown : ((Wbase_claim_enum)obj).Tid();
|
||||
}
|
||||
public static String To_str_or_fail(byte tid) {return Ary[tid].Key_str();}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
public class Wbase_claim_type {
|
||||
public Wbase_claim_type(byte tid, String key_str, String key_for_scrib) {
|
||||
this.tid = tid;
|
||||
this.key_str = key_str;
|
||||
this.key_bry = Bry_.new_u8(key_str);
|
||||
this.key_for_scrib = key_for_scrib;
|
||||
}
|
||||
public byte Tid() {return tid;} private final byte tid;
|
||||
public String Key_str() {return key_str;} private final String key_str;
|
||||
public byte[] Key_bry() {return key_bry;} private final byte[] key_bry;
|
||||
public String Key_for_scrib() {return key_for_scrib;} private final String key_for_scrib;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
public class Wbase_claim_type_ {
|
||||
public static final byte // NOT_SERIALIZED
|
||||
Tid__unknown = 0
|
||||
, Tid__value = 1
|
||||
, Tid__bad = 1
|
||||
, Tid__string = 2
|
||||
, Tid__quantity = 3
|
||||
, Tid__time = 4
|
||||
, Tid__globecoordinate = 5
|
||||
, Tid__monolingualtext = 6
|
||||
, Tid__entity = 7
|
||||
;
|
||||
private static final int Ary__len = 13;
|
||||
private static final Wbase_claim_type[] Ary = new Wbase_claim_type[Ary__len];
|
||||
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
|
||||
private static final Hash_adp hash_by_str = Hash_adp_.New();
|
||||
public static final Wbase_claim_type
|
||||
Itm__unknown = New(Tid__unknown , "unknown")
|
||||
, Itm__bad = New(Tid__bad , "bad") // NOTE: wikidata identifies several entries as "bad"; Q1615351|'s-Graveland, Q107538|Baco; DATE:2013-10-20
|
||||
, Itm__string = New(Tid__string , "string") // EX:wd:Property:P1030
|
||||
, Itm__quantity = New(Tid__quantity , "quantity")
|
||||
, Itm__time = New(Tid__time , "time")
|
||||
, Itm__globecoordinate = New(Tid__globecoordinate , "globecoordinate" , "globe-coordinate")
|
||||
, Itm__monolingualtext = New(Tid__monolingualtext , "monolingualtext")
|
||||
, Itm__entity = New(Tid__entity , "wikibase-entityid" , "wikibase-item")
|
||||
;
|
||||
private static Wbase_claim_type New(byte tid, String key) {return New(tid, key, key);}
|
||||
private static Wbase_claim_type New(byte tid, String key, String scrib) {
|
||||
Wbase_claim_type rv = new Wbase_claim_type(tid, key, scrib);
|
||||
hash_by_bry.Add(rv.Key_bry(), rv);
|
||||
hash_by_str.Add(rv.Key_str(), rv);
|
||||
Ary[tid] = rv;
|
||||
return rv;
|
||||
}
|
||||
public static String To_key_or_unknown(byte tid) {return tid < Ary__len ? Ary[tid].Key_str() : Itm__unknown.Key_str();}
|
||||
public static String To_scrib_or_unknown(byte tid) {return tid < Ary__len ? Ary[tid].Key_for_scrib() : Itm__unknown.Key_str();}
|
||||
public static byte To_tid_or_unknown(byte[] src) {return To_tid_or_unknown(src, 0, src.length);}
|
||||
public static byte To_tid_or_unknown(byte[] src, int bgn, int end) {
|
||||
Object obj = hash_by_bry.Get_by_mid(src, bgn, end);
|
||||
return obj == null ? Tid__unknown : ((Wbase_claim_type)obj).Tid();
|
||||
}
|
||||
public static byte To_tid_or_unknown(String src) {
|
||||
Object obj = hash_by_str.Get_by(src);
|
||||
return obj == null ? Tid__unknown : ((Wbase_claim_type)obj).Tid();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
public class Wbase_claim_value_type_ {
|
||||
public static final byte // SERIALIZED.MW
|
||||
Tid__novalue = 0
|
||||
, Tid__value = 1
|
||||
, Tid__somevalue = 2
|
||||
;
|
||||
private static final int Ary__len = 3;
|
||||
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
|
||||
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
|
||||
public static final Wbase_claim_enum
|
||||
Itm__novalue = New(Tid__novalue , "novalue")
|
||||
, Itm__value = New(Tid__value , "value")
|
||||
, Itm__somevalue = New(Tid__somevalue , "somevalue")
|
||||
;
|
||||
private static Wbase_claim_enum New(byte tid, String key) {
|
||||
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
|
||||
hash_by_bry.Add(rv.Key_bry(), rv);
|
||||
Ary[tid] = rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static String To_str_or_fail(byte tid) {return Ary[tid].Key_str();}
|
||||
public static byte[] To_bry_or_fail(byte tid) {return Ary[tid].Key_bry();}
|
||||
public static byte To_tid_or_fail(byte[] bry) {return ((Wbase_claim_enum)hash_by_bry.Get_by_or_fail(bry)).Tid();}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public abstract class Wbase_claim_base implements CompareAble {
|
||||
public Wbase_claim_base(int pid, byte snak_tid) {
|
||||
this.pid = pid;
|
||||
this.snak_tid = snak_tid;
|
||||
}
|
||||
public int Pid() {return pid;} private final int pid;
|
||||
public byte Snak_tid() {return snak_tid;} private final byte snak_tid;
|
||||
public byte Rank_tid() {return rank_tid;} private byte rank_tid = Wbase_claim_rank_.Tid__normal; // TEST: default to normal for tests
|
||||
public String Prop_type() {return Prop_type_statement;} private static final String Prop_type_statement = "statement";
|
||||
public byte[] Wguid() {return wguid;} private byte[] wguid;
|
||||
public Wbase_claim_grp_list Qualifiers() {return qualifiers;} private Wbase_claim_grp_list qualifiers;
|
||||
public int[] Qualifiers_order() {return qualifiers_order;} private int[] qualifiers_order;
|
||||
public Wbase_references_grp[] References() {return references;} private Wbase_references_grp[] references;
|
||||
public abstract byte Val_tid();
|
||||
public abstract void Welcome(Wbase_claim_visitor visitor);
|
||||
|
||||
public void Rank_tid_(byte v) {this.rank_tid = v;}
|
||||
public void Wguid_(byte[] v) {this.wguid = v;}
|
||||
public Wbase_claim_base Qualifiers_(Wbase_claim_grp_list v) {qualifiers = v; return this;}
|
||||
public void Qualifiers_order_(int[] v) {qualifiers_order = v;}
|
||||
public void References_(Wbase_references_grp[] v) {references = v;}
|
||||
|
||||
public int compareTo(Object obj) {
|
||||
Wbase_claim_base comp = (Wbase_claim_base)obj;
|
||||
return Int_.Compare(pid, comp.pid);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_entity extends Wbase_claim_base {
|
||||
public Wbase_claim_entity(int pid, byte snak_tid, byte entity_tid, byte[] entity_id_bry) {super(pid, snak_tid);
|
||||
this.entity_tid = entity_tid;
|
||||
this.entity_id_bry = entity_id_bry;
|
||||
this.entity_id = Bry_.To_int(entity_id_bry);
|
||||
}
|
||||
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__entity;}
|
||||
public int Entity_id() {return entity_id;} private final int entity_id;
|
||||
public byte[] Entity_id_bry() {return entity_id_bry;} private final byte[] entity_id_bry;
|
||||
public byte Entity_tid() {return entity_tid;} private final byte entity_tid;
|
||||
public boolean Entity_tid_is_qid() {return entity_tid == Wbase_claim_entity_type_.Tid__item;}
|
||||
public String Entity_tid_str() {return Wbase_claim_entity_type_.To_str_or_fail(entity_tid);}
|
||||
public byte[] Entity_tid_bry() {return Wbase_claim_entity_type_.To_bry_or_fail(entity_tid);}
|
||||
|
||||
public byte[] Page_ttl_db() {
|
||||
return entity_tid == Wbase_claim_entity_type_.Tid__item
|
||||
? Bry_.Add(Wdata_wiki_mgr.Ttl_prefix_qid_bry_db, entity_id_bry)
|
||||
: Bry_.Add(Wdata_wiki_mgr.Ttl_prefix_pid_bry, entity_id_bry)
|
||||
;
|
||||
}
|
||||
public byte[] Page_ttl_gui() {
|
||||
return entity_tid == Wbase_claim_entity_type_.Tid__item
|
||||
? Bry_.Add(Wdata_wiki_mgr.Ttl_prefix_qid_bry_gui, entity_id_bry)
|
||||
: Bry_.Add(Wdata_wiki_mgr.Ttl_prefix_pid_bry, entity_id_bry)
|
||||
;
|
||||
}
|
||||
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_entity(this);}
|
||||
@Override public String toString() {// TEST:
|
||||
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()), this.Entity_tid_str(), Int_.To_str(entity_id));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_entity_ {
|
||||
public static final byte
|
||||
Tid__entity_type = 0
|
||||
, Tid__numeric_id = 1
|
||||
;
|
||||
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
|
||||
public static final Wbase_claim_enum
|
||||
Itm__entity_type = New(Tid__entity_type , "entity-type")
|
||||
, Itm__numeric_id = New(Tid__numeric_id , "numeric-id")
|
||||
;
|
||||
private static Wbase_claim_enum New(byte tid, String key) {
|
||||
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
|
||||
hash_by_bry.Add(rv.Key_bry(), rv);
|
||||
return rv;
|
||||
}
|
||||
public static byte To_tid_or_invalid(byte[] page_url, byte[] key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_bry, page_url, key);}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_globecoordinate extends Wbase_claim_base {
|
||||
public Wbase_claim_globecoordinate(int pid, byte snak_tid, byte[] lat, byte[] lng, byte[] alt, byte[] prc, byte[] glb) {super(pid, snak_tid);
|
||||
this.lat = lat; this.lng = lng; this.alt = alt; this.prc = prc; this.glb = glb;
|
||||
}
|
||||
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__globecoordinate;}
|
||||
public byte[] Lat() {return lat;} private final byte[] lat;
|
||||
public byte[] Lng() {return lng;} private final byte[] lng;
|
||||
public byte[] Alt() {return alt;} private final byte[] alt;
|
||||
public byte[] Prc() {return prc;} private final byte[] prc;
|
||||
public byte[] Glb() {return glb;} private final byte[] glb;
|
||||
public byte[] Glb_ttl() {return glb_ttl;} private byte[] glb_ttl;
|
||||
|
||||
public void Glb_ttl_(byte[] v) {glb_ttl = v;}
|
||||
public Decimal_adp Prc_as_num() {
|
||||
if (prc_as_num == null)
|
||||
prc_as_num = Bry_.Eq(prc, Object_.Bry__null) ? Decimal_adp_.One : Decimal_adp_.parse(String_.new_a7(prc));
|
||||
return prc_as_num;
|
||||
} private Decimal_adp prc_as_num;
|
||||
|
||||
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_globecoordinate(this);}
|
||||
@Override public String toString() {// TEST:
|
||||
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()), String_.new_u8(lat), String_.new_u8(lng), String_.new_u8(alt), String_.new_u8(prc), String_.new_u8(glb));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_globecoordinate_ {
|
||||
public static final byte
|
||||
Tid__latitude = 0
|
||||
, Tid__longitude = 1
|
||||
, Tid__altitude = 2
|
||||
, Tid__precision = 3
|
||||
, Tid__globe = 4
|
||||
;
|
||||
private static final int Ary__len = 5;
|
||||
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
|
||||
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
|
||||
private static final Hash_adp hash_by_str = Hash_adp_.New();
|
||||
public static final Wbase_claim_enum
|
||||
Itm__latitude = New(Tid__latitude , "latitude")
|
||||
, Itm__longitude = New(Tid__longitude , "longitude")
|
||||
, Itm__altitude = New(Tid__altitude , "altitude")
|
||||
, Itm__precision = New(Tid__precision , "precision")
|
||||
, Itm__globe = New(Tid__globe , "globe")
|
||||
;
|
||||
private static Wbase_claim_enum New(byte tid, String key) {
|
||||
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
|
||||
hash_by_bry.Add(rv.Key_bry(), rv);
|
||||
hash_by_str.Add(rv.Key_str(), rv);
|
||||
Ary[tid] = rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static String To_str_or_invalid(byte tid) {return Ary[tid].Key_str();}
|
||||
public static byte[] To_bry_or_fail(byte tid) {return Ary[tid].Key_bry();}
|
||||
public static byte To_tid_or_invalid(byte[] page_url, String key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_str, page_url, key);}
|
||||
public static byte To_tid_or_invalid(byte[] page_url, byte[] key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_bry, page_url, key);}
|
||||
|
||||
public static String
|
||||
Val_globe_dflt_str = "http://www.wikidata.org/entity/Q2"
|
||||
;
|
||||
public static byte[]
|
||||
Val_globe_dflt_bry = Bry_.new_a7(Val_globe_dflt_str)
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_monolingualtext extends Wbase_claim_base {
|
||||
public Wbase_claim_monolingualtext(int pid, byte snak_tid, byte[] lang, byte[] text) {super(pid, snak_tid);
|
||||
this.lang = lang; this.text = text;
|
||||
}
|
||||
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__monolingualtext;}
|
||||
public byte[] Lang() {return lang;} private final byte[] lang;
|
||||
public byte[] Text() {return text;} private final byte[] text;
|
||||
|
||||
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_monolingualtext(this);}
|
||||
@Override public String toString() {// TEST:
|
||||
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()), String_.new_u8(lang), String_.new_u8(text));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_monolingualtext_ {
|
||||
public static final byte
|
||||
Tid__text = 0
|
||||
, Tid__language = 1
|
||||
;
|
||||
private static final int Ary__len = 2;
|
||||
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
|
||||
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
|
||||
public static final Wbase_claim_enum
|
||||
Itm__text = New(Tid__text , "text")
|
||||
, Itm__language = New(Tid__language , "language")
|
||||
;
|
||||
private static Wbase_claim_enum New(byte tid, String key) {
|
||||
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
|
||||
hash_by_bry.Add(rv.Key_bry(), rv);
|
||||
Ary[tid] = rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static String To_str_or_invalid(byte tid) {return Ary[tid].Key_str();}
|
||||
public static byte[] To_bry_or_fail(byte tid) {return Ary[tid].Key_bry();}
|
||||
public static byte To_tid_or_invalid(byte[] page_url, byte[] key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_bry, page_url, key);}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_quantity extends Wbase_claim_base {
|
||||
public Wbase_claim_quantity(int pid, byte snak_tid, byte[] amount, byte[] unit, byte[] ubound, byte[] lbound) {super(pid, snak_tid);
|
||||
this.amount = amount; this.unit = unit; this.ubound = ubound; this.lbound = lbound;
|
||||
}
|
||||
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__quantity;}
|
||||
public byte[] Amount() {return amount;} private final byte[] amount;
|
||||
public byte[] Ubound() {return ubound;} private final byte[] ubound;
|
||||
public byte[] Lbound() {return lbound;} private final byte[] lbound;
|
||||
public byte[] Unit() {return unit;} private final byte[] unit;
|
||||
|
||||
public Decimal_adp Amount_as_num() {
|
||||
if (amount_as_num == null) amount_as_num = To_decimal("amount", amount);
|
||||
return amount_as_num;
|
||||
} private Decimal_adp amount_as_num;
|
||||
public Decimal_adp Ubound_as_num() {
|
||||
if (ubound_as_num == null) ubound_as_num = To_decimal("upper", ubound);
|
||||
return ubound_as_num;
|
||||
} private Decimal_adp ubound_as_num;
|
||||
public Decimal_adp Lbound_as_num() {
|
||||
if (lbound_as_num == null) lbound_as_num = To_decimal("lower", lbound);
|
||||
return lbound_as_num;
|
||||
} private Decimal_adp lbound_as_num;
|
||||
private Decimal_adp To_decimal(String type, byte[] v) {
|
||||
if (v == null) throw Err_.new_("wbase", "value is null", "type", type);
|
||||
int len = v.length; if (len == 0) throw Err_.new_("wbase", "value is empty", "type", type);
|
||||
if (v[0] == Byte_ascii.Plus) v = Bry_.Mid(v, 1);
|
||||
return Decimal_adp_.parse(String_.new_a7(v));
|
||||
}
|
||||
|
||||
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_quantity(this);}
|
||||
@Override public String toString() {// TEST:
|
||||
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()), String_.new_u8(amount), String_.new_u8(unit), String_.new_u8(ubound), String_.new_u8(lbound));
|
||||
}
|
||||
public static final byte[] Unit_1 = Bry_.new_a7("1");
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_quantity_ {
|
||||
public static final byte
|
||||
Tid__amount = 0
|
||||
, Tid__unit = 1
|
||||
, Tid__upperbound = 2
|
||||
, Tid__lowerbound = 3
|
||||
;
|
||||
private static final int Ary__len = 4;
|
||||
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
|
||||
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
|
||||
private static final Hash_adp hash_by_str = Hash_adp_.New();
|
||||
public static final Wbase_claim_enum
|
||||
Itm__amount = New(Tid__amount , "amount")
|
||||
, Itm__unit = New(Tid__unit , "unit")
|
||||
, Itm__upperbound = New(Tid__upperbound , "upperBound")
|
||||
, Itm__lowerbound = New(Tid__lowerbound , "lowerBound")
|
||||
;
|
||||
private static Wbase_claim_enum New(byte tid, String key) {
|
||||
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
|
||||
hash_by_bry.Add(rv.Key_bry(), rv);
|
||||
hash_by_str.Add(rv.Key_str(), rv);
|
||||
Ary[tid] = rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static String To_str_or_invalid(byte tid) {return Ary[tid].Key_str();}
|
||||
public static byte[] To_bry_or_fail(byte tid) {return Ary[tid].Key_bry();}
|
||||
public static byte To_tid_or_invalid(byte[] page_url, String key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_str, page_url, key);}
|
||||
public static byte To_tid_or_invalid(byte[] page_url, byte[] key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_bry, page_url, key);}
|
||||
}
|
||||
@@ -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.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_string extends Wbase_claim_base {
|
||||
public Wbase_claim_string(int pid, byte snak_tid, byte[] val) {super(pid, snak_tid);
|
||||
this.val = val;
|
||||
}
|
||||
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__string;}
|
||||
public byte[] Val_str() {return val;} private final byte[] val;
|
||||
|
||||
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_str(this);}
|
||||
@Override public String toString() {// TEST:
|
||||
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()), String_.new_u8(val));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.times.*; import gplx.xowa.xtns.wbases.hwtrs.*;
|
||||
public class Wbase_claim_time extends Wbase_claim_base {
|
||||
public Wbase_claim_time(int pid, byte snak_tid, byte[] time, byte[] timezone, byte[] before, byte[] after, byte[] precision, byte[] calendar) {super(pid, snak_tid);
|
||||
this.time = time; this.before = before; this.after = after; this.precision = precision; this.calendar = calendar;
|
||||
}
|
||||
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__time;}
|
||||
public byte[] Time() {return time;} private final byte[] time;
|
||||
public byte[] Before() {return before;} private final byte[] before;
|
||||
public byte[] After() {return after;} private final byte[] after;
|
||||
public byte[] Precision() {return precision;} private final byte[] precision;
|
||||
public byte[] Calendar() {return calendar;} private final byte[] calendar;
|
||||
public byte[] Calendar_ttl() {return calendar_ttl;} private byte[] calendar_ttl;
|
||||
public boolean Calendar_is_julian() {return Bry_.Eq(calendar, Calendar_julian);}
|
||||
|
||||
public void Calendar_ttl_(byte[] v) {calendar_ttl = v;}
|
||||
|
||||
public Wbase_date Time_as_date() {
|
||||
if (time_as_date == null) time_as_date = Wbase_date.Parse(time, this.Precision_int(), this.Before_int(), this.After_int(), this.Calendar_is_julian());
|
||||
return time_as_date;
|
||||
} private Wbase_date time_as_date;
|
||||
public int Precision_int() {
|
||||
if (precision_int == Int_.Min_value) {
|
||||
precision_int = Bry_.To_int_or(precision, -1);
|
||||
if (precision_int == -1) {
|
||||
precision_int = Wbase_date.Fmt_ymdhns;
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown precision: ~{0}", String_.new_u8(precision));
|
||||
}
|
||||
}
|
||||
return precision_int;
|
||||
} private int precision_int = Int_.Min_value;
|
||||
public int Before_int() {
|
||||
if (before_int == Int_.Min_value) {
|
||||
before_int = Bry_.To_int_or(before, -1);
|
||||
if (before_int == -1) {
|
||||
before_int = 0;
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown before: ~{0}", String_.new_u8(before));
|
||||
}
|
||||
}
|
||||
return before_int;
|
||||
} private int before_int = Int_.Min_value;
|
||||
public int After_int() {
|
||||
if (after_int == Int_.Min_value) {
|
||||
after_int = Bry_.To_int_or(after, -1);
|
||||
if (after_int == -1) {
|
||||
after_int = 0;
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown after: ~{0}", String_.new_u8(after));
|
||||
}
|
||||
}
|
||||
return after_int;
|
||||
} private int after_int = Int_.Min_value;
|
||||
|
||||
public void Write_to_bfr(Bry_bfr bfr, Bry_bfr tmp_time_bfr, Bry_fmtr tmp_time_fmtr, Wdata_hwtr_msgs msgs, byte[] ttl) {
|
||||
try {
|
||||
Wbase_date date = this.Time_as_date();
|
||||
boolean calendar_is_julian = this.Calendar_is_julian();
|
||||
byte[] calendar_display = null;
|
||||
if (calendar_is_julian) {
|
||||
date = Wbase_date.Xto_julian(date);
|
||||
calendar_display = msgs.Time_julian();
|
||||
}
|
||||
Wbase_date.Xto_str(bfr, tmp_time_fmtr, tmp_time_bfr, msgs, date);
|
||||
if (calendar_display != null)
|
||||
bfr.Add_byte_space().Add(calendar_display);
|
||||
} catch (Exception e) {
|
||||
Xoa_app_.Usr_dlg().Warn_many("", "", "failed to write time; ttl=~{0} pid=~{1} err=~{2}", ttl, this.Pid(), Err_.Message_gplx_log(e));
|
||||
}
|
||||
}
|
||||
public static void Write_to_bfr(Bry_bfr bfr, Bry_bfr tmp_time_bfr, Bry_fmtr tmp_time_fmtr, Wdata_hwtr_msgs msgs
|
||||
, byte[] ttl, byte[] pid, Wbase_date date, boolean calendar_is_julian) {
|
||||
try {
|
||||
byte[] calendar_display = null;
|
||||
if (calendar_is_julian) {
|
||||
date = Wbase_date.Xto_julian(date);
|
||||
calendar_display = msgs.Time_julian();
|
||||
}
|
||||
Wbase_date.Xto_str(bfr, tmp_time_fmtr, tmp_time_bfr, msgs, date);
|
||||
if (calendar_display != null)
|
||||
bfr.Add_byte_space().Add(calendar_display);
|
||||
} catch (Exception e) {
|
||||
Xoa_app_.Usr_dlg().Warn_many("", "", "failed to write time; ttl=~{0} pid=~{1} err=~{2}", ttl, pid, Err_.Message_gplx_log(e));
|
||||
}
|
||||
}
|
||||
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_time(this);}
|
||||
@Override public String toString() {// TEST:
|
||||
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()), String_.new_u8(time), String_.new_u8(before), String_.new_u8(after), String_.new_u8(precision), String_.new_u8(calendar));
|
||||
}
|
||||
public static final byte[] Calendar_julian = Bry_.new_a7("http://www.wikidata.org/entity/Q1985786");
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.times.*;
|
||||
public class Wbase_claim_time_ {
|
||||
public static final byte
|
||||
Tid__time = 0
|
||||
, Tid__timezone = 1
|
||||
, Tid__before = 2
|
||||
, Tid__after = 3
|
||||
, Tid__precision = 4
|
||||
, Tid__calendarmodel = 5
|
||||
;
|
||||
private static final int Ary__len = 6;
|
||||
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
|
||||
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
|
||||
private static final Hash_adp hash_by_str = Hash_adp_.New();
|
||||
public static final Wbase_claim_enum
|
||||
Itm__time = New(Tid__time , "time")
|
||||
, Itm__timezone = New(Tid__timezone , "timezone")
|
||||
, Itm__before = New(Tid__before , "before")
|
||||
, Itm__after = New(Tid__after , "after")
|
||||
, Itm__precision = New(Tid__precision , "precision")
|
||||
, Itm__calendarmodel = New(Tid__calendarmodel , "calendarmodel")
|
||||
;
|
||||
private static Wbase_claim_enum New(byte tid, String key) {
|
||||
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
|
||||
hash_by_bry.Add(rv.Key_bry(), rv);
|
||||
hash_by_str.Add(rv.Key_str(), rv);
|
||||
Ary[tid] = rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static String To_str_or_invalid(byte tid) {return Ary[tid].Key_str();}
|
||||
public static byte[] To_bry_or_fail(byte tid) {return Ary[tid].Key_bry();}
|
||||
public static byte To_tid_or_invalid(byte[] page_url, String key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_str, page_url, key);}
|
||||
public static byte To_tid_or_invalid(byte[] page_url, byte[] key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_bry, page_url, key);}
|
||||
|
||||
public static final Wbase_data_itm
|
||||
Dflt__precision = Wbase_data_itm.New_int(11)
|
||||
, Dflt__before = Wbase_data_itm.New_int(0)
|
||||
, Dflt__after = Wbase_data_itm.New_int(0)
|
||||
, Dflt__timezone = Wbase_data_itm.New_int(0)
|
||||
, Dflt__calendarmodel = Wbase_data_itm.New_str("http://www.wikidata.org/entity/Q1985727")
|
||||
;
|
||||
|
||||
private static final byte[] Bry_year_prefix = Bry_.new_a7("+0000000");
|
||||
public static byte[] To_bry(Bry_bfr bfr, String date) {return To_bry(bfr, DateAdp_.parse_fmt(date, "yyyy-MM-dd HH:mm:ss"));}
|
||||
public static byte[] To_bry(Bry_bfr bfr, DateAdp date) {// +0000000yyyy-MM-ddTHH:mm:ssZ
|
||||
bfr
|
||||
.Add(Bry_year_prefix)
|
||||
.Add_int_fixed(date.Year(), 4)
|
||||
.Add_byte(Byte_ascii.Dash)
|
||||
.Add_int_fixed(date.Month(), 2)
|
||||
.Add_byte(Byte_ascii.Dash)
|
||||
.Add_int_fixed(date.Day(), 2)
|
||||
.Add_byte(Byte_ascii.Ltr_T)
|
||||
.Add_int_fixed(date.Hour(), 2)
|
||||
.Add_byte(Byte_ascii.Colon)
|
||||
.Add_int_fixed(date.Minute(), 2)
|
||||
.Add_byte(Byte_ascii.Colon)
|
||||
.Add_int_fixed(date.Second(), 2)
|
||||
.Add_byte(Byte_ascii.Ltr_Z)
|
||||
;
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_value extends Wbase_claim_base {
|
||||
public Wbase_claim_value(int pid, byte val_tid, byte snak_tid) {super(pid, snak_tid);
|
||||
this.val_tid = val_tid;
|
||||
}
|
||||
@Override public byte Val_tid() {return val_tid;} private final byte val_tid;
|
||||
|
||||
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_system(this);}
|
||||
@Override public String toString() {// TEST:
|
||||
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()));
|
||||
}
|
||||
|
||||
public static Wbase_claim_value New_novalue(int pid) {return new Wbase_claim_value(pid, Wbase_claim_type_.Tid__unknown , Wbase_claim_value_type_.Tid__novalue);}
|
||||
public static Wbase_claim_value New_somevalue(int pid) {return new Wbase_claim_value(pid, Wbase_claim_type_.Tid__unknown , Wbase_claim_value_type_.Tid__somevalue);}
|
||||
}
|
||||
@@ -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.xowa.xtns.wbases.claims.itms.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
|
||||
public class Wbase_data_itm {
|
||||
public Wbase_data_itm(int val_int, String val_str, byte[] val_bry) {
|
||||
this.val_int = val_int;
|
||||
this.val_str = val_str;
|
||||
this.val_bry = val_bry;
|
||||
}
|
||||
public int Val_int() {return val_int;} private final int val_int;
|
||||
public String Val_str() {return val_str;} private final String val_str;
|
||||
public byte[] Val_bry() {return val_bry;} private final byte[] val_bry;
|
||||
|
||||
public static Wbase_data_itm New_int(int val) {return new Wbase_data_itm(val, Int_.To_str(val), Int_.To_bry(val));}
|
||||
public static Wbase_data_itm New_str(String val) {return new Wbase_data_itm( -1, val, Bry_.new_u8(val));}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
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.xowa.xtns.wbases.claims.itms.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.xtns.wbases.hwtrs.*;
|
||||
public class Wbase_date {
|
||||
public Wbase_date(long year, int month, int day, int hour, int minute, int second, int precision, int before, int after, boolean calendar_is_julian) {
|
||||
this.year = year; this.month = month; this.day = day; this.hour = hour; this.minute = minute; this.second = second;
|
||||
this.precision = precision; this.before = before; this.after = after; this.calendar_is_julian = calendar_is_julian;
|
||||
}
|
||||
public long Year() {return year;} private final long year;
|
||||
public int Month() {return month;} private final int month;
|
||||
public int Day() {return day;} private final int day;
|
||||
public int Hour() {return hour;} private final int hour;
|
||||
public int Minute() {return minute;} private final int minute;
|
||||
public int Second() {return second;} private final int second;
|
||||
public int Precision() {return precision;} private final int precision;
|
||||
public int Before() {return before;} private final int before;
|
||||
public int After() {return after;} private final int after;
|
||||
public boolean Calendar_is_julian() {return calendar_is_julian;} private final boolean calendar_is_julian;
|
||||
public static Wbase_date Parse(byte[] date, int precision, int before, int after, boolean calendar_is_julian) {// EX:+00000002001-02-03T04:05:06Z
|
||||
int year_sign = 1;
|
||||
switch (date[0]) {
|
||||
case Byte_ascii.Plus: break;
|
||||
case Byte_ascii.Dash: year_sign = -1; break;
|
||||
default: throw Err_.new_unhandled(date[0]);
|
||||
}
|
||||
int year_end = Bry_find_.Find_fwd(date, Byte_ascii.Dash, 1);
|
||||
long year = Long_.parse_or(String_.new_a7(date, 1, year_end), -1); if (year == -1) throw Err_.new_wo_type("parse failed", "raw", String_.new_a7(date));
|
||||
int month = Bry_.To_int_or(date, year_end + 1, year_end + 3, -1);
|
||||
int day = Bry_.To_int_or(date, year_end + 4, year_end + 6, -1);
|
||||
int hour = Bry_.To_int_or(date, year_end + 7, year_end + 9, -1);
|
||||
int minute = Bry_.To_int_or(date, year_end + 10, year_end + 12, -1);
|
||||
int second = Bry_.To_int_or(date, year_end + 13, year_end + 15, -1);
|
||||
return new Wbase_date(year * year_sign, month, day, hour, minute, second, precision, before, after, calendar_is_julian);
|
||||
}
|
||||
public static Wbase_date Xto_julian(Wbase_date date) {
|
||||
int a = (int)Math_.Floor((14 - date.Month() / 12));
|
||||
int y = (int)date.Year() + 4800 - a;
|
||||
int m = date.Month() + 12 * a - 3;
|
||||
int julian = date.Day() + (int)Math_.Floor((153 * m + 2) / 5) + 365 * y + (int)Math_.Floor(y / 4) - (int)Math_.Floor(y / 100) + (int)Math_.Floor(y / 400) - 32045;
|
||||
int c = julian + 32082;
|
||||
int d = (int)Math_.Floor((4 * c + 3) / 1461);
|
||||
int e = c - (int)Math_.Floor((1461 * d) / 4);
|
||||
int n = (int)Math_.Floor((5 * e + 2) / 153);
|
||||
int new_y = d - 4800 + (int)Math_.Floor(n / 10);
|
||||
int new_m = n + 3 - 12 * (int)Math_.Floor(n / 10);
|
||||
int new_d = e - (int)Math_.Floor((153 * n + 2) / 5) + 1;
|
||||
return new Wbase_date(new_y, new_m, new_d, date.Hour(), date.Minute(), date.Second(), date.precision, date.before, date.after, date.calendar_is_julian);
|
||||
}
|
||||
public static void Xto_str(Bry_bfr bfr, Bry_fmtr tmp_fmtr, Bry_bfr tmp_bfr, Wdata_hwtr_msgs msgs, Wbase_date date) {
|
||||
boolean calendar_is_julian = date.calendar_is_julian;
|
||||
if (calendar_is_julian)
|
||||
date = Xto_julian(date);
|
||||
long year = date.Year();
|
||||
int months_bgn = msgs.Month_bgn_idx();
|
||||
byte[][] months = msgs.Ary();
|
||||
int precision = date.precision;
|
||||
byte[] time_spr = msgs.Sym_time_spr();
|
||||
switch (precision) {
|
||||
case Wbase_date.Fmt_ym: // EX: "Feb 2001"
|
||||
bfr.Add(months[months_bgn + date.Month() - List_adp_.Base1]);
|
||||
bfr.Add_byte_space();
|
||||
bfr.Add_long_variable(year);
|
||||
break;
|
||||
case Wbase_date.Fmt_ymd: // EX: "3 Feb 2001"
|
||||
bfr.Add_int_variable(date.Day());
|
||||
bfr.Add_byte_space();
|
||||
bfr.Add(months[months_bgn + date.Month() - List_adp_.Base1]);
|
||||
bfr.Add_byte_space();
|
||||
bfr.Add_long_variable(date.Year());
|
||||
break;
|
||||
case Wbase_date.Fmt_ymdh: // EX: "4:00 3 Feb 2011"
|
||||
bfr.Add_int_variable(date.Hour());
|
||||
bfr.Add(time_spr);
|
||||
bfr.Add_int_fixed(0, 2);
|
||||
bfr.Add_byte_space();
|
||||
bfr.Add_int_variable(date.Day());
|
||||
bfr.Add_byte_space();
|
||||
bfr.Add(months[months_bgn + date.Month() - List_adp_.Base1]);
|
||||
bfr.Add_byte_space();
|
||||
bfr.Add_long_variable(date.Year());
|
||||
break;
|
||||
case Wbase_date.Fmt_ymdhn: // EX: "4:05 3 Feb 2011"
|
||||
bfr.Add_int_variable(date.Hour());
|
||||
bfr.Add(time_spr);
|
||||
bfr.Add_int_fixed(date.Minute(), 2);
|
||||
bfr.Add_byte_space();
|
||||
bfr.Add_int_variable(date.Day());
|
||||
bfr.Add_byte_space();
|
||||
bfr.Add(months[months_bgn + date.Month() - List_adp_.Base1]);
|
||||
bfr.Add_byte_space();
|
||||
bfr.Add_long_variable(date.Year());
|
||||
break;
|
||||
default:
|
||||
if (precision <= 9) // y, round to (9 - prec)
|
||||
Xto_str_fmt_y(bfr, tmp_fmtr, tmp_bfr, msgs, date, precision);
|
||||
else { // EX: "4:05:06 3 Feb 2011"
|
||||
bfr.Add_int_variable(date.Hour());
|
||||
bfr.Add(time_spr);
|
||||
bfr.Add_int_fixed(date.Minute(), 2);
|
||||
bfr.Add(time_spr);
|
||||
bfr.Add_int_fixed(date.Second(), 2);
|
||||
bfr.Add_byte_space();
|
||||
bfr.Add_int_variable(date.Day());
|
||||
bfr.Add_byte_space();
|
||||
bfr.Add(months[months_bgn + date.Month() - List_adp_.Base1]);
|
||||
bfr.Add_byte_space();
|
||||
bfr.Add_long_variable(date.Year());
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (calendar_is_julian)
|
||||
bfr.Add(msgs.Time_julian());
|
||||
Xto_str_beforeafter(bfr, tmp_fmtr, tmp_bfr, msgs, date);
|
||||
}
|
||||
private static void Xto_str_beforeafter(Bry_bfr bfr, Bry_fmtr tmp_fmtr, Bry_bfr tmp_bfr, Wdata_hwtr_msgs msgs, Wbase_date date) {
|
||||
byte[] bry = null;
|
||||
int before = date.before;
|
||||
int after = date.after;
|
||||
if (before == 0) {
|
||||
if (after != 0)
|
||||
bry = tmp_bfr.Add(msgs.Sym_plus()).Add_int_variable(after).To_bry_and_clear();
|
||||
}
|
||||
else {
|
||||
if (after == 0)
|
||||
bry = tmp_bfr.Add(msgs.Sym_minus()).Add_int_variable(before).To_bry_and_clear();
|
||||
else if (before == after)
|
||||
bry = tmp_bfr.Add(msgs.Sym_plusminus()).Add_int_variable(before).To_bry_and_clear();
|
||||
else
|
||||
bry = tmp_bfr.Add(msgs.Sym_minus()).Add_int_variable(before).Add(msgs.Sym_list_comma()).Add(msgs.Sym_plus()).Add_int_variable(after).To_bry_and_clear();
|
||||
}
|
||||
if (bry != null) {
|
||||
bry = tmp_fmtr.Fmt_(msgs.Sym_fmt_parentheses()).Bld_bry_many(tmp_bfr, bry);
|
||||
bfr.Add_byte_space().Add(bry);
|
||||
}
|
||||
}
|
||||
private static void Xto_str_fmt_y(Bry_bfr bfr, Bry_fmtr tmp_fmtr, Bry_bfr tmp_bfr, Wdata_hwtr_msgs msgs, Wbase_date date, int precision) {
|
||||
int year_pow = 9 - precision;
|
||||
byte[] year_fmt = msgs.Ary()[msgs.Time_year_idx() + year_pow];
|
||||
long year = date.Year();
|
||||
byte[] repl_fmt = null;
|
||||
if (year <= 0) { // negative
|
||||
if (year_pow < 4) // negative years < 999 get "BC"
|
||||
repl_fmt = msgs.Time_relative_bc();
|
||||
else // negative years > 999 get "ago"
|
||||
repl_fmt = msgs.Time_relative_ago();
|
||||
}
|
||||
else {
|
||||
if (year_pow > 4) // positive years > 999 get "in time"
|
||||
repl_fmt = msgs.Time_relative_in();
|
||||
}
|
||||
if (repl_fmt != null)
|
||||
year_fmt = tmp_fmtr.Fmt_(repl_fmt).Bld_bry_many(tmp_bfr, year_fmt);
|
||||
if (year <= 0)
|
||||
year *= -1; // convert negative to positive; note that negative year will be reported with "BC" / "ago"
|
||||
switch (year_pow) {
|
||||
case 0: break; // noop
|
||||
default:
|
||||
year = (int)(year / Math_.Pow(10, year_pow));
|
||||
break;
|
||||
}
|
||||
byte[] year_bry = tmp_fmtr.Fmt_(year_fmt).Bld_bry_many(tmp_bfr, year);
|
||||
bfr.Add(year_bry);
|
||||
}
|
||||
public static final int
|
||||
Fmt_y = 9
|
||||
, Fmt_ym = 10
|
||||
, Fmt_ymd = 11
|
||||
, Fmt_ymdh = 12
|
||||
, Fmt_ymdhn = 13
|
||||
, Fmt_ymdhns = 14 // anything >13 ?
|
||||
;
|
||||
}
|
||||
@@ -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.xowa.xtns.wbases.claims.itms.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
|
||||
import org.junit.*; import gplx.core.brys.fmtrs.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.parsers.*; import gplx.xowa.xtns.wbases.hwtrs.*;
|
||||
public class Wbase_date_tst {
|
||||
@Before public void init() {fxt.Clear();} private Wbase_date_fxt fxt = new Wbase_date_fxt();
|
||||
@Test public void Parse() {
|
||||
fxt.Test_parse("+00000002001-02-03T04:05:06Z", 2001, 2, 3, 4, 5, 6);
|
||||
fxt.Test_parse("-98765432109-02-03T04:05:06Z", -98765432109L, 2, 3, 4, 5, 6);
|
||||
}
|
||||
@Test public void Julian() {
|
||||
fxt.Test_julian(Int_.Ary(1600, 1, 2), Int_.Ary(1600, 1, 18));
|
||||
}
|
||||
@Test public void Xto_str() {
|
||||
String date = "+00000002001-02-03T04:05:06Z";
|
||||
fxt.Test_xto_str(date, Wbase_date.Fmt_ym , "Feb 2001");
|
||||
fxt.Test_xto_str(date, Wbase_date.Fmt_ymd , "3 Feb 2001");
|
||||
fxt.Test_xto_str(date, Wbase_date.Fmt_ymdh , "4:00 3 Feb 2001");
|
||||
fxt.Test_xto_str(date, Wbase_date.Fmt_ymdhn , "4:05 3 Feb 2001");
|
||||
fxt.Test_xto_str(date, Wbase_date.Fmt_ymdhns , "4:05:06 3 Feb 2001");
|
||||
}
|
||||
@Test public void Xto_str_year() {
|
||||
fxt.Test_xto_str("+00000001970-01-01T00:00:00Z", 9, "1970");
|
||||
fxt.Test_xto_str("-00000001234-01-01T00:00:00Z", 9, "1234 BC");
|
||||
fxt.Test_xto_str("+00000001987-01-01T00:00:00Z", 8, "1980s");
|
||||
fxt.Test_xto_str("+00000001987-01-01T00:00:00Z", 7, "19. century");
|
||||
fxt.Test_xto_str("+00000001987-01-01T00:00:00Z", 6, "1. millenium");
|
||||
fxt.Test_xto_str("+00000012345-01-01T00:00:00Z", 5, "10,000 years");
|
||||
fxt.Test_xto_str("+00000123456-01-01T00:00:00Z", 4, "in 100,000 years");
|
||||
}
|
||||
@Test public void Xto_str_julian() {
|
||||
fxt.Init_calendar_is_julian_(Bool_.Y).Test_xto_str("+00000001600-01-02T00:00:00Z", Wbase_date.Fmt_ymd, "18 Jan 1600<sup>jul</sup>");
|
||||
}
|
||||
@Test public void Xto_str_before_after() {
|
||||
String date = "+00000002001-02-03T04:05:06Z";
|
||||
fxt.Clear().Init_before_(1).Test_xto_str(date, Wbase_date.Fmt_ymd, "3 Feb 2001 (-1)");
|
||||
fxt.Clear().Init_after_ (1).Test_xto_str(date, Wbase_date.Fmt_ymd, "3 Feb 2001 (+1)");
|
||||
fxt.Clear().Init_before_(1).Init_after_(1).Test_xto_str(date, Wbase_date.Fmt_ymd, "3 Feb 2001 (±1)");
|
||||
fxt.Clear().Init_before_(1).Init_after_(2).Test_xto_str(date, Wbase_date.Fmt_ymd, "3 Feb 2001 (-1, +2)");
|
||||
}
|
||||
}
|
||||
class Wbase_date_fxt {
|
||||
private Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(16);
|
||||
private Wdata_hwtr_msgs msgs;
|
||||
private final Bry_fmtr tmp_time_fmtr = Bry_fmtr.new_(); private final Bry_bfr tmp_time_bfr = Bry_bfr_.New_w_size(32);
|
||||
public Wbase_date_fxt Clear() {
|
||||
init_before = init_after = 0;
|
||||
init_calendar_is_julian = false;
|
||||
return this;
|
||||
}
|
||||
public boolean Init_calendar_is_julian() {return init_calendar_is_julian;} public Wbase_date_fxt Init_calendar_is_julian_(boolean v) {init_calendar_is_julian = v; return this;} private boolean init_calendar_is_julian;
|
||||
public int Init_before() {return init_before;} public Wbase_date_fxt Init_before_(int v) {init_before = v; return this;} private int init_before;
|
||||
public int Init_after() {return init_after;} public Wbase_date_fxt Init_after_(int v) {init_after = v; return this;} private int init_after;
|
||||
public void Test_parse(String raw, long expd_y, int expd_m, int expd_d, int expd_h, int expd_n, int expd_s) {
|
||||
Wbase_date actl_date = Wbase_date.Parse(Bry_.new_a7(raw), Wbase_date.Fmt_ymdhns, init_before, init_after, init_calendar_is_julian);
|
||||
Tfds.Eq(expd_y, actl_date.Year());
|
||||
Tfds.Eq(expd_m, actl_date.Month());
|
||||
Tfds.Eq(expd_d, actl_date.Day());
|
||||
Tfds.Eq(expd_h, actl_date.Hour());
|
||||
Tfds.Eq(expd_n, actl_date.Minute());
|
||||
Tfds.Eq(expd_s, actl_date.Second());
|
||||
}
|
||||
public void Test_julian(int[] orig_ary, int[] expd) {
|
||||
Wbase_date orig = new Wbase_date(orig_ary[0], orig_ary[1], orig_ary[2], 0, 0, 0, 0, 0, 0, init_calendar_is_julian);
|
||||
Wbase_date actl = Wbase_date.Xto_julian(orig);
|
||||
Tfds.Eq(expd[0], (int)actl.Year(), "y");
|
||||
Tfds.Eq(expd[1], actl.Month(), "m");
|
||||
Tfds.Eq(expd[2], actl.Day(), "d");
|
||||
}
|
||||
public void Test_xto_str(String raw, int precision, String expd) {
|
||||
if (msgs == null) msgs = Wdata_hwtr_msgs.new_en_();
|
||||
Wbase_date date = Wbase_date.Parse(Bry_.new_a7(raw), precision, init_before, init_after, init_calendar_is_julian);
|
||||
Wbase_date.Xto_str(tmp_bfr, tmp_time_fmtr, tmp_time_bfr, msgs, date);
|
||||
Tfds.Eq(expd, tmp_bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user