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

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

see #15310 - remove most of deprecated APIs

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