source: josm/trunk/src/org/openstreetmap/josm/gui/widgets/HistoryComboBoxModel.java@ 19103

Last change on this file since 19103 was 19103, checked in by taylor.smock, 13 months ago

Cleanup some new PMD warnings from PMD 7.x (followup of r19101)

  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.widgets;
3
4import java.util.ArrayList;
5import java.util.List;
6
7import org.openstreetmap.josm.gui.tagging.ac.AutoCompComboBoxModel;
8import org.openstreetmap.josm.spi.preferences.Config;
9
10/**
11 * A data model for the {@link HistoryComboBox}.
12 * <p>
13 * This model is an {@link AutoCompComboBoxModel} specialized in {@code String}s. It offers
14 * convenience functions to serialize to and from the JOSM preferences.
15 *
16 * @since 18173
17 */
18public class HistoryComboBoxModel extends AutoCompComboBoxModel<String> {
19
20 HistoryComboBoxModel() {
21 // The user's preference for max. number of items in histories.
22 setSize(Config.getPref().getInt("search.history-size", 15));
23 }
24
25 /**
26 * Adds strings to the model.
27 * <p>
28 * Strings are added only until the max. history size is reached.
29 *
30 * @param strings the strings to add
31 */
32 public void addAllStrings(List<String> strings) {
33 strings.forEach(this::addElement);
34 }
35
36 /**
37 * Gets all items in the history as a list of strings.
38 *
39 * @return the items in the history
40 */
41 public List<String> asStringList() {
42 List<String> list = new ArrayList<>(getSize());
43 this.forEach(list::add);
44 return list;
45 }
46
47 /**
48 * Gets a preference loader and saver for this model.
49 *
50 * @return the instance
51 */
52 public Preferences prefs() {
53 return prefs(x -> x, x -> x);
54 }
55}
Note: See TracBrowser for help on using the repository browser.