Search in sources :

Example 96 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class TestCustomPoint method testCustomPointRecordMap.

@Test
public void testCustomPointRecordMap() throws CloneNotSupportedException {
    final Map<String, CustomPoint> input = asMap("1", new CustomPoint("1,1"), "2", new CustomPoint("2,2"), "3", new CustomPoint("3,3"));
    final DataMap inputDataMap = new DataMap(asMap("1", "1,1", "2", "2,2", "3", "3,3"));
    CustomPointRecord record = new CustomPointRecord();
    CustomPointMap a1 = new CustomPointMap(inputDataMap);
    record.setCustomPointMap(a1);
    CustomPointRecord recordCopy = new CustomPointRecord(record.data().copy());
    for (Map.Entry<String, CustomPoint> e : input.entrySet()) {
        assertEquals(recordCopy.getCustomPointMap().get(e.getKey()), e.getValue());
    }
}
Also used : DataMap(com.linkedin.data.DataMap) Map(java.util.Map) TestUtil.asMap(com.linkedin.data.TestUtil.asMap) CustomPoint(com.linkedin.data.template.TestCustom.CustomPoint) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 97 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class CustomAnyRecord method getValue.

public <T extends RecordTemplate> T getValue(Class<T> clazz) throws TemplateOutputCastException {
    T result = null;
    DataMap map = data();
    DataSchema schema = DataTemplateUtil.getSchema(clazz);
    String key = schema.getUnionMemberKey();
    Object valueData = (map.size() == 1 ? map.get(key) : null);
    if (valueData != null) {
        if (_cachedValue != null && _cachedValue.data() == valueData && clazz.isInstance(_cachedValue)) {
            @SuppressWarnings("unchecked") T value = (T) _cachedValue;
            result = value;
        } else {
            result = DataTemplateUtil.wrap(valueData, schema, clazz);
            _cachedValue = result;
        }
    }
    return result;
}
Also used : RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) DataMap(com.linkedin.data.DataMap)

Example 98 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class CustomAnyRecord method setValue.

public <T extends RecordTemplate> AnyRecord setValue(T value) {
    DataSchema schema = value.schema();
    String key = schema.getUnionMemberKey();
    DataMap map = data();
    map.clear();
    map.put(key, value.data());
    _cachedValue = value;
    return this;
}
Also used : RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) DataMap(com.linkedin.data.DataMap)

Example 99 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class CustomAnyRecord method getValue.

public <T extends RecordTemplate> T getValue(Class<T> clazz) throws TemplateOutputCastException {
    T result = null;
    DataMap map = data();
    DataSchema schema = DataTemplateUtil.getSchema(clazz);
    String key = schema.getUnionMemberKey();
    Object valueData = (map.size() == 1 ? map.get(key) : null);
    if (valueData != null) {
        if (_cachedValue != null && _cachedValue.data() == valueData && clazz.isInstance(_cachedValue)) {
            @SuppressWarnings("unchecked") T value = (T) _cachedValue;
            result = value;
        } else {
            result = DataTemplateUtil.wrap(valueData, schema, clazz);
            _cachedValue = result;
        }
    }
    return result;
}
Also used : RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) DataMap(com.linkedin.data.DataMap)

Example 100 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class CustomAnyRecord method setValue.

public <T extends RecordTemplate> AnyRecord setValue(T value) {
    DataSchema schema = value.schema();
    String key = schema.getUnionMemberKey();
    DataMap map = data();
    map.clear();
    map.put(key, value.data());
    _cachedValue = value;
    return this;
}
Also used : RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) DataMap(com.linkedin.data.DataMap)

Aggregations

DataMap (com.linkedin.data.DataMap)471 Test (org.testng.annotations.Test)238 DataList (com.linkedin.data.DataList)130 ByteString (com.linkedin.data.ByteString)110 HashMap (java.util.HashMap)56 TestUtil.dataMapFromString (com.linkedin.data.TestUtil.dataMapFromString)49 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)47 TestUtil.dataSchemaFromString (com.linkedin.data.TestUtil.dataSchemaFromString)46 DataSchema (com.linkedin.data.schema.DataSchema)45 Map (java.util.Map)45 ArrayList (java.util.ArrayList)31 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)23 PathSpec (com.linkedin.data.schema.PathSpec)21 RecordTemplate (com.linkedin.data.template.RecordTemplate)21 DataProvider (org.testng.annotations.DataProvider)20 HashSet (java.util.HashSet)19 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)18 PatchTree (com.linkedin.data.transform.patch.request.PatchTree)18 CompoundKey (com.linkedin.restli.common.CompoundKey)18 IOException (java.io.IOException)18