use of org.javarosa.core.util.externalizable.PrototypeFactory in project javarosa by opendatakit.
the class QuestionDataElementTests method setUp.
public void setUp() throws Exception {
super.setUp();
stringData = new StringData("Answer Value");
integerData = new IntegerData(4);
stringReference = new IDataReference() {
String reference = "stringValue";
public Object getReference() {
return reference;
}
public void setReference(Object reference) {
this.reference = (String) reference;
}
/*
public boolean referenceMatches(IDataReference reference) {
return this.reference.equals(reference.getReference());
}
public IDataReference clone() {
IDataReference newReference = null;
try {
newReference = (IDataReference)this.getClass().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
newReference.setReference(reference);
return newReference;
}
*/
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
}
public void writeExternal(DataOutputStream out) throws IOException {
}
};
integerReference = new IDataReference() {
Integer intReference = new Integer(15);
public Object getReference() {
return intReference;
}
public void setReference(Object reference) {
this.intReference = (Integer) reference;
}
/*
public boolean referenceMatches(IDataReference reference) {
return this.intReference.equals(reference.getReference());
}
public IDataReference clone() {
IDataReference newReference = null;
try {
newReference = (IDataReference)this.getClass().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
newReference.setReference(intReference);
return newReference;
}
*/
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
}
public void writeExternal(DataOutputStream out) throws IOException {
}
};
intElement = new TreeElement("intElement");
intElement.setValue(integerData);
stringElement = new TreeElement(stringElementName);
stringElement.setValue(stringData);
}
use of org.javarosa.core.util.externalizable.PrototypeFactory in project javarosa by opendatakit.
the class QuestionDataGroupTests method setUp.
public void setUp() throws Exception {
super.setUp();
stringData = new StringData("Answer Value");
integerData = new IntegerData(4);
stringReference = new IDataReference() {
String reference = "stringValue";
public Object getReference() {
return reference;
}
public void setReference(Object reference) {
this.reference = (String) reference;
}
/*
public boolean referenceMatches(IDataReference reference) {
return this.reference.equals(reference.getReference());
}
public IDataReference clone() {
IDataReference newReference = null;
try {
newReference = (IDataReference)this.getClass().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
newReference.setReference(reference);
return newReference;
}
*/
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
}
public void writeExternal(DataOutputStream out) throws IOException {
}
};
integerReference = new IDataReference() {
Integer intReference = new Integer(15);
public Object getReference() {
return intReference;
}
public void setReference(Object reference) {
this.intReference = (Integer) reference;
}
/*
public boolean referenceMatches(IDataReference reference) {
return this.intReference.equals(reference.getReference());
}
public IDataReference clone() {
IDataReference newReference = null;
try {
newReference = (IDataReference)this.getClass().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
newReference.setReference(intReference);
return newReference;
}
*/
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
}
public void writeExternal(DataOutputStream out) throws IOException {
}
};
intElement = new TreeElement("intElement");
intElement.setValue(integerData);
stringElement = new TreeElement(stringElementName);
stringElement.setValue(stringData);
group = new TreeElement(groupName);
}
use of org.javarosa.core.util.externalizable.PrototypeFactory in project javarosa by opendatakit.
the class LocalizerTest method testSerialize.
private void testSerialize(Localizer l, String msg) {
PrototypeFactory pf = new PrototypeFactory();
pf.addClass(TableLocaleSource.class);
ExternalizableTest.testExternalizable(l, this, pf, "Localizer [" + msg + "]");
}
use of org.javarosa.core.util.externalizable.PrototypeFactory 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);
}
Aggregations