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

org.openlr.binary.reader.LocationReferenceReader Maven / Gradle / Ivy

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

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

import java.io.ByteArrayInputStream;
import java.io.IOException;

public class LocationReferenceReader {
    private final StatusReader statusReader;
    private final LineLocationReferenceReader lineLocationReferenceReader;
    private final GeoCoordinateLocationReferenceReader geoCoordinateLocationReferenceReader;
    private final PointAlongLineLocationReferenceReader pointAlongLineLocationReferenceReader;
    private final PointOfInterestWithAccessPointLocationReferenceReader pointOfInterestWithAccessPointLocationReferenceReader;
    private final CircleLocationReferenceReader circleLocationReferenceReader;
    private final PolygonLocationReferenceReader polygonLocationReferenceReader;
    private final RectangleLocationReferenceReader rectangleLocationReferenceReader;
    private final GridLocationReferenceReader gridLocationReferenceReader;
    private final ClosedLineLocationReferenceReader closedLineLocationReferenceReader;

    LocationReferenceReader(StatusReader statusReader, LineLocationReferenceReader lineLocationReferenceReader, GeoCoordinateLocationReferenceReader geoCoordinateLocationReferenceReader, PointAlongLineLocationReferenceReader pointAlongLineLocationReferenceReader, PointOfInterestWithAccessPointLocationReferenceReader pointOfInterestWithAccessPointLocationReferenceReader, CircleLocationReferenceReader circleLocationReferenceReader, PolygonLocationReferenceReader polygonLocationReferenceReader, RectangleLocationReferenceReader rectangleLocationReferenceReader, GridLocationReferenceReader gridLocationReferenceReader, ClosedLineLocationReferenceReader closedLineLocationReferenceReader) {
        this.statusReader = statusReader;
        this.lineLocationReferenceReader = lineLocationReferenceReader;
        this.geoCoordinateLocationReferenceReader = geoCoordinateLocationReferenceReader;
        this.pointAlongLineLocationReferenceReader = pointAlongLineLocationReferenceReader;
        this.pointOfInterestWithAccessPointLocationReferenceReader = pointOfInterestWithAccessPointLocationReferenceReader;
        this.circleLocationReferenceReader = circleLocationReferenceReader;
        this.polygonLocationReferenceReader = polygonLocationReferenceReader;
        this.rectangleLocationReferenceReader = rectangleLocationReferenceReader;
        this.gridLocationReferenceReader = gridLocationReferenceReader;
        this.closedLineLocationReferenceReader = closedLineLocationReferenceReader;
    }

    public LocationReference read(ByteArrayInputStream inputStream) throws IOException {
        Status status = statusReader.read(inputStream);

        if (status.getVersion() != 3) {
            throw new IllegalArgumentException("Unsupported version of the binary format");
        }

        inputStream.reset();

        if (status.isAttributeFlag() && status.getAreaFlag() == 0 && !status.isPointFlag()) {
            return lineLocationReferenceReader.read(inputStream);
        }
        else if (!status.isAttributeFlag() && status.getAreaFlag() == 0 && status.isPointFlag()) {
            return geoCoordinateLocationReferenceReader.read(inputStream);
        }
        else if (status.isAttributeFlag() && status.getAreaFlag() == 0 && status.isPointFlag() && inputStream.available() <= 17) {
            return pointAlongLineLocationReferenceReader.read(inputStream);
        }
        else if (status.isAttributeFlag() && status.getAreaFlag() == 0 && status.isPointFlag()) {
            return pointOfInterestWithAccessPointLocationReferenceReader.read(inputStream);
        }
        else if (!status.isAttributeFlag() && status.getAreaFlag() == 0 && !status.isPointFlag()) {
            return circleLocationReferenceReader.read(inputStream);
        }
        else if (!status.isAttributeFlag() && status.getAreaFlag() == 1 && !status.isPointFlag()) {
            return polygonLocationReferenceReader.read(inputStream);
        }
        else if (!status.isAttributeFlag() && status.getAreaFlag() == 2 && !status.isPointFlag() && inputStream.available() <= 13) {
            return rectangleLocationReferenceReader.read(inputStream);
        }
        else if (!status.isAttributeFlag() && status.getAreaFlag() == 2 && !status.isPointFlag()) {
            return gridLocationReferenceReader.read(inputStream);
        }
        else if (status.isAttributeFlag() && status.getAreaFlag() == 3 && !status.isPointFlag()) {
            return closedLineLocationReferenceReader.read(inputStream);
        }
        else {
            throw new IllegalArgumentException("Unknown location reference type");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy