Ignore:
Timestamp:
2015-06-20T23:42:21+02:00 (9 years ago)
Author:
Don-vip
Message:

checkstyle: enable relevant whitespace checks and fix them

File:
1 edited

Legend:

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

    r8449 r8510  
    5959    // GPVTG
    6060    public static enum GPVTG {
    61         COURSE(1),COURSE_REF(2), // true course
     61        COURSE(1), COURSE_REF(2), // true course
    6262        COURSE_M(3), COURSE_M_REF(4), // magnetic course
    6363        SPEED_KN(5), SPEED_KN_UNIT(6), // speed in knots
     
    107107        HEIGHT(9), HEIGHT_UNTIS(10), // height above NN (above geoid)
    108108        HEIGHT_2(11), HEIGHT_2_UNTIS(12), // height geoid - height ellipsoid (WGS84)
    109         GPS_AGE(13),// Age of differential GPS data
     109        GPS_AGE(13), // Age of differential GPS data
    110110        REF(14); // REF station
    111111
     
    153153        return ps.unknown;
    154154    }
     155
    155156    public int getParserZeroCoordinates() {
    156157        return ps.zeroCoord;
    157158    }
     159
    158160    public int getParserChecksumErrors() {
    159161        return ps.checksumErrors+ps.noChecksum;
    160162    }
     163
    161164    public int getParserMalformed() {
    162165        return ps.malformed;
    163166    }
     167
    164168    public int getNumberOfCoordinates() {
    165169        return ps.success;
     
    176180            int loopstart_char = rd.read();
    177181            ps = new NMEAParserState();
    178             if(loopstart_char == -1)
     182            if (loopstart_char == -1)
    179183                //TODO tell user about the problem?
    180184                return;
    181             sb.append((char)loopstart_char);
    182             ps.pDate="010100"; // TODO date problem
    183             while(true) {
     185            sb.append((char) loopstart_char);
     186            ps.pDate = "010100"; // TODO date problem
     187            while (true) {
    184188                // don't load unparsable files completely to memory
    185                 if(sb.length()>=1020) {
     189                if (sb.length() >= 1020) {
    186190                    sb.delete(0, sb.length()-1);
    187191                }
    188192                int c = rd.read();
    189                 if(c=='$') {
     193                if (c == '$') {
    190194                    parseNMEASentence(sb.toString(), ps);
    191195                    sb.delete(0, sb.length());
    192196                    sb.append('$');
    193                 } else if(c == -1) {
     197                } else if (c == -1) {
    194198                    // EOF: add last WayPoint if it works out
    195                     parseNMEASentence(sb.toString(),ps);
     199                    parseNMEASentence(sb.toString(), ps);
    196200                    break;
    197201                } else {
    198                     sb.append((char)c);
     202                    sb.append((char) c);
    199203                }
    200204            }
     
    237241            if (chkstrings.length > 1) {
    238242                byte[] chb = chkstrings[0].getBytes(StandardCharsets.UTF_8);
    239                 int chk=0;
     243                int chk = 0;
    240244                for (int i = 1; i < chb.length; i++) {
    241245                    chk ^= chb[i];
    242246                }
    243                 if (Integer.parseInt(chkstrings[1].substring(0,2),16) != chk) {
     247                if (Integer.parseInt(chkstrings[1].substring(0, 2), 16) != chk) {
    244248                    ps.checksumErrors++;
    245                     ps.pWp=null;
     249                    ps.pWp = null;
    246250                    return false;
    247251                }
     
    257261
    258262            // handle the packet content
    259             if("$GPGGA".equals(e[0]) || "$GNGGA".equals(e[0])) {
     263            if ("$GPGGA".equals(e[0]) || "$GNGGA".equals(e[0])) {
    260264                // Position
    261265                LatLon latLon = parseLatLon(
     
    265269                        e[GPGGA.LONGITUDE.position]
    266270                );
    267                 if (latLon==null) {
     271                if (latLon == null) {
    268272                    throw new IllegalDataException("Malformed lat/lon");
    269273                }
     
    278282                Date d = readTime(currentDate+accu);
    279283
    280                 if((ps.pTime==null) || (currentwp==null) || !ps.pTime.equals(accu)) {
     284                if ((ps.pTime == null) || (currentwp == null) || !ps.pTime.equals(accu)) {
    281285                    // this node is newer than the previous, create a new waypoint.
    282                     // no matter if previous WayPoint was null, we got something
    283                     // better now.
    284                     ps.pTime=accu;
     286                    // no matter if previous WayPoint was null, we got something better now.
     287                    ps.pTime = accu;
    285288                    currentwp = new WayPoint(latLon);
    286289                }
    287                 if(!currentwp.attr.containsKey("time")) {
     290                if (!currentwp.attr.containsKey("time")) {
    288291                    // As this sentence has no complete time only use it
    289292                    // if there is no time so far
     
    291294                }
    292295                // elevation
    293                 accu=e[GPGGA.HEIGHT_UNTIS.position];
    294                 if("M".equals(accu)) {
     296                accu = e[GPGGA.HEIGHT_UNTIS.position];
     297                if ("M".equals(accu)) {
    295298                    // Ignore heights that are not in meters for now
    296                     accu=e[GPGGA.HEIGHT.position];
    297                     if(!accu.isEmpty()) {
     299                    accu = e[GPGGA.HEIGHT.position];
     300                    if (!accu.isEmpty()) {
    298301                        Double.parseDouble(accu);
    299302                        // if it throws it's malformed; this should only happen if the
    300303                        // device sends nonstandard data.
    301                         if(!accu.isEmpty()) { // FIX ? same check
     304                        if (!accu.isEmpty()) { // FIX ? same check
    302305                            currentwp.put(GpxConstants.PT_ELE, accu);
    303306                        }
     
    305308                }
    306309                // number of sattelites
    307                 accu=e[GPGGA.SATELLITE_COUNT.position];
     310                accu = e[GPGGA.SATELLITE_COUNT.position];
    308311                int sat = 0;
    309                 if(!accu.isEmpty()) {
     312                if (!accu.isEmpty()) {
    310313                    sat = Integer.parseInt(accu);
    311314                    currentwp.put(GpxConstants.PT_SAT, accu);
    312315                }
    313316                // h-dilution
    314                 accu=e[GPGGA.HDOP.position];
    315                 if(!accu.isEmpty()) {
     317                accu = e[GPGGA.HDOP.position];
     318                if (!accu.isEmpty()) {
    316319                    currentwp.put(GpxConstants.PT_HDOP, Float.valueOf(accu));
    317320                }
    318321                // fix
    319                 accu=e[GPGGA.QUALITY.position];
    320                 if(!accu.isEmpty()) {
     322                accu = e[GPGGA.QUALITY.position];
     323                if (!accu.isEmpty()) {
    321324                    int fixtype = Integer.parseInt(accu);
    322325                    switch(fixtype) {
     
    325328                        break;
    326329                    case 1:
    327                         if(sat < 4) {
     330                        if (sat < 4) {
    328331                            currentwp.put(GpxConstants.PT_FIX, "2d");
    329332                        } else {
     
    338341                    }
    339342                }
    340             } else if("$GPVTG".equals(e[0]) || "$GNVTG".equals(e[0])) {
     343            } else if ("$GPVTG".equals(e[0]) || "$GNVTG".equals(e[0])) {
    341344                // COURSE
    342345                accu = e[GPVTG.COURSE_REF.position];
    343                 if("T".equals(accu)) {
     346                if ("T".equals(accu)) {
    344347                    // other values than (T)rue are ignored
    345348                    accu = e[GPVTG.COURSE.position];
    346                     if(!accu.isEmpty()) {
     349                    if (!accu.isEmpty()) {
    347350                        Double.parseDouble(accu);
    348351                        currentwp.put("course", accu);
     
    351354                // SPEED
    352355                accu = e[GPVTG.SPEED_KMH_UNIT.position];
    353                 if(accu.startsWith("K")) {
     356                if (accu.startsWith("K")) {
    354357                    accu = e[GPVTG.SPEED_KMH.position];
    355                     if(!accu.isEmpty()) {
     358                    if (!accu.isEmpty()) {
    356359                        double speed = Double.parseDouble(accu);
    357360                        speed /= 3.6; // speed in m/s
     
    359362                    }
    360363                }
    361             } else if("$GPGSA".equals(e[0]) || "$GNGSA".equals(e[0])) {
     364            } else if ("$GPGSA".equals(e[0]) || "$GNGSA".equals(e[0])) {
    362365                // vdop
    363                 accu=e[GPGSA.VDOP.position];
    364                 if(!accu.isEmpty()) {
     366                accu = e[GPGSA.VDOP.position];
     367                if (!accu.isEmpty()) {
    365368                    currentwp.put(GpxConstants.PT_VDOP, Float.valueOf(accu));
    366369                }
    367370                // hdop
    368                 accu=e[GPGSA.HDOP.position];
    369                 if(!accu.isEmpty()) {
     371                accu = e[GPGSA.HDOP.position];
     372                if (!accu.isEmpty()) {
    370373                    currentwp.put(GpxConstants.PT_HDOP, Float.valueOf(accu));
    371374                }
    372375                // pdop
    373                 accu=e[GPGSA.PDOP.position];
    374                 if(!accu.isEmpty()) {
     376                accu = e[GPGSA.PDOP.position];
     377                if (!accu.isEmpty()) {
    375378                    currentwp.put(GpxConstants.PT_PDOP, Float.valueOf(accu));
    376379                }
    377             } else if("$GPRMC".equals(e[0]) || "$GNRMC".equals(e[0])) {
     380            } else if ("$GPRMC".equals(e[0]) || "$GNRMC".equals(e[0])) {
    378381                // coordinates
    379382                LatLon latLon = parseLatLon(
     
    393396                Date d = readTime(currentDate+time);
    394397
    395                 if(ps.pTime==null || currentwp==null || !ps.pTime.equals(time)) {
     398                if (ps.pTime == null || currentwp == null || !ps.pTime.equals(time)) {
    396399                    // this node is newer than the previous, create a new waypoint.
    397                     ps.pTime=time;
     400                    ps.pTime = time;
    398401                    currentwp = new WayPoint(latLon);
    399402                }
     
    402405                // speed
    403406                accu = e[GPRMC.SPEED.position];
    404                 if(!accu.isEmpty() && !currentwp.attr.containsKey("speed")) {
     407                if (!accu.isEmpty() && !currentwp.attr.containsKey("speed")) {
    405408                    double speed = Double.parseDouble(accu);
    406409                    speed *= 0.514444444; // to m/s
     
    409412                // course
    410413                accu = e[GPRMC.COURSE.position];
    411                 if(!accu.isEmpty() && !currentwp.attr.containsKey("course")) {
     414                if (!accu.isEmpty() && !currentwp.attr.containsKey("course")) {
    412415                    Double.parseDouble(accu);
    413416                    currentwp.put("course", accu);
     
    426429            }
    427430            ps.pDate = currentDate;
    428             if(ps.pWp != currentwp) {
    429                 if(ps.pWp!=null) {
     431            if (ps.pWp != currentwp) {
     432                if (ps.pWp != null) {
    430433                    ps.pWp.setTime();
    431434                }
     
    440443            // out of bounds and such
    441444            ps.malformed++;
    442             ps.pWp=null;
     445            ps.pWp = null;
    443446            return false;
    444447        }
     
    452455        // return a zero latlon instead of null so it is logged as zero coordinate
    453456        // instead of malformed sentence
    454         if(widthNorth.isEmpty() && lengthEast.isEmpty()) return new LatLon(0.0,0.0);
     457        if (widthNorth.isEmpty() && lengthEast.isEmpty()) return new LatLon(0.0, 0.0);
    455458
    456459        // The format is xxDDLL.LLLL
     
    463466        int latdeg = Integer.parseInt(widthNorth.substring(0, latdegsep));
    464467        double latmin = Double.parseDouble(widthNorth.substring(latdegsep));
    465         if(latdeg < 0) {
     468        if (latdeg < 0) {
    466469            latmin *= -1.0;
    467470        }
     
    476479        int londeg = Integer.parseInt(lengthEast.substring(0, londegsep));
    477480        double lonmin = Double.parseDouble(lengthEast.substring(londegsep));
    478         if(londeg < 0) {
     481        if (londeg < 0) {
    479482            lonmin *= -1.0;
    480483        }
Note: See TracChangeset for help on using the changeset viewer.