source: josm/trunk/src/org/openstreetmap/josm/gui/tagging/TagModel.java@ 7005

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

see #8465 - use diamond operator where applicable

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.tagging;
3
4import java.util.ArrayList;
5import java.util.List;
6
7public class TagModel {
8
9 /** the name of the tag */
10 private String name = null;
11
12 /** the list of values */
13 private List<String> values = null;
14
15 /**
16 * constructor
17 */
18 public TagModel() {
19 values = new ArrayList<>();
20 setName("");
21 setValue("");
22 }
23
24 /**
25 * constructor
26 * @param name the tag name
27 */
28 public TagModel(String name) {
29 this();
30 setName(name);
31 }
32
33 /**
34 * constructor
35 *
36 * @param name the tag name
37 * @param value the tag value
38 */
39 public TagModel(String name, String value) {
40 this();
41 setName(name);
42 setValue(value);
43 }
44
45 /**
46 * sets the name. Converts name to "" if null.
47 * @param name the tag name
48 */
49 public final void setName(String name) {
50 name = (name == null) ? "" : name;
51 this.name = name;
52 }
53
54 /**
55 * @return the tag name
56 */
57 public String getName(){
58 return name;
59 }
60
61 /**
62 * removes all values from the list of values
63 */
64 public void clearValues() {
65 this.values.clear();
66 }
67
68 /**
69 * sets a unique value for this tag. Converts value to "", if null.
70 * @param value the value.
71 */
72 public final void setValue(String value) {
73 value = (value == null) ? "" : value;
74 clearValues();
75 this.values.add(value);
76 }
77
78 /**
79 *
80 * @param value the value to be checked; converted to "" if null
81 * @return true, if the values of this tag include <code>value</code>; false otherwise
82 */
83 public boolean hasValue(String value) {
84 value = (value == null) ? "" : value;
85 return values.contains(value);
86 }
87
88 public void addValue(String value) {
89 value = (value == null) ? "" : value;
90 if (hasValue(value)) {
91 return;
92 }
93 values.add(value);
94 }
95
96 /**
97 * removes a value from the list of values. Converts value to "" if null
98 * @param value the value
99 */
100 public void removeValue(String value){
101 value = (value == null) ? "" : value;
102 values.remove(value);
103 }
104
105 public List<String> getValues() {
106 return values;
107 }
108
109 public String getValue() {
110 if (getValueCount() == 0) {
111 return "";
112 } else if (getValueCount() == 1) {
113 return values.get(0);
114 } else {
115 StringBuilder sb = new StringBuilder();
116 for (int i =0; i < values.size(); i++) {
117 sb.append(values.get(i));
118 if (i + 1 < values.size()) {
119 sb.append(";");
120 }
121 }
122 return sb.toString();
123 }
124 }
125
126 public int getValueCount() {
127 return values.size();
128 }
129}
Note: See TracBrowser for help on using the repository browser.