001/* 002 * Copyright 2008-2019 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2015-2019 Ping Identity Corporation 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021package com.unboundid.ldap.sdk.unboundidds.monitors; 022 023 024 025import java.io.Serializable; 026import java.util.Arrays; 027import java.util.Collections; 028import java.util.Date; 029import java.util.List; 030 031import com.unboundid.util.NotMutable; 032import com.unboundid.util.ThreadSafety; 033import com.unboundid.util.ThreadSafetyLevel; 034import com.unboundid.util.Validator; 035 036 037 038/** 039 * This class provides a data structure for providing information about the data 040 * presented in an attribute in a Directory Server monitor entry. It includes 041 * a human-readable display name, a human-readable description, a class that 042 * represents the data type for the values, and the set of values. 043 * <BR> 044 * <BLOCKQUOTE> 045 * <B>NOTE:</B> This class, and other classes within the 046 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 047 * supported for use against Ping Identity, UnboundID, and 048 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 049 * for proprietary functionality or for external specifications that are not 050 * considered stable or mature enough to be guaranteed to work in an 051 * interoperable way with other types of LDAP servers. 052 * </BLOCKQUOTE> 053 */ 054@NotMutable() 055@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 056public final class MonitorAttribute 057 implements Serializable 058{ 059 /** 060 * The serial version UID for this serializable class. 061 */ 062 private static final long serialVersionUID = 7931725606171964572L; 063 064 065 066 // The data type for the values of this monitor attribute. 067 private final Class<?> dataType; 068 069 // The set of values for this monitor attribute. 070 private final Object[] values; 071 072 // The description for this monitor attribute. 073 private final String description; 074 075 // The display name for this monitor attribute. 076 private final String displayName; 077 078 // The name used to identify this monitor attribute. 079 private final String name; 080 081 082 083 /** 084 * Creates a new monitor attribute with the provided information. It will 085 * have a single Boolean value. 086 * 087 * @param name The name used to identify this monitor attribute. It 088 * must not be {@code null}. 089 * @param displayName The human-readable display name for this monitor 090 * attribute. It must not be {@code null}. 091 * @param description A human-readable description for this monitor 092 * attribute. It may be {@code null} if no description 093 * is available. 094 * @param value The {@code Boolean} value for this monitor attribute. 095 * It must not be {@code null}. 096 */ 097 public MonitorAttribute(final String name, final String displayName, 098 final String description, final Boolean value) 099 { 100 this(name, displayName, description, Boolean.class, new Object[] { value }); 101 102 Validator.ensureNotNull(value); 103 } 104 105 106 107 /** 108 * Creates a new monitor attribute with the provided information. It will 109 * have a single Date value. 110 * 111 * @param name The name used to identify this monitor attribute. It 112 * must not be {@code null}. 113 * @param displayName The human-readable display name for this monitor 114 * attribute. It must not be {@code null}. 115 * @param description A human-readable description for this monitor 116 * attribute. It may be {@code null} if no description 117 * is available. 118 * @param value The {@code Date} value for this monitor attribute. It 119 * must not be {@code null}. 120 */ 121 public MonitorAttribute(final String name, final String displayName, 122 final String description, final Date value) 123 { 124 this(name, displayName, description, Date.class, new Object[] { value }); 125 126 Validator.ensureNotNull(value); 127 } 128 129 130 131 /** 132 * Creates a new monitor attribute with the provided information. It will 133 * have one or more Date values. 134 * 135 * @param name The name used to identify this monitor attribute. It 136 * must not be {@code null}. 137 * @param displayName The human-readable display name for this monitor 138 * attribute. It must not be {@code null}. 139 * @param description A human-readable description for this monitor 140 * attribute. It may be {@code null} if no description 141 * is available. 142 * @param values The set of {@code Date} values for this monitor 143 * attribute. It must not be {@code null} or empty. 144 */ 145 public MonitorAttribute(final String name, final String displayName, 146 final String description, final Date[] values) 147 { 148 this(name, displayName, description, Date.class, values); 149 } 150 151 152 153 /** 154 * Creates a new monitor attribute with the provided information. It will 155 * have a single Double value. 156 * 157 * @param name The name used to identify this monitor attribute. It 158 * must not be {@code null}. 159 * @param displayName The human-readable display name for this monitor 160 * attribute. It must not be {@code null}. 161 * @param description A human-readable description for this monitor 162 * attribute. It may be {@code null} if no description 163 * is available. 164 * @param value The {@code Double} value for this monitor attribute. 165 * It must not be {@code null}. 166 */ 167 public MonitorAttribute(final String name, final String displayName, 168 final String description, final Double value) 169 { 170 this(name, displayName, description, Double.class, new Object[] { value }); 171 172 Validator.ensureNotNull(value); 173 } 174 175 176 177 /** 178 * Creates a new monitor attribute with the provided information. It will 179 * have one or more Double values. 180 * 181 * @param name The name used to identify this monitor attribute. It 182 * must not be {@code null}. 183 * @param displayName The human-readable display name for this monitor 184 * attribute. It must not be {@code null}. 185 * @param description A human-readable description for this monitor 186 * attribute. It may be {@code null} if no description 187 * is available. 188 * @param values The set of {@code Double} values for this monitor 189 * attribute. It must not be {@code null} or empty. 190 */ 191 public MonitorAttribute(final String name, final String displayName, 192 final String description, final Double[] values) 193 { 194 this(name, displayName, description, Double.class, values); 195 } 196 197 198 199 /** 200 * Creates a new monitor attribute with the provided information. It will 201 * have a single Long value. 202 * 203 * @param name The name used to identify this monitor attribute. It 204 * must not be {@code null}. 205 * @param displayName The human-readable display name for this monitor 206 * attribute. It must not be {@code null}. 207 * @param description A human-readable description for this monitor 208 * attribute. It may be {@code null} if no description 209 * is available. 210 * @param value The {@code Integer} value for this monitor attribute. 211 * It must not be {@code null}. 212 */ 213 public MonitorAttribute(final String name, final String displayName, 214 final String description, final Integer value) 215 { 216 this(name, displayName, description, Integer.class, new Object[] { value }); 217 218 Validator.ensureNotNull(value); 219 } 220 221 222 223 /** 224 * Creates a new monitor attribute with the provided information. It will 225 * have a single Long value. 226 * 227 * @param name The name used to identify this monitor attribute. It 228 * must not be {@code null}. 229 * @param displayName The human-readable display name for this monitor 230 * attribute. It must not be {@code null}. 231 * @param description A human-readable description for this monitor 232 * attribute. It may be {@code null} if no description 233 * is available. 234 * @param values The set of {@code Integer} values for this monitor 235 * attribute. It must not be {@code null} or empty. 236 */ 237 public MonitorAttribute(final String name, final String displayName, 238 final String description, final Integer[] values) 239 { 240 this(name, displayName, description, Integer.class, values); 241 } 242 243 244 245 /** 246 * Creates a new monitor attribute with the provided information. It will 247 * have a single Long value. 248 * 249 * @param name The name used to identify this monitor attribute. It 250 * must not be {@code null}. 251 * @param displayName The human-readable display name for this monitor 252 * attribute. It must not be {@code null}. 253 * @param description A human-readable description for this monitor 254 * attribute. It may be {@code null} if no description 255 * is available. 256 * @param value The {@code Long} value for this monitor attribute. It 257 * must not be {@code null}. 258 */ 259 public MonitorAttribute(final String name, final String displayName, 260 final String description, final Long value) 261 { 262 this(name, displayName, description, Long.class, new Object[] { value }); 263 264 Validator.ensureNotNull(value); 265 } 266 267 268 269 /** 270 * Creates a new monitor attribute with the provided information. It will 271 * have one or more Long values. 272 * 273 * @param name The name used to identify this monitor attribute. It 274 * must not be {@code null}. 275 * @param displayName The human-readable display name for this monitor 276 * attribute. It must not be {@code null}. 277 * @param description A human-readable description for this monitor 278 * attribute. It may be {@code null} if no description 279 * is available. 280 * @param values The set of {@code Long} values for this monitor 281 * attribute. It must not be {@code null} or empty. 282 */ 283 public MonitorAttribute(final String name, final String displayName, 284 final String description, final Long[] values) 285 { 286 this(name, displayName, description, Long.class, values); 287 } 288 289 290 291 /** 292 * Creates a new monitor attribute with the provided information. It will 293 * have a single String value. 294 * 295 * @param name The name used to identify this monitor attribute. It 296 * must not be {@code null}. 297 * @param displayName The human-readable display name for this monitor 298 * attribute. It must not be {@code null}. 299 * @param description A human-readable description for this monitor 300 * attribute. It may be {@code null} if no description 301 * is available. 302 * @param value The {@code String} value for this monitor attribute. 303 * It must not be {@code null}. 304 */ 305 public MonitorAttribute(final String name, final String displayName, 306 final String description, final String value) 307 { 308 this(name, displayName, description, String.class, new Object[] { value }); 309 310 Validator.ensureNotNull(value); 311 } 312 313 314 315 /** 316 * Creates a new monitor attribute with the provided information. It will 317 * have one or more String values. 318 * 319 * @param name The name used to identify this monitor attribute. It 320 * must not be {@code null}. 321 * @param displayName The human-readable display name for this monitor 322 * attribute. It must not be {@code null}. 323 * @param description A human-readable description for this monitor 324 * attribute. It may be {@code null} if no description 325 * is available. 326 * @param values The set of {@code String} values for this monitor 327 * attribute. It must not be {@code null} or empty. 328 */ 329 public MonitorAttribute(final String name, final String displayName, 330 final String description, final String[] values) 331 { 332 this(name, displayName, description, String.class, values); 333 } 334 335 336 337 /** 338 * Creates a new monitor attribute with the provided information. 339 * 340 * @param name The name used to identify this monitor attribute. It 341 * must not be {@code null}. 342 * @param displayName The human-readable display name for this monitor 343 * attribute. It must not be {@code null}. 344 * @param description A human-readable description for this monitor 345 * attribute. It may be {@code null} if no description 346 * is available. 347 * @param dataType The data type for this monitor attribute. It may be 348 * one of the following classes: Boolean, Date, Double, 349 * Long, and String. It must not be {@code null}. 350 * @param values The set of values for this monitor attribute. The 351 * data type for the values must correspond to the value 352 * of the {@code dataType} attribute. It must not be 353 * {@code null} or empty. 354 */ 355 private MonitorAttribute(final String name, final String displayName, 356 final String description, final Class<?> dataType, 357 final Object[] values) 358 { 359 Validator.ensureNotNull(name, displayName, dataType, values); 360 Validator.ensureFalse(values.length == 0, 361 "MonitorAttribute.values must not be empty."); 362 363 this.name = name; 364 this.displayName = displayName; 365 this.description = description; 366 this.dataType = dataType; 367 this.values = values; 368 } 369 370 371 372 /** 373 * Retrieves the name used to identify this monitor attribute. It is not 374 * necessarily human-readable, but it should be used as the key for this 375 * monitor attribute in the map returned by the 376 * {@code MonitorEntry.getMonitorAttributes} method. 377 * 378 * @return The name used to identify this monitor attribute. 379 */ 380 public String getName() 381 { 382 return name; 383 } 384 385 386 387 /** 388 * Retrieves the human-readable display name for this monitor attribute. 389 * 390 * @return The human-readable display name for this monitor attribute. 391 */ 392 public String getDisplayName() 393 { 394 return displayName; 395 } 396 397 398 399 /** 400 * Retrieves the human-readable description for this monitor attribute, if 401 * available. 402 * 403 * @return The human-readable description for this monitor attribute, or 404 * {@code null} if none is available. 405 */ 406 public String getDescription() 407 { 408 return description; 409 } 410 411 412 413 /** 414 * Retrieves the class representing the data type for this monitor attribute. 415 * It will be one of the following class types: Boolean, Date, Double, Long, 416 * or String. 417 * 418 * @return The class representing the data type for this monitor attribute. 419 */ 420 public Class<?> getDataType() 421 { 422 return dataType; 423 } 424 425 426 427 /** 428 * Indicates whether this monitor attribute has multiple values. 429 * 430 * @return {@code true} if this monitor attribute has more than one value, or 431 * {@code false} if not. 432 */ 433 public boolean hasMultipleValues() 434 { 435 return (values.length > 1); 436 } 437 438 439 440 /** 441 * Retrieves the value for this monitor attribute as an {@code Object}. If it 442 * has multiple values, then the first will be returned. 443 * 444 * @return The value for this monitor attribute as an {@code Object}. 445 */ 446 public Object getValue() 447 { 448 return values[0]; 449 } 450 451 452 453 /** 454 * Retrieves the set of values for this monitor attribute as a list of 455 * {@code Object}s. 456 * 457 * @return The set of values for this monitor attribute as a list of 458 * {@code Object}s. 459 */ 460 public List<Object> getValues() 461 { 462 return Collections.unmodifiableList(Arrays.asList(values)); 463 } 464 465 466 467 /** 468 * Retrieves the value for this monitor attribute as a {@code Boolean} object. 469 * 470 * @return The value for this monitor attribute as a {@code Boolean} object. 471 * 472 * @throws ClassCastException If the data type for this monitor attribute is 473 * not {@code Boolean}. 474 */ 475 public Boolean getBooleanValue() 476 throws ClassCastException 477 { 478 return (Boolean) values[0]; 479 } 480 481 482 483 /** 484 * Retrieves the value for this monitor attribute as a {@code Date} object. 485 * 486 * @return The value for this monitor attribute as a {@code Date} object. 487 * 488 * @throws ClassCastException If the data type for this monitor attribute is 489 * not {@code Date}. 490 */ 491 public Date getDateValue() 492 throws ClassCastException 493 { 494 return (Date) values[0]; 495 } 496 497 498 499 /** 500 * Retrieves the values for this monitor attribute as a list of {@code Date} 501 * objects. 502 * 503 * @return The values for this monitor attribute as a list of {@code Date} 504 * objects. 505 * 506 * @throws ClassCastException If the data type for this monitor attribute is 507 * not {@code Date}. 508 */ 509 public List<Date> getDateValues() 510 throws ClassCastException 511 { 512 return Collections.unmodifiableList(Arrays.asList((Date[]) values)); 513 } 514 515 516 517 /** 518 * Retrieves the value for this monitor attribute as a {@code Double} object. 519 * 520 * @return The value for this monitor attribute as a {@code Double} object. 521 * 522 * @throws ClassCastException If the data type for this monitor attribute is 523 * not {@code Double}. 524 */ 525 public Double getDoubleValue() 526 throws ClassCastException 527 { 528 return (Double) values[0]; 529 } 530 531 532 533 /** 534 * Retrieves the values for this monitor attribute as a list of {@code Double} 535 * objects. 536 * 537 * @return The values for this monitor attribute as a list of {@code Double} 538 * objects. 539 * 540 * @throws ClassCastException If the data type for this monitor attribute is 541 * not {@code Double}. 542 */ 543 public List<Double> getDoubleValues() 544 throws ClassCastException 545 { 546 return Collections.unmodifiableList(Arrays.asList((Double[]) values)); 547 } 548 549 550 551 /** 552 * Retrieves the value for this monitor attribute as an {@code Integer} 553 * object. 554 * 555 * @return The value for this monitor attribute as an {@code Integer} object. 556 * 557 * @throws ClassCastException If the data type for this monitor attribute is 558 * not {@code Integer}. 559 */ 560 public Integer getIntegerValue() 561 throws ClassCastException 562 { 563 return (Integer) values[0]; 564 } 565 566 567 568 /** 569 * Retrieves the values for this monitor attribute as a list of 570 * {@code Integer} objects. 571 * 572 * @return The values for this monitor attribute as a list of {@code Integer} 573 * objects. 574 * 575 * @throws ClassCastException If the data type for this monitor attribute is 576 * not {@code Integer}. 577 */ 578 public List<Integer> getIntegerValues() 579 throws ClassCastException 580 { 581 return Collections.unmodifiableList(Arrays.asList((Integer[]) values)); 582 } 583 584 585 586 /** 587 * Retrieves the value for this monitor attribute as a {@code Long} object. 588 * 589 * @return The value for this monitor attribute as a {@code Long} object. 590 * 591 * @throws ClassCastException If the data type for this monitor attribute is 592 * not {@code Long}. 593 */ 594 public Long getLongValue() 595 throws ClassCastException 596 { 597 return (Long) values[0]; 598 } 599 600 601 602 /** 603 * Retrieves the values for this monitor attribute as a list of {@code Long} 604 * objects. 605 * 606 * @return The values for this monitor attribute as a list of {@code Long} 607 * objects. 608 * 609 * @throws ClassCastException If the data type for this monitor attribute is 610 * not {@code Long}. 611 */ 612 public List<Long> getLongValues() 613 throws ClassCastException 614 { 615 return Collections.unmodifiableList(Arrays.asList((Long[]) values)); 616 } 617 618 619 620 /** 621 * Retrieves the value for this monitor attribute as a {@code String} object. 622 * 623 * @return The value for this monitor attribute as a {@code String} object. 624 * 625 * @throws ClassCastException If the data type for this monitor attribute is 626 * not {@code String}. 627 */ 628 public String getStringValue() 629 throws ClassCastException 630 { 631 return (String) values[0]; 632 } 633 634 635 636 /** 637 * Retrieves the values for this monitor attribute as a list of {@code String} 638 * objects. 639 * 640 * @return The values for this monitor attribute as a list of {@code String} 641 * objects. 642 * 643 * @throws ClassCastException If the data type for this monitor attribute is 644 * not {@code String}. 645 */ 646 public List<String> getStringValues() 647 throws ClassCastException 648 { 649 return Collections.unmodifiableList(Arrays.asList((String[]) values)); 650 } 651 652 653 654 /** 655 * Retrieves a string representation of this monitor attribute. 656 * 657 * @return A string representation of this monitor attribute. 658 */ 659 @Override() 660 public String toString() 661 { 662 final StringBuilder buffer = new StringBuilder(); 663 toString(buffer); 664 return buffer.toString(); 665 } 666 667 668 669 /** 670 * Appends a string representation of this monitor attribute to the provided 671 * buffer. 672 * 673 * @param buffer The buffer to which the string representation should be 674 * appended. 675 */ 676 public void toString(final StringBuilder buffer) 677 { 678 buffer.append("MonitorAttribute(name='"); 679 buffer.append(name); 680 buffer.append("', values={"); 681 682 for (int i=0; i < values.length; i++) 683 { 684 if (i > 0) 685 { 686 buffer.append(", "); 687 } 688 689 buffer.append('\''); 690 buffer.append(String.valueOf(values[i])); 691 buffer.append('\''); 692 } 693 694 buffer.append("})"); 695 } 696}