001    /**
002     * Copyright (C) 2007-2011, Jens Lehmann
003     *
004     * This file is part of DL-Learner.
005     *
006     * DL-Learner is free software; you can redistribute it and/or modify
007     * it under the terms of the GNU General Public License as published by
008     * the Free Software Foundation; either version 3 of the License, or
009     * (at your option) any later version.
010     *
011     * DL-Learner is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014     * GNU General Public License for more details.
015     *
016     * You should have received a copy of the GNU General Public License
017     * along with this program.  If not, see <http://www.gnu.org/licenses/>.
018     */
019    
020    package org.dllearner.core.options;
021    
022    
023    /**
024     * Represents a configuration option with values of type value. Similar to the
025     * integer option a minimum and a maximum value can specified.
026     * 
027     * @author Jens Lehmann
028     * 
029     */
030    public class DoubleConfigOption extends ConfigOption<Double> {
031    
032            private double lowerLimit = Double.MIN_VALUE;
033            private double upperLimit = Double.MAX_VALUE;
034    
035            public DoubleConfigOption(String name, String description, Double defaultValue) {
036                    super(name, description, defaultValue);
037                    
038            }
039    
040            public DoubleConfigOption(String name, String description) {
041                    super(name, description);
042                    
043            }
044    
045            /* (non-Javadoc)
046             * @see org.dllearner.core.config.ConfigOption#getValueTypeAsJavaString()
047             */
048            @Override
049            public String getValueTypeAsJavaString(){
050                    return "double";
051            }
052            
053            /*
054             * (non-Javadoc)
055             * 
056             * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object)
057             */
058            @Override
059            public boolean isValidValue(Double value) {
060                    double tolerance = 0.0001;
061                    return ((value >= lowerLimit-tolerance) && (value <= upperLimit+tolerance));
062            }
063    
064            /**
065             * @return the The lowest possible value for this configuration option.
066             */
067            public double getLowerLimit() {
068                    return lowerLimit;
069            }
070    
071            /**
072             * @param lowerLimit
073             *            The lowest possible value for this configuration option.
074             */
075            public void setLowerLimit(double lowerLimit) {
076                    this.lowerLimit = lowerLimit;
077            }
078    
079            /**
080             * @return the The highest possible value for this configuration option.
081             */
082            public double getUpperLimit() {
083                    return upperLimit;
084            }
085    
086            /**
087             * @param upperLimit
088             *            The highest possible value for this configuration option.
089             */
090            public void setUpperLimit(double upperLimit) {
091                    this.upperLimit = upperLimit;
092            }
093    
094            /*
095             * (non-Javadoc)
096             * 
097             * @see org.dllearner.core.ConfigOption#checkType(java.lang.Object)
098             */
099            @Override
100            public boolean checkType(Object object) {
101                    return (object instanceof Double);
102            }
103    
104            @Override
105            public String getAllowedValuesDescription() {
106                    String str = getValueTypeAsJavaString()+" ";//getClass().toString();
107                    if (lowerLimit != Double.MIN_VALUE)
108                            str += " min " + lowerLimit;
109                    if (upperLimit != Double.MAX_VALUE)
110                            str += " max " + upperLimit;
111                    return str;
112            }
113    
114            /*
115             * (non-Javadoc)
116             * 
117             * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object)
118             */
119            @Override
120            public String getValueFormatting(Double value) {
121                    if (value != null)
122                            return value.toString() + ";";
123                    else
124                            return null;
125            }
126    
127    }