Search in sources :

Example 16 with StringData

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);
}
Also used : StringData(org.javarosa.core.model.data.StringData)

Example 17 with StringData

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);
}
Also used : StringData(org.javarosa.core.model.data.StringData)

Example 18 with StringData

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;
}
Also used : StringData(org.javarosa.core.model.data.StringData)

Example 19 with StringData

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 + "]");
    }
}
Also used : IAnswerData(org.javarosa.core.model.data.IAnswerData) IntegerData(org.javarosa.core.model.data.IntegerData) LongData(org.javarosa.core.model.data.LongData) Date(java.util.Date) DecimalData(org.javarosa.core.model.data.DecimalData) DateData(org.javarosa.core.model.data.DateData) TreeReference(org.javarosa.core.model.instance.TreeReference) DateTimeData(org.javarosa.core.model.data.DateTimeData) TimeData(org.javarosa.core.model.data.TimeData) DateTimeData(org.javarosa.core.model.data.DateTimeData) StringData(org.javarosa.core.model.data.StringData)

Aggregations

StringData (org.javarosa.core.model.data.StringData)19 IntegerData (org.javarosa.core.model.data.IntegerData)7 TreeElement (org.javarosa.core.model.instance.TreeElement)6 DateData (org.javarosa.core.model.data.DateData)4 TimeData (org.javarosa.core.model.data.TimeData)4 Date (java.util.Date)3 IDataReference (org.javarosa.core.model.IDataReference)3 DateTimeData (org.javarosa.core.model.data.DateTimeData)3 DecimalData (org.javarosa.core.model.data.DecimalData)3 IAnswerData (org.javarosa.core.model.data.IAnswerData)3 LongData (org.javarosa.core.model.data.LongData)3 AbstractTreeElement (org.javarosa.core.model.instance.AbstractTreeElement)3 FormInstance (org.javarosa.core.model.instance.FormInstance)3 Test (org.junit.Test)3 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 IOException (java.io.IOException)2 RandomString (net.bytebuddy.utility.RandomString)2 FormDef (org.javarosa.core.model.FormDef)2 BooleanData (org.javarosa.core.model.data.BooleanData)2