protected static byte[] extractBytes( final byte[] seq, final int numBytes, final boolean infiniteEndKey) { final byte[] bytes = new byte[numBytes + 2]; bytes[0] = 1; bytes[1] = 0; for (int i = 0; i < numBytes; i++) { if (i >= seq.length) { if (infiniteEndKey) { // -1 is 0xff bytes[i + 2] = -1; } else { bytes[i + 2] = 0; } } else { bytes[i + 2] = seq[i]; } } return bytes; }
private static float getProgressForRange( final byte[] start, final byte[] end, final byte[] position) { final int maxDepth = Math.min(Math.max(end.length, start.length), position.length); final BigInteger startBI = new BigInteger(SplitsProvider.extractBytes(start, maxDepth)); final BigInteger endBI = new BigInteger(SplitsProvider.extractBytes(end, maxDepth)); final BigInteger positionBI = new BigInteger(SplitsProvider.extractBytes(position, maxDepth)); return (float) (positionBI.subtract(startBI).doubleValue() / endBI.subtract(startBI).doubleValue()); }
protected static BigInteger getStart(final GeoWaveRowRange range, final int cardinality) { final byte[] start = range.getStartSortKey(); byte[] startBytes; if (!range.isInfiniteStartSortKey() && (start != null)) { startBytes = extractBytes(start, cardinality); } else { startBytes = extractBytes(new byte[] {}, cardinality); } return new BigInteger(startBytes); }
protected static BigInteger getEnd(final GeoWaveRowRange range, final int cardinality) { final byte[] end = range.getEndSortKey(); byte[] endBytes; if (!range.isInfiniteStopSortKey() && (end != null)) { endBytes = extractBytes(end, cardinality); } else { endBytes = extractBytes(new byte[] {}, cardinality, true); } return new BigInteger(endBytes); }
protected static double getRangeLength(final GeoWaveRowRange range) { if ((range == null) || (range.getStartSortKey() == null) || (range.getEndSortKey() == null)) { return 1; } final byte[] start = range.getStartSortKey(); final byte[] end = range.getEndSortKey(); final int maxDepth = Math.max(end.length, start.length); final BigInteger startBI = new BigInteger(extractBytes(start, maxDepth)); final BigInteger endBI = new BigInteger(extractBytes(end, maxDepth)); return endBI.subtract(startBI).doubleValue(); }
protected static byte[] getMidpoint(final GeoWaveRowRange range) { if ((range.getStartSortKey() == null) || (range.getEndSortKey() == null)) { return null; } final byte[] start = range.getStartSortKey(); final byte[] end = range.getEndSortKey(); if (Arrays.equals(start, end)) { return null; } final int maxDepth = Math.max(end.length, start.length); final BigInteger startBI = new BigInteger(extractBytes(start, maxDepth)); final BigInteger endBI = new BigInteger(extractBytes(end, maxDepth)); final BigInteger rangeBI = endBI.subtract(startBI); if (rangeBI.equals(BigInteger.ZERO) || rangeBI.equals(BigInteger.ONE)) { return end; } final byte[] valueBytes = rangeBI.divide(TWO).add(startBI).toByteArray(); final byte[] bytes = new byte[valueBytes.length - 2]; System.arraycopy(valueBytes, 2, bytes, 0, bytes.length); return bytes; }