Ticket #20037: 20037-refactoring.patch
| File 20037-refactoring.patch, 4.2 KB (added by , 5 years ago) |
|---|
-
src/org/openstreetmap/josm/gui/download/OverpassQueryWizardDialog.java
90 90 */ 91 91 private Optional<String> tryParseSearchTerm(String searchTerm) { 92 92 try { 93 return Optional.of(SearchCompilerQueryWizard. getInstance().constructQuery(searchTerm));93 return Optional.of(SearchCompilerQueryWizard.constructQuery(searchTerm)); 94 94 } catch (UncheckedParseException | IllegalStateException ex) { 95 95 Logging.error(ex); 96 96 JOptionPane.showMessageDialog( -
src/org/openstreetmap/josm/tools/SearchCompilerQueryWizard.java
25 25 */ 26 26 public final class SearchCompilerQueryWizard { 27 27 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 class34 */35 public static SearchCompilerQueryWizard getInstance() {36 return instance;37 }38 39 28 private SearchCompilerQueryWizard() { 40 29 // private constructor for utility class 41 30 } … … 46 35 * @return an Overpass QL query 47 36 * @throws UncheckedParseException when the parsing fails 48 37 */ 49 public String constructQuery(final String search) {38 public static String constructQuery(final String search) { 50 39 try { 51 40 Matcher matcher = Pattern.compile("\\s+GLOBAL\\s*$", Pattern.CASE_INSENSITIVE).matcher(search); 52 41 if (matcher.find()) { … … 73 62 throw new IllegalStateException(mode); 74 63 } 75 64 } 76 65 77 66 final Match match = SearchCompiler.compile(search); 78 67 return constructQuery(match, "[bbox:{{bbox}}];", ""); 79 68 } catch (SearchParseError | UnsupportedOperationException e) { … … 81 70 } 82 71 } 83 72 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) { 85 74 final List<Match> normalized = normalizeToDNF(match); 86 75 final List<String> queryLines = new ArrayList<>(); 87 76 queryLines.add("[out:xml][timeout:90]" + bounds); -
test/unit/org/openstreetmap/josm/io/OverpassDownloadReaderTest.java
58 58 } 59 59 60 60 private String getExpandedQuery(String search) { 61 final String query = SearchCompilerQueryWizard. getInstance().constructQuery(search);61 final String query = SearchCompilerQueryWizard.constructQuery(search); 62 62 final String request = new OverpassDownloadReader(new Bounds(1, 2, 3, 4), null, query) 63 63 .getRequestForBbox(1, 2, 3, 4) 64 64 .substring("interpreter?data=".length()); -
test/unit/org/openstreetmap/josm/tools/SearchCompilerQueryWizardTest.java
23 23 public JOSMTestRules test = new JOSMTestRules().i18n("de"); 24 24 25 25 private static String constructQuery(String s) { 26 return SearchCompilerQueryWizard. getInstance().constructQuery(s);26 return SearchCompilerQueryWizard.constructQuery(s); 27 27 } 28 28 29 29 private void assertQueryEquals(String expectedQueryPart, String input) {
