1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-01-25 20:56:50 -05:00
parent 1b0042ef8a
commit efaf9dcd00
447 changed files with 10258 additions and 3016 deletions

View File

@@ -56,7 +56,7 @@ class Gfo_msg_root_fxt {
public void Tst_data_new_many(String path, String key, String fmt, Object... vals) {
Gfo_msg_data data = root.Data_new_many(Gfo_msg_itm_.Cmd_note, path, key, fmt, vals);
if (expd_item_uid != -1) Tfds.Eq(expd_item_uid, data.Item().Uid());;
if (expd_item_fmtr_arg_exists != Bool_.__byte) Tfds.Eq(Bool_.int_(expd_item_fmtr_arg_exists), data.Item().Fmtr().Fmt_args_exist());
if (expd_item_fmtr_arg_exists != Bool_.__byte) Tfds.Eq(Bool_.By_int(expd_item_fmtr_arg_exists), data.Item().Fmtr().Fmt_args_exist());
if (expd_data_str != null) Tfds.Eq(expd_data_str, data.Item().Gen_str_many(data.Vals()));
}
}

View File

@@ -47,8 +47,6 @@ public class Array_ {
rv[i + curReplacePos] = add[i];
for (int i = curReplacePos + addInsertPos; i < curLen; i++) // copy old after curReplacePos
rv[i + newLen] = cur[i];
// tst_ReplaceInsert(ary_obj(0, 1, 4, 5) , ary_obj(1, 2, 3), 1, 1, ary_obj(0, 1, 2, 3, 4, 5));
// tst_ReplaceInsert(ary_obj(0, 1, 2, 4, 5), ary_obj(1, 2, 3), 1, 2, ary_obj(0, 1, 2, 3, 4, 5));//3,4 -> 4,5
return rv;
}
public static Object Resize(Object src, int trgLen) {

View File

@@ -16,36 +16,35 @@ 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 class Bool_ implements GfoInvkAble {
public static final boolean[] Ary_empty = new boolean[0];
public static final Class<?> ClassOf = Boolean.class;
public static int Xto_int(boolean v) {return v ? 1 : 0;}
public static String Xto_str_lower(boolean v) {return v ? "true" : "false";}
public static byte Xto_byte(boolean v) {return v ? Y_byte : N_byte;}
public static boolean cast_(Object obj) {try {return (Boolean)obj;} catch (Exception e) {throw Err_.type_mismatch_exc_(e, boolean.class, obj);}}
public static boolean cast_or_(Object obj, boolean v) {try {return (Boolean)obj;} catch (Exception e) {Err_.Noop(e); return v;}}
public static boolean int_(int v) {return v != 0;}
public static boolean TypeMatch(Class<?> type) {return type == boolean.class || type == Boolean.class;}
public class Bool_ implements GfoInvkAble {
public static final String Cls_val_name = "boolean";
public static final Class<?> Cls_ref_type = Boolean.class;
public static final boolean N = false , Y = true;
public static final byte N_byte = 0 , Y_byte = 1 , __byte = 127;
public static final int N_int = 0 , Y_int = 1 , __int = -1;
public static final String N_str = "n" , Y_str = "y";
public static final byte[] Y_bry = new byte[] {Byte_ascii.Ltr_y}, N_bry = new byte[] {Byte_ascii.Ltr_n};
public static final String True_str = "true", False_str = "false";
public static final byte[] True_bry = Bry_.new_ascii_(True_str), False_bry = Bry_.new_ascii_(False_str);
public static boolean cast_(Object obj) {try {return (Boolean)obj;} catch (Exception e) {throw Err_.type_mismatch_exc_(e, boolean.class, obj);}}
public static boolean cast_or_(Object obj, boolean v) {try {return (Boolean)obj;} catch (Exception e) {Err_.Noop(e); return v;}}
public static boolean By_int(int v) {return v != 0;}
public static boolean parse_(String raw) {
if ( String_.Eq(raw, "true")
|| String_.Eq(raw, "True") // needed for Store_Wtr(){boolVal.toString();}
)
)
return true;
else if ( String_.Eq(raw, "false")
|| String_.Eq(raw, "False")
)
)
return false;
throw Err_.parse_type_(boolean.class, raw);
}
public static final int N_int = 0, Y_int = 1, __int = -1;
public static final byte N_byte = 0, Y_byte = 1, __byte = 127;
public static final boolean N = false, Y = true;
public static final String N_str = "n", Y_str = "y";
public static final String True_str = "true", False_str = "false";
public static final byte[] True_bry = Bry_.new_ascii_(True_str), False_bry = Bry_.new_ascii_(False_str);
public static final byte[] Y_bry = new byte[] {Byte_ascii.Ltr_y}, N_bry = new byte[] {Byte_ascii.Ltr_n};
public static byte Xto_byte(boolean v) {return v ? Y_byte : N_byte;}
public static int Xto_int(boolean v) {return v ? 1 : 0;}
public static String Xto_str_lower(boolean v) {return v ? "true" : "false";}
public static final boolean[] Ary_empty = new boolean[0];
public static final Bool_ Gfs = new Bool_();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_to_str)) {
boolean v = m.ReadBool(GfsCore_.Arg_primitive);

View File

@@ -16,8 +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;
public class Bool_obj_ref {
public class Bool_obj_ref {
public boolean Val() {return val;} private boolean val;
public boolean Val_y() {return val;}
public boolean Val_n() {return !val;}
public Bool_obj_ref Val_y_() {val = true; return this;}
public Bool_obj_ref Val_n_() {val = false; return this;}
public Bool_obj_ref Val_(boolean v) {val = v; return this;}

View File

@@ -16,13 +16,14 @@ 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 class Bool_obj_val {
public class Bool_obj_val {
Bool_obj_val(int v) {val = v;} private final int val;
public boolean Val() {return val == 1;}
Bool_obj_val(int v) {val = v;} int val;
public static final Bool_obj_val
Null = new Bool_obj_val(-1)
, False = new Bool_obj_val(0)
, True = new Bool_obj_val(1);
Null = new Bool_obj_val(-1)
, False = new Bool_obj_val(0)
, True = new Bool_obj_val(1)
;
public static Bool_obj_val read_(Object o) {String s = String_.as_(o); return s == null ? (Bool_obj_val)o : parse_(s);}
public static Bool_obj_val parse_(String raw) {
if (String_.Eq(raw, "y")) return Bool_obj_val.True;

View File

@@ -19,11 +19,11 @@ package gplx;
import java.lang.*;
import gplx.ios.*;
public class Bry_ {
public static final String Cls_name = "byte[]";
public static final String Cls_val_name = "byte[]";
public static final int NotFound = -1;
public static final byte[] Empty = new byte[0];
public static final byte[][] Ary_empty = new byte[0][];
public static final Class<?> ClassOf = byte[].class;
public static final Class<?> Cls_ref_type = byte[].class;
public static byte[] bytes_(byte... ary) {return ary;}
public static byte[] ints_ (int... ary) {
int len = ary.length;

View File

@@ -172,7 +172,7 @@ public class Bry__tst {
byte[] ary_(int... ary) {
byte[] rv = new byte[ary.length];
for (int i = 0; i < ary.length; i++)
rv[i] = Byte_.int_(ary[i]);
rv[i] = Byte_.By_int(ary[i]);
return rv;
}
void tst_IncrementLast(byte[] ary, byte[] expd) {Tfds.Eq_ary(expd, Bry_.Increment_last(Bry_.Copy(ary)));}

View File

@@ -170,6 +170,7 @@ public class Bry_bfr {
Add_int_fixed(val, digit_len);
return this;
}
public Bry_bfr Add_int_digits(int digits, int val) {return Add_int(val, Int_.Log10(val), digits);}
public Bry_bfr Add_int_fixed(int val, int digits) {return Add_int(val, Int_.Log10(val), digits);}
public Bry_bfr Add_int(int val, int valLog, int arySlots) {
int aryBgn = bfr_len, aryEnd = bfr_len + arySlots;

View File

@@ -35,7 +35,7 @@ public class Bry_finder {
return Bry_finder.Not_found;
}
public static int Move_fwd(byte[] src, byte[] lkp, int cur, int end) {
int rv = Find_fwd(src, lkp, 0, src.length);
int rv = Find_fwd(src, lkp, cur, src.length);
return rv == Bry_finder.Not_found ? rv : rv + lkp.length;
}
public static int Find_fwd(byte[] src, byte[] lkp) {return Find(src, lkp, 0 , src.length, true);}

View File

@@ -16,19 +16,19 @@ 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 class Byte_ {
public static final byte MinValue = Byte.MIN_VALUE;
public static final String Cls_name = "byte";
public static byte[] Ary(byte... ary) {return ary;}
public static byte[] Ary_by_ints(int... ary) {
int ary_len = ary.length;
byte[] rv = new byte[ary_len];
for (int i = 0; i < ary_len; i++)
rv[i] = int_(ary[i]);
return rv;
}
public static String Xto_str(byte v) {return new Byte(v).toString();}
public static int Xto_int(byte v) {return v < 0 ? (int)v + 256 : v;}
public class Byte_ {
public static final String Cls_val_name = "byte";
public static final Class<?> Cls_ref_type = Byte.class;
public static final byte
Zero = 0
, Min_value = Byte.MIN_VALUE
, Max_value_127 = 127
;
public static byte cast_(Object o) {try {return (Byte)o;} catch (Exception e) {throw Err_.type_mismatch_exc_(e, byte.class, o);}}
public static byte parse_(String raw) {return Byte.parseByte(raw);}
public static byte By_int(int v) {return v > 127 ? (byte)(v - 256) : (byte)v;} // PERF?: (byte)(v & 0xff)
public static int Xto_int(byte v) {return v < 0 ? (int)v + 256 : v;}
public static String Xto_str(byte v) {return new Byte(v).toString();}
public static boolean In(byte v, byte... ary) {
for (byte itm : ary)
if (v == itm) return true;
@@ -39,11 +39,12 @@ public class Byte_ {
else if (lhs < rhs) return CompareAble_.Less;
else return CompareAble_.More;
}
public static byte cast_(Object o) {try {return (Byte)o;} catch (Exception e) {throw Err_.type_mismatch_exc_(e, byte.class, o);}}
public static byte parse_(String raw) {return Byte.parseByte(raw);}
public static byte int_(int v) {return v > 127 ? (byte)(v - 256) : (byte)v;} // PERF?: (byte)(v & 0xff)
public static byte Xto_boolean_byte(boolean v) {
return v ? Bool_.Y_byte : Bool_.N_byte;
public static byte[] Ary(byte... ary) {return ary;}
public static byte[] Ary_by_ints(int... ary) {
int ary_len = ary.length;
byte[] rv = new byte[ary_len];
for (int i = 0; i < ary_len; i++)
rv[i] = By_int(ary[i]);
return rv;
}
public static final byte Zero = 0, MaxValue_127 = 127;
}

View File

@@ -24,7 +24,7 @@ public class Byte__tst {
tst_int_( 128, 128); // NOTE: JAVA defines byte as -128 -> 127
tst_int_( 255, 255);
tst_int_( 256, 0); // NOTE: 256 will cast to 1; (byte)256 works same in both JAVA/.NET
} void tst_int_(int v, int expd) {Tfds.Eq((byte)expd, Byte_.int_(v));} // WORKAROUND/JAVA: expd is of type int b/c java promotes numbers to ints
} void tst_int_(int v, int expd) {Tfds.Eq((byte)expd, Byte_.By_int(v));} // WORKAROUND/JAVA: expd is of type int b/c java promotes numbers to ints
@Test public void XtoInt() {
tst_XtoInt( 0, 0);
tst_XtoInt( 127, 127);

View File

@@ -102,7 +102,9 @@ public class Byte_ascii {
, Quote_bry = new byte[] {Byte_ascii.Quote}
, Pipe_bry = new byte[] {Byte_ascii.Pipe}
, Underline_bry = new byte[] {Byte_ascii.Underline}
, Slash_bry = new byte[] {Byte_ascii.Slash}
, Asterisk_bry = new byte[] {Byte_ascii.Asterisk}
, Dash_bry = new byte[] {Byte_ascii.Dash}
, Space_bry = new byte[] {Byte_ascii.Space}
;
}

View File

@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Double_ {
public static final Class<?> ClassOf = Double.class;
public static final String Cls_name = "double";
public static final Class<?> Cls_ref_type = Double.class;
public static final String Cls_val_name = "double";
public static final double Inf_pos = Double.POSITIVE_INFINITY;;
public static final double NaN = Double.NaN;;
public static final byte[] NaN_bry = Bry_.new_ascii_("NaN");

View File

@@ -17,7 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Float_ {
public static final String Cls_name = "float";
public static final Class<?> Cls_ref_type = Float.class;
public static final String Cls_val_name = "float";
public static final float NaN = Float.NaN;;
public static boolean IsNaN(float v) {return Float.isNaN(v);}
public static int RoundUp(float val) {

View File

@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Int_ implements GfoInvkAble {
public static final Class<?> ClassOf = Integer.class;
public static final String Cls_name = "int";
public static final String Cls_val_name = "int";
public static final Class<?> Cls_ref_type = Integer.class;
public static final int Base1 = 1;
public static final int Const_dlm_len = 1;
public static final int Const_position_after_char = 1;

View File

@@ -17,9 +17,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Long_ {
public static final Class<?> Cls_ref_type = Long.class;
public static final long MinValue = Long.MIN_VALUE;
public static final long MaxValue = Long.MAX_VALUE;
public static final String Cls_name = "long";
public static final String Cls_val_name = "long";
public static final long Neg1 = -1;
public static final int Log10Ary_len = 21;
public static long[] Log10Ary = new long[]

View File

@@ -27,20 +27,19 @@ public class Object_ {
public static String Xto_str_strict_or_null(Object v) {return v == null ? null : ToString_lang(v);}
public static String Xto_str_strict_or_null_mark(Object v) {return v == null ? String_.Null_mark : ToString_lang(v);}
public static String Xto_str_strict_or_empty(Object v) {return v == null ? String_.Empty : ToString_lang(v);}
static String ToString_lang(Object v) {
if (v == null) return null;
private static String ToString_lang(Object v) {
Class<?> c = v.getClass();
if (ClassAdp_.Eq(c, Bry_.ClassOf)) return String_.new_utf8_((byte[])v);
else if (ClassAdp_.Eq(c, String_.ClassOf)) return (String)v;
if (ClassAdp_.Eq(c, String_.Cls_ref_type)) return (String)v;
else if (ClassAdp_.Eq(c, Bry_.Cls_ref_type)) return String_.new_utf8_((byte[])v);
else return v.toString();
}
public static String Xto_str_loose_or(Object v, String or) { // tries to pretty-print doubles; also standardizes true/false; DATE:2014-07-14
if (v == null) return null;
Class<?> c = ClassAdp_.ClassOf_obj(v);
if (ClassAdp_.Eq(c, Bry_.ClassOf)) return String_.new_utf8_((byte[])v);
else if (ClassAdp_.Eq(c, String_.ClassOf)) return (String)v;
else if (ClassAdp_.Eq(c, Bool_.ClassOf)) return Bool_.cast_(v) ? Bool_.True_str : Bool_.False_str; // always return true / false
else if (ClassAdp_.Eq(c, Double_.ClassOf)) return Double_.Xto_str_loose(Double_.cast_(v));
if (ClassAdp_.Eq(c, String_.Cls_ref_type)) return (String)v;
else if (ClassAdp_.Eq(c, Bry_.Cls_ref_type)) return String_.new_utf8_((byte[])v);
else if (ClassAdp_.Eq(c, Bool_.Cls_ref_type)) return Bool_.cast_(v) ? Bool_.True_str : Bool_.False_str; // always return "true" / "false"
else if (ClassAdp_.Eq(c, Double_.Cls_ref_type)) return Double_.Xto_str_loose(Double_.cast_(v));
else return v.toString();
}
}

View File

@@ -17,5 +17,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
public class Short_ {
public static final Class<?> Cls_ref_type = Short.class;
public static short cast_(Object obj) {try {return (Short)obj;} catch(Exception exc) {throw Err_.type_mismatch_exc_(exc, short.class, obj);}}
}

View File

@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx;
import java.lang.*;
public class String_ implements GfoInvkAble {
public static final Class<?> ClassOf = String.class;
public static final String Cls_name = "str" + "ing";
public static final Class<?> Cls_ref_type = String.class;
public static final String Cls_val_name = "str" + "ing";
public static final int Find_none = -1, Pos_neg1 = -1;
public static final String Null = null, Empty = "", Null_mark = "<<NULL>>", Tab = "\t", Lf = "\n", CrLf = "\r\n";
public static String cast_(Object v) {return (String)v;}

View File

@@ -25,6 +25,7 @@ import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
public class DateAdp_ implements GfoInvkAble {
public static final Class<?> Cls_ref_type = DateAdp.class;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_Now)) return Now();
else return GfoInvkAble_.Rv_unhandled;

View File

@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
public class DecimalAdp_ {
public static final Class<?> Cls_ref_type = DecimalAdp.class;

View File

@@ -84,7 +84,7 @@ public class KeyVal_ {
Ary_xto_str_nested(bfr, indent + 1, (KeyVal[])val);
continue; // don't add \n below
}
else if (ClassAdp_.Eq(val_type, Bool_.ClassOf)) { // val is boolean
else if (ClassAdp_.Eq(val_type, Bool_.Cls_ref_type)) { // val is boolean
boolean val_as_bool = Bool_.cast_(val);
bfr.Add(val_as_bool ? Bool_.True_bry : Bool_.False_bry); // add "true" or "false"; don't call toString
}

View File

@@ -42,6 +42,7 @@ public interface ListAdp extends EnumerAble {
String[] XtoStrAry();
Object Xto_ary(Class<?> memberType);
Object Xto_ary_and_clear(Class<?> memberType);
Object[] Xto_obj_ary();
void Reverse();
void Sort();

View File

@@ -77,6 +77,7 @@ class ListAdp_null implements ListAdp {
public Object Xto_ary_and_clear(Class<?> memberType) {return Object_.Ary_empty;}
public String XtoStr() {return "< NULL LIST >";}
public String[] XtoStrAry() {return new String[0];}
public Object[] Xto_obj_ary() {return Object_.Ary_empty;}
public java.util.Iterator iterator() {return Iterator_null._;}
public void Reverse() {}
public void SetAt(int i, Object o) {}

View File

@@ -25,6 +25,12 @@ public abstract class ListAdp_base implements ListAdp, GfoInvkAble {
Array_.Set(rv, i, list[i]);
return rv;
}
public Object[] Xto_obj_ary() {
Object[] rv = new Object[count];
for (int i = 0; i < count; ++i)
rv[i] = list[i];
return rv;
}
public java.util.Iterator iterator() {
if (count == 0)
return Iterator_null._;

View File

@@ -30,16 +30,16 @@ public class HexDecUtl {
public static int parse_or_(byte[] raw, int or) {return parse_or_(raw, 0, raw.length, or);}
public static int parse_or_(byte[] raw, int bgn, int end, int or) {
int rv = 0; int factor = 1;
byte b = Byte_.MaxValue_127;
byte b = Byte_.Max_value_127;
for (int i = end - 1; i >= bgn; i--) {
switch (raw[i]) {
case Byte_ascii.Num_0: b = 0; break; case Byte_ascii.Num_1: b = 1; break; case Byte_ascii.Num_2: b = 2; break; case Byte_ascii.Num_3: b = 3; break; case Byte_ascii.Num_4: b = 4; break;
case Byte_ascii.Num_5: b = 5; break; case Byte_ascii.Num_6: b = 6; break; case Byte_ascii.Num_7: b = 7; break; case Byte_ascii.Num_8: b = 8; break; case Byte_ascii.Num_9: b = 9; break;
case Byte_ascii.Ltr_A: b = 10; break; case Byte_ascii.Ltr_B: b = 11; break; case Byte_ascii.Ltr_C: b = 12; break; case Byte_ascii.Ltr_D: b = 13; break; case Byte_ascii.Ltr_E: b = 14; break; case Byte_ascii.Ltr_F: b = 15; break;
case Byte_ascii.Ltr_a: b = 10; break; case Byte_ascii.Ltr_b: b = 11; break; case Byte_ascii.Ltr_c: b = 12; break; case Byte_ascii.Ltr_d: b = 13; break; case Byte_ascii.Ltr_e: b = 14; break; case Byte_ascii.Ltr_f: b = 15; break;
default: b = Byte_.MaxValue_127; break;
default: b = Byte_.Max_value_127; break;
}
if (b == Byte_.MaxValue_127) return or;
if (b == Byte_.Max_value_127) return or;
rv += b * factor;
factor *= 16;
}

View File

@@ -455,6 +455,7 @@ public class IoEngine_system extends IoEngine_base {
try {
if (src_stream != null) src_stream.close();
if (src_conn != null) src_conn.disconnect();
src_conn.getInputStream().close();
} catch (Exception exc) {
Err_.Noop(exc);
}

View File

@@ -25,10 +25,31 @@ public class IoItmDir_ {
rv.ctor_IoItmBase_url(url);
return rv;
}
public static IoItmDir sub_(String name) {
IoItmDir rv = new IoItmDir(Bool_.Y);
rv.ctor_IoItmBase_url(Io_url_.mem_dir_("mem/" + name));
return rv;
}
static IoItmDir null_() {
IoItmDir rv = new IoItmDir(true); // TODO: NULL should be removed
rv.ctor_IoItmBase_url(Io_url_.Null);
rv.Exists_set(false);
return rv;
}
public static void Make(IoItmDir dir) {
Io_mgr._.CreateDir(dir.Url());
int len = dir.SubDirs().Count();
for (int i = 0; i < len; ++i) {
IoItmDir sub_dir = (IoItmDir)dir.SubDirs().FetchAt(i);
Make(sub_dir);
}
len = dir.SubFils().Count();
for (int i = 0; i < len; ++i) {
IoItmFil sub_fil = (IoItmFil)dir.SubFils().FetchAt(i);
String text = String_.Repeat("a", (int)sub_fil.Size());
Io_url sub_url = sub_fil.Url();
Io_mgr._.SaveFilStr(sub_url, text);
Io_mgr._.UpdateFilModifiedTime(sub_url, sub_fil.ModifiedTime());
}
}
}

View File

@@ -19,7 +19,13 @@ package gplx.ios; import gplx.*;
public class IoItmFil_ {
public static IoItmFil as_(Object obj) {return obj instanceof IoItmFil ? (IoItmFil)obj : null;}
public static final String
Prop_Size = "size"
, Prop_Modified = "modified";
Prop_Size = "size"
, Prop_Modified = "modified";
public static IoItmFil new_(Io_url url, long size, DateAdp created, DateAdp modified) {return new IoItmFil().ctor_IoItmFil(url, size, modified);}
public static IoItmFil sub_(String name, long size, DateAdp modified) {
IoItmFil rv = new IoItmFil();
rv.ctor_IoItmFil(Io_url_.mem_fil_("mem/" + name), size, modified);
rv.Name_(name);
return rv;
}
}

View File

@@ -51,4 +51,3 @@ public abstract class IoItm_base implements GfoInvkAble, CompareAble {
@gplx.Internal protected void ctor_IoItmBase_url(Io_url url) {this.url = url; this.name = url.NameAndExt();}
@gplx.Internal protected void ctor_IoItmBase_name(String name) {this.name = name;}
}

View File

@@ -28,6 +28,13 @@ public class Io_size_ {
String[] unit = Io_size_.Units[pow];
return valDecimal.Xto_str("#,###.000") + " " + String_.PadBgn(unit[0], 2, " ");
}
public static String Xto_str(long val, int exp_1024, String val_fmt, String unit_pad, boolean round_0_to_1) {
long exp_val = (long)Math_.Pow(1024, exp_1024);
DecimalAdp val_as_decimal = DecimalAdp_.divide_(val, exp_val);
if (round_0_to_1 && val_as_decimal.Comp_lt(1)) val_as_decimal = DecimalAdp_.One;
String[] unit = Io_size_.Units[exp_1024];
return val_as_decimal.Xto_str(val_fmt) + " " + String_.PadBgn(unit[0], 2, unit_pad);
}
public static long parse_or_(String raw, long or) {
if (raw == null || raw == String_.Empty) return or;
String[] terms = String_.Split(raw, " ");
@@ -46,11 +53,12 @@ public class Io_size_ {
val = val.Op_mult(1024);
curPow--;
}
DecimalAdp comp = val.Op_truncate_decimal();
if (!val.Eq(comp)) return or;
// DELETED:do not check for fractional bytes; EX: 10.7 GB DATE:2015-01-06
// DecimalAdp comp = val.Op_truncate_decimal();
// if (!val.Eq(comp)) return or;
return val.Xto_long();
}
static int parse_unitPow_(String unitStr) {
private static int parse_unitPow_(String unitStr) {
int unitLen = Array_.Len(Units);
int unitPow = -1;
for (int i = 0; i < unitLen; i++) {
@@ -59,16 +67,7 @@ public class Io_size_ {
}
return unitPow;
}
static String UnitsXtoStr() {
String_bldr sb = String_bldr_.new_();
int len = Array_.Len(Units);
for (int i = 0; i < len; i++) {
String[] eny = Units[i];
sb.Add_fmt("{0},{1};", eny[0], eny[1]);
}
return sb.XtoStr();
}
static final String[][] Units = new String[][]
private static final String[][] Units = new String[][]
{ String_.Ary("B", "BYTE")
, String_.Ary("KB", "KILOBYTE")
, String_.Ary("MB", "MEGABYTE")

View File

@@ -18,39 +18,52 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.ios; import gplx.*;
import org.junit.*;
public class Io_size__tst {
@Test public void XtoLong() {
tst_XtoLong("1", 1);
tst_XtoLong("1 KB", 1024);
tst_XtoLong("1 MB", 1024 * 1024);
tst_XtoLong("1 GB", 1024 * 1024 * 1024);
tst_XtoLong("12 kb", 12 * 1024);
tst_XtoLong("1.5 kb", 1024 + 512); // 1536
tst_XtoLong("1.5 mb", (long)(1024 * 1024 * 1.5));
tst_XtoLong("-1", -1); // NOTE: negative bytes allowed
private Io_size__fxt fxt = new Io_size__fxt();
@Test public void XtoLong() {
fxt.Test_XtoLong("1", 1);
fxt.Test_XtoLong("1 KB", 1024);
fxt.Test_XtoLong("1 MB", 1024 * 1024);
fxt.Test_XtoLong("1 GB", 1024 * 1024 * 1024);
fxt.Test_XtoLong("12 kb", 12 * 1024);
fxt.Test_XtoLong("1.5 kb", 1024 + 512); // 1536
fxt.Test_XtoLong("1.5 mb", (long)(1024 * 1024 * 1.5));
fxt.Test_XtoLong("-1", -1); // NOTE: negative bytes allowed
tst_XtoLongFail("1 kilobite");
tst_XtoLongFail("1 BB");
tst_XtoLongFail("1.1");
tst_XtoLongFail("1.51 kb");
fxt.Test_XtoLongFail("1 kilobite");
fxt.Test_XtoLongFail("1 BB");
// fxt.Test_XtoLongFail("1.1"); // DELETED:do not check for fractional bytes; EX: 10.7 GB DATE:2015-01-06
// fxt.Test_XtoLongFail("1.51 kb");
}
void tst_XtoLong(String raw, long expd) {Tfds.Eq(expd, Io_size_.parse_or_(raw, Long_.MinValue));}
void tst_XtoLongFail(String raw) {
@Test public void XtoStr() {
fxt.Test_XtoStr(1, "1.000 B");
fxt.Test_XtoStr(1024, "1.000 KB");
fxt.Test_XtoStr(1536, "1.500 KB");
fxt.Test_XtoStr(1024 * 1024, "1.000 MB");
fxt.Test_XtoStr(1016, "1,016.000 B"); // NOTE: 1016 is not 1.016 KB
}
@Test public void Xto_str_full() {
fxt.Test_Xto_str( 500, 1, "#,###", " ", Bool_.Y, "1 KB");
fxt.Test_Xto_str( 1000, 1, "#,###", " ", Bool_.Y, "1 KB");
fxt.Test_Xto_str( 2000, 1, "#,###", " ", Bool_.Y, "2 KB");
fxt.Test_Xto_str( 1234567, 1, "#,###", " ", Bool_.Y, "1,206 KB");
fxt.Test_Xto_str(1234567890, 1, "#,###", " ", Bool_.Y, "1,205,633 KB");
}
@Test public void EqualsTest() {
fxt.Test_Equals("1", "1");
fxt.Test_Equals("1 kb", "1 kb");
fxt.Test_Equals("1024", "1 kb");
fxt.Test_Equals("1048576", "1 mb");
fxt.Test_Equals("1024 kb", "1 mb");
fxt.Test_Equals("1.5 kb", "1536 b");
}
}
class Io_size__fxt {
public void Test_XtoLong(String raw, long expd) {Tfds.Eq(expd, Io_size_.parse_or_(raw, Long_.MinValue));}
public void Test_XtoLongFail(String raw) {
long val = Io_size_.parse_or_(raw, Long_.MinValue);
if (val != Long_.MinValue) Tfds.Fail("expd parse failure; raw=" + raw);
}
@Test public void XtoStr() {
tst_XtoStr(1, "1.000 B");
tst_XtoStr(1024, "1.000 KB");
tst_XtoStr(1536, "1.500 KB");
tst_XtoStr(1024 * 1024, "1.000 MB");
tst_XtoStr(1016, "1,016.000 B"); // NOTE: 1016 is not 1.016 KB
} void tst_XtoStr(long val, String expd) {Tfds.Eq(expd, Io_size_.Xto_str(val));}
@Test public void EqualsTest() {
tst_Equals("1", "1");
tst_Equals("1 kb", "1 kb");
tst_Equals("1024", "1 kb");
tst_Equals("1048576", "1 mb");
tst_Equals("1024 kb", "1 mb");
tst_Equals("1.5 kb", "1536 b");
} void tst_Equals(String lhs, String rhs) {Tfds.Eq(Io_size_.parse_or_(lhs, Long_.MinValue), Io_size_.parse_or_(rhs, Long_.MinValue));}
public void Test_Equals(String lhs, String rhs) {Tfds.Eq(Io_size_.parse_or_(lhs, Long_.MinValue), Io_size_.parse_or_(rhs, Long_.MinValue));}
public void Test_XtoStr(long val, String expd) {Tfds.Eq(expd, Io_size_.Xto_str(val));}
public void Test_Xto_str(long val, int exp_1024, String val_fmt, String unit_pad, boolean round_0_to_1, String expd) {Tfds.Eq(expd, Io_size_.Xto_str(val, exp_1024, val_fmt, unit_pad, round_0_to_1));}
}

View File

@@ -261,7 +261,7 @@ class XtoStrWkr_gplx implements XtoStrWkr {
String rv = null;
if (type == String.class) rv = String_.cast_(o);
else if (Int_.TypeMatch(type)) return Int_.Xto_str(Int_.cast_(o));
else if (Bool_.TypeMatch(type)) return Yn.Xto_str(Bool_.cast_(o));
else if (ClassAdp_.Eq(type, Bool_.Cls_ref_type)) return Yn.Xto_str(Bool_.cast_(o));
else if (type == DateAdp.class) return DateAdp_.cast_(o).XtoStr_gplx();
else rv = Object_.Xto_str_strict_or_empty(o);
return String_.Replace(rv, "'", "''");

View File

@@ -41,7 +41,7 @@ class DataRdr_null implements DataRdr {
public long ReadLong(String key) {return Long_.MinValue;} public long ReadLongOr(String key, long or) {return or;}
public double ReadDouble(String key) {return Double_.NaN;} public double ReadDoubleOr(String key, double or) {return or;}
public float ReadFloat(String key) {return Float_.NaN;} public float ReadFloatOr(String key, float or) {return or;}
public byte ReadByte(String key) {return Byte_.MinValue;} public byte ReadByteOr(String key, byte or) {return or;}
public byte ReadByte(String key) {return Byte_.Min_value;} public byte ReadByteOr(String key, byte or) {return or;}
public DecimalAdp ReadDecimal(String key) {return DecimalAdp_.Zero;}public DecimalAdp ReadDecimalOr(String key, DecimalAdp or) {return or;}
public DateAdp ReadDate(String key) {return DateAdp_.MinValue;} public DateAdp ReadDateOr(String key, DateAdp or) {return or;}
public gplx.ios.Io_stream_rdr ReadRdr(String key) {return gplx.ios.Io_stream_rdr_.Null;}

View File

@@ -116,9 +116,9 @@ class GfsCore_ {
Object primitive = null;
if (invk == null) { // rv is primitive; find appropriate mgr
Class<?> type = rv.getClass();
if (type == String.class) invk = String_.Gfs;
else if (Int_.TypeMatch(type)) invk = Int_.Gfs;
else if (Bool_.TypeMatch(type)) invk = Bool_.Gfs;
if (type == String.class) invk = String_.Gfs;
else if (Int_.TypeMatch(type)) invk = Int_.Gfs;
else if (ClassAdp_.Eq(type, Bool_.Cls_ref_type)) invk = Bool_.Gfs;
else throw Err_.new_("unknown primitive").Add("type", ClassAdp_.NameOf_type(type)).Add("obj", Object_.Xto_str_strict_or_null_mark(rv));
primitive = rv;
}