Ignore:
Timestamp:
2023-10-12T19:01:49+02:00 (8 months ago)
Author:
taylor.smock
Message:

See #16567: Update to JUnit 5

This adds the @TaggingPresets annotation used by r18866 (see #23196). The
annotation tries to only initialize the presets when the current preset list does
not have the same hashCode as the default preset list. In order for this to work,
TaggingPresets#getTaggingPresets had to return a List (the method contract
has not changed), which calculates the hashCode in a deterministic manner.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresets.java

    r18691 r18867  
    4242
    4343    /** The collection of tagging presets */
    44     private static final Collection<TaggingPreset> taggingPresets = new ArrayList<>();
     44    private static final List<TaggingPreset> TAGGING_PRESETS = new ArrayList<>();
    4545
    4646    /** cache for key/value pairs found in the preset */
     
    6969     */
    7070    public static void readFromPreferences() {
    71         taggingPresets.clear();
    72         taggingPresets.addAll(TaggingPresetReader.readFromPreferences(false, false));
    73         cachePresets(taggingPresets);
     71        TAGGING_PRESETS.clear();
     72        TAGGING_PRESETS.addAll(TaggingPresetReader.readFromPreferences(false, false));
     73        cachePresets(TAGGING_PRESETS);
    7474    }
    7575
     
    8989
    9090        readFromPreferences();
    91         final List<TaggingPreset> activeLayerChangeListeners = new ArrayList<>(taggingPresets.size());
    92         for (TaggingPreset tp: taggingPresets) {
     91        final List<TaggingPreset> activeLayerChangeListeners = new ArrayList<>(TAGGING_PRESETS.size());
     92        for (TaggingPreset tp: TAGGING_PRESETS) {
    9393            if (!(tp instanceof TaggingPresetSeparator)) {
    9494                MainApplication.getToolbar().register(tp);
     
    9797        }
    9898        MainApplication.getLayerManager().addActiveLayerChangeListeners(activeLayerChangeListeners);
    99         if (taggingPresets.isEmpty()) {
     99        if (TAGGING_PRESETS.isEmpty()) {
    100100            presetsMenu.setVisible(false);
    101101        } else {
    102102            Map<TaggingPresetMenu, JMenu> submenus = new HashMap<>();
    103             for (final TaggingPreset p : taggingPresets) {
     103            for (final TaggingPreset p : TAGGING_PRESETS) {
    104104                JMenu m = p.group != null ? submenus.get(p.group) : presetsMenu;
    105105                if (m == null && p.group != null) {
     
    127127            }
    128128        }
    129         if (SORT_MENU.get()) {
     129        if (Boolean.TRUE.equals(SORT_MENU.get())) {
    130130            TaggingPresetMenu.sortMenu(presetsMenu);
    131131        }
     
    142142    public static void destroy() {
    143143        ToolbarPreferences toolBar = MainApplication.getToolbar();
    144         for (TaggingPreset tp: taggingPresets) {
     144        for (TaggingPreset tp: TAGGING_PRESETS) {
    145145            toolBar.unregister(tp);
    146146            if (!(tp instanceof TaggingPresetSeparator)) {
     
    148148            }
    149149        }
    150         taggingPresets.clear();
     150        TAGGING_PRESETS.clear();
    151151        PRESET_TAG_CACHE.clear();
    152152        PRESET_ROLE_CACHE.clear();
     
    191191     */
    192192    public static Collection<TaggingPreset> getTaggingPresets() {
    193         return Collections.unmodifiableCollection(taggingPresets);
     193        return Collections.unmodifiableList(TAGGING_PRESETS);
    194194    }
    195195
     
    264264     */
    265265    public static void addTaggingPresets(Collection<TaggingPreset> presets) {
    266         if (presets != null && taggingPresets.addAll(presets)) {
     266        if (presets != null && TAGGING_PRESETS.addAll(presets)) {
    267267            listeners.forEach(TaggingPresetListener::taggingPresetsModified);
    268268        }
Note: See TracChangeset for help on using the changeset viewer.