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