static public AnnotationTile getTileFromJSON( JSONObject json ) throws IllegalArgumentException { try { TileIndex index = new TileIndex( json.getInt("level"), json.getInt("x"), json.getInt("y"), AnnotationIndexer.NUM_BINS, AnnotationIndexer.NUM_BINS ); // create tile with empty bins DenseTileData<AnnotationBin> tile = new DenseTileData<>( index ); // for all binkeys Iterator<?> binKeys = json.keys(); while( binKeys.hasNext() ) { String binKey = (String)binKeys.next(); if( json.get(binKey) instanceof JSONObject ){ JSONObject bin = (JSONObject)json.get(binKey); BinIndex binIndex = BinIndex.fromString( binKey ); tile.setBin( binIndex.getX(), binIndex.getY(), getBinFromJSON( bin )); } } return new AnnotationTile( tile.getDefinition(), tile.getData() ); } catch ( Exception e ) { throw new IllegalArgumentException( e ); } }
@Test public void testBinStringification () { BinIndex b = new BinIndex(23, 41); String bs = b.toString(); Assert.assertEquals("[23, 41]", bs); BinIndex b2 = BinIndex.fromString(bs); Assert.assertEquals(b, b2); }