@Test public void test() throws IOException { OSHNode node100 = buildHOSMNode( Arrays.asList(new OSMNode(100l, 1, new OSHDBTimestamp(1l), 0l, 123, new int[]{1, 2}, 494094984l, 86809727l))); OSHNode node102 = buildHOSMNode( Arrays.asList(new OSMNode(102l, 1, new OSHDBTimestamp(1l), 0l, 123, new int[]{2, 1}, 494094984l, 86809727l))); OSHNode node104 = buildHOSMNode( Arrays.asList(new OSMNode(104l, 1, new OSHDBTimestamp(1l), 0l, 123, new int[]{2, 4}, 494094984l, 86809727l))); OSHWay way200 = buildHOSMWay(Arrays.asList(new OSMWay(200, 1, new OSHDBTimestamp(3333l), 4444l, 23, new int[]{1, 2}, new OSMMember[]{new OSMMember(100, OSMType.NODE, 0), new OSMMember(104, OSMType.NODE, 0)})), Arrays.asList(node100, node104)); OSHWay way202 = buildHOSMWay(Arrays.asList(new OSMWay(202, 1, new OSHDBTimestamp(3333l), 4444l, 23, new int[]{1, 2}, new OSMMember[]{new OSMMember(100, OSMType.NODE, 0), new OSMMember(102, OSMType.NODE, 0)})), Arrays.asList(node100, node102)); OSHRelation relation300 = OSHRelationImpl.build(Arrays.asList( new OSMRelation(300, 1, new OSHDBTimestamp(3333l), 4444l, 23, new int[]{}, new OSMMember[]{new OSMMember(100, OSMType.NODE, 0, null), new OSMMember(102, OSMType.NODE, 0, null)}), new OSMRelation(300, 2, new OSHDBTimestamp(3333l), 4444l, 23, new int[]{1, 2}, new OSMMember[]{new OSMMember(100, OSMType.NODE, 0, null), new OSMMember(102, OSMType.NODE, 0, null)})), Arrays.asList(node100, node102), Arrays.asList()); OSHRelation relation301 = OSHRelationImpl.build(Arrays.asList( new OSMRelation(301, 1, new OSHDBTimestamp(3333l), 4444l, 23, new int[]{}, new OSMMember[]{new OSMMember(200, OSMType.WAY, 1, null), new OSMMember(202, OSMType.WAY, 1, null)}), new OSMRelation(301, 2, new OSHDBTimestamp(3333l), 4444l, 23, new int[]{1, 2}, new OSMMember[]{new OSMMember(200, OSMType.WAY, 1, null), new OSMMember(202, OSMType.WAY, 1, null)})), Arrays.asList(), Arrays.asList(way200, way202)); long cellId = 1; int cellLevel = 2; long baseId = 1234; GridOSHRelations hosmCell = GridOSHRelations.compact(cellId, cellLevel, baseId, 0, 0, 0, Arrays.asList(relation300, relation301)); }
public static GridOSHRelations compact(final long id, final int level, final long baseId, final long baseTimestamp, final long baseLongitude, final long baseLatitude, final List<OSHRelation> list) throws IOException { int offset = 0; final ByteArrayOutputStream out = new ByteArrayOutputStream(); final int[] index = new int[list.size()]; for (int i = 0; i < index.length; i++) { final OSHRelation osh = list.get(i); final ByteBuffer buffer = OSHRelationImpl.buildRecord(OSHEntities.toList(osh.getVersions()),osh.getNodes(),osh.getWays(),baseId, baseTimestamp, baseLongitude, baseLatitude); index[i] = offset; out.write(buffer.array(),0,buffer.remaining()); offset += buffer.remaining(); } final byte[] data = out.toByteArray(); return new GridOSHRelations(id, level, baseId, baseTimestamp, baseLongitude, baseLatitude, index, data); }
GridOSHRelations extends GridOSHEntity implements Iterable<OSHRelation> { public static GridOSHRelations compact(final long id, final int level, final long baseId, final long baseTimestamp, final long baseLongitude, final long baseLatitude, final List<OSHRelation> list) throws IOException { int offset = 0; final ByteArrayOutputStream out = new ByteArrayOutputStream(); final int[] index = new int[list.size()]; for (int i = 0; i < index.length; i++) { final OSHRelation osh = list.get(i); final ByteBuffer buffer = OSHRelationImpl.buildRecord(OSHEntities.toList(osh.getVersions()),osh.getNodes(),osh.getWays(),baseId, baseTimestamp, baseLongitude, baseLatitude); index[i] = offset; out.write(buffer.array(),0,buffer.remaining()); offset += buffer.remaining(); } final byte[] data = out.toByteArray(); return new GridOSHRelations(id, level, baseId, baseTimestamp, baseLongitude, baseLatitude, index, data); } }
GridOSHRelations extends GridOSHEntity implements Iterable<OSHRelation> { public static GridOSHRelations compact(final long id, final int level, final long baseId, final long baseTimestamp, final long baseLongitude, final long baseLatitude, final List<OSHRelation> list) throws IOException { int offset = 0; final ByteArrayOutputStream out = new ByteArrayOutputStream(); final int[] index = new int[list.size()]; for (int i = 0; i < index.length; i++) { final OSHRelation osh = list.get(i); final ByteBuffer buffer = OSHRelationImpl.buildRecord(OSHEntities.toList(osh.getVersions()),osh.getNodes(),osh.getWays(),baseId, baseTimestamp, baseLongitude, baseLatitude); index[i] = offset; out.write(buffer.array(),0,buffer.remaining()); offset += buffer.remaining(); } final byte[] data = out.toByteArray(); return new GridOSHRelations(id, level, baseId, baseTimestamp, baseLongitude, baseLatitude, index, data); } private  GridOSHRelations(final long id, final int level, final long baseId, final long baseTimestamp,
          final long baseLongitude, final long baseLatitude, final int[] index, final byte[] data); }
