Search in sources :

Example 21 with ExtWrapNullable

use of org.javarosa.core.util.externalizable.ExtWrapNullable in project javarosa by opendatakit.

the class DataInstance method readExternal.

public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
    recordid = ExtUtil.readInt(in);
    formId = ExtUtil.readInt(in);
    name = (String) ExtUtil.read(in, new ExtWrapNullable(String.class), pf);
    instanceid = (String) ExtUtil.nullIfEmpty(ExtUtil.readString(in));
}
Also used : ExtWrapNullable(org.javarosa.core.util.externalizable.ExtWrapNullable)

Example 22 with ExtWrapNullable

use of org.javarosa.core.util.externalizable.ExtWrapNullable in project javarosa by opendatakit.

the class DataInstance method writeExternal.

public void writeExternal(DataOutputStream out) throws IOException {
    ExtUtil.writeNumeric(out, recordid);
    ExtUtil.writeNumeric(out, formId);
    ExtUtil.write(out, new ExtWrapNullable(name));
    ExtUtil.write(out, ExtUtil.emptyIfNull(instanceid));
}
Also used : ExtWrapNullable(org.javarosa.core.util.externalizable.ExtWrapNullable)

Example 23 with ExtWrapNullable

use of org.javarosa.core.util.externalizable.ExtWrapNullable in project javarosa by opendatakit.

the class FormInstance method writeExternal.

public void writeExternal(DataOutputStream out) throws IOException {
    super.writeExternal(out);
    ExtUtil.write(out, new ExtWrapNullable(schema));
    ExtUtil.write(out, new ExtWrapNullable(dateSaved));
    ExtUtil.write(out, new ExtWrapMap(namespaces));
    ExtUtil.write(out, getRoot());
}
Also used : ExtWrapMap(org.javarosa.core.util.externalizable.ExtWrapMap) ExtWrapNullable(org.javarosa.core.util.externalizable.ExtWrapNullable)

Example 24 with ExtWrapNullable

use of org.javarosa.core.util.externalizable.ExtWrapNullable in project javarosa by opendatakit.

the class TreeReference method writeExternal.

@Override
public void writeExternal(DataOutputStream out) throws IOException {
    ExtUtil.writeNumeric(out, refLevel);
    ExtUtil.write(out, new ExtWrapNullable(instanceName));
    ExtUtil.writeNumeric(out, contextType);
    ExtUtil.writeNumeric(out, size());
    for (TreeReferenceLevel l : data) {
        ExtUtil.write(out, l);
    }
}
Also used : ExtWrapNullable(org.javarosa.core.util.externalizable.ExtWrapNullable)

Example 25 with ExtWrapNullable

use of org.javarosa.core.util.externalizable.ExtWrapNullable in project javarosa by opendatakit.

the class ExternalizableTest method doTests.

