@Test public void testInvalidLocationReference() { Coordinates lastCoordinates = Coordinates.newBuilder() .setLongitude(4.2) .setLatitude(5.2) .build(); LineAttributes lastLineAttributes = LineAttributes.newBuilder() .setBearing(270) .setFrc(FRC.FRC_1) .setFow(FOW.FOW_MULTIPLE_CARRIAGEWAY) .build(); LocationReferencePoint last = LocationReferencePoint.newBuilder() .setCoordinates(lastCoordinates) .setLineAttributes(lastLineAttributes) .build(); PointAlongLineLocationReference pointAlongLineLocationReference = PointAlongLineLocationReference.newBuilder() .setLast(last) .setPositiveOffset(20) .build(); LocationReferenceData locationReferenceData = LocationReferenceData.newBuilder() .setPointAlongLineLocationReference(pointAlongLineLocationReference) .build(); try { pointAlongLineDecoder.decode("1", locationReferenceData); fail(); } catch (PhysicalFormatException e) { assertEquals(e.getErrorCode(), OpenLRProtoStatusCode.INVALID_LOCATION_REFERENCE); } }
@Override public RawLocationReference decode(String id, LocationReferenceData data) throws OpenLRProtoException { if (!data.hasPointAlongLineLocationReference()) { throw new OpenLRProtoException(OpenLRProtoStatusCode.MISSING_LOCATION_REFERENCE); } PointAlongLineLocationReference pointAlongLineLocationReference = data.getPointAlongLineLocationReference(); if (!pointAlongLineLocationReference.hasFirst()) { throw new OpenLRProtoException(OpenLRProtoStatusCode.INVALID_LOCATION_REFERENCE); } LocationReferencePoint first = locationReferencePointDecoder.decode( pointAlongLineLocationReference.getFirst(), 1, false); if (!pointAlongLineLocationReference.hasLast()) { throw new OpenLRProtoException(OpenLRProtoStatusCode.INVALID_LOCATION_REFERENCE); } LocationReferencePoint last = locationReferencePointDecoder.decode( pointAlongLineLocationReference.getLast(), 2, true); Offsets offsets = new OffsetsProtoImpl(pointAlongLineLocationReference.getPositiveOffset()); SideOfRoad sideOfRoad = map(pointAlongLineLocationReference.getSideOfRoad()); Orientation orientation = map(pointAlongLineLocationReference.getOrientation()); return new RawPointAlongLocRef(id, first, last, offsets, sideOfRoad, orientation); }
PointAlongLineDecoder implements LocationReferenceDecoder { @Override public RawLocationReference decode(String id, LocationReferenceData data) throws OpenLRProtoException { if (!data.hasPointAlongLineLocationReference()) { throw new OpenLRProtoException(OpenLRProtoStatusCode.MISSING_LOCATION_REFERENCE); } PointAlongLineLocationReference pointAlongLineLocationReference = data.getPointAlongLineLocationReference(); if (!pointAlongLineLocationReference.hasFirst()) { throw new OpenLRProtoException(OpenLRProtoStatusCode.INVALID_LOCATION_REFERENCE); } LocationReferencePoint first = locationReferencePointDecoder.decode( pointAlongLineLocationReference.getFirst(), 1, false); if (!pointAlongLineLocationReference.hasLast()) { throw new OpenLRProtoException(OpenLRProtoStatusCode.INVALID_LOCATION_REFERENCE); } LocationReferencePoint last = locationReferencePointDecoder.decode( pointAlongLineLocationReference.getLast(), 2, true); Offsets offsets = new OffsetsProtoImpl(pointAlongLineLocationReference.getPositiveOffset()); SideOfRoad sideOfRoad = map(pointAlongLineLocationReference.getSideOfRoad()); Orientation orientation = map(pointAlongLineLocationReference.getOrientation()); return new RawPointAlongLocRef(id, first, last, offsets, sideOfRoad, orientation); } }
PointAlongLineDecoder implements LocationReferenceDecoder { @Override public RawLocationReference decode(String id, LocationReferenceData data) throws OpenLRProtoException { if (!data.hasPointAlongLineLocationReference()) { throw new OpenLRProtoException(OpenLRProtoStatusCode.MISSING_LOCATION_REFERENCE); } PointAlongLineLocationReference pointAlongLineLocationReference = data.getPointAlongLineLocationReference(); if (!pointAlongLineLocationReference.hasFirst()) { throw new OpenLRProtoException(OpenLRProtoStatusCode.INVALID_LOCATION_REFERENCE); } LocationReferencePoint first = locationReferencePointDecoder.decode( pointAlongLineLocationReference.getFirst(), 1, false); if (!pointAlongLineLocationReference.hasLast()) { throw new OpenLRProtoException(OpenLRProtoStatusCode.INVALID_LOCATION_REFERENCE); } LocationReferencePoint last = locationReferencePointDecoder.decode( pointAlongLineLocationReference.getLast(), 2, true); Offsets offsets = new OffsetsProtoImpl(pointAlongLineLocationReference.getPositiveOffset()); SideOfRoad sideOfRoad = map(pointAlongLineLocationReference.getSideOfRoad()); Orientation orientation = map(pointAlongLineLocationReference.getOrientation()); return new RawPointAlongLocRef(id, first, last, offsets, sideOfRoad, orientation); } PointAlongLineDecoder(LocationReferencePointDecoder locationReferencePointDecoder); }
PointAlongLineDecoder implements LocationReferenceDecoder { @Override public RawLocationReference decode(String id, LocationReferenceData data) throws OpenLRProtoException { if (!data.hasPointAlongLineLocationReference()) { throw new OpenLRProtoException(OpenLRProtoStatusCode.MISSING_LOCATION_REFERENCE); } PointAlongLineLocationReference pointAlongLineLocationReference = data.getPointAlongLineLocationReference(); if (!pointAlongLineLocationReference.hasFirst()) { throw new OpenLRProtoException(OpenLRProtoStatusCode.INVALID_LOCATION_REFERENCE); } LocationReferencePoint first = locationReferencePointDecoder.decode( pointAlongLineLocationReference.getFirst(), 1, false); if (!pointAlongLineLocationReference.hasLast()) { throw new OpenLRProtoException(OpenLRProtoStatusCode.INVALID_LOCATION_REFERENCE); } LocationReferencePoint last = locationReferencePointDecoder.decode( pointAlongLineLocationReference.getLast(), 2, true); Offsets offsets = new OffsetsProtoImpl(pointAlongLineLocationReference.getPositiveOffset()); SideOfRoad sideOfRoad = map(pointAlongLineLocationReference.getSideOfRoad()); Orientation orientation = map(pointAlongLineLocationReference.getOrientation()); return new RawPointAlongLocRef(id, first, last, offsets, sideOfRoad, orientation); } PointAlongLineDecoder(LocationReferencePointDecoder locationReferencePointDecoder); @Override RawLocationReference decode(String id, LocationReferenceData data); }
PointAlongLineDecoder implements LocationReferenceDecoder { @Override public RawLocationReference decode(String id, LocationReferenceData data) throws OpenLRProtoException { if (!data.hasPointAlongLineLocationReference()) { throw new OpenLRProtoException(OpenLRProtoStatusCode.MISSING_LOCATION_REFERENCE); } PointAlongLineLocationReference pointAlongLineLocationReference = data.getPointAlongLineLocationReference(); if (!pointAlongLineLocationReference.hasFirst()) { throw new OpenLRProtoException(OpenLRProtoStatusCode.INVALID_LOCATION_REFERENCE); } LocationReferencePoint first = locationReferencePointDecoder.decode( pointAlongLineLocationReference.getFirst(), 1, false); if (!pointAlongLineLocationReference.hasLast()) { throw new OpenLRProtoException(OpenLRProtoStatusCode.INVALID_LOCATION_REFERENCE); } LocationReferencePoint last = locationReferencePointDecoder.decode( pointAlongLineLocationReference.getLast(), 2, true); Offsets offsets = new OffsetsProtoImpl(pointAlongLineLocationReference.getPositiveOffset()); SideOfRoad sideOfRoad = map(pointAlongLineLocationReference.getSideOfRoad()); Orientation orientation = map(pointAlongLineLocationReference.getOrientation()); return new RawPointAlongLocRef(id, first, last, offsets, sideOfRoad, orientation); } PointAlongLineDecoder(LocationReferencePointDecoder locationReferencePointDecoder); @Override RawLocationReference decode(String id, LocationReferenceData data);  }