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