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());
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations