Changeset 9816 in josm for trunk


Ignore:
Timestamp:
2016-02-17T21:40:45+01:00 (9 years ago)
Author:
Don-vip
Message:

add more unit tests, javadoc, fix code style issues

Location:
trunk
Files:
6 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java

    r9078 r9816  
    5555    private NodeListPopupMenu popupMenu;
    5656
     57    /**
     58     * Constructs a new {@code NodeListViewer}.
     59     * @param model history browser model
     60     */
     61    public NodeListViewer(HistoryBrowserModel model) {
     62        setModel(model);
     63        build();
     64    }
     65
    5766    protected JScrollPane embeddInScrollPane(JTable table) {
    5867        JScrollPane pane = new JScrollPane(table);
     
    96105            public void tableChanged(TableModelEvent e) {
    97106                if (e.getSource() instanceof DiffTableModel) {
    98                     final DiffTableModel model = (DiffTableModel) e.getSource();
    99                     if (reversed == null || reversed != model.isReversed()) {
    100                         reversed = model.isReversed();
     107                    final DiffTableModel mod = (DiffTableModel) e.getSource();
     108                    if (reversed == null || reversed != mod.isReversed()) {
     109                        reversed = mod.isReversed();
    101110                        columnModel.getColumn(0).setHeaderValue(reversed ? reversedText : nonReversedText);
    102111                        table.getTableHeader().setToolTipText(
     
    164173    }
    165174
    166     public NodeListViewer(HistoryBrowserModel model) {
    167         setModel(model);
    168         build();
    169     }
    170 
    171175    protected void unregisterAsObserver(HistoryBrowserModel model) {
    172176        if (currentInfoPanel != null) {
     
    187191    }
    188192
     193    /**
     194     * Sets the history browser model.
     195     * @param model the history browser model
     196     */
    189197    public void setModel(HistoryBrowserModel model) {
    190198        if (this.model != null) {
     
    231239        @Override
    232240        public void actionPerformed(ActionEvent e) {
    233             if (!isEnabled()) return;
     241            if (!isEnabled())
     242                return;
    234243            OsmPrimitive p = getPrimitiveToZoom();
    235244            if (p != null) {
     
    248257
    249258        protected OsmPrimitive getPrimitiveToZoom() {
    250             if (primitiveId == null) return null;
     259            if (primitiveId == null)
     260                return null;
    251261            OsmDataLayer editLayer = Main.main.getEditLayer();
    252             if (editLayer == null) return null;
     262            if (editLayer == null)
     263                return null;
    253264            return editLayer.data.getPrimitiveById(primitiveId);
    254265        }
     
    277288        @Override
    278289        public void actionPerformed(ActionEvent e) {
    279             if (!isEnabled()) return;
    280             run();
     290            if (isEnabled()) {
     291                run();
     292            }
    281293        }
    282294
     
    314326        DiffTableModel castedModel = (DiffTableModel) model;
    315327        Long id = (Long) castedModel.getValueAt(row, 0).value;
    316         if (id == null) return null;
    317         return new SimplePrimitiveId(id, OsmPrimitiveType.NODE);
     328        return id == null ? null : new SimplePrimitiveId(id, OsmPrimitiveType.NODE);
    318329    }
    319330
     
    342353        @Override
    343354        public void mouseClicked(MouseEvent e) {
    344             if (e.getClickCount() < 2) return;
     355            if (e.getClickCount() < 2)
     356                return;
    345357            int row = table.rowAtPoint(e.getPoint());
    346             if (row <= 0) return;
     358            if (row <= 0)
     359                return;
    347360            PrimitiveId pid = primitiveIdAtRow(table.getModel(), row);
    348361            if (pid == null || pid.isNew())
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorModel.java

    r9657 r9816  
    102102    }
    103103
    104     public void removeProperyChangeListener(PropertyChangeListener listener) {
     104    public void removePropertyChangeListener(PropertyChangeListener listener) {
    105105        propChangeSupport.removePropertyChangeListener(listener);
    106106    }
     
    133133            throw new IndexOutOfBoundsException("unexpected rowIndex: rowIndex=" + rowIndex);
    134134
    135         TagModel tag = tags.get(rowIndex);
    136         switch(columnIndex) {
    137         case 0:
    138         case 1:
    139             return tag;
    140 
    141         default:
    142             throw new IndexOutOfBoundsException("unexpected columnIndex: columnIndex=" + columnIndex);
    143         }
     135        return tags.get(rowIndex);
    144136    }
    145137
     
    147139    public void setValueAt(Object value, int row, int col) {
    148140        TagModel tag = get(row);
    149         if (tag == null) return;
    150         switch(col) {
    151         case 0:
    152             updateTagName(tag, (String) value);
    153             break;
    154         case 1:
    155             String v = (String) value;
    156             if (tag.getValueCount() > 1 && !v.isEmpty()) {
    157                 updateTagValue(tag, v);
    158             } else if (tag.getValueCount() <= 1) {
    159                 updateTagValue(tag, v);
     141        if (tag != null) {
     142            switch(col) {
     143            case 0:
     144                updateTagName(tag, (String) value);
     145                break;
     146            case 1:
     147                String v = (String) value;
     148                if (tag.getValueCount() > 1 && !v.isEmpty()) {
     149                    updateTagValue(tag, v);
     150                } else if (tag.getValueCount() <= 1) {
     151                    updateTagValue(tag, v);
     152                }
    160153            }
    161154        }
     
    208201     */
    209202    public void add(String name, String value) {
    210         name = (name == null) ? "" : name;
    211         value = (value == null) ? "" : value;
    212 
    213         TagModel tag = get(name);
     203        String key = (name == null) ? "" : name;
     204        String val = (value == null) ? "" : value;
     205
     206        TagModel tag = get(key);
    214207        if (tag == null) {
    215             tag = new TagModel(name, value);
     208            tag = new TagModel(key, val);
    216209            int index = tags.size();
    217210            while (index >= 1 && tags.get(index - 1).getName().isEmpty() && tags.get(index - 1).getValue().isEmpty()) {
     
    220213            tags.add(index, tag);
    221214        } else {
    222             tag.addValue(value);
     215            tag.addValue(val);
    223216        }
    224217        setDirty(true);
     
    232225     */
    233226    public TagModel get(String name) {
    234         name = (name == null) ? "" : name;
     227        String key = (name == null) ? "" : name;
    235228        for (TagModel tag : tags) {
    236             if (tag.getName().equals(name))
     229            if (tag.getName().equals(key))
    237230                return tag;
    238231        }
     
    241234
    242235    public TagModel get(int idx) {
    243         if (idx >= tags.size()) return null;
    244         return tags.get(idx);
     236        return idx >= tags.size() ? null : tags.get(idx);
    245237    }
    246238
     
    293285     */
    294286    public void delete(String name) {
    295         if (name == null) return;
     287        if (name == null)
     288            return;
    296289        Iterator<TagModel> it = tags.iterator();
    297290        boolean changed = false;
     
    474467     */
    475468    public boolean includesTag(String key) {
    476         if (key == null) return false;
    477         for (TagModel tag : tags) {
    478             if (tag.getName().equals(key))
    479                 return true;
     469        if (key != null) {
     470            for (TagModel tag : tags) {
     471                if (tag.getName().equals(key))
     472                    return true;
     473            }
    480474        }
    481475        return false;
     
    502496        List<Command> commands = new ArrayList<>();
    503497
    504         for (OsmPrimitive primitive : primitives) {
    505             for (String oldkey : primitive.keySet()) {
     498        for (OsmPrimitive prim : primitives) {
     499            for (String oldkey : prim.keySet()) {
    506500                if (!currentkeys.contains(oldkey)) {
    507501                    ChangePropertyCommand deleteCommand =
    508                         new ChangePropertyCommand(primitive, oldkey, null);
     502                        new ChangePropertyCommand(prim, oldkey, null);
    509503                    commands.add(deleteCommand);
    510504                }
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagModel.java

    r8840 r9816  
    55import java.util.List;
    66
     7/**
     8 * Tag model.
     9 * @since 1762
     10 */
    711public class TagModel {
    812
     
    4852     */
    4953    public final void setName(String name) {
    50         name = (name == null) ? "" : name;
    51         this.name = name;
     54        this.name = (name == null) ? "" : name;
    5255    }
    5356
    5457    /**
     58     * returns the tag name (key).
    5559     * @return the tag name
    5660     */
     
    7175     */
    7276    public final void setValue(String value) {
    73         value = (value == null) ? "" : value;
    7477        clearValues();
    75         this.values.add(value);
     78        this.values.add((value == null) ? "" : value);
    7679    }
    7780
    7881    /**
    79      *
     82     * determines if this tag model has a specific value
    8083     * @param value the value to be checked; converted to "" if null
    8184     * @return true, if the values of this tag include <code>value</code>; false otherwise
    8285     */
    8386    public boolean hasValue(String value) {
    84         value = (value == null) ? "" : value;
    85         return values.contains(value);
     87        return values.contains((value == null) ? "" : value);
    8688    }
    8789
     90    /**
     91     * adds a tag value
     92     * @param value the value to add; converted to "" if null
     93     */
    8894    public void addValue(String value) {
    89         value = (value == null) ? "" : value;
    90         if (hasValue(value)) {
     95        String val = (value == null) ? "" : value;
     96        if (hasValue(val)) {
    9197            return;
    9298        }
    93         values.add(value);
     99        values.add(val);
    94100    }
    95101
     
    99105     */
    100106    public void removeValue(String value) {
    101         value = (value == null) ? "" : value;
    102         values.remove(value);
     107        values.remove((value == null) ? "" : value);
    103108    }
    104109
     110    /**
     111     * returns the list of values
     112     * @return the list of values
     113     */
    105114    public List<String> getValues() {
    106115        return values;
    107116    }
    108117
     118    /**
     119     * returns the value(s) as string
     120     * @return the value(s) as string, joined with a semicolon (;) if multiple values
     121     */
    109122    public String getValue() {
    110123        if (getValueCount() == 0) {
     
    124137    }
    125138
     139    /**
     140     * returns the number of values
     141     * @return the number of values
     142     */
    126143    public int getValueCount() {
    127144        return values.size();
Note: See TracChangeset for help on using the changeset viewer.