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