Ticket #20037: 20037-refactoring.patch

File 20037-refactoring.patch, 4.2 KB (added by GerdP, 5 years ago)

refactoring only

  • src/org/openstreetmap/josm/gui/download/OverpassQueryWizardDialog.java

     
    9090     */
    9191    private Optional<String> tryParseSearchTerm(String searchTerm) {
    9292        try {
    93             return Optional.of(SearchCompilerQueryWizard.getInstance().constructQuery(searchTerm));
     93            return Optional.of(SearchCompilerQueryWizard.constructQuery(searchTerm));
    9494        } catch (UncheckedParseException | IllegalStateException ex) {
    9595            Logging.error(ex);
    9696            JOptionPane.showMessageDialog(
  • src/org/openstreetmap/josm/tools/SearchCompilerQueryWizard.java

     
    2525 */
    2626public final class SearchCompilerQueryWizard {
    2727
    28     private static final SearchCompilerQueryWizard instance = new SearchCompilerQueryWizard();
    29 
    30     /**
    31      * Replies the unique instance of this class.
    32      *
    33      * @return the unique instance of this class
    34      */
    35     public static SearchCompilerQueryWizard getInstance() {
    36         return instance;
    37     }
    38 
    3928    private SearchCompilerQueryWizard() {
    4029        // private constructor for utility class
    4130    }
     
    4635     * @return an Overpass QL query
    4736     * @throws UncheckedParseException when the parsing fails
    4837     */
    49     public String constructQuery(final String search) {
     38    public static String constructQuery(final String search) {
    5039        try {
    5140            Matcher matcher = Pattern.compile("\\s+GLOBAL\\s*$", Pattern.CASE_INSENSITIVE).matcher(search);
    5241            if (matcher.find()) {
     
    7362                    throw new IllegalStateException(mode);
    7463                }
    7564            }
    76            
     65
    7766            final Match match = SearchCompiler.compile(search);
    7867            return constructQuery(match, "[bbox:{{bbox}}];", "");
    7968        } catch (SearchParseError | UnsupportedOperationException e) {
     
    8170        }
    8271    }
    8372
    84     private String constructQuery(final Match match, final String bounds, final String queryLineSuffix) {
     73    private static String constructQuery(final Match match, final String bounds, final String queryLineSuffix) {
    8574        final List<Match> normalized = normalizeToDNF(match);
    8675        final List<String> queryLines = new ArrayList<>();
    8776        queryLines.add("[out:xml][timeout:90]" + bounds);
  • test/unit/org/openstreetmap/josm/io/OverpassDownloadReaderTest.java

     
    5858    }
    5959
    6060    private String getExpandedQuery(String search) {
    61         final String query = SearchCompilerQueryWizard.getInstance().constructQuery(search);
     61        final String query = SearchCompilerQueryWizard.constructQuery(search);
    6262        final String request = new OverpassDownloadReader(new Bounds(1, 2, 3, 4), null, query)
    6363                .getRequestForBbox(1, 2, 3, 4)
    6464                .substring("interpreter?data=".length());
  • test/unit/org/openstreetmap/josm/tools/SearchCompilerQueryWizardTest.java

     
    2323    public JOSMTestRules test = new JOSMTestRules().i18n("de");
    2424
    2525    private static String constructQuery(String s) {
    26         return SearchCompilerQueryWizard.getInstance().constructQuery(s);
     26        return SearchCompilerQueryWizard.constructQuery(s);
    2727    }
    2828
    2929    private void assertQueryEquals(String expectedQueryPart, String input) {