package hu.supercluster.overpasser.library.query;

import java.util.Set;

class OverpassQueryBuilder {
    private StringBuilder builder;

    public OverpassQueryBuilder() {
        builder = new StringBuilder();
    }

    public OverpassQueryBuilder append(String statement) {
        builder.append(statement);

        return this;
    }

    public OverpassQueryBuilder boundingBox(double lat1, double lon1, double lat2, double lon2) {
        builder.append(String.format("(%s,%s,%s,%s)",
                        lat1, lon1,
                        lat2, lon2
                )
        );

        return this;
    }

    public OverpassQueryBuilder standaloneParam(String name) {
        return paramRel(name, "", "");
    }

    public OverpassQueryBuilder clause(String name, String value) {
        return paramRel(name, ":", value);
    }

    public OverpassQueryBuilder equals(String name, String value) {
        return paramRel(name, "=", value);
    }

    public OverpassQueryBuilder multipleValues(String name, Set<String> values) {
        StringBuilder joiner = new StringBuilder();
        for (String value : values) {
            joiner.append(value);
            joiner.append("|");
        }

        joiner.setLength(joiner.length() - 1);

        return paramRel(name, "~", joiner.toString());
    }

    public OverpassQueryBuilder notEquals(String name, String value) {
        return paramRel(name, "!=", value);
    }

    public OverpassQueryBuilder regexMatches(String name, String value) {
        return paramRel(name, "~", value);
    }

    public OverpassQueryBuilder regexDoesntMatch(String name, String value) {
        return paramRel(name, "!~", value);
    }

    private OverpassQueryBuilder paramRel(String name, String rel, String value) {
        String quotedValue = value.isEmpty() ? "" : String.format("\"%s\"", value);

        builder.append(String.format("[\"%s\"%s%s]", name, rel, quotedValue));

        return this;
    }

    public String build() {
        return builder.toString();
    }
}

@@ -44,16 +44,41 @@
 query;%0A%0A
+import java.util.Locale;%0A
 import j
@@ -121,16 +121,68 @@
 ilder %7B%0A
+    private static final Locale LOCALE = Locale.US;%0A
     priv
@@ -535,30 +535,104 @@
 .append(
-String.format(
+%0A                String.format(%0A                        LOCALE,%0A                        
 %22(%25s,%25s,
@@ -2053,16 +2053,24 @@
 .format(
+LOCALE, 
 %22%5B%5C%22%25s%5C%22

Use Locale.US in String.format()