Changeset 99 for java/main/src/main/java/com/framsticks/params
- Timestamp:
- 07/10/13 22:41:02 (11 years ago)
- Location:
- java/main/src/main/java/com/framsticks/params
- Files:
-
- 3 added
- 1 deleted
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/params/AccessInterface.java
r98 r99 2 2 3 3 4 import com.framsticks.params.types.EventParam; 4 5 import com.framsticks.params.types.ProcedureParam; 5 6 … … 39 40 <T> int set(ValueParam param, T value); 40 41 42 void reg(EventParam param, EventListener<?> listener); 43 44 void regRemove(EventParam param, EventListener<?> listener); 45 41 46 void setDefault(boolean numericOnly); 42 47 … … 50 55 51 56 void setMax(int i); 52 53 void copyFrom(AccessInterface src);54 57 55 58 void save(SinkInterface sink); … … 80 83 CompositeParam getCompositeParam(int number); 81 84 85 ParamBuilder buildParam(ParamBuilder builder); 86 82 87 83 88 } -
java/main/src/main/java/com/framsticks/params/ArrayListAccess.java
r98 r99 1 1 package com.framsticks.params; 2 2 3 import com.framsticks.params.types.ArrayListParam; 3 4 import com.framsticks.util.UnimplementedException; 4 5 import com.framsticks.util.lang.Numbers; … … 15 16 16 17 List<Object> list; 18 17 19 18 20 public ArrayListAccess(AccessInterface elementAccess) { … … 35 37 return null; 36 38 } 37 return Param.build().id(Integer.toString(i)).forAccess(elementAccess).finish(CompositeParam.class);39 return paramBuilder.id(Integer.toString(i)).finish(CompositeParam.class); 38 40 } 39 41 … … 109 111 } 110 112 111 @Override112 public String computeIdentifierFor(Object selected) {113 return Integer.toString(list.size());114 }115 113 116 114 @Override … … 131 129 @Override 132 130 public Param next() { 133 Param param = Param.build().id(Integer.toString(internal.nextIndex())).forAccess(elementAccess).finish();131 Param param = paramBuilder.id(Integer.toString(internal.nextIndex())).finish(CompositeParam.class); 134 132 internal.next(); 135 133 return param; … … 156 154 } 157 155 156 @Override 157 public ParamBuilder buildParam(ParamBuilder builder) { 158 return builder.name(containedTypeName + " list").type(ArrayListParam.class).containedTypeName(containedTypeName); 159 } 158 160 159 161 } -
java/main/src/main/java/com/framsticks/params/FramsClass.java
r98 r99 5 5 import com.framsticks.util.FramsticksException; 6 6 import com.framsticks.util.lang.Containers; 7 import com.framsticks.util.lang.Strings; 7 8 // import com.framsticks.util.FramsticksException; 8 9 … … 60 61 61 62 this.id = builder.getId(); 62 this.name = builder.getName();63 this.name = Strings.toStringEmptyProof(builder.getName(), this.id); 63 64 this.description = builder.getDescription(); 64 65 this.groups = Containers.build(builder.groupBuilders); -
java/main/src/main/java/com/framsticks/params/FramsClassBuilder.java
r98 r99 40 40 41 41 public static ParamBuilder induceParamType(ParamBuilder builder, Type type) { 42 // if (type.equals(Void.TYPE)) { 43 // throw new ConstructionException().msg("void is not a valid type"); 44 // } 42 45 43 46 if (type instanceof ParameterizedType) { … … 47 50 //TODO make implementation here 48 51 boolean map = false; 52 StringBuilder b = new StringBuilder(); 49 53 if (rawType.equals(Map.class)) { 50 54 containedType = p.getActualTypeArguments()[1]; 51 55 map = true; 56 b.append("l"); 52 57 } else if (rawType.equals(List.class)) { 53 58 containedType = p.getActualTypeArguments()[0]; 59 b.append("l"); 60 } else if (rawType.equals(EventListener.class)) { 61 containedType = p.getActualTypeArguments()[0]; 62 b.append("e"); 54 63 } 55 64 if (!(containedType instanceof Class)) { 56 65 return builder; 57 66 } 67 b.append(" "); 68 58 69 Class<?> containedClass = (Class<?>) containedType; 59 StringBuilder b = new StringBuilder();60 b.append("l ");61 70 FramsClassAnnotation fca = containedClass.getAnnotation(FramsClassAnnotation.class); 62 71 if (fca == null) { 63 log.error("the class is not annotated: " + containedClass); 64 return builder; 72 throw new ConstructionException().msg("the contained class is not annotated").arg("class", containedClass); 65 73 } 66 74 b.append(getName(fca, containedClass)); 75 //TODO parametrize this 67 76 if (map) { 68 77 b.append(" name"); … … 109 118 return builder; 110 119 } 120 111 121 112 122 // builder.type("o " + (cl).getCanonicalName()); … … 174 184 } 175 185 if (argsNum == 1) { 176 return n.startsWith("set") ? Strings.uncapitalize(n.substring(3)) : n; 186 if (n.startsWith("set")) { 187 return Strings.uncapitalize(n.substring(3)); 188 } 189 if (n.startsWith("add")) { 190 return Strings.uncapitalize(n.substring(3)); 191 } 192 if (n.startsWith("remove")) { 193 return Strings.uncapitalize(n.substring(6)); 194 } 195 return n; 177 196 } 178 197 log.error("invalid number of arguments"); -
java/main/src/main/java/com/framsticks/params/InvalidOperationException.java
r90 r99 1 1 package com.framsticks.params; 2 2 3 import com.framsticks.util. FramsticksException;3 import com.framsticks.util.UnsupportedOperationException; 4 4 5 5 @SuppressWarnings("serial") 6 public class InvalidOperationException extends FramsticksException {6 public class InvalidOperationException extends UnsupportedOperationException { 7 7 8 8 } -
java/main/src/main/java/com/framsticks/params/ListAccess.java
r97 r99 5 5 import static com.framsticks.util.lang.Containers.filterInstanceof; 6 6 7 import com.framsticks.params.types.EventParam; 7 8 import com.framsticks.params.types.ProcedureParam; 8 9 … … 13 14 14 15 final AccessInterface elementAccess; 16 final String containedTypeName; 17 18 protected final ParamBuilder paramBuilder; 15 19 16 20 public ListAccess(AccessInterface elementAccess) { 17 21 this.elementAccess = elementAccess; 22 this.containedTypeName = elementAccess.getId(); 23 paramBuilder = elementAccess.buildParam(new ParamBuilder()); 18 24 } 19 25 … … 48 54 49 55 @Override 50 public void copyFrom(AccessInterface src) {51 }52 53 @Override54 56 public void save(SinkInterface sink) { 55 57 for (CompositeParam p : filterInstanceof(getParams(), CompositeParam.class)) { … … 70 72 } 71 73 72 public abstract String computeIdentifierFor(Object selected); 74 /** 75 * @return the containedTypeName 76 */ 77 public String getContainedTypeName() { 78 return containedTypeName; 79 } 73 80 74 81 @Override … … 85 92 @Override 86 93 public Object call(String id, Object[] arguments) { 87 throw new InvalidOperationException().msg("list access does not support calling methods").arg("id", id) ;94 throw new InvalidOperationException().msg("list access does not support calling methods").arg("id", id).arg("access", this); 88 95 } 89 96 90 97 @Override 91 98 public Object call(ProcedureParam param, Object[] arguments) { 92 throw new InvalidOperationException().msg("list access does not support calling methods").arg("param", param) ;99 throw new InvalidOperationException().msg("list access does not support calling methods").arg("param", param).arg("access", this); 93 100 } 94 101 102 @Override 103 public void reg(EventParam param, EventListener<?> listener) { 104 throw new InvalidOperationException().msg("list access does not support registering events").arg("param", param).arg("access", this); 105 } 106 107 @Override 108 public void regRemove(EventParam param, EventListener<?> listener) { 109 throw new InvalidOperationException().msg("list access does not support registering events").arg("param", param).arg("access", this); 110 } 111 112 113 @Override 114 public String toString() { 115 StringBuilder b = new StringBuilder(); 116 b.append("list of ").append(containedTypeName); 117 if (getSelected() != null) { 118 b.append("[").append(getParamCount()).append("]"); 119 } 120 return b.toString(); 121 } 95 122 }; -
java/main/src/main/java/com/framsticks/params/Param.java
r96 r99 97 97 98 98 public boolean isUserHidden() { 99 return (flags & Flags.USERHIDDEN) != 0;99 return (flags & ParamFlags.USERHIDDEN) != 0; 100 100 } 101 101 -
java/main/src/main/java/com/framsticks/params/ParamBuilder.java
r97 r99 7 7 import com.framsticks.util.FramsticksException; 8 8 import com.framsticks.util.Misc; 9 import com.framsticks.util.lang.FlagsUtil; 9 10 import com.framsticks.util.lang.Strings; 10 11 … … 66 67 private int extra = 0; 67 68 68 String containedTypeName; 69 protected String containedTypeName; 70 71 protected String eventArgumentTypeName; 69 72 70 73 protected Class<?> storageType; … … 116 119 } 117 120 121 public ParamBuilder containedTypeName(String containedTypeName) { 122 this.containedTypeName = containedTypeName; 123 return this; 124 } 125 118 126 /** 119 127 * @return the resultType … … 160 168 public String getUid() { 161 169 return uid; 170 } 171 172 public ParamBuilder uid(String uid) { 173 this.uid = uid; 174 return this; 162 175 } 163 176 … … 322 335 case 'e': { 323 336 type(EventParam.class); 324 break; 325 } 326 case 'l': { 327 containedTypeName = second; 328 if (third != null) { 329 type(UniqueListParam.class); 330 uid = third; 331 } else { 332 type(ArrayListParam.class); 333 } 334 break; 335 } 336 default:{ 337 log.error("unknown type: " + first); 338 return this; 339 } 340 } 337 eventArgumentTypeName(second); 338 break; 339 } 340 case 'l': { 341 containedTypeName = second; 342 if (third != null) { 343 type(UniqueListParam.class); 344 uid = third; 345 } else { 346 type(ArrayListParam.class); 347 } 348 break; 349 } 350 default: { 351 log.error("unknown type: " + first); 352 return this; 353 } 354 } 355 return this; 356 } 357 358 public ParamBuilder eventArgumentTypeName(String eventArgumentTypeName) { 359 this.eventArgumentTypeName = eventArgumentTypeName; 341 360 return this; 342 361 } … … 438 457 id(paramEntryValues[0]); 439 458 group(Integer.valueOf(paramEntryValues[1])); 440 flags(Flags .read(paramEntryValues[2]));459 flags(FlagsUtil.read(ParamFlags.class, paramEntryValues[2])); 441 460 name(paramEntryValues[3]); 442 461 type(paramEntryValues[4]); … … 464 483 break; 465 484 case FLAGS_FIELD: 466 flags(Flags .read(value));485 flags(FlagsUtil.read(ParamFlags.class, value)); 467 486 break; 468 487 case HELP_FIELD: … … 492 511 } 493 512 513 /** 514 * @return the eventArgumentTypeName 515 */ 516 public String getEventArgumentTypeName() { 517 return eventArgumentTypeName; 518 } 519 494 520 public Class<?> getStorageType() { 495 521 return storageType; 496 }497 498 public ParamBuilder forAccess(AccessInterface access) {499 return name(access.getId()).type("o " + access.getId());500 522 } 501 523 -
java/main/src/main/java/com/framsticks/params/ParamCandidate.java
r90 r99 73 73 protected final OneTime<Method> getter = new OneTime<>("getter"); 74 74 protected final OneTime<Method> caller = new OneTime<>("caller"); 75 protected final OneTime<Method> adder = new OneTime<>("adder"); 76 protected final OneTime<Method> remover = new OneTime<>("remover"); 75 77 76 78 protected final List<ParamAnnotation> annotations = new LinkedList<>(); … … 142 144 143 145 /** 146 * @return the getter 147 */ 148 public Method getAdder() { 149 return adder.get(); 150 } 151 152 /** 153 * @return the getter 154 */ 155 public Method getRemover() { 156 return remover.get(); 157 } 158 159 /** 144 160 * @return the annotations 145 161 */ … … 150 166 void validate() throws ConstructionException { 151 167 try { 168 if (adder.has() != remover.has()) { 169 throw new ConstructionException().msg("only one of event manipulator methods is defined"); 170 } 171 if (adder.has() && remover.has()) { 172 return; 173 } 152 174 if (caller.has()) { 153 175 if (!isPublic(caller)) { … … 174 196 throw new ConstructionException().msg("missing getter or field"); 175 197 } 198 if (getter.has() || field.has() || setter.has()) { 199 if (type.get().equals(Void.TYPE)) { 200 throw new ConstructionException().msg("type of field is void"); 201 } 202 } 176 203 } catch (ConstructionException e) { 177 204 throw e.arg("in", this); … … 183 210 return false; 184 211 } 212 if (adder.has() || remover.has()) { 213 return false; 214 } 185 215 if (Collection.class.isAssignableFrom(getRawType())) { 186 216 return false; … … 197 227 boolean isReadOnly() { 198 228 if (caller.has()) { 229 return false; 230 } 231 if (adder.has() || remover.has()) { 199 232 return false; 200 233 } … … 229 262 } 230 263 Type[] ps = m.getGenericParameterTypes(); 264 Class<?>[] pts = m.getParameterTypes(); 231 265 if (ps.length == 0) { 266 if (m.getReturnType().equals(Void.TYPE)) { 267 throw new ConstructionException().msg("failed to add getter of void return type"); 268 } 232 269 getter.set(m); 233 270 setType(m.getGenericReturnType()); … … 235 272 } 236 273 if (ps.length == 1) { 274 if (pts[0].equals(EventListener.class)) { 275 if (member.getName().startsWith("add")) { 276 adder.set(m); 277 setType(ps[0]); 278 return; 279 } 280 if (member.getName().startsWith("remove")) { 281 remover.set(m); 282 setType(ps[0]); 283 return; 284 } 285 throw new ConstructionException().msg("invalid name of event manipulator").arg("method", m).arg("in", this); 286 } 237 287 setter.set(m); 238 288 setType(ps[0]); … … 251 301 int f = 0; 252 302 if (isReadOnly()) { 253 f |= Flags.READONLY;303 f |= ParamFlags.READONLY; 254 304 } 255 305 return f; -
java/main/src/main/java/com/framsticks/params/PropertiesAccess.java
r96 r99 4 4 import java.util.Map; 5 5 6 import com.framsticks.params.types.EventParam; 6 7 import com.framsticks.params.types.ProcedureParam; 7 8 … … 97 98 @Override 98 99 public Object call(String id, Object[] arguments) { 99 throw new InvalidOperationException().msg(" listaccess does not support calling methods").arg("id", id);100 throw new InvalidOperationException().msg("properties access does not support calling methods").arg("id", id); 100 101 } 101 102 102 103 @Override 103 104 public Object call(ProcedureParam param, Object[] arguments) { 104 throw new InvalidOperationException().msg("list access does not support calling methods").arg("param", param); 105 throw new InvalidOperationException().msg("properties access does not support calling methods").arg("param", param); 106 } 107 108 @Override 109 public void reg(EventParam param, EventListener<?> listener) { 110 throw new InvalidOperationException().msg("properties access does not support registering events").arg("param", param).arg("access", this); 111 } 112 113 @Override 114 public void regRemove(EventParam param, EventListener<?> listener) { 115 throw new InvalidOperationException().msg("properties access does not support registering events").arg("param", param).arg("access", this); 105 116 } 106 117 -
java/main/src/main/java/com/framsticks/params/ReflectionAccess.java
r98 r99 17 17 18 18 import com.framsticks.params.annotations.AutoAppendAnnotation; 19 import com.framsticks.params.types.EventParam; 19 20 import com.framsticks.params.types.ProcedureParam; 20 21 import com.framsticks.util.FramsticksException; … … 57 58 } 58 59 60 public interface ReflectedAdder{ 61 public void reg(Object object, EventListener<?> listener) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException; 62 } 63 64 public interface ReflectedRemover{ 65 public void regRemove(Object object, EventListener<?> listener) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException; 66 } 67 59 68 protected final Map<ValueParam, ReflectedSetter> setters = new IdentityHashMap<>(); 60 69 protected final Map<ValueParam, ReflectedGetter> getters = new IdentityHashMap<>(); 61 70 protected final Map<ProcedureParam, ReflectedCaller> callers = new IdentityHashMap<>(); 71 protected final Map<EventParam, ReflectedAdder> adders = new IdentityHashMap<>(); 72 protected final Map<EventParam, ReflectedRemover> removers = new IdentityHashMap<>(); 73 62 74 protected final List<Method> autoAppendMethods = new ArrayList<>(); 63 75 … … 100 112 } 101 113 114 for (final EventParam ep : filterInstanceof(framsClass.getParamEntries(), EventParam.class)) { 115 if (!candidates.containsKey(ep.getId())) { 116 log.trace("java class does not implement the event param " + ep); 117 continue; 118 } 119 ParamCandidate ec = candidates.get(ep.getId()); 120 final Method adder = ec.getAdder(); 121 final Method remover = ec.getRemover(); 122 123 backend.adders.put(ep, new ReflectedAdder() { 124 125 @Override 126 public void reg(Object object, EventListener<?> listener) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { 127 adder.invoke(object, listener); 128 } 129 }); 130 131 backend.removers.put(ep, new ReflectedRemover() { 132 133 @Override 134 public void regRemove(Object object, EventListener<?> listener) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { 135 remover.invoke(object, listener); 136 } 137 }); 138 } 139 102 140 for (final ValueParam vp : filterInstanceof(framsClass.getParamEntries(), ValueParam.class)) { 103 141 if (!candidates.containsKey(vp.getId())) { … … 105 143 } 106 144 ParamCandidate pc = candidates.get(vp.getId()); 107 if (pc.isReadOnly() && !vp.hasFlag( Flags.READONLY)) {145 if (pc.isReadOnly() && !vp.hasFlag(ParamFlags.READONLY)) { 108 146 throw new ConstructionException().msg("readonly state conflict").arg("param", vp); 109 147 } … … 200 238 } 201 239 202 public ReflectionAccess(Class<?> reflectedClass) throws ConstructionException {203 this(reflectedClass, FramsClass.build().forClass(reflectedClass));204 }205 206 240 public static boolean typeMatch(Class<?> a, Class<?> b) { 207 assert !b.isPrimitive(); 241 if (b.isPrimitive()) { 242 throw new FramsticksException().msg("failed to match type, right argument is primitive").arg("left", a).arg("right", b); 243 } 208 244 if (!a.isPrimitive()) { 209 245 return a.equals(b); … … 219 255 return b.equals(Boolean.class); 220 256 } 221 assert false; 222 return false; 223 } 224 225 public ReflectionAccess(Class<?> reflectedClass, FramsClass framsClass) throws ConstructionException { 257 throw new FramsticksException().msg("failed to match types").arg("left", a).arg("right", b); 258 } 259 260 261 262 263 public ReflectionAccess(Class<?> javaClass) throws ConstructionException { 264 this(javaClass, FramsClass.build().forClass(javaClass)); 265 } 266 267 268 public ReflectionAccess(Class<?> javaClass, FramsClass framsClass) throws ConstructionException { 269 this(javaClass, framsClass, Backend.getOrCreateFor(javaClass, framsClass)); 270 } 271 272 protected ReflectionAccess(Class<?> javaClass, FramsClass framsClass, Backend backend) throws ConstructionException { 226 273 super(framsClass); 227 this.javaClass = reflectedClass; 228 this.backend = Backend.getOrCreateFor(reflectedClass, framsClass); 229 } 230 274 this.javaClass = javaClass; 275 this.backend = backend; 276 } 277 278 @Override 279 public ReflectionAccess cloneAccess() throws ConstructionException { 280 return new ReflectionAccess(javaClass, framsClass, backend); 281 } 231 282 232 283 @Override … … 268 319 } catch (FramsticksException e) { 269 320 throw e.arg("param", param).arg("value", value).arg("access", this); 321 } 322 } 323 324 @Override 325 public void reg(EventParam param, EventListener<?> listener) { 326 try { 327 try { 328 if (object == null) { 329 throw new FramsticksException().msg("no object set"); 330 } 331 332 backend.adders.get(param).reg(object, listener); 333 return; 334 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { 335 throw new FramsticksException().msg("failed to add listener").cause(e); 336 } 337 } catch (FramsticksException e) { 338 throw e.arg("param", param).arg("access", this); 339 } 340 } 341 342 @Override 343 public void regRemove(EventParam param, EventListener<?> listener) { 344 try { 345 try { 346 if (object == null) { 347 throw new FramsticksException().msg("no object set"); 348 } 349 350 backend.removers.get(param).regRemove(object, listener); 351 return; 352 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { 353 throw new FramsticksException().msg("failed to remove listener").cause(e); 354 } 355 } catch (FramsticksException e) { 356 throw e.arg("param", param).arg("access", this); 270 357 } 271 358 } … … 352 439 } 353 440 354 @Override355 public ReflectionAccess cloneAccess() throws ConstructionException {356 return new ReflectionAccess(javaClass, framsClass);357 }358 441 359 442 @Override … … 368 451 } 369 452 370 @Override371 public String toString() {372 StringBuilder b = new StringBuilder();373 b.append(framsClass);374 if (object != null) {375 b.append("(").append(object).append(")");376 }377 return b.toString();378 }379 453 380 454 @Override -
java/main/src/main/java/com/framsticks/params/Registry.java
r98 r99 46 46 register(javaClass); 47 47 associate(javaClass, putFramsClass(FramsClass.build().forClass(javaClass))); 48 for (Class<?> r : javaClass.getAnnotation(FramsClassAnnotation.class).register()) { 49 registerAndBuild(r); 50 } 48 51 return this; 49 52 } … … 122 125 } 123 126 127 public FramsClass getFramsClassForJavaClass(Class<?> javaClass) { 128 return javaToFramsAssociation.get(javaClass); 129 } 130 124 131 public Set<Class<?>> getReflectedClasses() { 125 132 return javaClasses.getValues(); -
java/main/src/main/java/com/framsticks/params/SimpleAbstractAccess.java
r98 r99 6 6 import org.apache.log4j.Logger; 7 7 8 import com.framsticks.util.UnimplementedException; 8 import com.framsticks.params.types.ObjectParam; 9 import com.framsticks.util.FramsticksException; 10 import static com.framsticks.params.SetStateFlags.*; 9 11 10 12 /** … … 105 107 @Override 106 108 public <T> int set(ValueParam param, T value) { 107 int flags = 0;108 109 109 110 //String id = param.getEffectiveId(); … … 115 116 internalSet(param, casted); 116 117 } 117 flags =result.getFlags();118 return result.getFlags(); 118 119 } catch (CastFailure e) { 119 log.error("casting failure while set: ", e); 120 } 121 return flags; 120 throw new FramsticksException() 121 .msg("casting failure while set") 122 .arg("param", param) 123 .arg("value", value) 124 .arg("value's type", (value == null ? "<null>" : value.getClass().getCanonicalName())) 125 .arg("in", this).cause(e); 126 } 122 127 } 123 128 … … 167 172 set(i, max); 168 173 } 169 }170 171 @Override172 public void copyFrom(AccessInterface src) {173 throw new UnimplementedException();174 // clearValues();175 //TODO: iterate over self, and pull from src176 /*177 for (int i = 0; i < src.getFramsClass().size(); i++) {178 this.set(i, src.get(i, Object.class));179 }180 */181 174 } 182 175 … … 257 250 continue; 258 251 } 259 if ((param.getFlags() & Flags.DONTLOAD) != 0) {252 if ((param.getFlags() & ParamFlags.DONTLOAD) != 0) { 260 253 log.debug("DontLoad flag was set - not loading..."); 261 254 } else { 262 255 int retFlags = this.set((ValueParam) param, entry.value); 263 if ((retFlags & ( Flags.PSET_HITMIN | Flags.PSET_HITMAX)) != 0) {264 String which = ((retFlags & Flags.PSET_HITMIN) != 0) ? "small" : "big";256 if ((retFlags & (PSET_HITMIN | PSET_HITMAX)) != 0) { 257 String which = ((retFlags & PSET_HITMIN) != 0) ? "small" : "big"; 265 258 log.warn("value of key '" + entry.key + "' was too " + which + ", adjusted"); 266 259 } … … 304 297 }*/ 305 298 299 @Override 300 public String toString() { 301 StringBuilder b = new StringBuilder(); 302 b.append(framsClass); 303 if (getSelected() != null) { 304 b.append("(").append(getSelected()).append(")"); 305 } 306 return b.toString(); 307 } 308 309 @Override 310 public ParamBuilder buildParam(ParamBuilder builder) { 311 return builder.name(getId()).type(ObjectParam.class).containedTypeName(getId()); 312 } 306 313 307 314 } -
java/main/src/main/java/com/framsticks/params/UniqueListAccess.java
r98 r99 1 1 package com.framsticks.params; 2 2 3 import com.framsticks.params.types.UniqueListParam; 3 4 import com.framsticks.util.FramsticksException; 4 5 import com.framsticks.util.UnimplementedException; … … 80 81 return null; 81 82 } 82 return Param.build().id(Integer.toString(i)).forAccess(elementAccess).finish(CompositeParam.class); 83 Iterator<Map.Entry<String, Object>> iterator = map.entrySet().iterator(); 84 while (i > 0 && iterator.hasNext()) { 85 iterator.next(); 86 --i; 87 } 88 if (i > 0) { 89 return null; 90 } 91 if (!iterator.hasNext()) { 92 return null; 93 } 94 return paramBuilder.id(getUidOf(iterator.next().getValue())).finish(CompositeParam.class); 83 95 } 84 96 … … 96 108 return null; 97 109 } 98 return Param.build().id(id).forAccess(elementAccess).finish(CompositeParam.class);110 return paramBuilder.id(id).finish(CompositeParam.class); 99 111 } 100 112 … … 148 160 String uid = elementAccess.get(uidName, String.class); 149 161 elementAccess.select(tmp); 150 if (uid == null) {151 return null;152 }153 162 return uid; 154 163 } … … 233 242 } 234 243 235 @Override236 244 public String computeIdentifierFor(Object selected) { 237 245 String uid = getUidOf(selected); … … 260 268 @Override 261 269 public Param next() { 262 return Param.build().id(internal.next().getKey()).forAccess(elementAccess).finish();270 return paramBuilder.id(internal.next().getKey()).finish(); 263 271 } 264 272 … … 282 290 return getParam(number); 283 291 } 292 293 @Override 294 public ParamBuilder buildParam(ParamBuilder builder) { 295 return builder.name(containedTypeName + " list").type(UniqueListParam.class).containedTypeName(containedTypeName).uid(uidName); 296 } 297 284 298 } -
java/main/src/main/java/com/framsticks/params/Util.java
r90 r99 36 36 } 37 37 38 public static int copyParams(AccessInterface to, AccessInterface from) { 38 public static int takeAllNonNullValues(AccessInterface to, AccessInterface from) { 39 int copied = 0; 40 for (ValueParam f : filterInstanceof(from.getParams(), ValueParam.class)) { 41 Object v = from.get(f, Object.class); 42 if (v == null) { 43 continue; 44 } 45 to.set(f, v); 46 ++copied; 47 } 48 return copied; 49 } 50 51 public static int copyExistingParamsTypeSafe(AccessInterface to, AccessInterface from) { 39 52 int copied = 0; 40 53 for (ValueParam f : filterInstanceof(from.getParams(), ValueParam.class)) { -
java/main/src/main/java/com/framsticks/params/annotations/FramsClassAnnotation.java
r90 r99 13 13 14 14 String[] order() default {}; 15 Class<?>[] register() default {}; 15 16 } -
java/main/src/main/java/com/framsticks/params/types/EventParam.java
r87 r99 12 12 public class EventParam extends Param { 13 13 14 protected final String eventArgumentTypeName; 14 15 15 16 … … 19 20 public EventParam(ParamBuilder builder) { 20 21 super(builder); 22 eventArgumentTypeName = builder.getEventArgumentTypeName(); 21 23 } 22 24 23 25 @Override 24 26 public Class<?> getStorageType() { 25 return Void. class;27 return Void.TYPE; 26 28 } 27 29 28 30 @Override 29 31 public String getFramsTypeName() { 30 return "e";32 return eventArgumentTypeName != null ? "e " + eventArgumentTypeName : "e"; 31 33 } 32 34 } -
java/main/src/main/java/com/framsticks/params/types/NumberParam.java
r87 r99 2 2 3 3 import com.framsticks.params.CastFailure; 4 import com.framsticks.params.Flags;5 4 import com.framsticks.params.ParamBuilder; 6 5 import com.framsticks.params.PrimitiveParam; … … 10 9 11 10 import javax.annotation.concurrent.Immutable; 11 import static com.framsticks.params.SetStateFlags.*; 12 12 13 13 /** … … 40 40 } 41 41 if (min != null && v.compareTo(getMin(type)) < 0) { 42 return new ReassignResult<T>(getMin(type), Flags.PSET_HITMIN);42 return new ReassignResult<T>(getMin(type), PSET_HITMIN); 43 43 } 44 44 if (max != null && v.compareTo(getMax(type)) > 0) { 45 return new ReassignResult<T>(getMax(type), Flags.PSET_HITMAX);45 return new ReassignResult<T>(getMax(type), PSET_HITMAX); 46 46 } 47 47 return ReassignResult.create(v); -
java/main/src/main/java/com/framsticks/params/types/ProcedureParam.java
r97 r99 54 54 @Override 55 55 public Class<?> getStorageType() { 56 return Void. class;56 return Void.TYPE; 57 57 } 58 58
Note: See TracChangeset
for help on using the changeset viewer.