Changeset 12859 in josm


Ignore:
Timestamp:
2017-09-14T21:35:25+02:00 (2 months ago)
Author:
Don-vip
Message:

see #15229 - see #15182 - deprecate non-GUI AutoCompletion* classes from gui.tagging.ac. Offer better replacements in new data.tagging.ac package

Location:
trunk
Files:
9 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java

    r12846 r12859  
    7777import org.openstreetmap.josm.data.preferences.ListProperty;
    7878import org.openstreetmap.josm.data.preferences.StringProperty;
     79import org.openstreetmap.josm.data.tagging.ac.AutoCompletionItem;
    7980import org.openstreetmap.josm.gui.ExtendedDialog;
    8081import org.openstreetmap.josm.gui.IExtendedDialog;
     
    8384import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
    8485import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox;
    85 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
    8686import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
    8787import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
     
    112112    private String objKey;
    113113
    114     static final Comparator<AutoCompletionListItem> DEFAULT_AC_ITEM_COMPARATOR =
     114    static final Comparator<AutoCompletionItem> DEFAULT_AC_ITEM_COMPARATOR =
    115115            (o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getValue(), o2.getValue());
    116116
     
    393393        private final String key;
    394394        private final transient Map<String, Integer> m;
    395         private final transient Comparator<AutoCompletionListItem> usedValuesAwareComparator;
    396 
    397         private final transient ListCellRenderer<AutoCompletionListItem> cellRenderer = new ListCellRenderer<AutoCompletionListItem>() {
     395        private final transient Comparator<AutoCompletionItem> usedValuesAwareComparator;
     396
     397        private final transient ListCellRenderer<AutoCompletionItem> cellRenderer = new ListCellRenderer<AutoCompletionItem>() {
    398398            private final DefaultListCellRenderer def = new DefaultListCellRenderer();
    399399            @Override
    400             public Component getListCellRendererComponent(JList<? extends AutoCompletionListItem> list,
    401                     AutoCompletionListItem value, int index, boolean isSelected, boolean cellHasFocus) {
     400            public Component getListCellRendererComponent(JList<? extends AutoCompletionItem> list,
     401                    AutoCompletionItem value, int index, boolean isSelected, boolean cellHasFocus) {
    402402                Component c = def.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    403403                if (c instanceof JLabel) {
     
    447447
    448448            AutoCompletionManager autocomplete = AutoCompletionManager.of(MainApplication.getLayerManager().getEditLayer().data);
    449             List<AutoCompletionListItem> keyList = autocomplete.getKeys();
    450             keyList.sort(DEFAULT_AC_ITEM_COMPARATOR);
     449            List<AutoCompletionItem> keyList = autocomplete.getTagKeys(DEFAULT_AC_ITEM_COMPARATOR);
    451450
    452451            keys = new AutoCompletingComboBox(key);
    453             keys.setPossibleACItems(keyList);
     452            keys.setPossibleAcItems(keyList);
    454453            keys.setEditable(true);
    455454            keys.setSelectedItem(key);
     
    460459            p.add(keys, GBC.eol().fill(GBC.HORIZONTAL));
    461460
    462             List<AutoCompletionListItem> valueList = autocomplete.getValues(getAutocompletionKeys(key));
    463             valueList.sort(usedValuesAwareComparator);
     461            List<AutoCompletionItem> valueList = autocomplete.getTagValues(getAutocompletionKeys(key), usedValuesAwareComparator);
    464462
    465463            final String selection = m.size() != 1 ? tr("<different>") : m.entrySet().iterator().next().getKey();
     
    469467
    470468            values.setEditable(true);
    471             values.setPossibleACItems(valueList);
     469            values.setPossibleAcItems(valueList);
    472470            values.setSelectedItem(selection);
    473471            values.getEditor().setItem(selection);
     
    630628        * @return The created adapter
    631629        */
    632         protected FocusAdapter addFocusAdapter(final AutoCompletionManager autocomplete, final Comparator<AutoCompletionListItem> comparator) {
     630        protected FocusAdapter addFocusAdapter(final AutoCompletionManager autocomplete, final Comparator<AutoCompletionItem> comparator) {
    633631           // get the combo box' editor component
    634632           final JTextComponent editor = values.getEditorComponent();
     
    639637                   String key = keys.getEditor().getItem().toString();
    640638
    641                    List<AutoCompletionListItem> valueList = autocomplete.getValues(getAutocompletionKeys(key));
    642                    valueList.sort(comparator);
     639                   List<AutoCompletionItem> valueList = autocomplete.getTagValues(getAutocompletionKeys(key), comparator);
    643640                   Logging.trace("Focus gained by {0}, e={1}", values, e);
    644                    values.setPossibleACItems(valueList);
     641                   values.setPossibleAcItems(valueList);
    645642                   values.getEditor().selectAll();
    646643                   objKey = key;
     
    692689
    693690            cacheRecentTags();
    694             AutoCompletionManager autocomplete = AutoCompletionManager.of(MainApplication.getLayerManager().getEditLayer().data);
    695             List<AutoCompletionListItem> keyList = autocomplete.getKeys();
     691            AutoCompletionManager autocomplete = AutoCompletionManager.of(Main.main.getEditDataSet());
     692            List<AutoCompletionItem> keyList = autocomplete.getTagKeys(DEFAULT_AC_ITEM_COMPARATOR);
    696693
    697694            // remove the object's tag keys from the list
    698695            keyList.removeIf(item -> containsDataKey(item.getValue()));
    699696
    700             keyList.sort(DEFAULT_AC_ITEM_COMPARATOR);
    701             keys.setPossibleACItems(keyList);
     697            keys.setPossibleAcItems(keyList);
    702698            keys.setEditable(true);
    703699
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/CustomProjectionChoice.java

    r12846 r12859  
    2424import org.openstreetmap.josm.data.projection.ProjectionConfigurationException;
    2525import org.openstreetmap.josm.data.projection.Projections;
     26import org.openstreetmap.josm.data.tagging.ac.AutoCompletionItem;
    2627import org.openstreetmap.josm.gui.ExtendedDialog;
    27 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
    2828import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator;
    2929import org.openstreetmap.josm.gui.widgets.HistoryComboBox;
     
    6565            input = new JosmTextField(30);
    6666            cbInput = new HistoryComboBox();
    67             cbInput.setPrototypeDisplayValue(new AutoCompletionListItem("xxxx"));
     67            cbInput.setPrototypeDisplayValue(new AutoCompletionItem("xxxx"));
    6868            cbInput.setEditor(new BasicComboBoxEditor() {
    6969                @Override
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingComboBox.java

    r12846 r12859  
    1010import java.util.Collection;
    1111import java.util.Locale;
     12import java.util.stream.Collectors;
    1213
    1314import javax.swing.ComboBoxEditor;
     
    2324import javax.swing.text.StyleConstants;
    2425
     26import org.openstreetmap.josm.data.tagging.ac.AutoCompletionItem;
     27import org.openstreetmap.josm.data.tagging.ac.AutoCompletionPriority;
    2528import org.openstreetmap.josm.gui.MainApplication;
    2629import org.openstreetmap.josm.gui.MapFrame;
     
    3538 * @since 272
    3639 */
    37 public class AutoCompletingComboBox extends JosmComboBox<AutoCompletionListItem> {
     40public class AutoCompletingComboBox extends JosmComboBox<AutoCompletionItem> {
    3841
    3942    private boolean autocompleteEnabled = true;
     
    8588     */
    8689    class AutoCompletingComboBoxDocument extends PlainDocument {
    87         private final JosmComboBox<AutoCompletionListItem> comboBox;
     90        private final JosmComboBox<AutoCompletionItem> comboBox;
    8891        private boolean selecting;
    8992
     
    9295         * @param comboBox the combobox
    9396         */
    94         AutoCompletingComboBoxDocument(final JosmComboBox<AutoCompletionListItem> comboBox) {
     97        AutoCompletingComboBoxDocument(final JosmComboBox<AutoCompletionItem> comboBox) {
    9598            this.comboBox = comboBox;
    9699        }
     
    159162            }
    160163            if (item != null) {
    161                 String newText = ((AutoCompletionListItem) item).getValue();
     164                String newText = ((AutoCompletionItem) item).getValue();
    162165                if (!newText.equals(curText)) {
    163166                    selecting = true;
     
    190193
    191194        private Object lookupItem(String pattern, boolean match) {
    192             ComboBoxModel<AutoCompletionListItem> model = comboBox.getModel();
    193             AutoCompletionListItem bestItem = null;
     195            ComboBoxModel<AutoCompletionItem> model = comboBox.getModel();
     196            AutoCompletionItem bestItem = null;
    194197            for (int i = 0, n = model.getSize(); i < n; i++) {
    195                 AutoCompletionListItem currentItem = model.getElementAt(i);
     198                AutoCompletionItem currentItem = model.getElementAt(i);
    196199                if (currentItem.getValue().equals(pattern))
    197200                    return currentItem;
     
    219222     */
    220223    public AutoCompletingComboBox(String prototype) {
    221         super(new AutoCompletionListItem(prototype));
     224        super(new AutoCompletionItem(prototype));
    222225        setRenderer(new AutoCompleteListCellRenderer());
    223226        final JTextComponent editorComponent = this.getEditorComponent();
     
    241244     */
    242245    @Override
     246    @SuppressWarnings("deprecation")
    243247    public void configureEditor(ComboBoxEditor cbEditor, Object item) {
    244248        if (item == null) {
     
    246250        } else if (item instanceof String) {
    247251            cbEditor.setItem(item);
     252        } else if (item instanceof AutoCompletionItem) {
     253            cbEditor.setItem(((AutoCompletionItem) item).getValue());
    248254        } else if (item instanceof AutoCompletionListItem) {
    249             cbEditor.setItem(((AutoCompletionListItem) item).getValue());
     255            cbEditor.setItem(((AutoCompletionListItem) item).getItem().getValue());
    250256        } else
    251257            throw new IllegalArgumentException("Unsupported item: "+item);
     
    254260    /**
    255261     * Selects a given item in the ComboBox model
    256      * @param item      excepts AutoCompletionListItem, String and null
     262     * @param item      excepts AutoCompletionItem, String and null
    257263     */
    258264    @Override
     265    @SuppressWarnings("deprecation")
    259266    public void setSelectedItem(Object item) {
    260267        if (item == null) {
    261268            super.setSelectedItem(null);
     269        } else if (item instanceof AutoCompletionItem) {
     270            super.setSelectedItem(item);
    262271        } else if (item instanceof AutoCompletionListItem) {
    263             super.setSelectedItem(item);
     272            super.setSelectedItem(((AutoCompletionListItem) item).getItem());
    264273        } else if (item instanceof String) {
    265274            String s = (String) item;
    266275            // find the string in the model or create a new item
    267276            for (int i = 0; i < getModel().getSize(); i++) {
    268                 AutoCompletionListItem acItem = getModel().getElementAt(i);
     277                AutoCompletionItem acItem = getModel().getElementAt(i);
    269278                if (s.equals(acItem.getValue())) {
    270279                    super.setSelectedItem(acItem);
     
    272281                }
    273282            }
    274             super.setSelectedItem(new AutoCompletionListItem(s, AutoCompletionItemPriority.UNKNOWN));
     283            super.setSelectedItem(new AutoCompletionItem(s, AutoCompletionPriority.UNKNOWN));
    275284        } else {
    276285            throw new IllegalArgumentException("Unsupported item: "+item);
     
    283292     */
    284293    public void setPossibleItems(Collection<String> elems) {
    285         DefaultComboBoxModel<AutoCompletionListItem> model = (DefaultComboBoxModel<AutoCompletionListItem>) this.getModel();
     294        DefaultComboBoxModel<AutoCompletionItem> model = (DefaultComboBoxModel<AutoCompletionItem>) this.getModel();
    286295        Object oldValue = this.getEditor().getItem(); // Do not use getSelectedItem(); (fix #8013)
    287296        model.removeAllElements();
    288297        for (String elem : elems) {
    289             model.addElement(new AutoCompletionListItem(elem, AutoCompletionItemPriority.UNKNOWN));
     298            model.addElement(new AutoCompletionItem(elem, AutoCompletionPriority.UNKNOWN));
    290299        }
    291300        // disable autocomplete to prevent unnecessary actions in AutoCompletingComboBoxDocument#insertString
     
    298307     * Sets the items of the combobox to the given {@code AutoCompletionListItem}s.
    299308     * @param elems AutoCompletionListItem items
    300      */
     309     * @deprecated to be removed end of 2017. Use {@link #setPossibleAcItems(Collection)} instead
     310     */
     311    @Deprecated
    301312    public void setPossibleACItems(Collection<AutoCompletionListItem> elems) {
    302         DefaultComboBoxModel<AutoCompletionListItem> model = (DefaultComboBoxModel<AutoCompletionListItem>) this.getModel();
     313        setPossibleAcItems(elems.stream().map(AutoCompletionListItem::getItem).collect(Collectors.toList()));
     314    }
     315
     316    /**
     317     * Sets the items of the combobox to the given {@code AutoCompletionItem}s.
     318     * @param elems AutoCompletionItem items
     319     * @since 12859
     320     */
     321    public void setPossibleAcItems(Collection<AutoCompletionItem> elems) {
     322        DefaultComboBoxModel<AutoCompletionItem> model = (DefaultComboBoxModel<AutoCompletionItem>) this.getModel();
    303323        Object oldValue = getSelectedItem();
    304324        Object editorOldValue = this.getEditor().getItem();
    305325        model.removeAllElements();
    306         for (AutoCompletionListItem elem : elems) {
     326        for (AutoCompletionItem elem : elems) {
    307327            model.addElement(elem);
    308328        }
     
    359379     * renders an AutoCompletionListItem by showing only the string value part
    360380     */
    361     public static class AutoCompleteListCellRenderer extends JLabel implements ListCellRenderer<AutoCompletionListItem> {
     381    public static class AutoCompleteListCellRenderer extends JLabel implements ListCellRenderer<AutoCompletionItem> {
    362382
    363383        /**
     
    370390        @Override
    371391        public Component getListCellRendererComponent(
    372                 JList<? extends AutoCompletionListItem> list,
    373                 AutoCompletionListItem item,
     392                JList<? extends AutoCompletionItem> list,
     393                AutoCompletionItem item,
    374394                int index,
    375395                boolean isSelected,
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingTextField.java

    r12846 r12859  
    9999            if (autoCompletionList.getFilteredSize() > 0 && !Objects.equals(str, noAutoCompletionString)) {
    100100                // there are matches. Insert the new text and highlight the auto completed suffix
    101                 String matchingString = autoCompletionList.getFilteredItem(0).getValue();
     101                String matchingString = autoCompletionList.getFilteredItemAt(0).getValue();
    102102                remove(0, getLength());
    103103                super.insertString(0, matchingString, a);
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionItemPriority.java

    r10378 r12859  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.tagging.ac;
     3
     4import org.openstreetmap.josm.data.tagging.ac.AutoCompletionPriority;
    35
    46/**
     
    810 * Instances of this class are not modifiable.
    911 * @since 1762
     12 * @deprecated to be removed end of 2017. Use {@link AutoCompletionPriority} instead
    1013 */
     14@Deprecated
    1115public class AutoCompletionItemPriority implements Comparable<AutoCompletionItemPriority> {
    1216
     
    1620     * usually not used by the user.
    1721     */
    18     public static final AutoCompletionItemPriority IS_IN_STANDARD_AND_IN_DATASET = new AutoCompletionItemPriority(true, true, false);
     22    public static final AutoCompletionItemPriority IS_IN_STANDARD_AND_IN_DATASET = new AutoCompletionItemPriority(
     23            AutoCompletionPriority.IS_IN_STANDARD_AND_IN_DATASET);
    1924
    2025    /**
     
    2227     * the value of a tag name=*.
    2328     */
    24     public static final AutoCompletionItemPriority IS_IN_DATASET = new AutoCompletionItemPriority(true, false, false);
     29    public static final AutoCompletionItemPriority IS_IN_DATASET = new AutoCompletionItemPriority(AutoCompletionPriority.IS_IN_DATASET);
    2530
    2631    /**
     
    2833     * or a standard value for a given tag name (from the presets).
    2934     */
    30     public static final AutoCompletionItemPriority IS_IN_STANDARD = new AutoCompletionItemPriority(false, true, false);
     35    public static final AutoCompletionItemPriority IS_IN_STANDARD = new AutoCompletionItemPriority(AutoCompletionPriority.IS_IN_STANDARD);
    3136
    3237    /**
    3338     * Indicates that this is a value from a selected object.
    3439     */
    35     public static final AutoCompletionItemPriority IS_IN_SELECTION = new AutoCompletionItemPriority(false, false, true);
     40    public static final AutoCompletionItemPriority IS_IN_SELECTION = new AutoCompletionItemPriority(AutoCompletionPriority.IS_IN_SELECTION);
    3641
    3742    /** Unknown priority. This is the lowest priority. */
    38     public static final AutoCompletionItemPriority UNKNOWN = new AutoCompletionItemPriority(false, false, false);
     43    public static final AutoCompletionItemPriority UNKNOWN = new AutoCompletionItemPriority(AutoCompletionPriority.UNKNOWN);
    3944
    4045    private static final int NO_USER_INPUT = Integer.MAX_VALUE;
    4146
    42     private final int userInput;
    43     private final boolean inDataSet;
    44     private final boolean inStandard;
    45     private final boolean selected;
     47    private final AutoCompletionPriority priority;
    4648
    4749    /**
     
    5658     */
    5759    public AutoCompletionItemPriority(boolean inDataSet, boolean inStandard, boolean selected, Integer userInput) {
    58         this.inDataSet = inDataSet;
    59         this.inStandard = inStandard;
    60         this.selected = selected;
    61         this.userInput = userInput == null ? NO_USER_INPUT : userInput;
     60        this(new AutoCompletionPriority(inDataSet, inStandard, selected, userInput));
    6261    }
    6362
     
    7473
    7574    /**
     75     * Constructs a new {@code AutoCompletionItemPriority} from an existing {@link AutoCompletionPriority}.
     76     * @param other {@code AutoCompletionPriority} to convert
     77     * @since 12859
     78     */
     79    public AutoCompletionItemPriority(AutoCompletionPriority other) {
     80        this.priority = other;
     81    }
     82
     83    /**
    7684     * Determines if the item is found in the currently active data layer.
    7785     * @return {@code true} if the item is found in the currently active data layer
    7886     */
    7987    public boolean isInDataSet() {
    80         return inDataSet;
     88        return priority.isInDataSet();
    8189    }
    8290
     
    8694     */
    8795    public boolean isInStandard() {
    88         return inStandard;
     96        return priority.isInStandard();
    8997    }
    9098
     
    94102     */
    95103    public boolean isSelected() {
    96         return selected;
     104        return priority.isSelected();
    97105    }
    98106
     
    104112     */
    105113    public Integer getUserInput() {
    106         return userInput == NO_USER_INPUT ? null : userInput;
     114        return priority.getUserInput();
    107115    }
    108116
     
    113121    @Override
    114122    public int compareTo(AutoCompletionItemPriority other) {
    115         int ui = Integer.compare(other.userInput, userInput);
    116         if (ui != 0)
    117             return ui;
    118 
    119         int sel = Boolean.compare(selected, other.selected);
    120         if (sel != 0)
    121             return sel;
    122 
    123         int ds = Boolean.compare(inDataSet, other.inDataSet);
    124         if (ds != 0)
    125             return ds;
    126 
    127         int std = Boolean.compare(inStandard, other.inStandard);
    128         if (std != 0)
    129             return std;
    130 
    131         return 0;
     123        return priority.compareTo(other.priority);
    132124    }
    133125
     
    139131     */
    140132    public AutoCompletionItemPriority mergeWith(AutoCompletionItemPriority other) {
    141         return new AutoCompletionItemPriority(
    142                 inDataSet || other.inDataSet,
    143                 inStandard || other.inStandard,
    144                 selected || other.selected,
    145                 Math.min(userInput, other.userInput));
     133        return new AutoCompletionItemPriority(priority.mergeWith(other.priority));
    146134    }
    147135
    148136    @Override
    149137    public String toString() {
    150         return String.format("<Priority; userInput: %s, inDataSet: %b, inStandard: %b, selected: %b>",
    151                 userInput == NO_USER_INPUT ? "no" : Integer.toString(userInput), inDataSet, inStandard, selected);
     138        return priority.toString();
     139    }
     140
     141    /**
     142     * Returns the underlying priority.
     143     * @return the underlying priority
     144     * @since 12859
     145     */
     146    public AutoCompletionPriority getPriority() {
     147        return priority;
    152148    }
    153149}
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionList.java

    r10137 r12859  
    55import java.util.Collection;
    66import java.util.Collections;
    7 import java.util.HashMap;
    87import java.util.List;
    9 import java.util.Map;
     8import java.util.Set;
     9import java.util.stream.Collectors;
    1010
    1111import javax.swing.JTable;
    1212import javax.swing.table.AbstractTableModel;
    1313
     14import org.openstreetmap.josm.data.tagging.ac.AutoCompletionItem;
     15import org.openstreetmap.josm.data.tagging.ac.AutoCompletionPriority;
     16import org.openstreetmap.josm.data.tagging.ac.AutoCompletionSet;
    1417import org.openstreetmap.josm.tools.CheckParameterUtil;
    1518
    1619/**
    17  * AutoCompletionList manages a list of {@link AutoCompletionListItem}s.
     20 * AutoCompletionList manages a graphical list of {@link AutoCompletionItem}s.
    1821 *
    1922 * The list is sorted, items with higher priority first, then according to lexicographic order
    20  * on the value of the {@link AutoCompletionListItem}.
     23 * on the value of the {@link AutoCompletionItem}.
    2124 *
    22  * AutoCompletionList maintains two views on the list of {@link AutoCompletionListItem}s.
     25 * AutoCompletionList maintains two views on the list of {@link AutoCompletionItem}s.
    2326 * <ol>
    2427 *   <li>the bare, unfiltered view which includes all items</li>
     
    3336
    3437    /** the bare list of AutoCompletionItems */
    35     private final transient List<AutoCompletionListItem> list;
     38    private final transient AutoCompletionSet list;
    3639    /**  the filtered list of AutoCompletionItems */
    37     private final transient ArrayList<AutoCompletionListItem> filtered;
     40    private final transient ArrayList<AutoCompletionItem> filtered;
    3841    /** the filter expression */
    3942    private String filter;
    40     /** map from value to priority */
    41     private final transient Map<String, AutoCompletionListItem> valutToItemMap;
    4243
    4344    /**
     
    4546     */
    4647    public AutoCompletionList() {
    47         list = new ArrayList<>();
     48        list = new AutoCompletionSet();
    4849        filtered = new ArrayList<>();
    49         valutToItemMap = new HashMap<>();
    5050    }
    5151
     
    8181
    8282    /**
    83      * adds an AutoCompletionListItem to the list. Only adds the item if it
     83     * adds an {@link AutoCompletionListItem} to the list. Only adds the item if it
    8484     * is not null and if not in the list yet.
    8585     *
    8686     * @param item the item
    87      */
     87     * @deprecated To be removed end of 2017. Use {@link #add(AutoCompletionItem)} instead
     88     */
     89    @Deprecated
    8890    public void add(AutoCompletionListItem item) {
    8991        if (item == null)
    9092            return;
    91         appendOrUpdatePriority(item);
    92         sort();
    93         filter();
    94     }
    95 
    96     /**
    97      * adds another AutoCompletionList to this list. An item is only
     93        add(item.getItem());
     94    }
     95
     96    /**
     97     * adds an {@link AutoCompletionItem} to the list. Only adds the item if it
     98     * is not null and if not in the list yet.
     99     *
     100     * @param item the item
     101     * @since 12859
     102     */
     103    public void add(AutoCompletionItem item) {
     104        if (item != null && list.add(item)) {
     105            filter();
     106        }
     107    }
     108
     109    /**
     110     * adds another {@link AutoCompletionList} to this list. An item is only
    98111     * added it is not null and if it does not exist in the list yet.
    99112     *
     
    103116    public void add(AutoCompletionList other) {
    104117        CheckParameterUtil.ensureParameterNotNull(other, "other");
    105         for (AutoCompletionListItem item : other.list) {
    106             appendOrUpdatePriority(item);
    107         }
    108         sort();
    109         filter();
    110     }
    111 
    112     /**
    113      * adds a list of AutoCompletionListItem to this list. Only items which
     118        add(other.list);
     119    }
     120
     121    /**
     122     * adds a colleciton of {@link AutoCompletionItem} to this list. An item is only
     123     * added it is not null and if it does not exist in the list yet.
     124     *
     125     * @param collection auto completion collection; must not be null
     126     * @throws IllegalArgumentException if other is null
     127     * @since 12859
     128     */
     129    public void add(Collection<AutoCompletionItem> collection) {
     130        CheckParameterUtil.ensureParameterNotNull(collection, "collection");
     131        if (list.addAll(collection)) {
     132            filter();
     133        }
     134    }
     135
     136    /**
     137     * adds a list of {@link AutoCompletionListItem} to this list. Only items which
    114138     * are not null and which do not exist yet in the list are added.
    115139     *
    116140     * @param other a list of AutoCompletionListItem; must not be null
    117141     * @throws IllegalArgumentException if other is null
    118      */
     142     * @deprecated to be removed end of 2017. Use {@link #add(Collection)} instead
     143     */
     144    @Deprecated
    119145    public void add(List<AutoCompletionListItem> other) {
    120146        CheckParameterUtil.ensureParameterNotNull(other, "other");
    121         for (AutoCompletionListItem toadd : other) {
    122             appendOrUpdatePriority(toadd);
    123         }
    124         sort();
    125         filter();
     147        add(other.stream().map(AutoCompletionListItem::getItem).collect(Collectors.toList()));
    126148    }
    127149
     
    132154     * @param values a list of strings to add
    133155     * @param priority the priority to use
    134      */
     156     * @deprecated to be removed end of 2017. Use {@link #add(Collection, AutoCompletionPriority)} instead
     157     */
     158    @Deprecated
    135159    public void add(Collection<String> values, AutoCompletionItemPriority priority) {
    136         if (values == null)
    137             return;
    138         for (String value : values) {
    139             if (value == null) {
    140                 continue;
    141             }
    142             AutoCompletionListItem item = new AutoCompletionListItem(value, priority);
    143             appendOrUpdatePriority(item);
    144 
    145         }
    146         sort();
    147         filter();
     160        add(values, priority.getPriority());
     161    }
     162
     163    /**
     164     * adds a list of strings to this list. Only strings which
     165     * are not null and which do not exist yet in the list are added.
     166     *
     167     * @param values a list of strings to add
     168     * @param priority the priority to use
     169     * @since 12859
     170     */
     171    public void add(Collection<String> values, AutoCompletionPriority priority) {
     172        if (values != null && list.addAll(values, priority)) {
     173            filter();
     174        }
    148175    }
    149176
     
    153180     */
    154181    public void addUserInput(Collection<String> values) {
    155         if (values == null)
    156             return;
    157         int i = 0;
    158         for (String value : values) {
    159             if (value != null) {
    160                 appendOrUpdatePriority(
    161                         new AutoCompletionListItem(value, new AutoCompletionItemPriority(false, false, false, i++)));
    162             }
    163         }
    164         sort();
    165         filter();
    166     }
    167 
    168     protected void appendOrUpdatePriority(AutoCompletionListItem toAdd) {
    169         AutoCompletionListItem item = valutToItemMap.get(toAdd.getValue());
    170         if (item == null) {
    171             // new item does not exist yet. Add it to the list
    172             list.add(toAdd);
    173             valutToItemMap.put(toAdd.getValue(), toAdd);
    174         } else {
    175             item.setPriority(item.getPriority().mergeWith(toAdd.getPriority()));
     182        if (values != null && list.addUserInput(values)) {
     183            filter();
    176184        }
    177185    }
     
    183191     * @param item the item to check
    184192     * @return true, if item is in the list; false, otherwise
    185      */
     193     * @deprecated to be removed end of 2017. Use {@link #contains(AutoCompletionItem)} instead
     194     */
     195    @Deprecated
    186196    public boolean contains(AutoCompletionListItem item) {
    187197        if (item == null)
    188198            return false;
     199        return contains(item.getItem());
     200    }
     201
     202    /**
     203     * checks whether a specific item is already in the list. Matches for the
     204     * the value <strong>and</strong> the priority of the item
     205     *
     206     * @param item the item to check
     207     * @return true, if item is in the list; false, otherwise
     208     * @since 12859
     209     */
     210    public boolean contains(AutoCompletionItem item) {
    189211        return list.contains(item);
    190212    }
     
    198220     */
    199221    public boolean contains(String value) {
    200         if (value == null)
    201             return false;
    202         for (AutoCompletionListItem item: list) {
    203             if (item.getValue().equals(value))
    204                 return true;
    205         }
    206         return false;
     222        return list.contains(value);
    207223    }
    208224
    209225    /**
    210226     * removes the auto completion item with key <code>key</code>
    211      * @param key  the key;
     227     * @param key the key
    212228     */
    213229    public void remove(String key) {
    214         if (key == null)
    215             return;
    216         for (int i = 0; i < list.size(); i++) {
    217             AutoCompletionListItem item = list.get(i);
    218             if (item.getValue().equals(key)) {
    219                 list.remove(i);
    220                 return;
    221             }
    222         }
    223     }
    224 
    225     /**
    226      * sorts the list
    227      */
    228     protected void sort() {
    229         Collections.sort(list);
     230        if (key != null) {
     231            list.remove(key);
     232        }
    230233    }
    231234
     
    235238            // Collections.copy throws an exception "Source does not fit in dest"
    236239            filtered.ensureCapacity(list.size());
    237             for (AutoCompletionListItem item: list) {
    238                 filtered.add(item);
    239             }
     240            filtered.addAll(list);
    240241            return;
    241242        }
     
    244245        // value to the list of filtered values
    245246        //
    246         for (AutoCompletionListItem item : list) {
    247             if (item.getValue().startsWith(filter)) {
    248                 filtered.add(item);
    249             }
    250         }
     247        list.stream().filter(e -> e.getValue().startsWith(filter)).forEach(filtered::add);
    251248        fireTableDataChanged();
    252249    }
     
    258255     */
    259256    public int getFilteredSize() {
    260         return this.filtered.size();
     257        return filtered.size();
    261258    }
    262259
     
    267264     *
    268265     * @throws IndexOutOfBoundsException if idx is out of bounds
    269      */
     266     * @deprecated to be removed end of 2017. Use {@link #getFilteredItemAt(int)} instead
     267     */
     268    @Deprecated
    270269    public AutoCompletionListItem getFilteredItem(int idx) {
    271         if (idx < 0 || idx >= getFilteredSize())
    272             throw new IndexOutOfBoundsException("idx out of bounds. idx=" + idx);
     270        return new AutoCompletionListItem(getFilteredItemAt(idx));
     271    }
     272
     273    /**
     274     * replies the idx-th item from the list of filtered items
     275     * @param idx the index; must be in the range 0 &lt;= idx &lt; {@link #getFilteredSize()}
     276     * @return the item
     277     *
     278     * @throws IndexOutOfBoundsException if idx is out of bounds
     279     * @since 12859
     280     */
     281    public AutoCompletionItem getFilteredItemAt(int idx) {
    273282        return filtered.get(idx);
    274283    }
    275284
    276     List<AutoCompletionListItem> getList() {
     285    AutoCompletionSet getSet() {
    277286        return list;
    278287    }
    279288
    280     List<AutoCompletionListItem> getUnmodifiableList() {
    281         return Collections.unmodifiableList(list);
     289    Set<AutoCompletionItem> getUnmodifiableSet() {
     290        return Collections.unmodifiableSet(list);
    282291    }
    283292
    284293    /**
    285294     * removes all elements from the auto completion list
    286      *
    287295     */
    288296    public void clear() {
    289         valutToItemMap.clear();
    290297        list.clear();
    291298        fireTableDataChanged();
     
    299306    @Override
    300307    public int getRowCount() {
    301 
    302308        return list == null ? 0 : getFilteredSize();
    303309    }
     
    305311    @Override
    306312    public Object getValueAt(int rowIndex, int columnIndex) {
    307         return list == null ? null : getFilteredItem(rowIndex);
     313        return list == null ? null : getFilteredItemAt(rowIndex);
    308314    }
    309315}
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionListItem.java

    r10378 r12859  
    22package org.openstreetmap.josm.gui.tagging.ac;
    33
    4 import org.openstreetmap.josm.tools.CheckParameterUtil;
     4import org.openstreetmap.josm.data.tagging.ac.AutoCompletionItem;
    55
    66/**
     
    1515 *
    1616 * The value is a string which will be displayed in the auto completion list.
    17  *
     17 * @deprecated To be removed end of 2017. Use {@link AutoCompletionItem} instead
    1818 */
     19@Deprecated
    1920public class AutoCompletionListItem implements Comparable<AutoCompletionListItem> {
    2021
    21     /** the pritority of this item */
    22     private AutoCompletionItemPriority priority;
    23     /** the value of this item */
    24     private String value;
     22    /** the item */
     23    private final AutoCompletionItem item;
    2524
    2625    /**
     
    3029     */
    3130    public AutoCompletionListItem(String value, AutoCompletionItemPriority priority) {
    32         this.value = value;
    33         this.priority = priority;
     31        this.item = new AutoCompletionItem(value, priority.getPriority());
    3432    }
    3533
     
    3937     */
    4038    public AutoCompletionListItem(String value) {
    41         this.value = value;
    42         priority = AutoCompletionItemPriority.UNKNOWN;
     39        this.item = new AutoCompletionItem(value);
    4340    }
    4441
     
    4744     */
    4845    public AutoCompletionListItem() {
    49         value = "";
    50         priority = AutoCompletionItemPriority.UNKNOWN;
     46        this.item = new AutoCompletionItem();
     47    }
     48
     49    /**
     50     * Constructs a new {@code AutoCompletionListItem} from an existing {@link AutoCompletionItem}.
     51     * @param other {@code AutoCompletionItem} to convert
     52     * @since 12859
     53     */
     54    public AutoCompletionListItem(AutoCompletionItem other) {
     55        this.item = other;
    5156    }
    5257
     
    5661     */
    5762    public AutoCompletionItemPriority getPriority() {
    58         return priority;
     63        return new AutoCompletionItemPriority(item.getPriority());
    5964    }
    6065
     
    6469     */
    6570    public void setPriority(AutoCompletionItemPriority priority) {
    66         this.priority = priority;
     71        item.setPriority(priority.getPriority());
    6772    }
    6873
     
    7277     */
    7378    public String getValue() {
    74         return value;
     79        return item.getValue();
    7580    }
    7681
     
    8186     */
    8287    public void setValue(String value) {
    83         CheckParameterUtil.ensureParameterNotNull(value, "value");
    84         this.value = value;
     88        item.setValue(value);
    8589    }
    8690
    8791    @Override
    8892    public String toString() {
    89         StringBuilder sb = new StringBuilder();
    90         sb.append("<val='")
    91           .append(value)
    92           .append("',")
    93           .append(priority)
    94           .append('>');
    95         return sb.toString();
     93        return item.toString();
    9694    }
    9795
    9896    @Override
    9997    public int hashCode() {
    100         final int prime = 31;
    101         int result = 1;
    102         result = prime * result
    103                 + ((priority == null) ? 0 : priority.hashCode());
    104         result = prime * result + ((value == null) ? 0 : value.hashCode());
    105         return result;
     98        return item.hashCode();
    10699    }
    107100
     
    113106            return false;
    114107        if (obj instanceof String)
    115             return obj.equals(value);
     108            return obj.equals(item.getValue());
    116109        if (getClass() != obj.getClass())
    117110            return false;
    118111        final AutoCompletionListItem other = (AutoCompletionListItem) obj;
    119         if (priority == null) {
    120             if (other.priority != null)
    121                 return false;
    122         } else if (!priority.equals(other.priority))
    123             return false;
    124         if (value == null) {
    125             if (other.value != null)
    126                 return false;
    127         } else if (!value.equals(other.value))
    128             return false;
    129         return true;
     112        return item.equals(other.item);
    130113    }
    131114
    132115    @Override
    133116    public int compareTo(AutoCompletionListItem other) {
    134         int ret = other.priority.compareTo(priority); // higher priority items come first in the list
    135         if (ret != 0)
    136             return ret;
    137         else
    138             return this.value.compareTo(other.value);
     117        return item.compareTo(other.item);
     118    }
     119
     120    /**
     121     * Returns the underlying item.
     122     * @return the underlying item
     123     * @since 12859
     124     */
     125    public AutoCompletionItem getItem() {
     126        return item;
    139127    }
    140128}
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionManager.java

    r12758 r12859  
    66import java.util.Collection;
    77import java.util.Collections;
     8import java.util.Comparator;
    89import java.util.HashMap;
    910import java.util.HashSet;
     
    1516import java.util.Set;
    1617import java.util.function.Function;
     18import java.util.stream.Collectors;
    1719
    1820import org.openstreetmap.josm.data.osm.DataSet;
     
    2931import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
    3032import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
     33import org.openstreetmap.josm.data.tagging.ac.AutoCompletionItem;
     34import org.openstreetmap.josm.data.tagging.ac.AutoCompletionPriority;
     35import org.openstreetmap.josm.data.tagging.ac.AutoCompletionSet;
    3136import org.openstreetmap.josm.gui.MainApplication;
    3237import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     
    4651 * possible auto completion values for each key.
    4752 *
    48  * Each DataSet is assigned one AutoCompletionManager instance such that
     53 * Each DataSet can be assigned one AutoCompletionManager instance such that
    4954 * <ol>
    5055 *   <li>any key used in a tag in the data set is part of the key list in the cache</li>
    51  *   <li>any value used in a tag for a specific key is part of the autocompletion list of
    52  *     this key</li>
     56 *   <li>any value used in a tag for a specific key is part of the autocompletion list of this key</li>
    5357 * </ol>
    5458 *
     
    271275
    272276    /**
    273      * Populates the {@link AutoCompletionList} with the currently cached
    274      * member roles.
     277     * Populates the {@link AutoCompletionList} with the currently cached member roles.
    275278     *
    276279     * @param list the list to populate
    277280     */
    278281    public void populateWithMemberRoles(AutoCompletionList list) {
    279         list.add(TaggingPresets.getPresetRoles(), AutoCompletionItemPriority.IS_IN_STANDARD);
    280         list.add(getRoleCache(), AutoCompletionItemPriority.IS_IN_DATASET);
     282        list.add(TaggingPresets.getPresetRoles(), AutoCompletionPriority.IS_IN_STANDARD);
     283        list.add(getRoleCache(), AutoCompletionPriority.IS_IN_DATASET);
    281284    }
    282285
     
    297300            for (TaggingPreset tp : presets) {
    298301                if (tp.roles != null) {
    299                     list.add(Utils.transform(tp.roles.roles, (Function<Role, String>) x -> x.key), AutoCompletionItemPriority.IS_IN_STANDARD);
     302                    list.add(Utils.transform(tp.roles.roles, (Function<Role, String>) x -> x.key), AutoCompletionPriority.IS_IN_STANDARD);
    300303                }
    301304            }
    302             list.add(r.getMemberRoles(), AutoCompletionItemPriority.IS_IN_DATASET);
     305            list.add(r.getMemberRoles(), AutoCompletionPriority.IS_IN_DATASET);
    303306        } else {
    304307            populateWithMemberRoles(list);
     
    312315     */
    313316    public void populateWithKeys(AutoCompletionList list) {
    314         list.add(TaggingPresets.getPresetKeys(), AutoCompletionItemPriority.IS_IN_STANDARD);
    315         list.add(new AutoCompletionListItem("source", AutoCompletionItemPriority.IS_IN_STANDARD));
    316         list.add(getDataKeys(), AutoCompletionItemPriority.IS_IN_DATASET);
     317        list.add(TaggingPresets.getPresetKeys(), AutoCompletionPriority.IS_IN_STANDARD);
     318        list.add(new AutoCompletionItem("source", AutoCompletionPriority.IS_IN_STANDARD));
     319        list.add(getDataKeys(), AutoCompletionPriority.IS_IN_DATASET);
    317320        list.addUserInput(getUserInputKeys());
    318321    }
    319322
    320323    /**
    321      * Populates the an {@link AutoCompletionList} with the currently cached
    322      * values for a tag
     324     * Populates the an {@link AutoCompletionList} with the currently cached values for a tag
    323325     *
    324326     * @param list the list to populate
     
    330332
    331333    /**
    332      * Populates the an {@link AutoCompletionList} with the currently cached
    333      * values for some given tags
     334     * Populates the an {@link AutoCompletionList} with the currently cached values for some given tags
    334335     *
    335336     * @param list the list to populate
     
    338339    public void populateWithTagValues(AutoCompletionList list, List<String> keys) {
    339340        for (String key : keys) {
    340             list.add(TaggingPresets.getPresetValues(key), AutoCompletionItemPriority.IS_IN_STANDARD);
    341             list.add(getDataValues(key), AutoCompletionItemPriority.IS_IN_DATASET);
     341            list.add(TaggingPresets.getPresetValues(key), AutoCompletionPriority.IS_IN_STANDARD);
     342            list.add(getDataValues(key), AutoCompletionPriority.IS_IN_DATASET);
    342343            list.addUserInput(getUserInputValues(key));
    343344        }
     
    347348     * Returns the currently cached tag keys.
    348349     * @return a list of tag keys
    349      */
     350     * @deprecated to be removed end of 2017. Use {@link #getTagKeys()} instead
     351     */
     352    @Deprecated
    350353    public List<AutoCompletionListItem> getKeys() {
    351         AutoCompletionList list = new AutoCompletionList();
    352         populateWithKeys(list);
    353         return list.getList();
     354        return getTagKeys().stream().map(AutoCompletionListItem::new).collect(Collectors.toList());
    354355    }
    355356
     
    358359     * @param key the tag key
    359360     * @return a list of tag values
    360      */
     361     * @deprecated to be removed end of 2017. Use {@link #getTagValues(String)} instead
     362     */
     363    @Deprecated
    361364    public List<AutoCompletionListItem> getValues(String key) {
    362         return getValues(Arrays.asList(key));
     365        return getTagValues(key).stream().map(AutoCompletionListItem::new).collect(Collectors.toList());
    363366    }
    364367
     
    367370     * @param keys the tag keys
    368371     * @return a list of tag values
    369      */
     372     * @deprecated to be removed end of 2017. Use {@link #getTagValues(List)} instead
     373     */
     374    @Deprecated
    370375    public List<AutoCompletionListItem> getValues(List<String> keys) {
     376        return getTagValues(keys).stream().map(AutoCompletionListItem::new).collect(Collectors.toList());
     377    }
     378
     379    private static List<AutoCompletionItem> setToList(AutoCompletionSet set, Comparator<AutoCompletionItem> comparator) {
     380        List<AutoCompletionItem> list = set.stream().collect(Collectors.toList());
     381        list.sort(comparator);
     382        return list;
     383    }
     384
     385    /**
     386     * Returns the currently cached tag keys.
     387     * @return a set of tag keys
     388     * @since 12859
     389     */
     390    public AutoCompletionSet getTagKeys() {
     391        AutoCompletionList list = new AutoCompletionList();
     392        populateWithKeys(list);
     393        return list.getSet();
     394    }
     395
     396    /**
     397     * Returns the currently cached tag keys.
     398     * @param comparator the custom comparator used to sort the list
     399     * @return a list of tag keys
     400     * @since 12859
     401     */
     402    public List<AutoCompletionItem> getTagKeys(Comparator<AutoCompletionItem> comparator) {
     403        return setToList(getTagKeys(), comparator);
     404    }
     405
     406    /**
     407     * Returns the currently cached tag values for a given tag key.
     408     * @param key the tag key
     409     * @return a set of tag values
     410     * @since 12859
     411     */
     412    public AutoCompletionSet getTagValues(String key) {
     413        return getTagValues(Arrays.asList(key));
     414    }
     415
     416    /**
     417     * Returns the currently cached tag values for a given tag key.
     418     * @param key the tag key
     419     * @param comparator the custom comparator used to sort the list
     420     * @return a list of tag values
     421     * @since 12859
     422     */
     423    public List<AutoCompletionItem> getTagValues(String key, Comparator<AutoCompletionItem> comparator) {
     424        return setToList(getTagValues(key), comparator);
     425    }
     426
     427    /**
     428     * Returns the currently cached tag values for a given list of tag keys.
     429     * @param keys the tag keys
     430     * @return a set of tag values
     431     * @since 12859
     432     */
     433    public AutoCompletionSet getTagValues(List<String> keys) {
    371434        AutoCompletionList list = new AutoCompletionList();
    372435        populateWithTagValues(list, keys);
    373         return list.getList();
    374     }
    375 
    376     /*********************************************************
     436        return list.getSet();
     437    }
     438
     439    /**
     440     * Returns the currently cached tag values for a given list of tag keys.
     441     * @param keys the tag keys
     442     * @param comparator the custom comparator used to sort the list
     443     * @return a set of tag values
     444     * @since 12859
     445     */
     446    public List<AutoCompletionItem> getTagValues(List<String> keys, Comparator<AutoCompletionItem> comparator) {
     447        return setToList(getTagValues(keys), comparator);
     448    }
     449
     450    /*
    377451     * Implementation of the DataSetListener interface
    378452     *
    379      **/
     453     */
    380454
    381455    @Override
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/package-info.java

    r8624 r12859  
    22
    33/**
    4  * Provides classes for handling autocompletion of tags.
     4 * Provides GUI classes for handling autocompletion of tags.
    55 */
    66package org.openstreetmap.josm.gui.tagging.ac;
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Combo.java

    r12846 r12859  
    44import javax.swing.JPanel;
    55
     6import org.openstreetmap.josm.data.tagging.ac.AutoCompletionPriority;
    67import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    7 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionItemPriority;
    88import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
    99import org.openstreetmap.josm.gui.widgets.JosmComboBox;
     
    6464        AutoCompletionList acList = tf.getAutoCompletionList();
    6565        if (acList != null) {
    66             acList.add(getDisplayValues(), AutoCompletionItemPriority.IS_IN_STANDARD);
     66            acList.add(getDisplayValues(), AutoCompletionPriority.IS_IN_STANDARD);
    6767        }
    6868        combobox.setEditor(tf);
  • trunk/src/org/openstreetmap/josm/gui/widgets/ComboBoxHistory.java

    r9983 r12859  
    99import javax.swing.DefaultComboBoxModel;
    1010
    11 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
     11import org.openstreetmap.josm.data.tagging.ac.AutoCompletionItem;
    1212
    1313/**
    1414 * A data model for {@link HistoryComboBox}
    1515 */
    16 class ComboBoxHistory extends DefaultComboBoxModel<AutoCompletionListItem> implements Iterable<AutoCompletionListItem> {
     16class ComboBoxHistory extends DefaultComboBoxModel<AutoCompletionItem> implements Iterable<AutoCompletionItem> {
    1717
    1818    private final int maxSize;
     
    3131     */
    3232    public void addElement(String s) {
    33         addElement(new AutoCompletionListItem(s));
     33        addElement(new AutoCompletionItem(s));
    3434    }
    3535
     
    3939     */
    4040    @Override
    41     public void addElement(AutoCompletionListItem o) {
     41    public void addElement(AutoCompletionItem o) {
    4242        String newEntry = o.getValue();
    4343
     
    6464
    6565    @Override
    66     public Iterator<AutoCompletionListItem> iterator() {
    67         return new Iterator<AutoCompletionListItem>() {
     66    public Iterator<AutoCompletionItem> iterator() {
     67        return new Iterator<AutoCompletionItem>() {
    6868
    6969            private int position = -1;
     
    8080
    8181            @Override
    82             public AutoCompletionListItem next() {
     82            public AutoCompletionItem next() {
    8383                if (!hasNext())
    8484                    throw new NoSuchElementException();
     
    102102
    103103    /**
    104      * Returns the {@link AutoCompletionListItem} items as strings
     104     * Returns the {@link AutoCompletionItem} items as strings
    105105     * @return a list of strings
    106106     */
    107107    public List<String> asStringList() {
    108108        List<String> list = new ArrayList<>(maxSize);
    109         for (AutoCompletionListItem item : this) {
     109        for (AutoCompletionItem item : this) {
    110110            list.add(item.getValue());
    111111        }
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelperTest.java

    r12619 r12859  
    1717import org.junit.Rule;
    1818import org.junit.Test;
    19 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
     19import org.openstreetmap.josm.data.tagging.ac.AutoCompletionItem;
    2020import org.openstreetmap.josm.testutils.JOSMTestRules;
    2121
     
    4646    @Test
    4747    public void testAcItemComparator() {
    48         List<AutoCompletionListItem> list = new ArrayList<>();
    49         list.add(new AutoCompletionListItem("Bing Sat"));
    50         list.add(new AutoCompletionListItem("survey"));
    51         list.add(new AutoCompletionListItem("Bing"));
    52         list.add(new AutoCompletionListItem("digitalglobe"));
    53         list.add(new AutoCompletionListItem("bing"));
    54         list.add(new AutoCompletionListItem("DigitalGlobe"));
     48        List<AutoCompletionItem> list = new ArrayList<>();
     49        list.add(new AutoCompletionItem("Bing Sat"));
     50        list.add(new AutoCompletionItem("survey"));
     51        list.add(new AutoCompletionItem("Bing"));
     52        list.add(new AutoCompletionItem("digitalglobe"));
     53        list.add(new AutoCompletionItem("bing"));
     54        list.add(new AutoCompletionItem("DigitalGlobe"));
    5555        list.sort(TagEditHelper.DEFAULT_AC_ITEM_COMPARATOR);
    5656        assertEquals(Arrays.asList("Bing", "bing", "Bing Sat", "digitalglobe", "DigitalGlobe", "survey"),
    57                 list.stream().map(AutoCompletionListItem::getValue).collect(Collectors.toList()));
     57                list.stream().map(AutoCompletionItem::getValue).collect(Collectors.toList()));
    5858    }
    5959
Note: See TracChangeset for help on using the changeset viewer.