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 import java.util.List;
023 import java.util.SortedSet;
024 import java.util.TreeSet;
025
026 import org.dllearner.utilities.datastructures.StringTuple;
027
028 /**
029 * A list if string tuples, for instance for specifying several parameters or
030 * replacement rules.
031 *
032 * @author Jens Lehmann
033 */
034 public class StringTupleListConfigOption extends ConfigOption<List<StringTuple>> {
035
036
037 public StringTupleListConfigOption(String name, String description, List<StringTuple> defaultValue, boolean mandatory, boolean requiresInit) {
038 super(name, description, defaultValue, mandatory, requiresInit);
039
040 }
041
042 public StringTupleListConfigOption(String name, String description, List<StringTuple> defaultValue) {
043 super(name, description, defaultValue);
044
045 }
046
047 public StringTupleListConfigOption(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 "List<StringTuple>";
058 }
059
060 /* (non-Javadoc)
061 * @see org.dllearner.core.config.ConfigOption#getJavaImports()
062 */
063 @Override
064 public SortedSet<String> getJavaImports() {
065 SortedSet<String> ret = new TreeSet<String>();
066 ret.add("java.util.List");
067 ret.add("org.dllearner.utilities.datastructures.StringTuple");
068 return ret;
069 }
070
071 /*
072 * (non-Javadoc)
073 *
074 * @see org.dllearner.core.config.ConfigOption#checkType(java.lang.Object)
075 */
076 @Override
077 public boolean checkType(Object object) {
078 if (!(object instanceof List<?>))
079 return false;
080
081 List<?> set = (List<?>) object;
082 for (Object element : set) {
083 if (!(element instanceof StringTuple))
084 return false;
085 }
086
087 return true;
088 }
089
090 /*
091 * (non-Javadoc)
092 *
093 * @see org.dllearner.core.config.ConfigOption#isValidValue(java.lang.Object)
094 */
095 @Override
096 public boolean isValidValue(List<StringTuple> value) {
097 return true;
098 }
099
100 /*
101 * (non-Javadoc)
102 *
103 * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object)
104 */
105 @Override
106 public String getValueFormatting(List<StringTuple> value) {
107 Integer count = 0;
108 if (value != null) {
109 String back = "[";
110 for (StringTuple i : value) {
111 if (count > 0)
112 back += ",";
113 back += "\n(\"" + i.a + "\",\"" + i.b + "\")";
114 count++;
115 }
116 back += "];";
117 return back;
118 } else
119 return null;
120 }
121
122 }