if (contents.size() == 0) {
return null;
}
// System.out.format("%d Relations ",contents.size());
StringTable stable = getStringTable();
Osmformat.PrimitiveGroup.Builder builder = Osmformat.PrimitiveGroup
.newBuilder();
for (Relation i : contents) {
Osmformat.Relation.Builder bi = Osmformat.Relation.newBuilder();
bi.setId(i.getId());
RelationMember[] arr = new RelationMember[i.getMembers().size()];
i.getMembers().toArray(arr);
long lastid = 0;
for (RelationMember j : i.getMembers()) {
long id = j.getMemberId();
bi.addMemids(id - lastid);
lastid = id;
if (j.getMemberType() == EntityType.Node) {
bi.addTypes(MemberType.NODE);
} else if (j.getMemberType() == EntityType.Way) {
bi.addTypes(MemberType.WAY);
} else if (j.getMemberType() == EntityType.Relation) {
bi.addTypes(MemberType.RELATION);
} else {
assert (false); // Software bug: Unknown entity.
}
bi.addRolesSid(stable.getIndex(j.getMemberRole()));
}
for (Tag t : i.getTags()) {
bi.addKeys(stable.getIndex(t.getKey()));
bi.addVals(stable.getIndex(t.getValue()));
}
if (!omit_metadata) {
bi.setInfo(serializeMetadata(i));
}
builder.addRelations(bi);