Ignore:
Timestamp:
2014-04-27T15:35:47+02:00 (10 years ago)
Author:
Don-vip
Message:

see #8465 - use String switch/case where applicable

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java

    r7005 r7012  
    9696        int shortcut = -1;
    9797
     98        // TODO: convert this to switch/case and make sure the parsing still works
    9899        /* leave as single line for shortcut overview parsing! */
    99100        if (mode.equals("data")) { shortcut = KeyEvent.VK_1; }
     
    130131        putValue("help", "Action/AutoScale/" + modeHelp);
    131132        this.mode = mode;
    132         if (mode.equals("data")) {
     133        switch (mode) {
     134        case "data":
    133135            putValue("help", ht("/Action/ZoomToData"));
    134         } else if (mode.equals("layer")) {
     136            break;
     137        case "layer":
    135138            putValue("help", ht("/Action/ZoomToLayer"));
    136         } else if (mode.equals("selection")) {
     139            break;
     140        case "selection":
    137141            putValue("help", ht("/Action/ZoomToSelection"));
    138         } else if (mode.equals("conflict")) {
     142            break;
     143        case "conflict":
    139144            putValue("help", ht("/Action/ZoomToConflict"));
    140         } else if (mode.equals("problem")) {
     145            break;
     146        case "problem":
    141147            putValue("help", ht("/Action/ZoomToProblem"));
    142         } else if (mode.equals("download")) {
     148            break;
     149        case "download":
    143150            putValue("help", ht("/Action/ZoomToDownload"));
    144         } else if (mode.equals("previous")) {
     151            break;
     152        case "previous":
    145153            putValue("help", ht("/Action/ZoomToPrevious"));
    146         } else if (mode.equals("next")) {
     154            break;
     155        case "next":
    147156            putValue("help", ht("/Action/ZoomToNext"));
    148         } else {
     157            break;
     158        default:
    149159            throw new IllegalArgumentException("Unknown mode: "+mode);
    150160        }
     
    154164    public void autoScale()  {
    155165        if (Main.isDisplayingMapView()) {
    156             if (mode.equals("previous")) {
     166            switch(mode) {
     167            case "previous":
    157168                Main.map.mapView.zoomPrevious();
    158             } else if (mode.equals("next")) {
     169                break;
     170            case "next":
    159171                Main.map.mapView.zoomNext();
    160             } else {
     172                break;
     173            default:
    161174                BoundingXYVisitor bbox = getBoundingBox();
    162175                if (bbox != null && bbox.getBounds() != null) {
     
    187200
    188201    private BoundingXYVisitor getBoundingBox() {
    189         BoundingXYVisitor v = mode.equals("problem") ? new ValidatorBoundingXYVisitor() : new BoundingXYVisitor();
    190 
    191         if (mode.equals("problem")) {
     202        BoundingXYVisitor v = "problem".equals(mode) ? new ValidatorBoundingXYVisitor() : new BoundingXYVisitor();
     203
     204        switch(mode) {
     205        case "problem":
    192206            TestError error = Main.map.validatorDialog.getSelectedError();
    193207            if (error == null) return null;
     
    195209            if (v.getBounds() == null) return null;
    196210            v.enlargeBoundingBox(Main.pref.getDouble("validator.zoom-enlarge-bbox", 0.0002));
    197         } else if (mode.equals("data")) {
     211            break;
     212        case "data":
    198213            for (Layer l : Main.map.mapView.getAllLayers()) {
    199214                l.visitBoundingBox(v);
    200215            }
    201         } else if (mode.equals("layer")) {
     216            break;
     217        case "layer":
    202218            if (Main.main.getActiveLayer() == null)
    203219                return null;
     
    206222            if (l == null) return null;
    207223            l.visitBoundingBox(v);
    208         } else if (mode.equals("selection") || mode.equals("conflict")) {
     224            break;
     225        case "selection":
     226        case "conflict":
    209227            Collection<OsmPrimitive> sel = new HashSet<>();
    210             if (mode.equals("selection")) {
     228            if ("selection".equals(mode)) {
    211229                sel = getCurrentDataSet().getSelected();
    212             } else if (mode.equals("conflict")) {
     230            } else {
    213231                Conflict<? extends OsmPrimitive> c = Main.map.conflictDialog.getSelectedConflict();
    214232                if (c != null) {
     
    221239                JOptionPane.showMessageDialog(
    222240                        Main.parent,
    223                         (mode.equals("selection") ? tr("Nothing selected to zoom to.") : tr("No conflicts to zoom to")),
     241                        ("selection".equals(mode) ? tr("Nothing selected to zoom to.") : tr("No conflicts to zoom to")),
    224242                        tr("Information"),
    225243                        JOptionPane.INFORMATION_MESSAGE
     
    236254            // ensure reasonable zoom level when zooming onto single nodes.
    237255            v.enlargeToMinDegrees(0.0005);
    238         } else if (mode.equals("download")) {
     256            break;
     257        case "download":
    239258            Bounds bounds = DownloadDialog.getSavedDownloadBounds();
    240259            if (bounds != null) {
     
    245264                }
    246265            }
     266            break;
    247267        }
    248268        return v;
     
    251271    @Override
    252272    protected void updateEnabledState() {
    253         if ("selection".equals(mode)) {
     273        switch(mode) {
     274        case "selection":
    254275            setEnabled(getCurrentDataSet() != null && ! getCurrentDataSet().getSelected().isEmpty());
    255         }  else if ("layer".equals(mode)) {
     276            break;
     277        case "layer":
    256278            if (!Main.isDisplayingMapView() || Main.map.mapView.getAllLayersAsList().isEmpty()) {
    257279                setEnabled(false);
     
    260282                setEnabled(true);
    261283            }
    262         } else if ("conflict".equals(mode)) {
     284            break;
     285        case "conflict":
    263286            setEnabled(Main.map != null && Main.map.conflictDialog.getSelectedConflict() != null);
    264         } else if ("problem".equals(mode)) {
     287            break;
     288        case "problem":
    265289            setEnabled(Main.map != null && Main.map.validatorDialog.getSelectedError() != null);
    266         } else if ("previous".equals(mode)) {
     290            break;
     291        case "previous":
    267292            setEnabled(Main.isDisplayingMapView() && Main.map.mapView.hasZoomUndoEntries());
    268         } else if ("next".equals(mode)) {
     293            break;
     294        case "next":
    269295            setEnabled(Main.isDisplayingMapView() && Main.map.mapView.hasZoomRedoEntries());
    270         } else {
    271             setEnabled(
    272                     Main.isDisplayingMapView()
    273                     && Main.map.mapView.hasLayers()
     296            break;
     297        default:
     298            setEnabled(Main.isDisplayingMapView() && Main.map.mapView.hasLayers()
    274299            );
    275300        }
     
    311336
    312337        public MapFrameAdapter() {
    313             if (mode.equals("conflict")) {
     338            if ("conflict".equals(mode)) {
    314339                conflictSelectionListener = new ListSelectionListener() {
    315340                    @Override public void valueChanged(ListSelectionEvent e) {
     
    317342                    }
    318343                };
    319             } else if (mode.equals("problem")) {
     344            } else if ("problem".equals(mode)) {
    320345                validatorSelectionListener = new TreeSelectionListener() {
    321346                    @Override public void valueChanged(TreeSelectionEvent e) {
  • trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java

    r7005 r7012  
    355355        if( !Main.pref.getBoolean("multipoly.alltags", false) )
    356356            for( RelationMember m : relation.getMembers() )
    357                 if( m.hasRole() && m.getRole().equals("outer") && m.isWay() )
     357                if( m.hasRole() && "outer".equals(m.getRole()) && m.isWay() )
    358358                    for( String key : values.keySet() )
    359359                        if( !m.getWay().hasKey(key) && !relation.hasKey(key) )
     
    407407            for (Entry<String, String> entry : values.entrySet()) {
    408408                String key = entry.getKey();
    409                 if (!r2.hasKey(key) && !key.equals("area") ) {
     409                if (!r2.hasKey(key) && !"area".equals(key) ) {
    410410                    if (relation.isNew())
    411411                        relation.put(key, entry.getValue());
  • trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java

    r7005 r7012  
    186186        } catch (InvalidUserInputException ex) {
    187187            String msg;
    188             if (ex.getMessage().equals("usage")) {
     188            if ("usage".equals(ex.getMessage())) {
    189189                msg = "<h2>" + tr("Usage") + "</h2>" + USAGE;
    190190            } else {
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r7005 r7012  
    105105        @Override
    106106        public Match get(String keyword, PushbackTokenizer tokenizer) throws ParseError {
    107             if ("modified".equals(keyword))
     107            switch(keyword) {
     108            case "modified":
    108109                return new Modified();
    109             else if ("selected".equals(keyword))
     110            case "selected":
    110111                return new Selected();
    111             else if ("incomplete".equals(keyword))
     112            case "incomplete":
    112113                return new Incomplete();
    113             else if ("untagged".equals(keyword))
     114            case "untagged":
    114115                return new Untagged();
    115             else if ("closed".equals(keyword))
     116            case "closed":
    116117                return new Closed();
    117             else if ("new".equals(keyword))
     118            case "new":
    118119                return new New();
    119             else if ("indownloadedarea".equals(keyword))
     120            case "indownloadedarea":
    120121                return new InDataSourceArea(false);
    121             else if ("allindownloadedarea".equals(keyword))
     122            case "allindownloadedarea":
    122123                return new InDataSourceArea(true);
    123             else if ("inview".equals(keyword))
     124            case "inview":
    124125                return new InView(false);
    125             else if ("allinview".equals(keyword))
     126            case "allinview":
    126127                return new InView(true);
    127             else if (tokenizer != null) {
    128                 if ("id".equals(keyword))
    129                     return new Id(tokenizer);
    130                 else if ("version".equals(keyword))
    131                     return new Version(tokenizer);
    132                 else if ("changeset".equals(keyword))
    133                     return new ChangesetId(tokenizer);
    134                 else if ("nodes".equals(keyword))
    135                     return new NodeCountRange(tokenizer);
    136                 else if ("tags".equals(keyword))
    137                     return new TagCountRange(tokenizer);
    138                 else if ("areasize".equals(keyword))
    139                     return new AreaSize(tokenizer);
    140                 else if ("nth".equals(keyword))
    141                     return new Nth(tokenizer, false);
    142                 else if ("nth%".equals(keyword))
    143                     return new Nth(tokenizer, true);
    144                 else if ("timestamp".equals(keyword)) {
    145                     String rangeS = " " + tokenizer.readTextOrNumber() + " "; // add leading/trailing space in order to get expected split (e.g. "a--" => {"a", ""})
    146                     String[] rangeA = rangeS.split("/");
    147                     if (rangeA.length == 1)
    148                         return new KeyValue(keyword, rangeS.trim(), regexSearch, caseSensitive);
    149                     else if (rangeA.length == 2) {
    150                         String rangeA1 = rangeA[0].trim();
    151                         String rangeA2 = rangeA[1].trim();
    152                         long minDate = DateUtils.fromString(rangeA1.isEmpty() ? "1980" : rangeA1).getTime(); // if min timestap is empty: use lowest possible date
    153                         long maxDate = rangeA2.isEmpty() ? System.currentTimeMillis() : DateUtils.fromString(rangeA2).getTime(); // if max timestamp is empty: use "now"
    154                         return new TimestampRange(minDate, maxDate);
    155                     } else
    156                         /*
    157                          * I18n: Don't translate timestamp keyword
    158                          */ throw new ParseError(tr("Expecting <i>min</i>/<i>max</i> after ''timestamp''"));
     128            default:
     129                if (tokenizer != null) {
     130                    switch (keyword) {
     131                    case "id":
     132                        return new Id(tokenizer);
     133                    case "version":
     134                        return new Version(tokenizer);
     135                    case "changeset":
     136                        return new ChangesetId(tokenizer);
     137                    case "nodes":
     138                        return new NodeCountRange(tokenizer);
     139                    case "tags":
     140                        return new TagCountRange(tokenizer);
     141                    case "areasize":
     142                        return new AreaSize(tokenizer);
     143                    case "nth":
     144                        return new Nth(tokenizer, false);
     145                    case "nth%":
     146                        return new Nth(tokenizer, true);
     147                    case "timestamp":
     148                        // add leading/trailing space in order to get expected split (e.g. "a--" => {"a", ""})
     149                        String rangeS = " " + tokenizer.readTextOrNumber() + " ";
     150                        String[] rangeA = rangeS.split("/");
     151                        if (rangeA.length == 1) {
     152                            return new KeyValue(keyword, rangeS.trim(), regexSearch, caseSensitive);
     153                        } else if (rangeA.length == 2) {
     154                            String rangeA1 = rangeA[0].trim();
     155                            String rangeA2 = rangeA[1].trim();
     156                            // if min timestap is empty: use lowest possible date
     157                            long minDate = DateUtils.fromString(rangeA1.isEmpty() ? "1980" : rangeA1).getTime();
     158                            // if max timestamp is empty: use "now"
     159                            long maxDate = rangeA2.isEmpty() ? System.currentTimeMillis() : DateUtils.fromString(rangeA2).getTime();
     160                            return new TimestampRange(minDate, maxDate);
     161                        } else {
     162                            // I18n: Don't translate timestamp keyword
     163                            throw new ParseError(tr("Expecting <i>min</i>/<i>max</i> after ''timestamp''"));
     164                        }
     165                    }
    159166                }
    160167            }
     
    13141321            value = "";
    13151322        }
    1316         if ("type".equals(key))
     1323        switch(key) {
     1324        case "type":
    13171325            return new ExactType(value);
    1318         else if ("user".equals(key))
     1326        case "user":
    13191327            return new UserMatch(value);
    1320         else if ("role".equals(key))
     1328        case "role":
    13211329            return new RoleMatch(value);
    1322         else
     1330        default:
    13231331            return new KeyValue(key, value, regexSearch, caseSensitive);
     1332        }
    13241333    }
    13251334
Note: See TracChangeset for help on using the changeset viewer.