- Timestamp:
- 07/14/13 23:20:04 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/params/SimpleAbstractAccess.java
r100 r101 4 4 import static com.framsticks.util.lang.Containers.filterInstanceof; 5 5 6 import org.apache.logging.log4j.Logger;7 import org.apache.logging.log4j.LogManager;8 6 9 7 import com.framsticks.params.types.ObjectParam; 10 8 import com.framsticks.util.FramsticksException; 11 import static com.framsticks.params.SetStateFlags.*;12 9 13 10 /** … … 23 20 * @author Piotr Sniegowski 24 21 */ 25 public abstract class SimpleAbstractAccess implements Access { 26 27 private final static Logger log = LogManager.getLogger(SimpleAbstractAccess.class.getName()); 22 public abstract class SimpleAbstractAccess implements ObjectAccess { 28 23 29 24 protected final FramsClass framsClass; … … 40 35 return framsClass; 41 36 } 42 43 /**44 * Simple String key, value class.45 */46 public static class Entry {47 48 public final String key;49 public final String value;50 51 public Entry(String key, String value) {52 this.key = key;53 this.value = value;54 }55 56 @Override57 public String toString() {58 return key + " = " + value;59 }60 }61 62 37 63 38 @Override … … 129 104 130 105 @Override 131 public void setDefault(boolean numericOnly) {132 for (int i = 0; i < framsClass.getParamCount(); i++) {133 setDefault(i, numericOnly);134 }135 }136 137 @Override138 public void setDefault(int i, boolean numericOnly) {139 ValueParam entry = framsClass.getParamEntry(i, ValueParam.class);140 if ((entry != null) && (!numericOnly || entry.isNumeric())) {141 set(i, entry.getDef(entry.getStorageType()));142 }143 }144 145 @Override146 public void setMin() {147 for (int i = 0; i < framsClass.getParamCount(); i++) {148 setMin(i);149 }150 }151 152 @Override153 public void setMin(int i) {154 PrimitiveParam<?> entry = framsClass.getParamEntry(i, PrimitiveParam.class);155 Object min = entry.getMin(entry.getStorageType());156 if (min != null) {157 set(i, min);158 }159 }160 161 @Override162 public void setMax() {163 for (int i = 0; i < framsClass.getParamCount(); i++) {164 setMax(i);165 }166 }167 168 @Override169 public void setMax(int i) {170 PrimitiveParam<?> entry = framsClass.getParamEntry(i, PrimitiveParam.class);171 Object max = entry.getMax(entry.getStorageType());172 if (max != null) {173 set(i, max);174 }175 }176 177 @Override178 106 public void save(SinkInterface sink) { 179 107 assert framsClass != null; … … 189 117 } 190 118 sink.breakLine(); 191 }192 193 private static Entry readEntry(SourceInterface source) {194 195 String line;196 String key = null;197 StringBuilder value = null;198 while ((line = source.readLine()) != null) {199 if (key == null) {200 int colonIndex = line.indexOf(':');201 if (colonIndex == -1) {202 return null;203 }204 key = line.substring(0, colonIndex);205 String inlineValue = line.substring(colonIndex + 1);206 207 208 if (!inlineValue.startsWith("~")) {209 return new Entry(key, inlineValue);210 }211 value = new StringBuilder();212 value.append(inlineValue.substring(1));213 continue;214 }215 if (value.length() != 0) {216 value.append(System.getProperty("line.separator"));217 }218 if (line.endsWith("~") && !line.endsWith("\\~")) {219 value.append(line.substring(0, line.length() - 1));220 return new Entry(key, value.toString().replaceAll("\\\\~", "~"));221 }222 value.append(line);223 }224 return null;225 }226 227 @Override228 public void load(SourceInterface source) {229 //TODO not clearing values, because get from manager gives only fields, not children230 //this.clearValues();231 232 Entry entry;233 while ((entry = readEntry(source)) != null) {234 Param param = getParam(entry.key);235 if (param == null) {236 throw new FramsticksException().msg("param not found in access").arg("name", entry.key).arg("access", this);237 }238 if (!(param instanceof ValueParam)) {239 throw new FramsticksException().msg("param is not a value param").arg("param", param).arg("access", this);240 }241 if ((param.getFlags() & ParamFlags.DONTLOAD) == 0) {242 int retFlags = this.set((ValueParam) param, entry.value);243 if ((retFlags & (PSET_HITMIN | PSET_HITMAX)) != 0) {244 String which = ((retFlags & PSET_HITMIN) != 0) ? "small" : "big";245 log.warn("value of key '{}' was too {}, adjusted", entry.key, which);246 }247 }248 }249 119 } 250 120 … … 266 136 } 267 137 268 /*269 protected <T extends Comparable<T>> int setAndCut(Param param, Object value, Class<T> type) {270 int flags = 0;271 T val = type.cast(value);272 T min = param.getMin(type);273 T max = param.getMax(type);274 if (min != null && val.compareTo(min) < 0) {275 val = min;276 flags |= Flags.PSET_HITMIN;277 }278 if (max != null && val.compareTo(max) > 0) {279 val = max;280 flags |= Flags.PSET_HITMAX;281 }282 internalSet(param, val);283 return flags;284 }*/285 286 287 138 @Override 288 139 public ParamBuilder buildParam(ParamBuilder builder) {
Note: See TracChangeset
for help on using the changeset viewer.