Changeset 11651 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2017-03-03T01:31:34+01:00 (7 years ago)
Author:
Don-vip
Message:

FindBugs - MS_MUTABLE_COLLECTION

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/OffsetBookmark.java

    r10742 r11651  
    1717
    1818public class OffsetBookmark {
    19     public static final List<OffsetBookmark> allBookmarks = new ArrayList<>();
     19    private static final List<OffsetBookmark> allBookmarks = new ArrayList<>();
    2020
    2121    public String projectionCode;
     
    9494    }
    9595
     96    /**
     97     * Returns all bookmarks.
     98     * @return all bookmarks (unmodifiable collection)
     99     * @since 11651
     100     */
     101    public static List<OffsetBookmark> getBookmarks() {
     102        return Collections.unmodifiableList(allBookmarks);
     103    }
     104
     105    /**
     106     * Returns the number of bookmarks.
     107     * @return the number of bookmarks
     108     * @since 11651
     109     */
     110    public static int getBookmarksSize() {
     111        return allBookmarks.size();
     112    }
     113
     114    /**
     115     * Adds a bookmark.
     116     * @param ob bookmark to add
     117     * @return {@code true}
     118     * @since 11651
     119     */
     120    public static boolean addBookmark(OffsetBookmark ob) {
     121        return allBookmarks.add(ob);
     122    }
     123
     124    /**
     125     * Removes a bookmark.
     126     * @param ob bookmark to remove
     127     * @return {@code true} if this list contained the specified element
     128     * @since 11651
     129     */
     130    public static boolean removeBookmark(OffsetBookmark ob) {
     131        return allBookmarks.remove(ob);
     132    }
     133
     134    /**
     135     * Returns the bookmark at the given index.
     136     * @param index bookmark index
     137     * @return the bookmark at the given index
     138     * @throws IndexOutOfBoundsException if the index is out of range
     139     *         (<tt>index &lt; 0 || index &gt;= size()</tt>)
     140     * @since 11651
     141     */
     142    public static OffsetBookmark getBookmarkByIndex(int index) {
     143        return allBookmarks.get(index);
     144    }
     145
    96146    public static OffsetBookmark getBookmarkByName(ImageryLayer layer, String name) {
    97147        for (OffsetBookmark b : allBookmarks) {
  • trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java

    r11581 r11651  
    231231    public JComponent getOffsetMenuItem(JComponent subMenu) {
    232232        JMenuItem adjustMenuItem = new JMenuItem(getAdjustAction());
    233         if (OffsetBookmark.allBookmarks.isEmpty()) return adjustMenuItem;
     233        List<OffsetBookmark> allBookmarks = OffsetBookmark.getBookmarks();
     234        if (allBookmarks.isEmpty()) return adjustMenuItem;
    234235
    235236        subMenu.add(adjustMenuItem);
     
    237238        boolean hasBookmarks = false;
    238239        int menuItemHeight = 0;
    239         for (OffsetBookmark b : OffsetBookmark.allBookmarks) {
     240        for (OffsetBookmark b : allBookmarks) {
    240241            if (!b.isUsable(this)) {
    241242                continue;
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreference.java

    r11641 r11651  
    806806
    807807    static class OffsetBookmarksPanel extends JPanel {
    808         private final transient List<OffsetBookmark> bookmarks = OffsetBookmark.allBookmarks;
    809808        private final OffsetsBookmarksModel model = new OffsetsBookmarksModel();
    810809
     
    868867
    869868            private OffsetBookmark getRow(int row) {
    870                 return bookmarks.get(row);
     869                return OffsetBookmark.getBookmarkByIndex(row);
    871870            }
    872871
    873872            private void addRow(OffsetBookmark i) {
    874                 bookmarks.add(i);
     873                OffsetBookmark.addBookmark(i);
    875874                int p = getRowCount() - 1;
    876875                fireTableRowsInserted(p, p);
     
    879878            @Override
    880879            public void removeRow(int i) {
    881                 bookmarks.remove(getRow(i));
     880                OffsetBookmark.removeBookmark(getRow(i));
    882881                fireTableRowsDeleted(i, i);
    883882            }
     
    885884            @Override
    886885            public int getRowCount() {
    887                 return bookmarks.size();
     886                return OffsetBookmark.getBookmarksSize();
    888887            }
    889888
    890889            @Override
    891890            public Object getValueAt(int row, int column) {
    892                 OffsetBookmark info = bookmarks.get(row);
     891                OffsetBookmark info = OffsetBookmark.getBookmarkByIndex(row);
    893892                switch (column) {
    894893                case 0:
     
    910909            @Override
    911910            public void setValueAt(Object o, int row, int column) {
    912                 OffsetBookmark info = bookmarks.get(row);
     911                OffsetBookmark info = OffsetBookmark.getBookmarkByIndex(row);
    913912                switch (column) {
    914913                case 1:
Note: See TracChangeset for help on using the changeset viewer.