001    /**
002     * Copyright (C) 2007, 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    
021    package org.dllearner.cli;
022    
023    import java.util.List;
024    import java.util.Set;
025    
026    import org.dllearner.utilities.datastructures.StringTuple;
027    
028    /**
029     * Represents one configuration option in a conf file, e.g.
030     * refinement.horizontalExpansionFactor = 0.6.
031     * 
032     * @author Jens Lehmann
033     *
034     */
035    public class ConfFileOption {
036    
037            private boolean containsSubOption = true;
038            private boolean isIntegerOption = false;
039            private boolean isDoubleOption = false;
040            private boolean isStringOption = false;
041            private boolean isSetOption = false;
042            private boolean isListOption = false;
043            private String option;
044            private String subOption;
045            private String stringValue;
046            private int intValue;
047            private double doubleValue;
048            private Set<String> setValues;
049            private List<StringTuple> listTuples;
050            
051            public ConfFileOption(String option, String value) {
052                    this(option, null, value);
053                    containsSubOption = false;
054            }
055            
056            public ConfFileOption(String option, String subOption, String value) {
057                    this.option = option;
058                    this.subOption = subOption;
059                    stringValue = value;
060                    isStringOption = true;
061            }
062            
063            public ConfFileOption(String option, int value) {
064                    this(option, null, value);
065                    containsSubOption = false;
066            }
067            
068            public ConfFileOption(String option, String subOption, int value) {
069                    this.option = option;
070                    this.subOption = subOption;
071                    intValue = value;
072                    isIntegerOption = true;
073            }
074    
075            public ConfFileOption(String option, double value) {
076                    this(option, null, value);
077                    containsSubOption = false;
078            }
079            
080            public ConfFileOption(String option, String subOption, double value) {
081                    this.option = option;
082                    this.subOption = subOption;
083                    doubleValue = value;
084                    isDoubleOption = true;
085            }
086            
087            public ConfFileOption(String option, Set<String> values) {
088                    this(option, null, values);
089                    containsSubOption = false;
090            }
091            
092            public ConfFileOption(String option, String subOption, Set<String> values) {
093                    this.option = option;
094                    this.subOption = subOption;
095                    isSetOption = true;
096                    setValues = values;
097            }
098            
099            public ConfFileOption(String option, List<StringTuple> tuples) {
100                    this(option, null, tuples);
101                    containsSubOption = false;
102            }
103            
104            public ConfFileOption(String option, String subOption, List<StringTuple> tuples) {
105                    this.option = option;
106                    this.subOption = subOption;
107                    isListOption = true;
108                    listTuples = tuples;
109            }       
110            
111            public boolean containsSubOption() {
112                    return containsSubOption;
113            }
114    
115            public int getIntValue() {
116                    return intValue;
117            }
118            
119            public String getOption() {
120                    return option;
121            }
122    
123            public String getStringValue() {
124                    return stringValue;
125            }
126    
127            public String getSubOption() {
128                    return subOption;
129            }
130            
131            public double getDoubleValue() {
132                    return doubleValue;
133            }
134    
135            public Set<String> getSetValues() {
136                    return setValues;
137            }       
138            
139            public List<StringTuple> getListTuples() {
140                    return listTuples;
141            }
142            
143            public Object getValue() {
144                    if(isIntegerOption)
145                            return intValue;
146                    else if(isDoubleOption)
147                            return doubleValue;
148                    else if(isStringOption)
149                            return stringValue;
150                    else if(isSetOption)
151                            return setValues;
152                    else
153                            return listTuples;
154            }
155                    
156            /**
157             * 
158             * @return The class of the value of the conf file option;
159             */
160            public Class<?> getType() {
161                    if(isIntegerOption)
162                            return Integer.class;
163                    else if(isDoubleOption)
164                            return Double.class;
165                    else if(isStringOption)
166                            return String.class;
167                    else
168                            return Set.class;               
169            }
170            
171            public boolean isIntegerOption() {
172                    return isIntegerOption;
173            }
174    
175            public boolean isDoubleOption() {
176                    return isDoubleOption;
177            }
178            
179            public boolean isNumeric() {
180                    return (isIntegerOption || isDoubleOption);
181            }
182            
183            public boolean isStringOption() {
184                    return isStringOption;
185            }       
186            
187            public boolean isSetOption() {
188                    return isSetOption;
189            }       
190            
191            public boolean isListOption() {
192                    return isListOption;
193            }       
194            
195            @Override
196            public String toString() {
197                    String completeOption = "Configuration Option: ";
198                    if(containsSubOption)
199                            completeOption += option + "." + subOption;
200                    else
201                            completeOption += option;
202                    if(isNumeric())
203                            if(isIntegerOption)
204                                    return completeOption + "=" + intValue;
205                            else
206                                    return completeOption + "=" + doubleValue;
207                    else
208                            return completeOption + "=" + stringValue;
209            }
210            
211            public String getFullName() {
212                    if(containsSubOption)
213                            return option + "." + subOption;
214                    else
215                            return option;
216            }
217    
218    }