PrimitiveGroup.java (1220B)
1 package osm.message; 2 3 import java.util.ArrayList; 4 import java.util.Iterator; 5 import java.util.List; 6 7 import protobuf.Message; 8 import protobuf.ProtobufReader; 9 10 // repeated Node nodes = 1; 11 // optional DenseNodes dense = 2; 12 // repeated Way ways = 3; 13 // repeated Relation relations = 4; 14 // repeated ChangeSet changesets = 5; 15 public class PrimitiveGroup implements Message<List<Entity>> { 16 private final PrimitiveBlock block; 17 18 public PrimitiveGroup(PrimitiveBlock block) { 19 this.block = block; 20 } 21 22 @Override 23 public List<Entity> parse(Iterator<ProtobufReader> iter) { 24 List<Entity> elements = new ArrayList<>(); 25 26 while (iter.hasNext()) { 27 ProtobufReader message = iter.next(); 28 switch (message.tag()) { 29 case 1 -> elements.add(message.message(new Node(block))); 30 case 2 -> elements.addAll(message.message(new DenseNodes(block))); 31 case 3 -> elements.add(message.message(new Way(block))); 32 case 4 -> elements.add(message.message(new Relation(block))); 33 case 5 -> message.skip(); 34 default -> message.throwUnexpected(); 35 } 36 } 37 38 return elements; 39 } 40 }