public void doTests() {
    // base types (built-in + externalizable)
    testExternalizable("string", String.class);
    testExternalizable(new Byte((byte) 0), Byte.class);
    testExternalizable(new Byte((byte) 0x55), Byte.class);
    testExternalizable(new Byte((byte) 0xe9), Byte.class);
    testExternalizable(new Short((short) 0), Short.class);
    testExternalizable(new Short((short) -12345), Short.class);
    testExternalizable(new Short((short) 12345), Short.class);
    testExternalizable(new Integer(0), Integer.class);
    testExternalizable(new Integer(1234567890), Integer.class);
    testExternalizable(new Integer(-1234567890), Integer.class);
    testExternalizable(new Long(0), Long.class);
    testExternalizable(new Long(1234567890123456789l), Long.class);
    testExternalizable(new Long(-1234567890123456789l), Long.class);
    testExternalizable(Boolean.TRUE, Boolean.class);
    testExternalizable(Boolean.FALSE, Boolean.class);
    testExternalizable(new Character('e'), Character.class);
    testExternalizable(new Float(123.45e6), Float.class);
    testExternalizable(new Double(123.45e6), Double.class);
    testExternalizable(new Date(), Date.class);
    testExternalizable(new SampleExtz("your", "mom"), SampleExtz.class);
    // base wrapper (end user will never use)
    testExternalizable("string", new ExtWrapBase(String.class));
    testExternalizable(new ExtWrapBase("string"), String.class);
    // nullables on base types
    testExternalizable(new ExtWrapNullable((String) null), new ExtWrapNullable(String.class));
    testExternalizable(new ExtWrapNullable("string"), new ExtWrapNullable(String.class));
    testExternalizable(new ExtWrapNullable((Integer) null), new ExtWrapNullable(Integer.class));
    testExternalizable(new ExtWrapNullable(new Integer(17)), new ExtWrapNullable(Integer.class));
    testExternalizable(new ExtWrapNullable((SampleExtz) null), new ExtWrapNullable(SampleExtz.class));
    testExternalizable(new ExtWrapNullable(new SampleExtz("hi", "there")), new ExtWrapNullable(SampleExtz.class));
    // lists of base types
    List<Integer> v = new ArrayList<Integer>();
    v.add(new Integer(27));
    v.add(new Integer(-73));
    v.add(new Integer(1024));
    v.add(new Integer(66066066));
    testExternalizable(new ExtWrapList(v), new ExtWrapList(Integer.class));
    List<String> vs = new ArrayList<String>();
    vs.add("alpha");
    vs.add("beta");
    vs.add("gamma");
    testExternalizable(new ExtWrapList(vs), new ExtWrapList(String.class));
    List<Object> w = new ArrayList<Object>();
    w.add(new SampleExtz("where", "is"));
    w.add(new SampleExtz("the", "beef"));
    testExternalizable(new ExtWrapList(w), new ExtWrapList(SampleExtz.class));
    // nullable lists; lists of nullables (no practical use)
    testExternalizable(new ExtWrapNullable(new ExtWrapList(v)), new ExtWrapNullable(new ExtWrapList(Integer.class)));
    testExternalizable(new ExtWrapNullable((ExtWrapList) null), new ExtWrapNullable(new ExtWrapList(Integer.class)));
    testExternalizable(new ExtWrapList(v, new ExtWrapNullable()), new ExtWrapList(new ExtWrapNullable(Integer.class)));
    // empty lists (base types)
    testExternalizable(new ExtWrapList(new ArrayList<String>()), new ExtWrapList(String.class));
    // sub-types don't matter for empties
    testExternalizable(new ExtWrapList(new ArrayList(), new ExtWrapBase(Integer.class)), new ExtWrapList(String.class));
    // lists of lists (including empties)
    ArrayList x = new ArrayList();
    x.add(new Integer(-35));
    x.add(new Integer(-31415926));
    ArrayList y = new ArrayList();
    y.add(v);
    y.add(x);
    y.add(new ArrayList());
    // risky to not specify 'leaf' type (Integer), but works in limited situations
    testExternalizable(new ExtWrapList(y, new ExtWrapList()), new ExtWrapList(new ExtWrapList(Integer.class)));
    // same as above
    testExternalizable(new ExtWrapList(new ArrayList(), new ExtWrapList()), new ExtWrapList(new ExtWrapList(Integer.class)));
    // tagged base types
    testExternalizable(new ExtWrapTagged("string"), new ExtWrapTagged());
    testExternalizable(new ExtWrapTagged(new Integer(5000)), new ExtWrapTagged());
    // tagged custom type
    PrototypeFactory pf = new PrototypeFactory();
    pf.addClass(SampleExtz.class);
    testExternalizable(new ExtWrapTagged(new SampleExtz("bon", "jovi")), new ExtWrapTagged(), pf);
    // tagged list (base type)
    testExternalizable(new ExtWrapTagged(new ExtWrapList(v)), new ExtWrapTagged());
    testExternalizable(new ExtWrapTagged(new ExtWrapList(w)), new ExtWrapTagged(), pf);
    // tagged nullables and compound lists
    testExternalizable(new ExtWrapTagged(new ExtWrapNullable("string")), new ExtWrapTagged());
    testExternalizable(new ExtWrapTagged(new ExtWrapNullable((String) null)), new ExtWrapTagged());
    testExternalizable(new ExtWrapTagged(new ExtWrapList(y, new ExtWrapList(Integer.class))), new ExtWrapTagged());
    testExternalizable(new ExtWrapTagged(new ExtWrapList(new ArrayList(), new ExtWrapList(Integer.class))), new ExtWrapTagged());
    // polymorphic lists
    List a = new ArrayList();
    a.add(new Integer(47));
    a.add("string");
    a.add(Boolean.FALSE);
    a.add(new SampleExtz("hello", "dolly"));
    testExternalizable(new ExtWrapListPoly(a), new ExtWrapListPoly(), pf);
    testExternalizable(new ExtWrapTagged(new ExtWrapListPoly(a)), new ExtWrapTagged(), pf);
    // polymorphic list with complex sub-types
    // note: must manually wrap children in polymorphic lists
    a.add(new ExtWrapList(y, new ExtWrapList(Integer.class)));
    testExternalizable(new ExtWrapListPoly(a), new ExtWrapListPoly(), pf);
    testExternalizable(new ExtWrapListPoly(new ArrayList()), new ExtWrapListPoly());
    // hashtables
    OrderedMap oh = new OrderedMap();
    testExternalizable(new ExtWrapMap(oh), new ExtWrapMap(String.class, Integer.class, ExtWrapMap.TYPE_ORDERED));
    testExternalizable(new ExtWrapMapPoly(oh), new ExtWrapMapPoly(Date.class, true));
    testExternalizable(new ExtWrapTagged(new ExtWrapMap(oh)), new ExtWrapTagged());
    testExternalizable(new ExtWrapTagged(new ExtWrapMapPoly(oh)), new ExtWrapTagged());
    oh.put("key1", new SampleExtz("a", "b"));
    oh.put("key2", new SampleExtz("c", "d"));
    oh.put("key3", new SampleExtz("e", "f"));
    testExternalizable(new ExtWrapMap(oh), new ExtWrapMap(String.class, SampleExtz.class, ExtWrapMap.TYPE_ORDERED), pf);
    testExternalizable(new ExtWrapTagged(new ExtWrapMap(oh)), new ExtWrapTagged(), pf);
    HashMap h = new HashMap();
    testExternalizable(new ExtWrapMap(h), new ExtWrapMap(String.class, Integer.class));
    testExternalizable(new ExtWrapMapPoly(h), new ExtWrapMapPoly(Date.class));
    testExternalizable(new ExtWrapTagged(new ExtWrapMap(h)), new ExtWrapTagged());
    testExternalizable(new ExtWrapTagged(new ExtWrapMapPoly(h)), new ExtWrapTagged());
    h.put("key1", new SampleExtz("e", "f"));
    h.put("key2", new SampleExtz("c", "d"));
    h.put("key3", new SampleExtz("a", "b"));
    testExternalizable(new ExtWrapMap(h), new ExtWrapMap(String.class, SampleExtz.class), pf);
    testExternalizable(new ExtWrapTagged(new ExtWrapMap(h)), new ExtWrapTagged(), pf);
    HashMap j = new HashMap();
    j.put(new Integer(17), h);
    j.put(new Integer(-3), h);
    HashMap k = new HashMap();
    k.put("key", j);
    testExternalizable(new ExtWrapMap(k, new ExtWrapMap(Integer.class, new ExtWrapMap(String.class, SampleExtz.class))), new ExtWrapMap(String.class, new ExtWrapMap(Integer.class, new ExtWrapMap(String.class, SampleExtz.class))), // note: this example contains mixed hashtable types; would choke if we used a tagging wrapper
    pf);
    OrderedMap m = new OrderedMap();
    m.put("a", "b");
    m.put("b", new Integer(17));
    m.put("c", new Short((short) -443));
    m.put("d", new SampleExtz("boris", "yeltsin"));
    m.put("e", new ExtWrapList(vs));
    testExternalizable(new ExtWrapMapPoly(m), new ExtWrapMapPoly(String.class, true), pf);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExtWrapMap(org.javarosa.core.util.externalizable.ExtWrapMap) ExtWrapListPoly(org.javarosa.core.util.externalizable.ExtWrapListPoly) ArrayList(java.util.ArrayList) ExtWrapList(org.javarosa.core.util.externalizable.ExtWrapList) List(java.util.List) ExtWrapList(org.javarosa.core.util.externalizable.ExtWrapList) ExtWrapNullable(org.javarosa.core.util.externalizable.ExtWrapNullable) ExtWrapTagged(org.javarosa.core.util.externalizable.ExtWrapTagged) Date(java.util.Date) ExtWrapBase(org.javarosa.core.util.externalizable.ExtWrapBase) PrototypeFactory(org.javarosa.core.util.externalizable.PrototypeFactory) OrderedMap(org.javarosa.core.util.OrderedMap) ExtWrapMapPoly(org.javarosa.core.util.externalizable.ExtWrapMapPoly)

Aggregations

ExtWrapNullable (org.javarosa.core.util.externalizable.ExtWrapNullable)27 ExtWrapTagged (org.javarosa.core.util.externalizable.ExtWrapTagged)13 ExtWrapListPoly (org.javarosa.core.util.externalizable.ExtWrapListPoly)9 ExtWrapList (org.javarosa.core.util.externalizable.ExtWrapList)7 ExtWrapMap (org.javarosa.core.util.externalizable.ExtWrapMap)7 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Date (java.util.Date)3 Condition (org.javarosa.core.model.condition.Condition)2 Recalculate (org.javarosa.core.model.condition.Recalculate)2 DeserializationException (org.javarosa.core.util.externalizable.DeserializationException)2 HashMap (java.util.HashMap)1 Constraint (org.javarosa.core.model.condition.Constraint)1 IConditionExpr (org.javarosa.core.model.condition.IConditionExpr)1 DataInstance (org.javarosa.core.model.instance.DataInstance)1 TreeElement (org.javarosa.core.model.instance.TreeElement)1 OSMTag (org.javarosa.core.model.osm.OSMTag)1 Localizer (org.javarosa.core.services.locale.Localizer)1 OrderedMap (org.javarosa.core.util.OrderedMap)1 ExtWrapBase (org.javarosa.core.util.externalizable.ExtWrapBase)1