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

Sonar/FindBugs - various bugfixes / violation fixes

Location:
trunk/src/org/openstreetmap/josm/tools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/AudioPlayer.java

    r6070 r6246  
    305305                                        bytesToSkip -= nBytesRead;
    306306                                    }
    307                                     if (bytesToSkip > 0) {
    308                                         audioInputStream.skip(bytesToSkip);
     307                                    while (bytesToSkip > 0) {
     308                                        long skippedBytes = audioInputStream.skip(bytesToSkip);
     309                                        bytesToSkip -= skippedBytes;
     310                                        if (skippedBytes == 0) {
     311                                            // Avoid inifinite loop
     312                                            Main.warn("Unable to skip bytes from audio input stream");
     313                                            bytesToSkip = 0;
     314                                        }
    309315                                    }
    310316                                    position = offset;
  • trunk/src/org/openstreetmap/josm/tools/Diff.java

    r6235 r6246  
    9797    public Diff(Object[] a,Object[] b) {
    9898        Map<Object,Integer> h = new HashMap<Object,Integer>(a.length + b.length);
    99         filevec = new file_data[] { new file_data(a,h),new file_data(b,h) };
     99        filevec = new FileData[] { new FileData(a,h),new FileData(b,h) };
    100100    }
    101101
     
    123123                   search of the edit matrix. */
    124124    private int fdiagoff, bdiagoff;
    125     private final file_data[] filevec;
     125    private final FileData[] filevec;
    126126    private int cost;
    127127    /** Snakes bigger than this are considered "big". */
     
    358358                filevec[0].changed_flag[1+filevec[0].realindexes[xoff++]] = true;
    359359            }
    360         } else
    361         {
     360        } else {
    362361            /* Find a point of correspondence in the middle of the files.  */
    363362
     
    378377                compareseq (xoff, b, yoff, b - d);
    379378                /* This used to use f instead of b,
    380            but that is incorrect!
    381            It is not necessarily the case that diagonal d
    382            has a snake from b to f.  */
     379                   but that is incorrect!
     380                   It is not necessarily the case that diagonal d
     381                   has a snake from b to f.  */
    383382                compareseq (b, xlim, b - d, ylim);
    384383            }
     
    388387    /** Discard lines from one file that have no matches in the other file.
    389388     */
    390 
    391389    private void discard_confusing_lines() {
    392390        filevec[0].discard_confusing_lines(filevec[1]);
     
    397395
    398396    /** Adjust inserts/deletes of blank lines to join changes
    399      as much as possible.
     397        as much as possible.
    400398     */
    401 
    402399    private void shift_boundaries() {
    403400        if (inhibit)
     
    409406    public interface ScriptBuilder {
    410407        /** Scan the tables of which lines are inserted and deleted,
    411      producing an edit script.
    412    @param changed0 true for lines in first file which do not match 2nd
    413    @param len0 number of lines in first file
    414    @param changed1 true for lines in 2nd file which do not match 1st
    415    @param len1 number of lines in 2nd file
    416    @return a linked list of changes - or null
     408            producing an edit script.
     409            @param changed0 true for lines in first file which do not match 2nd
     410            @param len0 number of lines in first file
     411            @param changed1 true for lines in 2nd file which do not match 1st
     412            @param len1 number of lines in 2nd file
     413            @return a linked list of changes - or null
    417414         */
    418         public change build_script(
     415        public Change build_script(
    419416                boolean[] changed0,int len0,
    420417                boolean[] changed1,int len1
     
    427424    static class ReverseScript implements ScriptBuilder {
    428425        @Override
    429         public  change build_script(
     426        public  Change build_script(
    430427                final boolean[] changed0,int len0,
    431428                final boolean[] changed1,int len1)
    432429        {
    433             change script = null;
     430            Change script = null;
    434431            int i0 = 0, i1 = 0;
    435432            while (i0 < len0 || i1 < len1) {
     
    446443
    447444                    /* Record this change.  */
    448                     script = new change(line0, line1, i0 - line0, i1 - line1, script);
     445                    script = new Change(line0, line1, i0 - line0, i1 - line1, script);
    449446                }
    450447
     
    459456    static class ForwardScript implements ScriptBuilder {
    460457        /** Scan the tables of which lines are inserted and deleted,
    461        producing an edit script in forward order.  */
     458            producing an edit script in forward order.  */
    462459        @Override
    463         public change build_script(
     460        public Change build_script(
    464461                final boolean[] changed0,int len0,
    465462                final boolean[] changed1,int len1)
    466463        {
    467             change script = null;
     464            Change script = null;
    468465            int i0 = len0, i1 = len1;
    469466
     
    483480
    484481                    /* Record this change.  */
    485                     script = new change(i0, i1, line0 - i0, line1 - i1, script);
     482                    script = new Change(i0, i1, line0 - i0, line1 - i1, script);
    486483                }
    487484
     
    499496    reverseScript = new ReverseScript();
    500497
    501     /* Report the differences of two files.  DEPTH is the current directory
    502      depth. */
    503     public final change diff_2(final boolean reverse) {
     498    /** Report the differences of two files.  DEPTH is the current directory
     499        depth. */
     500    public final Change diff_2(final boolean reverse) {
    504501        return diff(reverse ? reverseScript : forwardScript);
    505502    }
     
    513510     @return the head of a list of changes
    514511     */
    515     public change diff(final ScriptBuilder bld) {
     512    public Change diff(final ScriptBuilder bld) {
    516513
    517514        /* Some lines are obviously insertions or deletions
     
    566563     which the insertion was done; vice versa for INSERTED and LINE1.  */
    567564
    568     public static class change {
     565    public static class Change {
    569566        /** Previous or next edit command. */
    570         public change link;
     567        public Change link;
    571568        /** # lines of file 1 changed here.  */
    572569        public final int inserted;
     
    577574        /** Line number of 1st inserted line.  */
    578575        public final int line1;
    579         /** Change is ignorable. */
    580         public boolean ignore;
    581576
    582577        /** Cons an additional entry onto the front of an edit script OLD.
     
    587582       If DELETED is 0 then LINE0 is the number of the line before
    588583       which the insertion was done; vice versa for INSERTED and LINE1.  */
    589         public change(int line0, int line1, int deleted, int inserted, change old) {
     584        public Change(int line0, int line1, int deleted, int inserted, Change old) {
    590585            this.line0 = line0;
    591586            this.line1 = line1;
     
    604599     */
    605600
    606     class file_data {
     601    class FileData {
    607602
    608603        /** Allocate changed array for the results of comparison.  */
    609604        void clear() {
    610605            /* Allocate a flag for each line of each file, saying whether that line
    611      is an insertion or deletion.
    612      Allocate an extra element, always zero, at each end of each vector.
     606               is an insertion or deletion.
     607               Allocate an extra element, always zero, at each end of each vector.
    613608             */
    614609            changed_flag = new boolean[buffered_lines + 2];
     
    616611
    617612        /** Return equiv_count[I] as the number of lines in this file
    618        that fall in equivalence class I.
     613         that fall in equivalence class I.
    619614         @return the array of equivalence class counts.
    620615         */
     
    640635      @param f the other file
    641636         */
    642         void discard_confusing_lines(file_data f) {
     637        void discard_confusing_lines(FileData f) {
    643638            clear();
    644639            /* Set up table of which lines are going to be discarded. */
     
    729724
    730725                    /* Now we have the length of a run of discardable lines
    731            whose first and last are not provisional.  */
     726                       whose first and last are not provisional.  */
    732727                    length = j - i;
    733728
    734729                    /* If 1/4 of the lines in the run are provisional,
    735            cancel discarding of all provisional lines in the run.  */
    736                     if (provisional * 4 > length)
    737                     {
     730                       cancel discarding of all provisional lines in the run.  */
     731                    if (provisional * 4 > length) {
    738732                        while (j > i)
    739733                            if (discards[--j] == 2) {
    740734                                discards[j] = 0;
    741735                            }
    742                     }
    743                     else
    744                     {
     736                    } else {
    745737                        int consec;
    746738                        int minimum = 1;
     
    817809
    818810        /** Actually discard the lines.
    819       @param discards flags lines to be discarded
     811            @param discards flags lines to be discarded
    820812         */
    821813        private void discard(final byte[] discards) {
     
    833825        }
    834826
    835         file_data(int[] data) {
     827        FileData(int[] data) {
    836828            buffered_lines = data.length;
    837829            equivs = data;
     
    840832        }
    841833       
    842         file_data(Object[] data,Map<Object,Integer> h) {
     834        FileData(Object[] data,Map<Object,Integer> h) {
    843835            this(new int[data.length]);
    844836            // FIXME: diff 2.7 removes common prefix and common suffix
     
    866858         */
    867859
    868         void shift_boundaries(file_data f) {
     860        void shift_boundaries(FileData f) {
    869861            final boolean[] changed = changed_flag;
    870862            final boolean[] other_changed = f.changed_flag;
     
    909901
    910902                    /* If the first changed line matches the following unchanged one,
    911          and this run does not follow right after a previous run,
    912          and there are no lines deleted from the other file here,
    913          then classify the first changed line as unchanged
    914          and the following line as changed in its place.  */
     903                       and this run does not follow right after a previous run,
     904                       and there are no lines deleted from the other file here,
     905                       then classify the first changed line as unchanged
     906                       and the following line as changed in its place.  */
    915907
    916908                    /* You might ask, how could this run follow right after another?
    917          Only because the previous run was shifted here.  */
     909                       Only because the previous run was shifted here.  */
    918910
    919911                    if (end != i_end
     
    929921                        ++i;
    930922                        /* Since one line-that-matches is now before this run
    931              instead of after, we must advance in the other file
    932              to keep in synch.  */
     923                           instead of after, we must advance in the other file
     924                           to keep in synch.  */
    933925                        ++j;
    934926                    } else {
     
    965957           The results of comparison are stored here.  */
    966958        boolean[]       changed_flag;
    967 
    968959    }
    969960}
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r6230 r6246  
    181181
    182182        for (int pos = 0; pos < ways.size(); pos ++) {
    183             if (changedWays[pos] == false) {
     183            if (!changedWays[pos]) {
    184184                continue;
    185185            }
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r6235 r6246  
    412412                                    try {
    413413                                        return new ImageResource(ImageIO.read(new ByteArrayInputStream(bytes)));
    414                                     } catch (IOException e) {}
     414                                    } catch (IOException e) {
     415                                        Main.warn("IOException while reading image: "+e.getMessage());
     416                                    }
    415417                                }
    416418                    }
     
    522524                try {
    523525                    img = ImageIO.read(is.getFile().toURI().toURL());
    524                 } catch (IOException e) {}
     526                } catch (IOException e) {
     527                    Main.warn("IOException while reading HTTP image: "+e.getMessage());
     528                }
    525529                return img == null ? null : new ImageResource(img);
    526530            default:
  • trunk/src/org/openstreetmap/josm/tools/TextTagParser.java

    r6142 r6246  
    3434   
    3535    public static class TextAnalyzer {
    36         int start = 0;
    37         boolean keyFound = false;
    3836        boolean quotesStarted = false;
    3937        boolean esc = false;
     
    4240        String data;
    4341        int n;
    44         boolean notFound;
    4542
    4643        public TextAnalyzer(String text) {
Note: See TracChangeset for help on using the changeset viewer.