source: josm/trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionListItem.java@ 13121

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

fix #15547 - fix major performance drawback of AutoCompletionSet (regression from r12859)

  • Property svn:eol-style set to native
File size: 3.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.tagging.ac;
3
4import org.openstreetmap.josm.data.tagging.ac.AutoCompletionItem;
5
6/**
7 * Represents an entry in the list of auto completion values.
8 *
9 * An AutoCompletionListItem 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 list 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 AutoCompletionItemPriority}.
15 *
16 * The value is a string which will be displayed in the auto completion list.
17 * @deprecated To be removed end of 2017. Use {@link AutoCompletionItem} instead
18 */
19@Deprecated
20public class AutoCompletionListItem implements Comparable<AutoCompletionListItem> {
21
22 /** the item */
23 private final AutoCompletionItem item;
24
25 /**
26 * Constructs a new {@code AutoCompletionListItem} with the given value and priority.
27 * @param value The value
28 * @param priority The priority
29 */
30 public AutoCompletionListItem(String value, AutoCompletionItemPriority priority) {
31 this.item = new AutoCompletionItem(value, priority.getPriority());
32 }
33
34 /**
35 * Constructs a new {@code AutoCompletionListItem} with the given value and unknown priority.
36 * @param value The value
37 */
38 public AutoCompletionListItem(String value) {
39 this.item = new AutoCompletionItem(value);
40 }
41
42 /**
43 * Constructs a new {@code AutoCompletionListItem}.
44 */
45 public AutoCompletionListItem() {
46 this.item = new AutoCompletionItem();
47 }
48
49 /**
50 * Constructs a new {@code AutoCompletionListItem} from an existing {@link AutoCompletionItem}.
51 * @param other {@code AutoCompletionItem} to convert
52 * @since 12859
53 */
54 public AutoCompletionListItem(AutoCompletionItem other) {
55 this.item = other;
56 }
57
58 /**
59 * Returns the priority.
60 * @return the priority
61 */
62 public AutoCompletionItemPriority getPriority() {
63 return new AutoCompletionItemPriority(item.getPriority());
64 }
65
66 /**
67 * Sets the priority.
68 * @param priority the priority
69 */
70 public void setPriority(AutoCompletionItemPriority priority) {
71 item.setPriority(priority.getPriority());
72 }
73
74 /**
75 * Returns the value.
76 * @return the value
77 */
78 public String getValue() {
79 return item.getValue();
80 }
81
82 /**
83 * sets the value
84 * @param value the value; must not be null
85 * @throws IllegalArgumentException if value if null
86 */
87 public void setValue(String value) {
88 throw new UnsupportedOperationException("setValue() is no longer supported");
89 }
90
91 @Override
92 public String toString() {
93 return item.toString();
94 }
95
96 @Override
97 public int hashCode() {
98 return item.hashCode();
99 }
100
101 @Override
102 public boolean equals(Object obj) {
103 if (this == obj)
104 return true;
105 if (obj == null)
106 return false;
107 if (obj instanceof String)
108 return obj.equals(item.getValue());
109 if (getClass() != obj.getClass())
110 return false;
111 final AutoCompletionListItem other = (AutoCompletionListItem) obj;
112 return item.equals(other.item);
113 }
114
115 @Override
116 public int compareTo(AutoCompletionListItem other) {
117 return item.compareTo(other.item);
118 }
119
120 /**
121 * Returns the underlying item.
122 * @return the underlying item
123 * @since 12859
124 */
125 public AutoCompletionItem getItem() {
126 return item;
127 }
128}
Note: See TracBrowser for help on using the repository browser.