1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.tagging.ac;
|
---|
3 |
|
---|
4 | /**
|
---|
5 | * Describes the priority of an item in an autocompletion list.
|
---|
6 | * The selected flag is currently only used in plugins.
|
---|
7 | *
|
---|
8 | * Instances of this class are not modifiable.
|
---|
9 | */
|
---|
10 | public class AutoCompletionItemPriority implements Comparable<AutoCompletionItemPriority> {
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Indicates, that the value is standard and it is found in the data.
|
---|
14 | * This has higher priority than some arbitrary standard value that is
|
---|
15 | * usually not used by the user.
|
---|
16 | */
|
---|
17 | public static final AutoCompletionItemPriority IS_IN_STANDARD_AND_IN_DATASET = new AutoCompletionItemPriority(true, true, false);
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Indicates that this is an arbitrary value from the data set, i.e.
|
---|
21 | * the value of a tag name=*.
|
---|
22 | */
|
---|
23 | public static final AutoCompletionItemPriority IS_IN_DATASET = new AutoCompletionItemPriority(true, false, false);
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Indicates that this is a standard value, i.e. a standard tag name
|
---|
27 | * or a standard value for a given tag name (from the presets).
|
---|
28 | */
|
---|
29 | public static final AutoCompletionItemPriority IS_IN_STANDARD = new AutoCompletionItemPriority(false, true, false);
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Indicates that this is a value from a selected object.
|
---|
33 | */
|
---|
34 | public static final AutoCompletionItemPriority IS_IN_SELECTION = new AutoCompletionItemPriority(false, false, true);
|
---|
35 |
|
---|
36 | /** Unknown priority. This is the lowest priority. */
|
---|
37 | public static final AutoCompletionItemPriority UNKNOWN = new AutoCompletionItemPriority(false, false, false);
|
---|
38 |
|
---|
39 | private final boolean inDataSet;
|
---|
40 | private final boolean inStandard;
|
---|
41 | private final boolean selected;
|
---|
42 |
|
---|
43 | public AutoCompletionItemPriority(boolean inDataSet, boolean inStandard, boolean selected) {
|
---|
44 | this.inDataSet = inDataSet;
|
---|
45 | this.inStandard = inStandard;
|
---|
46 | this.selected = selected;
|
---|
47 | }
|
---|
48 |
|
---|
49 | public boolean isInDataSet() {
|
---|
50 | return inDataSet;
|
---|
51 | }
|
---|
52 |
|
---|
53 | public boolean isInStandard() {
|
---|
54 | return inStandard;
|
---|
55 | }
|
---|
56 |
|
---|
57 | public boolean isSelected() {
|
---|
58 | return selected;
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Imposes an ordering on the priorities.
|
---|
63 | * Currently, being in the current DataSet is worth more than being in the Presets.
|
---|
64 | */
|
---|
65 | @Override
|
---|
66 | public int compareTo(AutoCompletionItemPriority other) {
|
---|
67 | int sel = Boolean.valueOf(selected).compareTo(other.selected);
|
---|
68 | if (sel != 0) return sel;
|
---|
69 |
|
---|
70 | int ds = Boolean.valueOf(inDataSet).compareTo(other.inDataSet);
|
---|
71 | if (ds != 0) return ds;
|
---|
72 |
|
---|
73 | int std = Boolean.valueOf(inStandard).compareTo(other.inStandard);
|
---|
74 | if (std != 0) return std;
|
---|
75 |
|
---|
76 | return 0;
|
---|
77 | }
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Merges two priorities.
|
---|
81 | * The resulting priority is always >= the original ones.
|
---|
82 | */
|
---|
83 | public AutoCompletionItemPriority mergeWith(AutoCompletionItemPriority other) {
|
---|
84 | return new AutoCompletionItemPriority(
|
---|
85 | inDataSet || other.inDataSet,
|
---|
86 | inStandard || other.inStandard,
|
---|
87 | selected || other.selected);
|
---|
88 | }
|
---|
89 |
|
---|
90 | @Override public String toString() {
|
---|
91 | return String.format("<Priority; inDataSet: %b, inStandard: %b, selected: %b>", inDataSet, inStandard, selected);
|
---|
92 | }
|
---|
93 | }
|
---|