Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package org.onosproject.ui.topo; |
| 18 | |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 19 | import com.google.common.collect.Sets; |
| 20 | |
Simon Hunt | cd15027 | 2015-11-04 14:09:36 -0800 | [diff] [blame] | 21 | import java.text.NumberFormat; |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 22 | import java.util.ArrayList; |
| 23 | import java.util.List; |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 24 | import java.util.Set; |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Models a panel displayed on the Topology View. |
| 28 | */ |
| 29 | public class PropertyPanel { |
| 30 | |
Simon Hunt | cd15027 | 2015-11-04 14:09:36 -0800 | [diff] [blame] | 31 | private static final NumberFormat NF = NumberFormat.getInstance(); |
Simon Hunt | 00a27ff | 2015-07-28 18:53:40 -0700 | [diff] [blame] | 32 | |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 33 | private String title; |
Simon Hunt | a58d894 | 2017-08-11 12:51:14 -0700 | [diff] [blame] | 34 | private String glyphId; |
Simon Hunt | b745ca6 | 2015-07-28 15:37:11 -0700 | [diff] [blame] | 35 | private String id; |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 36 | private String navPath; |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 37 | private List<Prop> properties = new ArrayList<>(); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 38 | private List<ButtonId> buttons = new ArrayList<>(); |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 39 | |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 40 | /** |
| 41 | * Constructs a property panel model with the given title and |
Simon Hunt | a58d894 | 2017-08-11 12:51:14 -0700 | [diff] [blame] | 42 | * glyph identifier (icon to display). |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 43 | * |
Simon Hunt | a58d894 | 2017-08-11 12:51:14 -0700 | [diff] [blame] | 44 | * @param title title text |
| 45 | * @param glyphId glyph ID |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 46 | */ |
Simon Hunt | a58d894 | 2017-08-11 12:51:14 -0700 | [diff] [blame] | 47 | public PropertyPanel(String title, String glyphId) { |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 48 | this.title = title; |
Simon Hunt | a58d894 | 2017-08-11 12:51:14 -0700 | [diff] [blame] | 49 | this.glyphId = glyphId; |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 52 | /** |
Simon Hunt | cd15027 | 2015-11-04 14:09:36 -0800 | [diff] [blame] | 53 | * Returns a number formatter to use for formatting integer and long |
| 54 | * property values. |
| 55 | * <p> |
| 56 | * This default implementation uses a formatter for the default |
| 57 | * locale. For example: |
| 58 | * <pre> |
| 59 | * Locale.ENGLISH : 1000 -> "1,000" |
| 60 | * Locale.FRENCH : 1000 -> "1 000" |
| 61 | * Locale.GERMAN : 1000 -> "1.000" |
| 62 | * </pre> |
| 63 | * |
| 64 | * @return the number formatter |
| 65 | */ |
| 66 | protected NumberFormat formatter() { |
| 67 | return NF; |
| 68 | } |
| 69 | |
| 70 | /** |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 71 | * Adds a navigation path field to the panel data, to be included in |
| 72 | * the returned JSON data to the client. This is typically used to |
| 73 | * configure the topology view with the appropriate navigation path for |
| 74 | * a hot-link to some other view. |
| 75 | * |
| 76 | * @param navPath the navigation path |
| 77 | * @return self for chaining |
| 78 | */ |
| 79 | public PropertyPanel navPath(String navPath) { |
| 80 | this.navPath = navPath; |
| 81 | return this; |
| 82 | } |
| 83 | |
| 84 | /** |
Simon Hunt | b745ca6 | 2015-07-28 15:37:11 -0700 | [diff] [blame] | 85 | * Adds an ID field to the panel data, to be included in |
| 86 | * the returned JSON data to the client. |
| 87 | * |
| 88 | * @param id the identifier |
| 89 | * @return self, for chaining |
| 90 | */ |
| 91 | public PropertyPanel id(String id) { |
| 92 | this.id = id; |
| 93 | return this; |
| 94 | } |
| 95 | |
Simon Hunt | 00a27ff | 2015-07-28 18:53:40 -0700 | [diff] [blame] | 96 | /** |
| 97 | * Adds a property to the panel data. |
| 98 | * |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 99 | * @param key property key |
Simon Hunt | 879ce45 | 2017-08-10 23:32:00 -0700 | [diff] [blame] | 100 | * @param label property label (localized) |
Simon Hunt | 00a27ff | 2015-07-28 18:53:40 -0700 | [diff] [blame] | 101 | * @param value property value |
| 102 | * @return self, for chaining |
| 103 | */ |
Simon Hunt | 879ce45 | 2017-08-10 23:32:00 -0700 | [diff] [blame] | 104 | public PropertyPanel addProp(String key, String label, String value) { |
| 105 | properties.add(new Prop(key, label, value)); |
Simon Hunt | 00a27ff | 2015-07-28 18:53:40 -0700 | [diff] [blame] | 106 | return this; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Adds a property to the panel data, using a decimal formatter. |
| 111 | * |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 112 | * @param key property key |
Simon Hunt | 879ce45 | 2017-08-10 23:32:00 -0700 | [diff] [blame] | 113 | * @param label property label (localized) |
Simon Hunt | 00a27ff | 2015-07-28 18:53:40 -0700 | [diff] [blame] | 114 | * @param value property value |
| 115 | * @return self, for chaining |
| 116 | */ |
Simon Hunt | 879ce45 | 2017-08-10 23:32:00 -0700 | [diff] [blame] | 117 | public PropertyPanel addProp(String key, String label, int value) { |
| 118 | properties.add(new Prop(key, label, formatter().format(value))); |
Simon Hunt | 00a27ff | 2015-07-28 18:53:40 -0700 | [diff] [blame] | 119 | return this; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Adds a property to the panel data, using a decimal formatter. |
| 124 | * |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 125 | * @param key property key |
Simon Hunt | 879ce45 | 2017-08-10 23:32:00 -0700 | [diff] [blame] | 126 | * @param label property label (localized) |
Simon Hunt | 00a27ff | 2015-07-28 18:53:40 -0700 | [diff] [blame] | 127 | * @param value property value |
| 128 | * @return self, for chaining |
| 129 | */ |
Simon Hunt | 879ce45 | 2017-08-10 23:32:00 -0700 | [diff] [blame] | 130 | public PropertyPanel addProp(String key, String label, long value) { |
| 131 | properties.add(new Prop(key, label, formatter().format(value))); |
Simon Hunt | 00a27ff | 2015-07-28 18:53:40 -0700 | [diff] [blame] | 132 | return this; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Adds a property to the panel data. Note that the value's |
| 137 | * {@link Object#toString toString()} method is used to convert the |
| 138 | * value to a string. |
| 139 | * |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 140 | * @param key property key |
Simon Hunt | 879ce45 | 2017-08-10 23:32:00 -0700 | [diff] [blame] | 141 | * @param label property label (localized) |
Simon Hunt | 00a27ff | 2015-07-28 18:53:40 -0700 | [diff] [blame] | 142 | * @param value property value |
| 143 | * @return self, for chaining |
| 144 | */ |
Simon Hunt | 879ce45 | 2017-08-10 23:32:00 -0700 | [diff] [blame] | 145 | public PropertyPanel addProp(String key, String label, Object value) { |
| 146 | properties.add(new Prop(key, label, value.toString())); |
Simon Hunt | 00a27ff | 2015-07-28 18:53:40 -0700 | [diff] [blame] | 147 | return this; |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Adds a property to the panel data. Note that the value's |
| 152 | * {@link Object#toString toString()} method is used to convert the |
| 153 | * value to a string, from which the characters defined in the given |
| 154 | * regular expression string are stripped. |
| 155 | * |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 156 | * @param key property key |
Simon Hunt | a58d894 | 2017-08-11 12:51:14 -0700 | [diff] [blame] | 157 | * @param label property label (localized) |
Simon Hunt | 879ce45 | 2017-08-10 23:32:00 -0700 | [diff] [blame] | 158 | * @param value property value |
| 159 | * @param reStrip regexp characters to strip from value string |
| 160 | * @return self, for chaining |
| 161 | */ |
| 162 | public PropertyPanel addProp(String key, String label, |
| 163 | Object value, String reStrip) { |
| 164 | String val = value.toString().replaceAll(reStrip, ""); |
| 165 | properties.add(new Prop(key, label, val)); |
| 166 | return this; |
| 167 | } |
| 168 | |
Simon Hunt | 00a27ff | 2015-07-28 18:53:40 -0700 | [diff] [blame] | 169 | /** |
| 170 | * Adds a separator to the panel data. |
| 171 | * |
| 172 | * @return self, for chaining |
| 173 | */ |
| 174 | public PropertyPanel addSeparator() { |
| 175 | properties.add(new Separator()); |
| 176 | return this; |
| 177 | } |
Simon Hunt | b745ca6 | 2015-07-28 15:37:11 -0700 | [diff] [blame] | 178 | |
| 179 | /** |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 180 | * Returns the title text. |
| 181 | * |
| 182 | * @return title text |
| 183 | */ |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 184 | public String title() { |
| 185 | return title; |
| 186 | } |
| 187 | |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 188 | /** |
Simon Hunt | a58d894 | 2017-08-11 12:51:14 -0700 | [diff] [blame] | 189 | * Returns the glyph identifier. |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 190 | * |
Simon Hunt | a58d894 | 2017-08-11 12:51:14 -0700 | [diff] [blame] | 191 | * @return glyph identifier |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 192 | */ |
Simon Hunt | a58d894 | 2017-08-11 12:51:14 -0700 | [diff] [blame] | 193 | public String glyphId() { |
| 194 | return glyphId; |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 197 | /** |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 198 | * Returns the navigation path. |
| 199 | * |
| 200 | * @return the navigation path |
| 201 | */ |
| 202 | public String navPath() { |
| 203 | return navPath; |
| 204 | } |
| 205 | |
| 206 | /** |
Simon Hunt | b745ca6 | 2015-07-28 15:37:11 -0700 | [diff] [blame] | 207 | * Returns the internal ID. |
| 208 | * |
| 209 | * @return the ID |
| 210 | */ |
| 211 | public String id() { |
| 212 | return id; |
| 213 | } |
| 214 | |
| 215 | /** |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 216 | * Returns the list of properties to be displayed. |
| 217 | * |
| 218 | * @return the property list |
| 219 | */ |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 220 | public List<Prop> properties() { |
| 221 | return properties; |
| 222 | } |
| 223 | |
Simon Hunt | fb94011 | 2015-07-29 18:36:35 -0700 | [diff] [blame] | 224 | /** |
| 225 | * Returns the list of button descriptors. |
| 226 | * |
| 227 | * @return the button list |
| 228 | */ |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 229 | public List<ButtonId> buttons() { |
Simon Hunt | fb94011 | 2015-07-29 18:36:35 -0700 | [diff] [blame] | 230 | return buttons; |
| 231 | } |
| 232 | |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 233 | // == MUTATORS |
| 234 | |
| 235 | /** |
| 236 | * Sets the title text. |
| 237 | * |
| 238 | * @param title title text |
| 239 | * @return self, for chaining |
| 240 | */ |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 241 | public PropertyPanel title(String title) { |
| 242 | this.title = title; |
| 243 | return this; |
| 244 | } |
| 245 | |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 246 | /** |
Simon Hunt | a58d894 | 2017-08-11 12:51:14 -0700 | [diff] [blame] | 247 | * Sets the glyph identifier. |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 248 | * |
Simon Hunt | a58d894 | 2017-08-11 12:51:14 -0700 | [diff] [blame] | 249 | * @param glyphId glyph identifier |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 250 | * @return self, for chaining |
| 251 | */ |
Simon Hunt | a58d894 | 2017-08-11 12:51:14 -0700 | [diff] [blame] | 252 | public PropertyPanel glyphId(String glyphId) { |
| 253 | this.glyphId = glyphId; |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 254 | return this; |
| 255 | } |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 256 | |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 257 | /** |
| 258 | * Removes properties with the given keys from the list. |
| 259 | * |
| 260 | * @param keys keys of properties to remove |
| 261 | * @return self, for chaining |
| 262 | */ |
| 263 | public PropertyPanel removeProps(String... keys) { |
Simon Hunt | 3a0598f | 2015-08-04 19:59:04 -0700 | [diff] [blame] | 264 | Set<String> forRemoval = Sets.newHashSet(keys); |
| 265 | List<Prop> toKeep = new ArrayList<>(); |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 266 | for (Prop p : properties) { |
Simon Hunt | 3a0598f | 2015-08-04 19:59:04 -0700 | [diff] [blame] | 267 | if (!forRemoval.contains(p.key())) { |
| 268 | toKeep.add(p); |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 269 | } |
| 270 | } |
Simon Hunt | 3a0598f | 2015-08-04 19:59:04 -0700 | [diff] [blame] | 271 | properties = toKeep; |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 272 | return this; |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * Removes all currently defined properties. |
| 277 | * |
| 278 | * @return self, for chaining |
| 279 | */ |
| 280 | public PropertyPanel removeAllProps() { |
| 281 | properties.clear(); |
| 282 | return this; |
| 283 | } |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 284 | |
Simon Hunt | fb94011 | 2015-07-29 18:36:35 -0700 | [diff] [blame] | 285 | /** |
Simon Hunt | 3a0598f | 2015-08-04 19:59:04 -0700 | [diff] [blame] | 286 | * Adds the given button descriptor to the panel data. |
Simon Hunt | fb94011 | 2015-07-29 18:36:35 -0700 | [diff] [blame] | 287 | * |
Simon Hunt | 3a0598f | 2015-08-04 19:59:04 -0700 | [diff] [blame] | 288 | * @param button button descriptor |
Simon Hunt | fb94011 | 2015-07-29 18:36:35 -0700 | [diff] [blame] | 289 | * @return self, for chaining |
| 290 | */ |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 291 | public PropertyPanel addButton(ButtonId button) { |
Simon Hunt | 3a0598f | 2015-08-04 19:59:04 -0700 | [diff] [blame] | 292 | buttons.add(button); |
| 293 | return this; |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Removes buttons with the given descriptors from the list. |
| 298 | * |
| 299 | * @param descriptors descriptors to remove |
| 300 | * @return self, for chaining |
| 301 | */ |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 302 | public PropertyPanel removeButtons(ButtonId... descriptors) { |
| 303 | Set<ButtonId> forRemoval = Sets.newHashSet(descriptors); |
| 304 | List<ButtonId> toKeep = new ArrayList<>(); |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 305 | for (ButtonId bd : buttons) { |
Simon Hunt | 3a0598f | 2015-08-04 19:59:04 -0700 | [diff] [blame] | 306 | if (!forRemoval.contains(bd)) { |
| 307 | toKeep.add(bd); |
| 308 | } |
| 309 | } |
| 310 | buttons = toKeep; |
| 311 | return this; |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * Removes all currently defined buttons. |
| 316 | * |
| 317 | * @return self, for chaining |
| 318 | */ |
| 319 | public PropertyPanel removeAllButtons() { |
| 320 | buttons.clear(); |
Simon Hunt | fb94011 | 2015-07-29 18:36:35 -0700 | [diff] [blame] | 321 | return this; |
| 322 | } |
| 323 | |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 324 | // ==================== |
| 325 | |
Simon Hunt | b745ca6 | 2015-07-28 15:37:11 -0700 | [diff] [blame] | 326 | |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 327 | /** |
Simon Hunt | 879ce45 | 2017-08-10 23:32:00 -0700 | [diff] [blame] | 328 | * Simple data carrier for a property, composed of a key/label/value trio. |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 329 | */ |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 330 | public static class Prop { |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 331 | private final String key; |
Simon Hunt | 879ce45 | 2017-08-10 23:32:00 -0700 | [diff] [blame] | 332 | private final String label; |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 333 | private final String value; |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 334 | |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 335 | /** |
| 336 | * Constructs a property data value. |
| 337 | * |
Simon Hunt | 879ce45 | 2017-08-10 23:32:00 -0700 | [diff] [blame] | 338 | * @param key property key (localization key) |
| 339 | * @param label property label (localization value) |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 340 | * @param value property value |
| 341 | */ |
Simon Hunt | 879ce45 | 2017-08-10 23:32:00 -0700 | [diff] [blame] | 342 | public Prop(String key, String label, String value) { |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 343 | this.key = key; |
Simon Hunt | 879ce45 | 2017-08-10 23:32:00 -0700 | [diff] [blame] | 344 | this.label = label; |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 345 | this.value = value; |
| 346 | } |
| 347 | |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 348 | /** |
| 349 | * Returns the property's key. |
| 350 | * |
| 351 | * @return the key |
| 352 | */ |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 353 | public String key() { |
| 354 | return key; |
| 355 | } |
| 356 | |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 357 | /** |
Simon Hunt | 879ce45 | 2017-08-10 23:32:00 -0700 | [diff] [blame] | 358 | * Returns the property's (localized) label. |
| 359 | * |
| 360 | * @return the label |
| 361 | */ |
| 362 | public String label() { |
| 363 | return label; |
| 364 | } |
| 365 | |
| 366 | /** |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 367 | * Returns the property's value. |
| 368 | * |
| 369 | * @return the value |
| 370 | */ |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 371 | public String value() { |
| 372 | return value; |
| 373 | } |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 374 | |
Simon Hunt | 879ce45 | 2017-08-10 23:32:00 -0700 | [diff] [blame] | 375 | /* |
| 376 | * NOTE: equals/hashCode are only expressed in terms of key and value. |
| 377 | */ |
| 378 | |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 379 | @Override |
| 380 | public boolean equals(Object o) { |
| 381 | if (this == o) { |
| 382 | return true; |
| 383 | } |
| 384 | if (o == null || getClass() != o.getClass()) { |
| 385 | return false; |
| 386 | } |
| 387 | |
| 388 | Prop prop = (Prop) o; |
| 389 | return key.equals(prop.key) && value.equals(prop.value); |
| 390 | } |
| 391 | |
| 392 | @Override |
| 393 | public int hashCode() { |
| 394 | int result = key.hashCode(); |
| 395 | result = 31 * result + value.hashCode(); |
| 396 | return result; |
| 397 | } |
| 398 | |
| 399 | @Override |
| 400 | public String toString() { |
Simon Hunt | 879ce45 | 2017-08-10 23:32:00 -0700 | [diff] [blame] | 401 | return "{" + key + "(" + label + ") -> " + value + "}"; |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 402 | } |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Simon Hunt | 629b99e | 2015-07-27 17:38:33 -0700 | [diff] [blame] | 405 | /** |
| 406 | * Auxiliary class representing a separator property. |
| 407 | */ |
Simon Hunt | a58d894 | 2017-08-11 12:51:14 -0700 | [diff] [blame] | 408 | static class Separator extends Prop { |
| 409 | Separator() { |
Simon Hunt | 879ce45 | 2017-08-10 23:32:00 -0700 | [diff] [blame] | 410 | super("-", "-", ""); |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | |
Simon Hunt | 0af1ec3 | 2015-07-24 12:17:55 -0700 | [diff] [blame] | 414 | } |