001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.math3.ode; 018 019import java.util.ArrayList; 020import java.util.Collection; 021 022/** This abstract class provides boilerplate parameters list. 023 * 024 * @since 3.0 025 */ 026 027public abstract class AbstractParameterizable implements Parameterizable { 028 029 /** List of the parameters names. */ 030 private final Collection<String> parametersNames; 031 032 /** Simple constructor. 033 * @param names names of the supported parameters 034 */ 035 protected AbstractParameterizable(final String ... names) { 036 parametersNames = new ArrayList<String>(); 037 for (final String name : names) { 038 parametersNames.add(name); 039 } 040 } 041 042 /** Simple constructor. 043 * @param names names of the supported parameters 044 */ 045 protected AbstractParameterizable(final Collection<String> names) { 046 parametersNames = new ArrayList<String>(); 047 parametersNames.addAll(names); 048 } 049 050 /** {@inheritDoc} */ 051 public Collection<String> getParametersNames() { 052 return parametersNames; 053 } 054 055 /** {@inheritDoc} */ 056 public boolean isSupported(final String name) { 057 for (final String supportedName : parametersNames) { 058 if (supportedName.equals(name)) { 059 return true; 060 } 061 } 062 return false; 063 } 064 065 /** Check if a parameter is supported and throw an IllegalArgumentException if not. 066 * @param name name of the parameter to check 067 * @exception UnknownParameterException if the parameter is not supported 068 * @see #isSupported(String) 069 */ 070 public void complainIfNotSupported(final String name) 071 throws UnknownParameterException { 072 if (!isSupported(name)) { 073 throw new UnknownParameterException(name); 074 } 075 } 076 077}