BaseConfig.java
Go to the documentation of this file.
00001 /*
00002 * Copyright (C) 2014 Mickael Gaillard. All rights reserved.
00003 *
00004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005 * use this file except in compliance with the License. You may obtain a copy of
00006 * the License at
00007 *
00008 * http://www.apache.org/licenses/LICENSE-2.0
00009 *
00010 * Unless required by applicable law or agreed to in writing, software
00011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013 * License for the specific language governing permissions and limitations under
00014 * the License.
00015 */
00016 
00017 package org.ros.dynamic_reconfigure.server;
00018 
00019 import org.ros.dynamic_reconfigure.DynamicReconfigureParameterException;
00020 import org.ros.dynamic_reconfigure.Utils;
00021 import org.ros.node.ConnectedNode;
00022 
00023 import dynamic_reconfigure.BoolParameter;
00024 import dynamic_reconfigure.Config;
00025 import dynamic_reconfigure.ConfigDescription;
00026 import dynamic_reconfigure.DoubleParameter;
00027 import dynamic_reconfigure.IntParameter;
00028 import dynamic_reconfigure.StrParameter;
00029 
00035 public abstract class BaseConfig {
00036 
00037     private Config currentConfig;
00038     private Utils utils;
00039 
00040     public BaseConfig(ConnectedNode connectedNode) {
00041         this.currentConfig = connectedNode.getTopicMessageFactory().newFromType(Config._TYPE);
00042         this.utils = new Utils(connectedNode, this.currentConfig);
00043     }
00044 
00045     public void merge (Config configBase) {
00046         for (BoolParameter paramBase : configBase.getBools()) {
00047             for (BoolParameter param : this.currentConfig.getBools()) {
00048                 if (paramBase.getName().equals(param.getName())) {
00049                     param.setValue(paramBase.getValue());
00050                 }
00051             }
00052         }
00053         for (DoubleParameter paramBase : configBase.getDoubles()) {
00054             for (DoubleParameter param : this.currentConfig.getDoubles()) {
00055                 if (paramBase.getName().equals(param.getName())) {
00056                     param.setValue(paramBase.getValue());
00057                 }
00058             }
00059         }
00060         for (IntParameter paramBase : configBase.getInts()) {
00061             for (IntParameter param : this.currentConfig.getInts()) {
00062                 if (paramBase.getName().equals(param.getName())) {
00063                     param.setValue(paramBase.getValue());
00064                 }
00065             }
00066         }
00067         for (StrParameter paramBase : configBase.getStrs()) {
00068             for (StrParameter param : this.currentConfig.getStrs()) {
00069                 if (paramBase.getName().equals(param.getName())) {
00070                     param.setValue(paramBase.getValue());
00071                 }
00072             }
00073         }
00074     }
00075 
00076     public String getString(String name, String defaultValue) {
00077         String result = defaultValue;
00078 
00079         for (StrParameter param : this.currentConfig.getStrs()) {
00080             if (param.getName().equals(name)) {
00081                 result = param.getValue();
00082                 break;
00083             }
00084         }
00085 
00086         return result;
00087     }
00088 
00089     public Boolean getBool(String name, boolean defaultValue) {
00090         Boolean result = defaultValue;
00091 
00092         for (BoolParameter param : this.currentConfig.getBools()) {
00093             if (param.getName().equals(name)) {
00094                 result = param.getValue();
00095                 break;
00096             }
00097         }
00098 
00099         return result;
00100 
00101     }
00102 
00103     public Integer getInteger(String name, int defaultValue) {
00104         Integer result = defaultValue;
00105 
00106         for (IntParameter param : this.currentConfig.getInts()) {
00107             if (param.getName().equals(name)) {
00108                 result = param.getValue();
00109                 break;
00110             }
00111         }
00112 
00113         return result;
00114 
00115     }
00116 
00117     public Double getDouble(String name, double defaultValue) {
00118         Double result = defaultValue;
00119 
00120         for (DoubleParameter param : this.currentConfig.getDoubles()) {
00121             if (param.getName().equals(name)) {
00122                 result = param.getValue();
00123                 break;
00124             }
00125         }
00126 
00127         return result;
00128 
00129     }
00130 
00131     public void setString(String name, String value) {
00132         StrParameter result = null;
00133 
00134         for (StrParameter param : this.currentConfig.getStrs()) {
00135             if (param.getName().equals(name)) {
00136                 param.setValue(value);
00137                 result = param;
00138                 break;
00139             }
00140         }
00141 
00142         if (result == null) {
00143             throw new DynamicReconfigureParameterException("Parameter "+name+" not found !");
00144         }
00145     }
00146 
00147     public void setBool(String name, boolean value) {
00148         BoolParameter result = null;
00149 
00150         for (BoolParameter param : this.currentConfig.getBools()) {
00151             if (param.getName().equals(name)) {
00152                 param.setValue(value);
00153                 result = param;
00154                 break;
00155             }
00156         }
00157 
00158         if (result == null) {
00159             throw new DynamicReconfigureParameterException("Parameter "+name+" not found !");
00160         }
00161     }
00162 
00163     public void setInteger(String name, int value) {
00164         IntParameter result = null;
00165 
00166         for (IntParameter param : this.currentConfig.getInts()) {
00167             if (param.getName().equals(name)) {
00168                 param.setValue(value);
00169                 result = param;
00170                 break;
00171             }
00172         }
00173 
00174         if (result == null) {
00175             throw new DynamicReconfigureParameterException("Parameter "+name+" not found !");
00176         }
00177     }
00178 
00179     public void setDouble(String name, double value) {
00180         DoubleParameter result = null;
00181 
00182         for (DoubleParameter param : this.currentConfig.getDoubles()) {
00183             if (param.getName().equals(name)) {
00184                 param.setValue(value);
00185                 result = param;
00186                 break;
00187             }
00188         }
00189 
00190         if (result == null) {
00191             throw new DynamicReconfigureParameterException("Parameter "+name+" not found !");
00192         }
00193     }
00194 
00195     public Config getCurrentConfig() {
00196         return this.currentConfig;
00197     }
00198 
00199     public ConfigDescription makeConfigDescription() {
00200         return this.utils.makeConfigDescription();
00201     }
00202 
00203     public void addField(
00204             String name,
00205             String type,
00206             int level,
00207             String description,
00208             Object defaulValue,
00209             int min,
00210             int max) {
00211         utils.addField(name, type, level, description, defaulValue, min, max);
00212     }
00213 }


rosjava_dynamic_reconfigure
Author(s): Mickaƫl Gaillard , Erwan Le Huitouze
autogenerated on Thu Jun 6 2019 22:01:52