Ignore:
Timestamp:
2013-09-22T18:36:07+02:00 (11 years ago)
Author:
Don-vip
Message:

Sonar/FindBugs - various bugfixes / violation fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSourceHandler.java

    r6085 r6246  
    3131        AreaPrototype area = new AreaPrototype();
    3232        IconPrototype icon = new IconPrototype();
    33         public void init()
    34         {
     33        public void init() {
    3534            conditions = null;
    3635            scaleMax = Double.POSITIVE_INFINITY;
     
    5049    }
    5150
    52     Color convertColor(String colString)
    53     {
     51    Color convertColor(String colString) {
    5452        int i = colString.indexOf('#');
    5553        Color ret;
     
    8078
    8179    private void startElementLine(String qName, Attributes atts, LinePrototype line) {
    82         for (int count=0; count<atts.getLength(); count++)
    83         {
    84             if(atts.getQName(count).equals("width"))
    85             {
     80        for (int count=0; count<atts.getLength(); count++) {
     81            if(atts.getQName(count).equals("width")) {
    8682                String val = atts.getValue(count);
    8783                if (! (val.startsWith("+") || val.startsWith("-") || val.endsWith("%"))) {
    8884                    line.setWidth(Integer.parseInt(val));
    8985                }
    90             }
    91             else if (atts.getQName(count).equals("colour")) {
     86            } else if (atts.getQName(count).equals("colour")) {
    9287                line.color=convertColor(atts.getValue(count));
    9388            } else if (atts.getQName(count).equals("realwidth")) {
     
    122117    private void startElementLinemod(String qName, Attributes atts, LinemodPrototype line) {
    123118        startElementLine(qName, atts, line);
    124         for (int count=0; count<atts.getLength(); count++)
    125         {
    126             if(atts.getQName(count).equals("width"))
    127             {
     119        for (int count=0; count<atts.getLength(); count++) {
     120            if (atts.getQName(count).equals("width")) {
    128121                String val = atts.getValue(count);
    129                 if(val.startsWith("+"))
    130                 {
     122                if (val.startsWith("+")) {
    131123                    line.setWidth(Integer.parseInt(val.substring(1)));
    132124                    line.widthMode = LinemodPrototype.WidthMode.OFFSET;
    133                 }
    134                 else if(val.startsWith("-"))
    135                 {
     125                } else if(val.startsWith("-")) {
    136126                    line.setWidth(Integer.parseInt(val));
    137127                    line.widthMode = LinemodPrototype.WidthMode.OFFSET;
    138                 }
    139                 else if(val.endsWith("%"))
    140                 {
     128                } else if(val.endsWith("%")) {
    141129                    line.setWidth(Integer.parseInt(val.substring(0, val.length()-1)));
    142130                    line.widthMode = LinemodPrototype.WidthMode.PERCENT;
     
    151139
    152140    @Override public void startElement(String uri,String name, String qName, Attributes atts) {
    153         if (inDoc==true)
    154         {
     141        if (inDoc) {
    155142            if (qName.equals("rule")) {
    156143                inRule=true;
    157             } else if (qName.equals("rules"))
    158             {
     144            } else if (qName.equals("rules")) {
    159145                if (style.name == null) {
    160146                    style.name = atts.getValue("name");
     
    166152                    style.icon = atts.getValue("icon");
    167153                }
    168             }
    169             else if (qName.equals("scale_max")) {
     154            } else if (qName.equals("scale_max")) {
    170155                inScaleMax = true;
    171156            } else if (qName.equals("scale_min")) {
    172157                inScaleMin = true;
    173             } else if (qName.equals("condition") && inRule)
    174             {
     158            } else if (qName.equals("condition") && inRule) {
    175159                inCondition=true;
    176160                XmlCondition c = rule.cond;
    177                 if(c.key != null)
    178                 {
     161                if (c.key != null) {
    179162                    if(rule.conditions == null) {
    180163                        rule.conditions = new LinkedList<XmlCondition>();
     
    184167                    rule.conditions.add(c);
    185168                }
    186                 for (int count=0; count<atts.getLength(); count++)
    187                 {
    188                     if(atts.getQName(count).equals("k")) {
     169                for (int count=0; count<atts.getLength(); count++) {
     170                    if (atts.getQName(count).equals("k")) {
    189171                        c.key = atts.getValue(count);
    190                     } else if(atts.getQName(count).equals("v")) {
     172                    } else if (atts.getQName(count).equals("v")) {
    191173                        c.value = atts.getValue(count);
    192174                    } else if(atts.getQName(count).equals("b")) {
     
    199181                    error("The condition has no key!");
    200182                }
    201             }
    202             else if (qName.equals("line"))
    203             {
     183            } else if (qName.equals("line")) {
    204184                hadLine = inLine = true;
    205185                startElementLine(qName, atts, rule.line);
    206             }
    207             else if (qName.equals("linemod"))
    208             {
     186            } else if (qName.equals("linemod")) {
    209187                hadLineMod = inLineMod = true;
    210188                startElementLinemod(qName, atts, rule.linemod);
    211             }
    212             else if (qName.equals("icon"))
    213             {
     189            } else if (qName.equals("icon")) {
    214190                inIcon = true;
    215                 for (int count=0; count<atts.getLength(); count++)
    216                 {
     191                for (int count=0; count<atts.getLength(); count++) {
    217192                    if (atts.getQName(count).equals("src")) {
    218193                        IconReference icon = new IconReference(atts.getValue(count), style);
     
    227202                    }
    228203                }
    229             }
    230             else if (qName.equals("area"))
    231             {
     204            } else if (qName.equals("area")) {
    232205                hadArea = inArea = true;
    233206                for (int count=0; count<atts.getLength(); count++)
     
    251224    @Override public void endElement(String uri,String name, String qName)
    252225    {
    253         if (inRule && qName.equals("rule"))
    254         {
    255             if(hadLine)
     226        if (inRule && qName.equals("rule")) {
     227            if (hadLine) {
     228                style.add(rule.cond, rule.conditions,
     229                        new LinePrototype(rule.line, new Range(rule.scaleMin, rule.scaleMax)));
     230            }
     231            if (hadLineMod)
    256232            {
    257233                style.add(rule.cond, rule.conditions,
    258                         new LinePrototype(rule.line, new Range(rule.scaleMin, rule.scaleMax)));
    259             }
    260             if(hadLineMod)
     234                        new LinemodPrototype(rule.linemod, new Range(rule.scaleMin, rule.scaleMax)));
     235            }
     236            if (hadIcon)
    261237            {
    262238                style.add(rule.cond, rule.conditions,
    263                         new LinemodPrototype(rule.linemod, new Range(rule.scaleMin, rule.scaleMax)));
    264             }
    265             if(hadIcon)
    266             {
    267                 style.add(rule.cond, rule.conditions,
    268239                        new IconPrototype(rule.icon, new Range(rule.scaleMin, rule.scaleMax)));
    269240            }
    270             if(hadArea)
     241            if (hadArea)
    271242            {
    272243                style.add(rule.cond, rule.conditions,
     
    276247            hadLine = hadLineMod = hadIcon = hadArea = false;
    277248            rule.init();
    278         }
    279         else if (inCondition && qName.equals("condition")) {
     249        } else if (inCondition && qName.equals("condition")) {
    280250            inCondition = false;
    281251        } else if (inLine && qName.equals("line")) {
     
    294264    }
    295265
    296     @Override public void characters(char[] ch, int start, int length)
    297     {
    298         if (inScaleMax == true) {
     266    @Override public void characters(char[] ch, int start, int length) {
     267        if (inScaleMax) {
    299268            rule.scaleMax = Long.parseLong(new String(ch, start, length));
    300         } else if (inScaleMin == true) {
     269        } else if (inScaleMin) {
    301270            rule.scaleMin = Long.parseLong(new String(ch, start, length));
    302271        }
Note: See TracChangeset for help on using the changeset viewer.