Search in sources :

Example 1 with StringWithLocale

use of net.parostroj.timetable.model.LocalizedString.StringWithLocale in project grafikon by jub77.

the class LSAttributesItem method extractSimpleValue.

private LSAttributesValue extractSimpleValue(String key, Object value) {
    LSAttributesValue cValue = null;
    if (value instanceof String) {
        cValue = new LSAttributesValue((String) value, "string");
    } else if (value instanceof Boolean) {
        cValue = new LSAttributesValue(value.toString(), "boolean");
    } else if (value instanceof Integer) {
        cValue = new LSAttributesValue(value.toString(), "integer");
    } else if (value instanceof Long) {
        cValue = new LSAttributesValue(value.toString(), "long");
    } else if (value instanceof Float) {
        cValue = new LSAttributesValue(value.toString(), "float");
    } else if (value instanceof Double) {
        cValue = new LSAttributesValue(value.toString(), "double");
    } else if (value instanceof Scale) {
        cValue = new LSAttributesValue(value.toString(), "scale");
    } else if (value instanceof FreightColor) {
        cValue = new LSAttributesValue(((FreightColor) value).getKey(), "freight.color");
    } else if (value instanceof LengthUnit) {
        cValue = new LSAttributesValue(((LengthUnit) value).getKey(), "length.unit");
    } else if (value instanceof WeightUnit) {
        cValue = new LSAttributesValue(((WeightUnit) value).getKey(), "weight.unit");
    } else if (value instanceof Locale) {
        cValue = new LSAttributesValue(((Locale) value).toLanguageTag(), "locale");
    } else if (value instanceof TextTemplate) {
        TextTemplate tt = (TextTemplate) value;
        cValue = new LSAttributesValue(tt.getTemplate(), TEXT_TEMPLATE_KEY_PREFIX + tt.getLanguage().name());
    } else if (value instanceof Script) {
        Script script = (Script) value;
        cValue = new LSAttributesValue(script.getSourceCode(), SCRIPT_KEY_PREFIX + script.getLanguage().name());
    } else if (value instanceof ObjectWithId) {
        Pair<String, String> pair = this.convertToId((ObjectWithId) value);
        cValue = new LSAttributesValue(pair.second, pair.first);
    } else if (value instanceof StringWithLocale) {
        StringWithLocale stringWithLocale = (StringWithLocale) value;
        cValue = new LSAttributesValue(stringWithLocale.getString(), "string." + stringWithLocale.getLocale().toLanguageTag());
    } else {
        log.warn("Cannot convert value to string: {}", key);
    }
    return cValue;
}
Also used : StringWithLocale(net.parostroj.timetable.model.LocalizedString.StringWithLocale) WeightUnit(net.parostroj.timetable.model.units.WeightUnit) LengthUnit(net.parostroj.timetable.model.units.LengthUnit) StringWithLocale(net.parostroj.timetable.model.LocalizedString.StringWithLocale) Pair(net.parostroj.timetable.utils.Pair)

Aggregations

StringWithLocale (net.parostroj.timetable.model.LocalizedString.StringWithLocale)1 LengthUnit (net.parostroj.timetable.model.units.LengthUnit)1 WeightUnit (net.parostroj.timetable.model.units.WeightUnit)1 Pair (net.parostroj.timetable.utils.Pair)1