GridOSHRelations extends GridOSHEntity implements Iterable<OSHRelation> { public static GridOSHRelations compact(final long id, final int level, final long baseId, final long baseTimestamp, final long baseLongitude, final long baseLatitude, final List<OSHRelation> list) throws IOException { int offset = 0; final ByteArrayOutputStream out = new ByteArrayOutputStream(); final int[] index = new int[list.size()]; for (int i = 0; i < index.length; i++) { final OSHRelation osh = list.get(i); final ByteBuffer buffer = OSHRelationImpl.buildRecord(OSHEntities.toList(osh.getVersions()),osh.getNodes(),osh.getWays(),baseId, baseTimestamp, baseLongitude, baseLatitude); index[i] = offset; out.write(buffer.array(),0,buffer.remaining()); offset += buffer.remaining(); } final byte[] data = out.toByteArray(); return new GridOSHRelations(id, level, baseId, baseTimestamp, baseLongitude, baseLatitude, index, data); } private  GridOSHRelations(final long id, final int level, final long baseId, final long baseTimestamp,
          final long baseLongitude, final long baseLatitude, final int[] index, final byte[] data); static GridOSHRelations compact(final long id, final int level, final long baseId,
          final long baseTimestamp, final long baseLongitude, final long baseLatitude,
          final List<OSHRelation> list); @Override Iterable<? extends OSHEntity> getEntities(); @Override Iterator<OSHRelation> iterator(); @Override String toString(); }
GridOSHRelations extends GridOSHEntity implements Iterable<OSHRelation> { public static GridOSHRelations compact(final long id, final int level, final long baseId, final long baseTimestamp, final long baseLongitude, final long baseLatitude, final List<OSHRelation> list) throws IOException { int offset = 0; final ByteArrayOutputStream out = new ByteArrayOutputStream(); final int[] index = new int[list.size()]; for (int i = 0; i < index.length; i++) { final OSHRelation osh = list.get(i); final ByteBuffer buffer = OSHRelationImpl.buildRecord(OSHEntities.toList(osh.getVersions()),osh.getNodes(),osh.getWays(),baseId, baseTimestamp, baseLongitude, baseLatitude); index[i] = offset; out.write(buffer.array(),0,buffer.remaining()); offset += buffer.remaining(); } final byte[] data = out.toByteArray(); return new GridOSHRelations(id, level, baseId, baseTimestamp, baseLongitude, baseLatitude, index, data); } private  GridOSHRelations(final long id, final int level, final long baseId, final long baseTimestamp,
          final long baseLongitude, final long baseLatitude, final int[] index, final byte[] data); static GridOSHRelations compact(final long id, final int level, final long baseId,
          final long baseTimestamp, final long baseLongitude, final long baseLatitude,
          final List<OSHRelation> list); @Override Iterable<? extends OSHEntity> getEntities(); @Override Iterator<OSHRelation> iterator(); @Override String toString();  }