source: josm/trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionItemPritority.java@ 3214

Last change on this file since 3214 was 3214, checked in by bastiK, 14 years ago

autocompletion cleanup - fixes #2729

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package 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 */
10public class AutoCompletionItemPritority implements Comparable<AutoCompletionItemPritority> {
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 AutoCompletionItemPritority IS_IN_STANDARD_AND_IN_DATASET = new AutoCompletionItemPritority(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 AutoCompletionItemPritority IS_IN_DATASET = new AutoCompletionItemPritority(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 AutoCompletionItemPritority IS_IN_STANDARD = new AutoCompletionItemPritority(false, true, false);
30
31 /**
32 * Indicates that this is a value from a selected object.
33 */
34 public static AutoCompletionItemPritority IS_IN_SELECTION = new AutoCompletionItemPritority(false, false, true);
35
36 /** Unknown priority. This is the lowest priority. */
37 public static AutoCompletionItemPritority UNKNOWN = new AutoCompletionItemPritority(false, false, false);
38
39 private final boolean inDataSet;
40 private final boolean inStandard;
41 private final boolean selected;
42
43 public AutoCompletionItemPritority(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 public int compareTo(AutoCompletionItemPritority other) {
66 int sel = new Boolean(selected).compareTo(other.selected);
67 if (sel != 0) return sel;
68
69 int ds = new Boolean(inDataSet).compareTo(other.inDataSet);
70 if (ds != 0) return ds;
71
72 int std = new Boolean(inStandard).compareTo(other.inStandard);
73 if (std != 0) return std;
74
75 return 0;
76 }
77
78 /**
79 * Merges two priorities.
80 * The resulting priority is always >= the original ones.
81 */
82 public AutoCompletionItemPritority mergeWith(AutoCompletionItemPritority other) {
83 return new AutoCompletionItemPritority(
84 inDataSet || other.inDataSet,
85 inStandard || other.inStandard,
86 selected || other.selected);
87 }
88
89 @Override public String toString() {
90 return String.format("<Priority; inDataSet: %b, inStandard: %b, selected: %b>", inDataSet, inStandard, selected);
91 }
92}
Note: See TracBrowser for help on using the repository browser.