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 * A configuration option, which allows values of type integer. A minimum and
025 * maximum value of the argument can optionally be specified.
026 *
027 * @author Jens Lehmann
028 *
029 */
030 public class IntegerConfigOption extends ConfigOption<Integer> {
031
032 private int lowerLimit = Integer.MIN_VALUE;
033 private int upperLimit = Integer.MAX_VALUE;
034
035
036
037 public IntegerConfigOption(String name, String description, Integer defaultValue, boolean mandatory, boolean requiresInit) {
038 super(name, description, defaultValue, mandatory, requiresInit);
039
040 }
041
042 public IntegerConfigOption(String name, String description, Integer defaultValue) {
043 super(name, description, defaultValue);
044
045 }
046
047 public IntegerConfigOption(String name, String description) {
048 super(name, description);
049
050 }
051
052 /* (non-Javadoc)
053 * @see org.dllearner.core.config.ConfigOption#getValueTypeAsJavaString()
054 */
055 @Override
056 public String getValueTypeAsJavaString(){
057 return "int";
058 }
059
060 /*
061 * (non-Javadoc)
062 *
063 * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object)
064 */
065 @Override
066 public boolean isValidValue(Integer value) {
067 if (value >= lowerLimit && value <= upperLimit)
068 return true;
069 else
070 return false;
071 }
072
073 /**
074 * @return the The lowest possible value for this configuration option.
075 */
076 public int getLowerLimit() {
077 return lowerLimit;
078 }
079
080 /**
081 * @param lowerLimit
082 * The lowest possible value for this configuration option.
083 */
084 public void setLowerLimit(int lowerLimit) {
085 this.lowerLimit = lowerLimit;
086 }
087
088 /**
089 * @return the The highest possible value for this configuration option.
090 */
091 public int getUpperLimit() {
092 return upperLimit;
093 }
094
095 /**
096 * @param upperLimit
097 * The highest possible value for this configuration option.
098 */
099 public void setUpperLimit(int upperLimit) {
100 this.upperLimit = upperLimit;
101 }
102
103 /*
104 * (non-Javadoc)
105 *
106 * @see org.dllearner.core.ConfigOption#checkType(java.lang.Object)
107 */
108 @Override
109 public boolean checkType(Object object) {
110 return (object instanceof Integer);
111 }
112
113 @Override
114 public String getAllowedValuesDescription() {
115 String str = getValueTypeAsJavaString()+" ";
116 if (lowerLimit != Integer.MIN_VALUE)
117 str += " min " + lowerLimit;
118 if (upperLimit != Integer.MAX_VALUE)
119 str += " max " + upperLimit;
120 return str;
121 }
122
123 /*
124 * (non-Javadoc)
125 *
126 * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object)
127 */
128 @Override
129 public String getValueFormatting(Integer value) {
130 if (value != null)
131 return value.toString() + ";";
132 else
133 return null;
134 }
135 }