use of org.javarosa.core.model.data.StringData in project javarosa by opendatakit.
the class StringDataTests method testGetData.
public void testGetData() {
StringData data = new StringData(stringA);
assertEquals("StringData's getValue returned an incorrect String", data.getValue(), stringA);
}
use of org.javarosa.core.model.data.StringData in project javarosa by opendatakit.
the class StringDataTests method testSetData.
public void testSetData() {
StringData data = new StringData(stringA);
data.setValue(stringB);
assertTrue("StringData did not set value properly. Maintained old value.", !(data.getValue().equals(stringA)));
assertEquals("StringData did not properly set value ", data.getValue(), stringB);
data.setValue(stringA);
assertTrue("StringData did not set value properly. Maintained old value.", !(data.getValue().equals(stringB)));
assertEquals("StringData did not properly reset value ", data.getValue(), stringA);
}
use of org.javarosa.core.model.data.StringData in project javarosa by opendatakit.
the class QuestionPreloader method preloadProperty.
/**
* Preloads a StringData object for the preload type 'property'
*
* @param preloadParams The parameters determining the property to be retrieved
* @return A preload property value if the parameters can be parsed,
* null otherwise
*/
private IAnswerData preloadProperty(String preloadParams) {
String propname = preloadParams;
String propval = PropertyManager._().getSingularProperty(propname);
StringData data = null;
if (propval != null && propval.length() > 0) {
data = new StringData(propval);
}
return data;
}
use of org.javarosa.core.model.data.StringData in project javarosa by opendatakit.
the class RestoreUtils method addData.
public static void addData(FormInstance dm, String xpath, Object data, int dataType) {
if (data == null) {
dataType = -1;
}
IAnswerData val;
switch(dataType) {
case -1:
val = null;
break;
case Constants.DATATYPE_TEXT:
val = new StringData((String) data);
break;
case Constants.DATATYPE_INTEGER:
val = new IntegerData((Integer) data);
break;
case Constants.DATATYPE_LONG:
val = new LongData((Long) data);
break;
case Constants.DATATYPE_DECIMAL:
val = new DecimalData((Double) data);
break;
case Constants.DATATYPE_BOOLEAN:
val = new StringData(((Boolean) data).booleanValue() ? "t" : "f");
break;
case Constants.DATATYPE_DATE:
val = new DateData((Date) data);
break;
case Constants.DATATYPE_DATE_TIME:
val = new DateTimeData((Date) data);
break;
case Constants.DATATYPE_TIME:
val = new TimeData((Date) data);
break;
case Constants.DATATYPE_CHOICE_LIST:
val = (SelectMultiData) data;
break;
default:
throw new IllegalArgumentException("Don't know how to handle data type [" + dataType + "]");
}
TreeReference ref = absRef(xpath, dm);
if (dm.addNode(ref, val, dataType) == null) {
throw new RuntimeException("error setting value during object backup [" + xpath + "]");
}
}
Aggregations