1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2025-06-13 12:54:14 +00:00
gnosygnu_xowa/400_xowa/src/gplx/langs/jsons/Json_itm.java

60 lines
2.6 KiB
Java
Raw Normal View History

2015-07-13 01:10:02 +00:00
/*
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/>.
*/
2015-09-21 03:43:51 +00:00
package gplx.langs.jsons; import gplx.*; import gplx.langs.*;
2015-07-13 01:10:02 +00:00
public interface Json_itm {
2015-08-31 02:57:59 +00:00
byte Tid();
int Src_bgn();
int Src_end();
Object Data();
byte[] Data_bry();
void Print_as_json(Bry_bfr bfr, int depth);
boolean Data_eq(byte[] comp);
2015-07-13 01:10:02 +00:00
}
class Json_itm_null extends Json_itm_base {
Json_itm_null() {this.Ctor(-1, -1);}
2015-08-31 02:57:59 +00:00
@Override public byte Tid() {return Json_itm_.Tid__null;}
2015-07-13 01:10:02 +00:00
@Override public Object Data() {return null;}
2015-08-31 02:57:59 +00:00
@Override public void Print_as_json(Bry_bfr bfr, int depth) {bfr.Add(Object_.Bry__null);}
@Override public byte[] Data_bry() {return Object_.Bry__null;}
public static final Json_itm_null Null = new Json_itm_null();
2015-07-13 01:10:02 +00:00
}
class Json_itm_bool extends Json_itm_base {
2015-08-31 02:57:59 +00:00
private boolean data;
public Json_itm_bool(boolean data) {this.data = data; this.Ctor(-1, -1);}
@Override public byte Tid() {return Json_itm_.Tid__bool;}
2015-07-13 01:10:02 +00:00
@Override public Object Data() {return data;}
2015-08-31 02:57:59 +00:00
@Override public byte[] Data_bry() {return data ? Json_itm_.Bry__true : Json_itm_.Bry__false;}
@Override public void Print_as_json(Bry_bfr bfr, int depth) {bfr.Add(data ? Json_itm_.Bry__true: Json_itm_.Bry__false);}
public static final Json_itm_bool Bool_n = new Json_itm_bool(false), Bool_y = new Json_itm_bool(true);
2015-07-13 01:10:02 +00:00
}
class Json_itm_decimal extends Json_itm_base {
2015-08-31 02:57:59 +00:00
private final Json_doc doc; private Decimal_adp data; private byte[] data_bry;
public Json_itm_decimal(Json_doc doc, int src_bgn, int src_end) {this.Ctor(src_bgn, src_end); this.doc = doc;}
@Override public byte Tid() {return Json_itm_.Tid__decimal;}
2015-07-13 01:10:02 +00:00
@Override public Object Data() {
if (data == null)
2015-08-31 02:57:59 +00:00
data = Decimal_adp_.parse(String_.new_a7(this.Data_bry()));
2015-07-13 01:10:02 +00:00
return data;
2015-08-31 02:57:59 +00:00
}
2015-07-13 01:10:02 +00:00
@Override public byte[] Data_bry() {
if (data_bry == null) data_bry = Bry_.Mid(doc.Src(), this.Src_bgn(), this.Src_end());
return data_bry;
}
2015-08-31 02:57:59 +00:00
@Override public void Print_as_json(Bry_bfr bfr, int depth) {bfr.Add_mid(doc.Src(), this.Src_bgn(), this.Src_end());}
2015-07-13 01:10:02 +00:00
}