Search in sources :

Example 1 with NumberPreparer

use of uk.me.parabola.imgfmt.app.net.NumberPreparer in project mkgmap by openstreetmap.

the class NumberRangeTest method run.

private void run(String[] strings) {
    List<Numbers> numbers = new ArrayList<Numbers>();
    for (String s : strings) {
        Numbers n = new Numbers(s);
        n.setIndex(n.getNodeNumber());
        numbers.add(n);
    }
    NumberPreparer np = new NumberPreparer(numbers);
    BitWriter bitWriter = np.fetchBitStream();
    bytesUsed += bitWriter.getLength();
    // Now read it back in
    byte[] bytes = new byte[bitWriter.getLength()];
    System.arraycopy(bitWriter.getBytes(), 0, bytes, 0, bytes.length);
    NumberReader nr = new NumberReader(new BitReader(bytes));
    nr.setNumberOfNodes(numbers.get(numbers.size() - 1).getIndex() + 1);
    List<Numbers> list = nr.readNumbers(np.getSwapped());
    // Have to fix up the node numbers
    for (Numbers n : list) {
        n.setNodeNumber(n.getIndex());
    }
    // Test that they are the same.
    String orig = numbers.toString();
    String calculated = list.toString();
    if (!orig.equals(calculated)) {
        System.out.printf("Fail: expecting: %s\n            Got: %s\n", orig, calculated);
    }
}
Also used : BitWriter(uk.me.parabola.imgfmt.app.BitWriter) Numbers(uk.me.parabola.imgfmt.app.net.Numbers) ArrayList(java.util.ArrayList) NumberReader(func.lib.NumberReader) NumberPreparer(uk.me.parabola.imgfmt.app.net.NumberPreparer) BitReader(uk.me.parabola.imgfmt.app.BitReader)

Aggregations

NumberReader (func.lib.NumberReader)1 ArrayList (java.util.ArrayList)1 BitReader (uk.me.parabola.imgfmt.app.BitReader)1 BitWriter (uk.me.parabola.imgfmt.app.BitWriter)1 NumberPreparer (uk.me.parabola.imgfmt.app.net.NumberPreparer)1 Numbers (uk.me.parabola.imgfmt.app.net.Numbers)1