Search in sources :

Example 1 with FieldArraySetting

use of com.tvd12.dahlia.core.setting.FieldArraySetting in project dahlia by youngmonkeys.

the class LocalCollectionSettingReader method readFieldArraySetting.

protected FieldSetting readFieldArraySetting(JSONObject setting) {
    FieldArraySetting field = new FieldArraySetting();
    if (setting.has(SettingFields.MAX_SIZE))
        field.setMaxSize(setting.getInt(SettingFields.MAX_SIZE));
    if (setting.has(SettingFields.ITEM)) {
        JSONObject itemSetting = setting.getJSONObject(SettingFields.ITEM);
        DataType itemType = null;
        if (itemSetting.has(SettingFields.TYPE))
            itemType = DataType.valueOfName(itemSetting.getString(SettingFields.TYPE));
        else
            throw new IllegalArgumentException("item 'type' is required");
        FieldSetting item = readFieldSetting(itemType, itemSetting);
        field.setItem(item);
    } else {
        throw new IllegalArgumentException("'item' field is required");
    }
    return field;
}
Also used : FieldSetting(com.tvd12.dahlia.core.setting.FieldSetting) FieldArraySetting(com.tvd12.dahlia.core.setting.FieldArraySetting) JSONObject(org.json.JSONObject) DataType(com.tvd12.dahlia.core.data.DataType)

Example 2 with FieldArraySetting

use of com.tvd12.dahlia.core.setting.FieldArraySetting in project dahlia by youngmonkeys.

the class SettingObjectToArrayField method newSetting.

@Override
protected FieldArraySetting newSetting(SettingObjectToFields mappers, EzyObject object) {
    FieldArraySetting setting = new FieldArraySetting();
    setting.setMaxSize(object.get(SettingFields.MAX_SIZE, int.class));
    EzyObject itemSetting = object.get(SettingFields.ITEM, EzyObject.class);
    FieldSetting item = mappers.toSetting(itemSetting);
    setting.setItem(item);
    return setting;
}
Also used : FieldSetting(com.tvd12.dahlia.core.setting.FieldSetting) FieldArraySetting(com.tvd12.dahlia.core.setting.FieldArraySetting) EzyObject(com.tvd12.ezyfox.entity.EzyObject)

Example 3 with FieldArraySetting

use of com.tvd12.dahlia.core.setting.FieldArraySetting in project dahlia by youngmonkeys.

the class FieldArrayReader method readValue.

@Override
protected EzyArray readValue(FieldReaders readers, FileProxy file, FieldSetting setting) throws IOException {
    FieldArraySetting fs = (FieldArraySetting) setting;
    FieldSetting itemSetting = fs.getItem();
    int size = file.readShort();
    EzyArray array = EzyEntityFactory.newArray();
    for (int i = 0; i < size; ++i) {
        Object item = readers.readValue(file, itemSetting);
        array.add(item);
    }
    return array;
}
Also used : FieldSetting(com.tvd12.dahlia.core.setting.FieldSetting) FieldArraySetting(com.tvd12.dahlia.core.setting.FieldArraySetting) EzyArray(com.tvd12.ezyfox.entity.EzyArray)

Example 4 with FieldArraySetting

use of com.tvd12.dahlia.core.setting.FieldArraySetting in project dahlia by youngmonkeys.

the class FieldArrayWriter method writeValue.

@Override
protected void writeValue(FieldWriters writers, FileProxy file, FieldSetting setting, EzyArray value) throws IOException {
    int size = value.size();
    file.writeShort((short) size);
    FieldArraySetting fs = (FieldArraySetting) setting;
    FieldSetting itemSetting = fs.getItem();
    for (int i = 0; i < size; ++i) writers.write(file, itemSetting, value.get(i));
}
Also used : FieldSetting(com.tvd12.dahlia.core.setting.FieldSetting) FieldArraySetting(com.tvd12.dahlia.core.setting.FieldArraySetting)

Aggregations

FieldArraySetting (com.tvd12.dahlia.core.setting.FieldArraySetting)4 FieldSetting (com.tvd12.dahlia.core.setting.FieldSetting)4 DataType (com.tvd12.dahlia.core.data.DataType)1 EzyArray (com.tvd12.ezyfox.entity.EzyArray)1 EzyObject (com.tvd12.ezyfox.entity.EzyObject)1 JSONObject (org.json.JSONObject)1