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

at.gridgears.held.internal.FindLocationRequestMarshaller Maven / Gradle / Ivy

package at.gridgears.held.internal;

import at.gridgears.held.FindLocationRequest;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.lang3.NotImplementedException;

@SuppressFBWarnings("VA_FORMAT_STRING_USES_NEWLINE")
class FindLocationRequestMarshaller {
    String marshall(FindLocationRequest request) {
        return String.format("\n" +
                "\n" +
                "%s" +
                "%s" +
                "", marshallResponseTime(request), marshallLocationTypes(request), marshallDevice(request));
    }

    private String marshallResponseTime(FindLocationRequest request) {
        return request.getResponseTime().map(responseTime -> String.format(" responseTime=\"%s\"", responseTime)).orElse("");
    }

    private String marshallDevice(FindLocationRequest request) {
        return String.format("   \n" +
                "        %s\n" +
                "    \n", request.getIdentifier());
    }

    private String marshallLocationTypes(FindLocationRequest request) {
        StringBuilder result = new StringBuilder(30);
        if (!request.getLocationTypes().isEmpty()) {
            result.append(String.format("   \n", request.isExact()));
            request.getLocationTypes().forEach(locationType -> result.append(String.format("       %s\n", getLocationTypeString(locationType))));
            result.append("   \n");
        }

        return result.toString();
    }

    private String getLocationTypeString(FindLocationRequest.LocationType locationType) {
        String result;
        switch (locationType) {
            case ANY:
                result = "any";
                break;
            case GEODETIC:
                result = "geodetic";
                break;
            case CIVIC:
                result = "civic";
                break;
            case LOCATION_URI:
                result = "locationURI";
                break;
            default:
                throw new NotImplementedException("Marshalling of locationType '" + locationType + "' not implemented");
        }

        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy