class PointAlongLineEncoder implements LocationReferenceEncoder {

    @Override
    public LocationReference encode(RawLocationReference rawLocationReference) throws OpenLRProtoException {
        if (rawLocationReference.getLocationType() != LocationType.POINT_ALONG_LINE) {
            throw new OpenLRProtoException(OpenLRProtoStatusCode.INVALID_LOCATION_REFERENCE);
        }

        List<LocationReferencePoint> locationReferencePoints = rawLocationReference.getLocationReferencePoints();

        if (locationReferencePoints.size() < 2) {
            throw new OpenLRProtoException(OpenLRProtoStatusCode.INVALID_LOCATION_REFERENCE);
        }

        openlr.proto.schema.LocationReferencePoint first = locationReferencePointEncoder.encode(locationReferencePoints.get(0));
        openlr.proto.schema.LocationReferencePoint last = locationReferencePointEncoder.encode(locationReferencePoints.get(locationReferencePoints.size() - 1));

        Offsets offsets = rawLocationReference.getOffsets();
        int positiveLength = locationReferencePoints.get(0).getDistanceToNext();
        int positiveOffset = offsets.getPositiveOffset(positiveLength);

        openlr.proto.schema.SideOfRoad sideOfRoad = map(rawLocationReference.getSideOfRoad());
        openlr.proto.schema.Orientation orientation = map(rawLocationReference.getOrientation());

        PointAlongLineLocationReference pointAlongLineLocationReference = PointAlongLineLocationReference.newBuilder()
                .setFirst(first)
                .setLast(last)
                .setPositiveOffset(positiveOffset)
                .setSideOfRoad(sideOfRoad)
                .setOrientation(orientation)
                .build();

        LocationReferenceData locationReferenceData = LocationReferenceData.newBuilder()
                .setPointAlongLineLocationReference(pointAlongLineLocationReference)
                .build();

        return new LocationReferenceProtoImpl(rawLocationReference.getID(), LocationType.POINT_ALONG_LINE, locationReferenceData);
    }

      PointAlongLineEncoder(LocationReferencePointEncoder locationReferencePointEncoder);

}