Walker { public Set<Shape> walkShapes(Shape shape) { return walkShapes(shape, FunctionalUtils.alwaysTrue()); } Walker(Model model);  Walker(NeighborProvider provider); Set<Shape> walkShapes(Shape shape); Set<Shape> walkShapes(Shape shape, Predicate<Relationship> predicate); Iterator<Shape> iterateShapes(Shape shape); Iterator<Shape> iterateShapes(Shape shape, Predicate<Relationship> predicate);  }
@Test public void getASetOfConnectedShapes() { StringShape string = StringShape.builder() .id("ns.foo#String") .build(); MemberShape key = MemberShape.builder() .id("ns.foo#Map$key") .target(string.getId()) .build(); MemberShape value = MemberShape.builder() .id("ns.foo#Map$value") .target(string.getId()) .build(); MapShape map = MapShape.builder() .id("ns.foo#Map") .key(key) .value(value) .build(); MemberShape listMember = MemberShape.builder() .id("ns.foo#List$member") .target(map.getId()) .build(); ListShape list = ListShape.builder() .id("ns.foo#List") .member(listMember) .build(); Walker walker = new Walker(Model.builder() .addShape(list) .addShape(listMember) .addShape(map) .addShape(key) .addShape(value) .addShape(string) .build()); Set<Shape> connected = walker.walkShapes(listMember); assertThat(connected, containsInAnyOrder(list, listMember, map, key, value, string)); }
@Test public void supportsCycles() { StringShape string = StringShape.builder() .id("ns.foo#String") .build(); MemberShape key = MemberShape.builder() .id("ns.foo#Map$key") .target(string.getId()) .build(); MemberShape value = MemberShape.builder() .id("ns.foo#Map$value") .target("ns.foo#List") .build(); MapShape map = MapShape.builder() .id("ns.foo#Map") .key(key) .value(value) .build(); MemberShape listMember = MemberShape.builder() .id("ns.foo#List$member") .target(map.getId()) .build(); ListShape list = ListShape.builder() .id("ns.foo#List") .member(listMember) .build(); Walker walker = new Walker(Model.builder() .addShape(list) .addShape(listMember) .addShape(map) .addShape(key) .addShape(value) .addShape(string) .build()); Set<Shape> connected = walker.walkShapes(listMember); assertThat(connected, containsInAnyOrder(list, listMember, map, key, value, string)); }