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

Last change on this file since 2048 was 2048, checked in by Gubaer, 15 years ago

Improved auto completion
fixed #2729: Auto completion with numbers sometimes annoying (only fixed in presets, relation editor, not in property dialog)
fixed #2320: Preset dialog for house numbers should have autocompletion (auto completion now supported in all preset dialogs)

File size: 3.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.tagging.ac;
3
4/**
5 * Represents an entry in the list of auto completion values.
6 *
7 * An AutoCompletionListItem 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 list 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 * {@see AutoCompletionItemPritority}.
13 *
14 * The value is a string which will be displayed in the auto completion list.
15 *
16 */
17public class AutoCompletionListItem implements Comparable<AutoCompletionListItem>{
18
19 /** the pritority of this item */
20 private AutoCompletionItemPritority priority;
21 /** the value of this item */
22 private String value;
23
24 /**
25 * constructor
26 */
27 public AutoCompletionListItem() {
28 value = "";
29 priority = AutoCompletionItemPritority.UNKNOWN;
30 }
31
32 public AutoCompletionListItem(String value, AutoCompletionItemPritority priority) {
33 this.value = value;
34 this.priority = priority;
35 }
36
37 /**
38 *
39 * @return the priority
40 */
41 public AutoCompletionItemPritority getPriority() {
42 return priority;
43 }
44
45 /**
46 * sets the priority
47 * @param priority the priority
48 */
49 public void setPriority(AutoCompletionItemPritority priority) {
50 this.priority = priority;
51 }
52
53 /**
54 *
55 * @return the value
56 */
57 public String getValue() {
58 return value;
59 }
60
61 /**
62 * sets the value
63 * @param value the value; must not be null
64 * @exception IllegalArgumentException thrown, if value if null
65 */
66 public void setValue(String value) {
67 if (value == null)
68 throw new IllegalArgumentException("argument 'value' must not be null");
69 this.value = value;
70 }
71
72 @Override public String toString() {
73 StringBuilder sb = new StringBuilder();
74 sb.append("<AutoCompletionItemPritority: ");
75 sb.append("value='");
76 sb.append(value);
77 sb.append("',");
78 sb.append("priority='");
79 sb.append(priority.toString());
80 sb.append("'>");
81 return sb.toString();
82 }
83
84 @Override public int hashCode() {
85 final int prime = 31;
86 int result = 1;
87 result = prime * result
88 + ((priority == null) ? 0 : priority.hashCode());
89 result = prime * result + ((value == null) ? 0 : value.hashCode());
90 return result;
91 }
92
93 @Override public boolean equals(Object obj) {
94 if (this == obj)
95 return true;
96 if (obj == null)
97 return false;
98 if (getClass() != obj.getClass())
99 return false;
100 final AutoCompletionListItem other = (AutoCompletionListItem)obj;
101 if (priority == null) {
102 if (other.priority != null)
103 return false;
104 } else if (!priority.equals(other.priority))
105 return false;
106 if (value == null) {
107 if (other.value != null)
108 return false;
109 } else if (!value.equals(other.value))
110 return false;
111 return true;
112 }
113
114
115 public int compareTo(AutoCompletionListItem other) {
116 int ret = this.priority.compareTo(other.priority);
117 if (ret != 0)
118 return ret;
119 else
120 return this.value.compareTo(other.value);
121 }
122}
Note: See TracBrowser for help on using the repository browser.