001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2008 Sun Microsystems, Inc.
015 * Portions Copyright 2015 ForgeRock AS.
016 */
017package org.opends.server.admin;
018
019
020
021import java.util.ArrayList;
022import java.util.Arrays;
023import java.util.Collection;
024
025
026
027/**
028 * A default behavior provider which represents a well-defined set of default
029 * values. It should be used by properties which have default value(s) which are
030 * valid value(s) according to the constraints of the property's definition.
031 *
032 * @param <T>
033 *          The type of values represented by this provider.
034 */
035public final class DefinedDefaultBehaviorProvider<T> extends
036    DefaultBehaviorProvider<T> {
037
038  /** The collection of default values. */
039  private final Collection<String> values;
040
041
042
043  /**
044   * Create a new defined default behavior provider associated with the
045   * specified list of values.
046   *
047   * @param values
048   *          The list of values (must be non-<code>null</code> and not
049   *          empty) in their string representation.
050   * @throws IllegalArgumentException
051   *           If the list of values was <code>null</code> or empty.
052   */
053  public DefinedDefaultBehaviorProvider(String... values)
054      throws IllegalArgumentException {
055    if (values == null || values.length == 0) {
056      throw new IllegalArgumentException(
057          "Null or empty list of default values");
058    }
059    this.values = Arrays.asList(values);
060  }
061
062  /** {@inheritDoc} */
063  public <R, P> R accept(DefaultBehaviorProviderVisitor<T, R, P> v, P p) {
064    return v.visitDefined(this, p);
065  }
066
067  /**
068   * Get a copy of the default values.
069   *
070   * @return Returns a newly allocated collection containing a copy of the
071   *         default values.
072   */
073  public Collection<String> getDefaultValues() {
074    return new ArrayList<>(values);
075  }
076}