source: josm/trunk/src/org/openstreetmap/josm/data/tagging/ac/AutoCompletionItem.java@ 12859

Last change on this file since 12859 was 12859, checked in by Don-vip, 7 years ago

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

  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.tagging.ac;
3
4import org.openstreetmap.josm.tools.CheckParameterUtil;
5
6/**
7 * Represents an entry in the set of auto completion values.
8 *
9 * An AutoCompletionItem has a <em>priority</em> and a <em>value</em>.
10 *
11 * The priority helps to sort the auto completion items according to their importance. For instance,
12 * in an auto completion set for tag names, standard tag names would be assigned a higher
13 * priority than arbitrary tag names present in the current data set. There are three priority levels,
14 * {@link AutoCompletionPriority}.
15 *
16 * The value is a string which will be displayed in the auto completion list.
17 * @since 12859 (copied from {@code gui.tagging.ac.AutoCompletionListItem})
18 */
19public class AutoCompletionItem implements Comparable<AutoCompletionItem> {
20
21 /** the priority of this item */
22 private AutoCompletionPriority priority;
23 /** the value of this item */
24 private String value;
25
26 /**
27 * Constructs a new {@code AutoCompletionItem} with the given value and priority.
28 * @param value The value
29 * @param priority The priority
30 */
31 public AutoCompletionItem(String value, AutoCompletionPriority priority) {
32 this.value = value;
33 this.priority = priority;
34 }
35
36 /**
37 * Constructs a new {@code AutoCompletionItem} with the given value and unknown priority.
38 * @param value The value
39 */
40 public AutoCompletionItem(String value) {
41 this.value = value;
42 priority = AutoCompletionPriority.UNKNOWN;
43 }
44
45 /**
46 * Constructs a new {@code AutoCompletionItem}.
47 */
48 public AutoCompletionItem() {
49 value = "";
50 priority = AutoCompletionPriority.UNKNOWN;
51 }
52
53 /**
54 * Returns the priority.
55 * @return the priority
56 */
57 public AutoCompletionPriority getPriority() {
58 return priority;
59 }
60
61 /**
62 * Sets the priority.
63 * @param priority the priority
64 */
65 public void setPriority(AutoCompletionPriority priority) {
66 this.priority = priority;
67 }
68
69 /**
70 * Returns the value.
71 * @return the value
72 */
73 public String getValue() {
74 return value;
75 }
76
77 /**
78 * sets the value
79 * @param value the value; must not be null
80 * @throws IllegalArgumentException if value if null
81 */
82 public void setValue(String value) {
83 CheckParameterUtil.ensureParameterNotNull(value, "value");
84 this.value = value;
85 }
86
87 @Override
88 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();
96 }
97
98 @Override
99 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;
106 }
107
108 @Override
109 public boolean equals(Object obj) {
110 if (this == obj)
111 return true;
112 if (obj == null)
113 return false;
114 if (obj instanceof String)
115 return obj.equals(value);
116 if (getClass() != obj.getClass())
117 return false;
118 final AutoCompletionItem other = (AutoCompletionItem) 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;
130 }
131
132 @Override
133 public int compareTo(AutoCompletionItem 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);
139 }
140}
Note: See TracBrowser for help on using the repository browser.