use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class ProjectionUtil method createPathSpecMap.
private static DataMap createPathSpecMap(Set<PathSpec> paths) {
final DataMap pathSpecMap = new DataMap();
for (PathSpec p : paths) {
final List<String> components = p.getPathComponents();
DataMap currentMap = pathSpecMap;
for (int i = 0; i < components.size(); ++i) {
final String currentComponent = components.get(i);
final Object currentValue = currentMap.get(currentComponent);
if (i < components.size() - 1) {
if (currentValue instanceof DataMap) {
@SuppressWarnings("unchecked") final DataMap valueMap = (DataMap) currentValue;
currentMap = valueMap;
} else {
final DataMap newMap = new DataMap();
currentMap.put(currentComponent, newMap);
currentMap = newMap;
}
} else if (currentValue == null) {
currentMap.put(currentComponent, Null.getInstance());
}
}
}
return pathSpecMap;
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestPathSpec method testNestedFieldPathSpec.
@Test
public void testNestedFieldPathSpec() {
PathSpec p = RecordTest.fields().recordField().location();
Assert.assertEquals(p.toString(), "/recordField/location");
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestPathSpec method testUnionPathSpec.
@Test
public void testUnionPathSpec() {
PathSpec p = UnionTest.fields().unionWithInline().RecordInUnion().a();
Assert.assertEquals(p.toString(), "/unionWithInline/com.linkedin.pegasus.generator.test.RecordInUnion/a");
p = UnionTest.fields().unionWithoutNull().RecordBar().location();
Assert.assertEquals(p.toString(), "/unionWithoutNull/com.linkedin.pegasus.generator.test.RecordBar/location");
p = UnionTest.fields().unionWithNull().Null();
Assert.assertEquals(p.toString(), "/unionWithNull/null");
// Test path specs for Union member with aliases
p = UnionTest.fields().unionWithAliases().MemRecord().location();
Assert.assertEquals(p.toString(), "/unionWithAliases/memRecord/location");
p = UnionTest.fields().unionWithAliases().MemArray();
Assert.assertEquals(p.toString(), "/unionWithAliases/memArray");
p = UnionTest.fields().unionWithAliases().MemMap();
Assert.assertEquals(p.toString(), "/unionWithAliases/memMap");
p = UnionTest.fields().unionWithAliases().Null();
Assert.assertEquals(p.toString(), "/unionWithAliases/null");
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestPathSpec method testArrayRangePathSpec.
@Test
public void testArrayRangePathSpec() {
PathSpec p = ArrayTest.fields().intArray(10, 5);
Assert.assertEquals(p.toString(), "/intArray?start=10&count=5");
p = ArrayTest.fields().recordInlineArray(null, 2);
Assert.assertEquals(p.toString(), "/recordInlineArray?count=2");
p = ArrayTest.fields().unionArray(8, null);
Assert.assertEquals(p.toString(), "/unionArray?start=8");
p = ArrayTest.fields().stringArray(null, null);
Assert.assertEquals(p.toString(), "/stringArray");
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestPathSpec method testSelfReferencePathSpec.
@Test
public void testSelfReferencePathSpec() {
PathSpec p = AliasTest.fields().a1().a1().a1().a1();
Assert.assertEquals(p.toString(), "/a1/a1/a1/a1");
}
Aggregations