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-2016 ForgeRock AS. 016 */ 017package org.forgerock.opendj.config; 018 019import java.util.ArrayList; 020import java.util.Arrays; 021import java.util.Collection; 022 023/** 024 * A default behavior provider which represents a well-defined set of default 025 * values. It should be used by properties which have default value(s) which are 026 * valid value(s) according to the constraints of the property's definition. 027 * 028 * @param <T> 029 * The type of values represented by this provider. 030 */ 031public final class DefinedDefaultBehaviorProvider<T> extends DefaultBehaviorProvider<T> { 032 033 /** The collection of default values. */ 034 private final Collection<String> values; 035 036 /** 037 * Create a new defined default behavior provider associated with the 038 * specified list of values. 039 * 040 * @param values 041 * The list of values (must be non-<code>null</code> and not 042 * empty) in their string representation. 043 * @throws IllegalArgumentException 044 * If the list of values was <code>null</code> or empty. 045 */ 046 public DefinedDefaultBehaviorProvider(String... values) { 047 if (values == null || values.length == 0) { 048 throw new IllegalArgumentException("Null or empty list of default values"); 049 } 050 this.values = Arrays.asList(values); 051 } 052 053 @Override 054 public <R, P> R accept(DefaultBehaviorProviderVisitor<T, R, P> v, P p) { 055 return v.visitDefined(this, p); 056 } 057 058 /** 059 * Get a copy of the default values. 060 * 061 * @return Returns a newly allocated collection containing a copy of the 062 * default values. 063 */ 064 public Collection<String> getDefaultValues() { 065 return new ArrayList<>(values); 066 } 067 068}