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/gui
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/JosmUserIdentityManager.java

    r7004 r7012  
    240240    @Override
    241241    public void preferenceChanged(PreferenceChangeEvent evt) {
    242         if ("osm-server.username".equals(evt.getKey())) {
     242        switch (evt.getKey()) {
     243        case "osm-server.username":
    243244            if (!(evt.getNewValue() instanceof StringSetting)) return;
    244             String newValue = ((StringSetting) evt.getNewValue()).getValue();
    245             if (newValue == null || newValue.trim().length() == 0) {
     245            String newUserName = ((StringSetting) evt.getNewValue()).getValue();
     246            if (newUserName == null || newUserName.trim().isEmpty()) {
    246247                setAnonymous();
    247248            } else {
    248                 if (! newValue.equals(userName)) {
    249                     setPartiallyIdentified(newValue);
     249                if (! newUserName.equals(userName)) {
     250                    setPartiallyIdentified(newUserName);
    250251                }
    251252            }
    252253            return;
    253254
    254         } else if ("osm-server.url".equals(evt.getKey())) {
     255        case "osm-server.url":
    255256            if (!(evt.getNewValue() instanceof StringSetting)) return;
    256             String newValue = ((StringSetting) evt.getNewValue()).getValue();
    257             if (newValue == null || newValue.trim().isEmpty()) {
     257            String newUrl = ((StringSetting) evt.getNewValue()).getValue();
     258            if (newUrl == null || newUrl.trim().isEmpty()) {
    258259                setAnonymous();
    259260            } else if (isFullyIdentified()) {
    260261                setPartiallyIdentified(getUserName());
    261262            }
    262 
    263         } else if ("oauth.access-token.key".equals(evt.getKey())) {
     263            break;
     264
     265        case "oauth.access-token.key":
    264266            accessTokenKeyChanged = true;
    265 
    266         } else if ("oauth.access-token.secret".equals(evt.getKey())) {
     267            break;
     268
     269        case "oauth.access-token.secret":
    267270            accessTokenSecretChanged = true;
     271            break;
    268272        }
    269273
  • trunk/src/org/openstreetmap/josm/gui/MapMover.java

    r6990 r7012  
    5151                EastNorth center = nc.getCenter();
    5252                EastNorth newcenter = nc.getEastNorth(nc.getWidth()/2+nc.getWidth()/5, nc.getHeight()/2+nc.getHeight()/5);
    53                 if ("left".equals(action))
     53                switch(action) {
     54                case "left":
    5455                    nc.zoomTo(new EastNorth(2*center.east()-newcenter.east(), center.north()));
    55                 else if ("right".equals(action))
     56                    break;
     57                case "right":
    5658                    nc.zoomTo(new EastNorth(newcenter.east(), center.north()));
    57                 else if ("up".equals(action))
     59                    break;
     60                case "up":
    5861                    nc.zoomTo(new EastNorth(center.east(), 2*center.north()-newcenter.north()));
    59                 else if ("down".equals(action))
     62                    break;
     63                case "down":
    6064                    nc.zoomTo(new EastNorth(center.east(), newcenter.north()));
     65                    break;
     66                }
    6167            }
    6268        }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java

    r6986 r7012  
    355355
    356356        public boolean appliesImpl(Environment e) {
    357             if ("closed".equals(id)) {
     357            switch(id) {
     358            case "closed":
    358359                if (e.osm instanceof Way && ((Way) e.osm).isClosed())
    359360                    return true;
    360361                if (e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon())
    361362                    return true;
    362                 return false;
    363             } else if ("modified".equals(id)) {
     363                break;
     364            case "modified":
    364365                return e.osm.isModified() || e.osm.isNewOrUndeleted();
    365             } else if ("new".equals(id)) {
     366            case "new":
    366367                return e.osm.isNew();
    367             } else if ("connection".equals(id) && (e.osm instanceof Node)) {
    368                 return ((Node) e.osm).isConnectionNode();
    369             } else if ("tagged".equals(id)) {
     368            case "connection":
     369                return e.osm instanceof Node && ((Node) e.osm).isConnectionNode();
     370            case "tagged":
    370371                return e.osm.isTagged();
    371             } else if ("sameTags".equals(id)) {
     372            case "sameTags":
    372373                return e.osm.hasSameInterestingTags(Utils.firstNonNull(e.child, e.parent));
    373             } else if ("areaStyle".equals(id)) {
     374            case "areaStyle":
    374375                return ElemStyles.hasAreaElemStyle(e.osm, false);
    375             } else if ("unconnected".equals(id) && (e.osm instanceof Node)) {
    376                 return OsmPrimitive.getFilteredList(e.osm.getReferrers(), Way.class).isEmpty();
     376            case "unconnected":
     377                return e.osm instanceof Node && OsmPrimitive.getFilteredList(e.osm.getReferrers(), Way.class).isEmpty();
    377378            }
    378379            return false;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSourceHandler.java

    r7005 r7012  
    1414import org.xml.sax.helpers.DefaultHandler;
    1515
    16 public class XmlStyleSourceHandler extends DefaultHandler
    17 {
     16public class XmlStyleSourceHandler extends DefaultHandler {
    1817    private boolean inDoc, inRule, inCondition, inLine, inLineMod, inIcon, inArea, inScaleMax, inScaleMin;
    1918    private boolean hadLine, hadLineMod, hadIcon, hadArea;
     
    7978    private void startElementLine(String qName, Attributes atts, LinePrototype line) {
    8079        for (int count=0; count<atts.getLength(); count++) {
    81             if(atts.getQName(count).equals("width")) {
     80            switch (atts.getQName(count)) {
     81            case "width":
    8282                String val = atts.getValue(count);
    8383                if (! (val.startsWith("+") || val.startsWith("-") || val.endsWith("%"))) {
    8484                    line.setWidth(Integer.parseInt(val));
    8585                }
    86             } else if (atts.getQName(count).equals("colour")) {
    87                 line.color=convertColor(atts.getValue(count));
    88             } else if (atts.getQName(count).equals("realwidth")) {
    89                 line.realWidth=Integer.parseInt(atts.getValue(count));
    90             } else if (atts.getQName(count).equals("dashed")) {
     86                break;
     87            case "colour":
     88                line.color = convertColor(atts.getValue(count));
     89                break;
     90            case "realwidth":
     91                line.realWidth = Integer.parseInt(atts.getValue(count));
     92                break;
     93            case "dashed":
    9194                Float[] dashed;
    9295                try {
     
    105108                }
    106109                line.setDashed(dashed == null ? null : Arrays.asList(dashed));
    107             } else if (atts.getQName(count).equals("dashedcolour")) {
    108                 line.dashedColor=convertColor(atts.getValue(count));
    109             } else if(atts.getQName(count).equals("priority")) {
     110                break;
     111            case "dashedcolour":
     112                line.dashedColor = convertColor(atts.getValue(count));
     113                break;
     114            case "priority":
    110115                line.priority = Integer.parseInt(atts.getValue(count));
    111             } else if (!(atts.getQName(count).equals("mode") && line instanceof LinemodPrototype)){
     116                break;
     117            case "mode":
     118                if (line instanceof LinemodPrototype)
     119                    break;
     120            default:
    112121                error("The element \"" + qName + "\" has unknown attribute \"" + atts.getQName(count) + "\"!");
    113122            }
     
    118127        startElementLine(qName, atts, line);
    119128        for (int count=0; count<atts.getLength(); count++) {
    120             if (atts.getQName(count).equals("width")) {
     129            switch (atts.getQName(count)) {
     130            case "width":
    121131                String val = atts.getValue(count);
    122132                if (val.startsWith("+")) {
     
    132142                    line.setWidth(Integer.parseInt(val));
    133143                }
    134             } else if(atts.getQName(count).equals("mode")) {
    135                 line.over = !atts.getValue(count).equals("under");
    136             }
    137         }
    138     }
    139 
    140     @Override public void startElement(String uri,String name, String qName, Attributes atts) {
     144                break;
     145            case "mode":
     146                line.over = !"under".equals(atts.getValue(count));
     147                break;
     148            }
     149        }
     150    }
     151
     152    @Override
     153    public void startElement(String uri,String name, String qName, Attributes atts) {
    141154        if (inDoc) {
    142             if (qName.equals("rule")) {
    143                 inRule=true;
    144             } else if (qName.equals("rules")) {
     155            switch(qName) {
     156            case "rule":
     157                inRule = true;
     158                break;
     159            case "rules":
    145160                if (style.name == null) {
    146161                    style.name = atts.getValue("name");
     
    152167                    style.icon = atts.getValue("icon");
    153168                }
    154             } else if (qName.equals("scale_max")) {
     169                break;
     170            case "scale_max":
    155171                inScaleMax = true;
    156             } else if (qName.equals("scale_min")) {
     172                break;
     173            case "scale_min":
    157174                inScaleMin = true;
    158             } else if (qName.equals("condition") && inRule) {
    159                 inCondition=true;
    160                 XmlCondition c = rule.cond;
    161                 if (c.key != null) {
    162                     if(rule.conditions == null) {
    163                         rule.conditions = new LinkedList<>();
    164                     }
    165                     rule.conditions.add(new XmlCondition(rule.cond));
    166                     c = new XmlCondition();
    167                     rule.conditions.add(c);
    168                 }
    169                 for (int count=0; count<atts.getLength(); count++) {
    170                     if (atts.getQName(count).equals("k")) {
    171                         c.key = atts.getValue(count);
    172                     } else if (atts.getQName(count).equals("v")) {
    173                         c.value = atts.getValue(count);
    174                     } else if(atts.getQName(count).equals("b")) {
    175                         c.boolValue = atts.getValue(count);
    176                     } else {
    177                         error("The element \"" + qName + "\" has unknown attribute \"" + atts.getQName(count) + "\"!");
    178                     }
    179                 }
    180                 if(c.key == null) {
    181                     error("The condition has no key!");
    182                 }
    183             } else if (qName.equals("line")) {
     175                break;
     176            case "condition":
     177                if (inRule) {
     178                    inCondition = true;
     179                    XmlCondition c = rule.cond;
     180                    if (c.key != null) {
     181                        if(rule.conditions == null) {
     182                            rule.conditions = new LinkedList<>();
     183                        }
     184                        rule.conditions.add(new XmlCondition(rule.cond));
     185                        c = new XmlCondition();
     186                        rule.conditions.add(c);
     187                    }
     188                    for (int count=0; count<atts.getLength(); count++) {
     189                        switch (atts.getQName(count)) {
     190                        case "k":
     191                            c.key = atts.getValue(count);
     192                            break;
     193                        case "v":
     194                            c.value = atts.getValue(count);
     195                            break;
     196                        case "b":
     197                            c.boolValue = atts.getValue(count);
     198                            break;
     199                        default:
     200                            error("The element \"" + qName + "\" has unknown attribute \"" + atts.getQName(count) + "\"!");
     201                        }
     202                    }
     203                    if(c.key == null) {
     204                        error("The condition has no key!");
     205                    }
     206                }
     207                break;
     208            case "line":
    184209                hadLine = inLine = true;
    185210                startElementLine(qName, atts, rule.line);
    186             } else if (qName.equals("linemod")) {
     211                break;
     212            case "linemod":
    187213                hadLineMod = inLineMod = true;
    188214                startElementLinemod(qName, atts, rule.linemod);
    189             } else if (qName.equals("icon")) {
     215                break;
     216            case "icon":
    190217                inIcon = true;
    191218                for (int count=0; count<atts.getLength(); count++) {
    192                     if (atts.getQName(count).equals("src")) {
     219                    switch (atts.getQName(count)) {
     220                    case "src":
    193221                        IconReference icon = new IconReference(atts.getValue(count), style);
    194222                        hadIcon = (icon != null);
    195223                        rule.icon.icon = icon;
    196                     } else if (atts.getQName(count).equals("annotate")) {
     224                        break;
     225                    case "annotate":
    197226                        rule.icon.annotate = Boolean.parseBoolean (atts.getValue(count));
    198                     } else if(atts.getQName(count).equals("priority")) {
     227                        break;
     228                    case "priority":
    199229                        rule.icon.priority = Integer.parseInt(atts.getValue(count));
    200                     } else {
     230                        break;
     231                    default:
    201232                        error("The element \"" + qName + "\" has unknown attribute \"" + atts.getQName(count) + "\"!");
    202233                    }
    203234                }
    204             } else if (qName.equals("area")) {
     235                break;
     236            case "area":
    205237                hadArea = inArea = true;
    206                 for (int count=0; count<atts.getLength(); count++)
    207                 {
    208                     if (atts.getQName(count).equals("colour")) {
     238                for (int count=0; count<atts.getLength(); count++) {
     239                    switch (atts.getQName(count)) {
     240                    case "colour":
    209241                        rule.area.color=convertColor(atts.getValue(count));
    210                     } else if (atts.getQName(count).equals("closed")) {
     242                        break;
     243                    case "closed":
    211244                        rule.area.closed=Boolean.parseBoolean(atts.getValue(count));
    212                     } else if(atts.getQName(count).equals("priority")) {
     245                        break;
     246                    case "priority":
    213247                        rule.area.priority = Integer.parseInt(atts.getValue(count));
    214                     } else {
     248                        break;
     249                    default:
    215250                        error("The element \"" + qName + "\" has unknown attribute \"" + atts.getQName(count) + "\"!");
    216251                    }
    217252                }
    218             } else {
     253                break;
     254            default:
    219255                error("The element \"" + qName + "\" is unknown!");
    220256            }
     
    222258    }
    223259
    224     @Override public void endElement(String uri,String name, String qName)
    225     {
    226         if (inRule && qName.equals("rule")) {
     260    @Override
     261    public void endElement(String uri,String name, String qName) {
     262        if (inRule && "rule".equals(qName)) {
    227263            if (hadLine) {
    228264                style.add(rule.cond, rule.conditions,
    229265                        new LinePrototype(rule.line, new Range(rule.scaleMin, rule.scaleMax)));
    230266            }
    231             if (hadLineMod)
    232             {
     267            if (hadLineMod) {
    233268                style.add(rule.cond, rule.conditions,
    234269                        new LinemodPrototype(rule.linemod, new Range(rule.scaleMin, rule.scaleMax)));
    235270            }
    236             if (hadIcon)
    237             {
     271            if (hadIcon) {
    238272                style.add(rule.cond, rule.conditions,
    239273                        new IconPrototype(rule.icon, new Range(rule.scaleMin, rule.scaleMax)));
    240274            }
    241             if (hadArea)
    242             {
     275            if (hadArea) {
    243276                style.add(rule.cond, rule.conditions,
    244277                        new AreaPrototype(rule.area, new Range(rule.scaleMin, rule.scaleMax)));
     
    247280            hadLine = hadLineMod = hadIcon = hadArea = false;
    248281            rule.init();
    249         } else if (inCondition && qName.equals("condition")) {
     282        } else if (inCondition && "condition".equals(qName)) {
    250283            inCondition = false;
    251         } else if (inLine && qName.equals("line")) {
     284        } else if (inLine && "line".equals(qName)) {
    252285            inLine = false;
    253         } else if (inLineMod && qName.equals("linemod")) {
     286        } else if (inLineMod && "linemod".equals(qName)) {
    254287            inLineMod = false;
    255         } else if (inIcon && qName.equals("icon")) {
     288        } else if (inIcon && "icon".equals(qName)) {
    256289            inIcon = false;
    257         } else if (inArea && qName.equals("area")) {
     290        } else if (inArea && "area".equals(qName)) {
    258291            inArea = false;
    259         } else if (qName.equals("scale_max")) {
     292        } else if ("scale_max".equals(qName)) {
    260293            inScaleMax = false;
    261         } else if (qName.equals("scale_min")) {
     294        } else if ("scale_min".equals(qName)) {
    262295            inScaleMin = false;
    263296        }
    264297    }
    265298
    266     @Override public void characters(char[] ch, int start, int length) {
     299    @Override
     300    public void characters(char[] ch, int start, int length) {
    267301        if (inScaleMax) {
    268302            rule.scaleMax = Long.parseLong(new String(ch, start, length));
  • trunk/src/org/openstreetmap/josm/gui/widgets/MultiSplitLayout.java

    r7005 r7012  
    12301230                }
    12311231                String nodeType = st.sval.toUpperCase();
    1232                 if (nodeType.equals("LEAF")) {
     1232                if ("LEAF".equals(nodeType)) {
    12331233                    parseLeaf(st, parent);
    12341234                }
    1235                 else if (nodeType.equals("ROW") || nodeType.equals("COLUMN")) {
     1235                else if ("ROW".equals(nodeType) || "COLUMN".equals(nodeType)) {
    12361236                    Split split = new Split();
    1237                     split.setRowLayout(nodeType.equals("ROW"));
     1237                    split.setRowLayout("ROW".equals(nodeType));
    12381238                    addSplitChild(parent, split);
    12391239                    parseSplit(st, split);
Note: See TracChangeset for help on using the changeset viewer.