@Override public List<T> getBin (int x, int y) { return Arrays.asList(_data.getBin(x, y)); }
@Override public T getBin (int x, int y) { Map<Integer, T> originalValue = _base.getBin(x, y); if (null != originalValue && originalValue.containsKey(_slice)) return originalValue.get(_slice); return _defaultValue; }
@Override public T getBin (int x, int y) { T result = null; List<T> bin = _base.getBin(x, y); if (bin.size() > 0) { result = bin.get(_slice); } return result; }
@SuppressWarnings("unchecked") @Override public List<T> getBin (int x, int y) { List<T> result = new ArrayList<>(); for (int i = 0; i < _tileData1.getBin(x, y).size(); i++) { result.add((T) _op.calculate(_tileData1.getBin(x, y).get(i), _tileData2.getBin(x, y).get(i), _errorValue)); } return result; }
@Override public List<T> getBin(int x, int y) { List<T> binValue = new ArrayList<>(); for (TileData<List<T>> component: _components) { List<T> componentBin = component.getBin(x, y); if (null == componentBin) // Because we don't know the standard bin length of each component, if any are null, we have to give // up. return null; else binValue.addAll(componentBin); } return binValue; }
@Override public void setBin (int x, int y, T value) { List<T> originalValue = _base.getBin(x, y); List<T> newValue = new ArrayList<>(originalValue); newValue.set(_slice, value); _base.setBin(x, y, newValue); }
@Override public List<T> getBin(int x, int y) { List<T> result = new ArrayList<>(); for (T d: _tileData.getBin(x, y)) { result.add((T) _op.calculate(d, _errorValue)); } return result; }
@Override public void setBin (int x, int y, T value) { Map<Integer, T> originalValue = _base.getBin(x, y); Map<Integer, T> newValue = new HashMap<>(originalValue); newValue.put(_slice, value); _base.setBin(x, y, newValue); }
@Override public List<T> getBin(int x, int y) { List<T> origValue = _base.getBin(x, y); if (binNullForUs(origValue)) return null; List<T> result = new ArrayList<>(_slices.size()); for (int slice: _slices) { if (origValue.size() <= slice) result.add(null); else result.add(origValue.get(slice)); } return result; }
private int getBucketCount(TileData<List<?>> data) throws JSONException { int size = data.getBin(0,0).size(); if (size == 0) { // Try to get from metadata String maxArray = data.getMetaData("maximum array"); if (maxArray != null) { size = new JSONArray(maxArray).length(); } } return size; }
@Override public T getBin (int x, int y) { if (x < 0 || x >= getDefinition().getXBins()) { throw new IllegalArgumentException("Bin x index is outside of tile's valid bin range"); } if (y < 0 || y >= getDefinition().getYBins()) { throw new IllegalArgumentException("Bin y index is outside of tile's valid bin range"); } return _source.getBin(x + _xOffset, y + _yOffset); }
private int numSlices (TileData<?> tile) { int slices = 0; TileIndex index = tile.getDefinition(); for (int x=0; x < index.getXBins(); ++x) { for (int y = 0; y < index.getYBins(); ++y) { try { List<?> bin = (List<?>) tile.getBin(x, y); int size = bin.size(); if (size > slices) slices = size; } catch (ClassCastException|NullPointerException e) { // Swallow it, we don't care here. } } } return slices; } }
/** * Get all the data for a given tile, in a form that can be used to initialize a dense tile. */ static public <T> List<T> getData (TileData<T> tile) { if (tile instanceof DenseTileData) { return ((DenseTileData<T>) tile).getData(); } else { List<T> result = new ArrayList<>(); TileIndex idx = tile.getDefinition(); for (int y = 0; y < idx.getYBins(); ++y) { for (int x = 0; x < idx.getXBins(); ++x) { result.add(tile.getBin(x, y)); } } return result; } }
private boolean isDense () { TileIndex index = getDefinition(); int nullBins = 0; int bins = 0; for (int x=0; x<index.getXBins(); ++x) { for (int y=0; y<index.getYBins(); ++y) { if (binNullForUs(_base.getBin(x, y))) ++nullBins; ++bins; } } return nullBins*2 < bins; }
@Test public void testNullBinReplacement () { TileData<List<Integer>> base = new DenseTileData<List<Integer>>(new TileIndex(0, 0, 0, 1, 1), (List<Integer>) null); TileData<List<Integer>> slice = new DenseTileMultiSliceView<Integer>(base, Arrays.asList(2, 0)); slice.setBin(0, 0, Arrays.asList(4, 2)); Assert.assertEquals(2, base.getBin(0, 0).get(0).intValue()); Assert.assertNull( base.getBin(0, 0).get(1)); Assert.assertEquals(4, base.getBin(0, 0).get(2).intValue()); } @Test
@Test public void testUnmodifiableBinReplacement () { List<Integer> binVal = new ArrayList<>(); binVal.add(3); binVal.add(4); binVal.add(5); TileData<List<Integer>> base = new DenseTileData<List<Integer>>(new TileIndex(0, 0, 0, 1, 1)); base.setBin(0, 0, Collections.unmodifiableList(binVal)); TileData<List<Integer>> slice = new DenseTileMultiSliceView<Integer>(base, Arrays.asList(2, 0)); slice.setBin(0, 0, Arrays.asList(6, 2)); Assert.assertEquals(2, base.getBin(0, 0).get(0).intValue()); Assert.assertEquals(4, base.getBin(0, 0).get(1).intValue()); Assert.assertEquals(6, base.getBin(0, 0).get(2).intValue()); Assert.assertEquals(3, binVal.get(0).intValue()); Assert.assertEquals(4, binVal.get(1).intValue()); Assert.assertEquals(5, binVal.get(2).intValue()); }
private TileData<Double> addTiles (TileData<Double> a, TileData<Double> b) { int xBins = a.getDefinition().getXBins(); int yBins = a.getDefinition().getYBins(); List<Double> dc = new ArrayList<>(); for (int y = 0; y < yBins; ++y) { for (int x = 0; x < xBins; ++x) { dc.add(a.getBin(x, y) + b.getBin(x, y)); } } return new DenseTileData<Double>(a.getDefinition(), dc); }
@Test public void testModifiableBinReplacement () { List<Integer> binVal = new ArrayList<>(); binVal.add(3); binVal.add(4); binVal.add(5); TileData<List<Integer>> base = new DenseTileData<List<Integer>>(new TileIndex(0, 0, 0, 1, 1)); base.setBin(0, 0, binVal); TileData<List<Integer>> slice = new DenseTileMultiSliceView<Integer>(base, Arrays.asList(2, 0)); slice.setBin(0, 0, Arrays.asList(6, 2)); Assert.assertEquals(2, base.getBin(0, 0).get(0).intValue()); Assert.assertEquals(4, base.getBin(0, 0).get(1).intValue()); Assert.assertEquals(6, base.getBin(0, 0).get(2).intValue()); Assert.assertEquals(2, binVal.get(0).intValue()); Assert.assertEquals(4, binVal.get(1).intValue()); Assert.assertEquals(6, binVal.get(2).intValue()); }
/** * Check if two (single-value-per-bin) tiles are equal */ public static <T> void assertTilesEqual (TileData<T> expected, TileData<T> actual) { Assert.assertEquals(expected.getDefinition(), actual.getDefinition()); int xN = expected.getDefinition().getXBins(); int yN = expected.getDefinition().getYBins(); for (int x=0; x<xN; ++x) { for (int y=0; y<yN; ++y) { Assert.assertEquals(expected.getBin(x, y), actual.getBin(x, y)); } } }
public void testBackwardCompatbilitySerialize() throws IOException{ TestPyramidIO io = new TestPyramidIO(); TileSerializer<Double> serializer = new com.oculusinfo.binning.io.serialization.impl.BackwardCompatibilitySerializer(); TileIndex index = new TileIndex(0, 0, 0, 1, 1); TileData<Double> tile = new DenseTileData<Double>(index); tile.setBin(0, 0, 5.0); io.initializeForWrite("backwardsCompatibilityTest"); io.writeTiles("backwardsCompatibilityTest", serializer, Collections.singleton(tile)); List<TileData<Double>> tiles = io.readTiles("backwardsCompatibilityTest", serializer, Collections.singleton(index)); TileData<Double> tileOut = tiles.get(0); double dataOut = tileOut.getBin(0, 0); Assert.assertEquals(5.0, dataOut); }