Ignore:
Timestamp:
2009-12-13T11:48:12+01:00 (14 years ago)
Author:
jttt
Message:

Fixed some of the warnings found by FindBugs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/NmeaReader.java

    r1724 r2626  
    132132    public GpxData data;
    133133
    134 //  private final static SimpleDateFormat GGATIMEFMT =
    135 //      new SimpleDateFormat("HHmmss.SSS");
     134    //  private final static SimpleDateFormat GGATIMEFMT =
     135    //      new SimpleDateFormat("HHmmss.SSS");
    136136    private final static SimpleDateFormat RMCTIMEFMT =
    137137        new SimpleDateFormat("ddMMyyHHmmss.SSS");
     
    142142    {
    143143        Date d = RMCTIMEFMT.parse(p, new ParsePosition(0));
     144        if (d == null) {
     145            d = RMCTIMEFMTSTD.parse(p, new ParsePosition(0));
     146        }
    144147        if (d == null)
    145             d = RMCTIMEFMTSTD.parse(p, new ParsePosition(0));
    146         if (d == null) throw(null); // malformed
     148            throw new RuntimeException("Date is malformed"); // malformed
    147149        return d;
    148150    }
     
    181183            int loopstart_char = rd.read();
    182184            ps = new NMEAParserState();
    183             if(loopstart_char == -1) {// zero size file
     185            if(loopstart_char == -1)
    184186                //TODO tell user about the problem?
    185187                return;
    186             }
    187188            sb.append((char)loopstart_char);
    188189            ps.p_Date="010100"; // TODO date problem
    189190            while(true) {
    190191                // don't load unparsable files completely to memory
    191                 if(sb.length()>=1020) sb.delete(0, sb.length()-1);
     192                if(sb.length()>=1020) {
     193                    sb.delete(0, sb.length()-1);
     194                }
    192195                int c = rd.read();
    193196                if(c=='$') {
     
    199202                    ParseNMEASentence(sb.toString(),ps);
    200203                    break;
    201                 } else sb.append((char)c);
     204                } else {
     205                    sb.append((char)c);
     206                }
    202207            }
    203208            rd.close();
     
    209214        }
    210215    }
    211     private class NMEAParserState {
     216    private static class NMEAParserState {
    212217        protected Collection<WayPoint> waypoints = new ArrayList<WayPoint>();
    213218        protected String p_Time;
     
    239244                byte[] chb = chkstrings[0].getBytes();
    240245                int chk=0;
    241                 for(int i = 1; i < chb.length; i++) chk ^= chb[i];
     246                for(int i = 1; i < chb.length; i++) {
     247                    chk ^= chb[i];
     248                }
    242249                if(Integer.parseInt(chkstrings[1].substring(0,2),16) != chk) {
    243250                    //System.out.println("Checksum error");
     
    246253                    return false;
    247254                }
     255            } else {
     256                ps.no_checksum++;
    248257            }
    249             else
    250                 ps.no_checksum++;
    251258            // now for the content
    252259            String[] e = chkstrings[0].split(",");
     
    264271                        e[GPGGA.LATITUDE.position],
    265272                        e[GPGGA.LONGITUDE.position]
    266                     );
     273                );
    267274                if(latLon==null) throw(null); // malformed
    268275
     
    291298                accu=e[GPGGA.HEIGHT_UNTIS.position];
    292299                if(accu.equals("M")) {
    293                         // Ignore heights that are not in meters for now
    294                         accu=e[GPGGA.HEIGHT.position];
    295                         if(!accu.equals("")) {
     300                    // Ignore heights that are not in meters for now
     301                    accu=e[GPGGA.HEIGHT.position];
     302                    if(!accu.equals("")) {
    296303                        Double.parseDouble(accu);
    297304                        // if it throws it's malformed; this should only happen if the
    298305                        // device sends nonstandard data.
    299                         if(!accu.equals("")) currentwp.attr.put("ele", accu);
     306                        if(!accu.equals("")) {
     307                            currentwp.attr.put("ele", accu);
     308                        }
    300309                    }
    301310                }
     
    309318                // h-dilution
    310319                accu=e[GPGGA.HDOP.position];
    311                 if(!accu.equals(""))
     320                if(!accu.equals("")) {
    312321                    currentwp.attr.put("hdop", Float.parseFloat(accu));
     322                }
    313323                // fix
    314324                accu=e[GPGGA.QUALITY.position];
     
    320330                        break;
    321331                    case 1:
    322                         if(sat < 4) currentwp.attr.put("fix", "2d");
    323                         else currentwp.attr.put("fix", "3d");
     332                        if(sat < 4) {
     333                            currentwp.attr.put("fix", "2d");
     334                        } else {
     335                            currentwp.attr.put("fix", "3d");
     336                        }
    324337                        break;
    325338                    case 2:
     
    354367                // vdop
    355368                accu=e[GPGSA.VDOP.position];
    356                 if(!accu.equals(""))
     369                if(!accu.equals("")) {
    357370                    currentwp.attr.put("vdop", Float.parseFloat(accu));
     371                }
    358372                // hdop
    359373                accu=e[GPGSA.HDOP.position];
    360                 if(!accu.equals(""))
     374                if(!accu.equals("")) {
    361375                    currentwp.attr.put("hdop", Float.parseFloat(accu));
     376                }
    362377                // pdop
    363378                accu=e[GPGSA.PDOP.position];
    364                 if(!accu.equals(""))
     379                if(!accu.equals("")) {
    365380                    currentwp.attr.put("pdop", Float.parseFloat(accu));
     381                }
    366382            }
    367383            else if(e[0].equals("$GPRMC")) {
     
    372388                        e[GPRMC.WIDTH_NORTH.position],
    373389                        e[GPRMC.LENGTH_EAST.position]
    374                     );
    375                 if(latLon==null) throw(null);
     390                );
    376391                if((latLon.lat()==0.0) && (latLon.lon()==0.0)) {
    377392                    ps.zero_coord++;
     
    439454
    440455    private LatLon parseLatLon(String ns, String ew, String dlat, String dlon)
    441         throws NumberFormatException {
     456    throws NumberFormatException {
    442457        String widthNorth = dlat.trim();
    443458        String lengthEast = dlon.trim();
     
    456471        int latdeg = Integer.parseInt(widthNorth.substring(0, latdegsep));
    457472        double latmin = Double.parseDouble(widthNorth.substring(latdegsep));
    458         if(latdeg < 0) // strange data with '-' sign
     473        if(latdeg < 0) {
    459474            latmin *= -1.0;
     475        }
    460476        double lat = latdeg + latmin / 60;
    461477        if ("S".equals(ns)) {
     
    468484        int londeg = Integer.parseInt(lengthEast.substring(0, londegsep));
    469485        double lonmin = Double.parseDouble(lengthEast.substring(londegsep));
    470         if(londeg < 0) // strange data with '-' sign
     486        if(londeg < 0) {
    471487            lonmin *= -1.0;
     488        }
    472489        double lon = londeg + lonmin / 60;
    473490        if ("W".equals(ew)) {
Note: See TracChangeset for help on using the changeset viewer.