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

Last change on this file since 4868 was 4868, checked in by jttt, 12 years ago

fix some warnings

  • 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
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(String value, AutoCompletionItemPritority priority) {
28 this.value = value;
29 this.priority = priority;
30 }
31
32 public AutoCompletionListItem(String value) {
33 this.value = value;
34 priority = AutoCompletionItemPritority.UNKNOWN;
35 }
36
37 public AutoCompletionListItem() {
38 value = "";
39 priority = AutoCompletionItemPritority.UNKNOWN;
40 }
41
42
43 /**
44 *
45 * @return the priority
46 */
47 public AutoCompletionItemPritority getPriority() {
48 return priority;
49 }
50
51 /**
52 * sets the priority
53 * @param priority the priority
54 */
55 public void setPriority(AutoCompletionItemPritority priority) {
56 this.priority = priority;
57 }
58
59 /**
60 *
61 * @return the value
62 */
63 public String getValue() {
64 return value;
65 }
66
67 /**
68 * sets the value
69 * @param value the value; must not be null
70 * @exception IllegalArgumentException thrown, if value if null
71 */
72 public void setValue(String value) {
73 if (value == null)
74 throw new IllegalArgumentException("argument 'value' must not be null");
75 this.value = value;
76 }
77
78 @Override public String toString() {
79 StringBuilder sb = new StringBuilder();
80 sb.append("<val='");
81 sb.append(value);
82 sb.append("',");
83 sb.append(priority.toString());
84 sb.append(">");
85 return sb.toString();
86 }
87
88 @Override public int hashCode() {
89 final int prime = 31;
90 int result = 1;
91 result = prime * result
92 + ((priority == null) ? 0 : priority.hashCode());
93 result = prime * result + ((value == null) ? 0 : value.hashCode());
94 return result;
95 }
96
97 @Override public boolean equals(Object obj) {
98 if (this == obj)
99 return true;
100 if (obj == null)
101 return false;
102 if (getClass() != obj.getClass())
103 return false;
104 final AutoCompletionListItem other = (AutoCompletionListItem)obj;
105 if (priority == null) {
106 if (other.priority != null)
107 return false;
108 } else if (!priority.equals(other.priority))
109 return false;
110 if (value == null) {
111 if (other.value != null)
112 return false;
113 } else if (!value.equals(other.value))
114 return false;
115 return true;
116 }
117
118 public int compareTo(AutoCompletionListItem other) {
119 int ret = other.priority.compareTo(priority); // higher priority items come first in the list
120 if (ret != 0)
121 return ret;
122 else
123 return this.value.compareTo(other.value);
124 }
125}
Note: See TracBrowser for help on using the repository browser.