All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openlr.binary.writer.CircleLocationReferenceWriter Maven / Gradle / Ivy

The newest version!
package org.openlr.binary.writer;

import org.openlr.binary.format.Status;
import org.openlr.locationreference.CircleLocationReference;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

class CircleLocationReferenceWriter {
    private final StatusWriter statusWriter;
    private final CoordinateWriter coordinateWriter;
    private final IntegerWriter integerWriter;

    CircleLocationReferenceWriter(StatusWriter statusWriter, CoordinateWriter coordinateWriter, IntegerWriter integerWriter) {
        this.statusWriter = statusWriter;
        this.coordinateWriter = coordinateWriter;
        this.integerWriter = integerWriter;
    }

    void write(CircleLocationReference circleLocationReference, ByteArrayOutputStream outputStream) throws IOException {
        Status status = new Status(3, false, 0, false);
        statusWriter.write(status, outputStream);

        coordinateWriter.writeAbsoluteCoordinate(circleLocationReference.getCenter(), outputStream);

        int radius = circleLocationReference.getRadius();
        int numberOfBytesForRadius = determineNumberOfBytesForRadius(radius);
        integerWriter.write(radius, numberOfBytesForRadius, outputStream);
    }

    private int determineNumberOfBytesForRadius(int radius) {
        int i = 1;
        while (radius >= Math.pow(2, 8 * i)) {
            i++;
        }
        return i;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy