Ignore:
Timestamp:
2013-11-05T01:53:15+01:00 (12 years ago)
Author:
Don-vip
Message:

Sonar/Findbugs - fix of recent violations

File:
1 edited

Legend:

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

    r6340 r6365  
    3434/**
    3535 * List class that read and save its content from the bookmark file.
    36  * @author imi
     36 * @since 6340
    3737 */
    3838public class BookmarkList extends JList {
     
    4040    /**
    4141     * Class holding one bookmarkentry.
    42      * @author imi
    4342     */
    4443    public static class Bookmark implements Comparable<Bookmark> {
     
    4645        private Bounds area;
    4746
     47        /**
     48         * Constructs a new {@code Bookmark} with the given contents.
     49         * @param list Bookmark contents as a list of 5 elements. First item is the name, then come bounds arguments (minlat, minlon, maxlat, maxlon)
     50         * @throws NumberFormatException If the bounds arguments are not numbers
     51         * @throws IllegalArgumentException If list contain less than 5 elements
     52         */
    4853        public Bookmark(Collection<String> list) throws NumberFormatException, IllegalArgumentException {
    4954            List<String> array = new ArrayList<String>(list);
     
    5661
    5762        /**
    58          * Constructs a new {@code Bookmark}.
     63         * Constructs a new empty {@code Bookmark}.
    5964         */
    6065        public Bookmark() {
     
    6368        }
    6469
     70        /**
     71         * Constructs a new unamed {@code Bookmark} for the given area.
     72         * @param area The bookmark area
     73         */
    6574        public Bookmark(Bounds area) {
    6675            this.area = area;
     
    7584            return name.toLowerCase().compareTo(b.name.toLowerCase());
    7685        }
    77 
     86       
     87        @Override
     88        public int hashCode() {
     89            final int prime = 31;
     90            int result = 1;
     91            result = prime * result + ((area == null) ? 0 : area.hashCode());
     92            result = prime * result + ((name == null) ? 0 : name.hashCode());
     93            return result;
     94        }
     95
     96        @Override
     97        public boolean equals(Object obj) {
     98            if (this == obj)
     99                return true;
     100            if (obj == null)
     101                return false;
     102            if (getClass() != obj.getClass())
     103                return false;
     104            Bookmark other = (Bookmark) obj;
     105            if (area == null) {
     106                if (other.area != null)
     107                    return false;
     108            } else if (!area.equals(other.area))
     109                return false;
     110            if (name == null) {
     111                if (other.name != null)
     112                    return false;
     113            } else if (!name.equals(other.name))
     114                return false;
     115            return true;
     116        }
     117
     118        /**
     119         * Returns the bookmark area
     120         * @return The bookmark area
     121         */
    78122        public Bounds getArea() {
    79123            return area;
    80124        }
    81125
     126        /**
     127         * Returns the bookmark name
     128         * @return The bookmark name
     129         */
    82130        public String getName() {
    83131            return name;
    84132        }
    85133
     134        /**
     135         * Sets the bookmark name
     136         * @param name The bookmark name
     137         */
    86138        public void setName(String name) {
    87139            this.name = name;
    88140        }
    89141
     142        /**
     143         * Sets the bookmark area
     144         * @param area The bookmark area
     145         */
    90146        public void setArea(Bounds area) {
    91147            this.area = area;
     
    94150
    95151    /**
    96      * Create a bookmark list as well as the Buttons add and remove.
     152     * Creates a bookmark list as well as the Buttons add and remove.
    97153     */
    98154    public BookmarkList() {
     
    106162     * Loads the bookmarks from file.
    107163     */
    108     public void load() {
     164    public final void load() {
    109165        DefaultListModel model = (DefaultListModel)getModel();
    110166        model.removeAllElements();
     
    161217                    save();
    162218                    Main.info("Removing obsolete bookmarks file");
    163                     bookmarkFile.delete();
     219                    if (!bookmarkFile.delete()) {
     220                        bookmarkFile.deleteOnExit();
     221                    }
    164222                }
    165223            } catch (IOException e) {
    166                 e.printStackTrace();
     224                Main.error(e);
    167225                JOptionPane.showMessageDialog(
    168226                        Main.parent,
     
    179237
    180238    /**
    181      * Save all bookmarks to the preferences file
     239     * Saves all bookmarks to the preferences file
    182240     */
    183241    public void save() {
Note: See TracChangeset for help on using the changeset viewer.