Ignore:
Timestamp:
07/14/13 23:20:04 (11 years ago)
Author:
psniegowski
Message:

HIGHLIGHTS:

  • improve tree side notes
  • improve GUI layout
  • add foldable list of occured events to EventControl?
  • improve automatic type conversion in proxy listeners
  • implement several Access functionalities as algorithms independent of Access type
  • introduce draft base classes for distributed experiments
  • automatically register dependant Java classes to FramsClass? registry
  • add testing prime experiment and configuration
  • simplify and improve task dispatching

CHANGELOG:
Improve task dispatching in RemoteTree?.

GUI no longer hangs on connection problems.

Make all dispatchers joinables.

Refactorize Thread dispatcher.

Remove Task and PeriodicTask?.

Use Java utilities in those situations.

Reworking tasks dispatching.

Fix bug in EventControl? listener dispatching.

Minor improvements.

Add testing configuration for ExternalProcess? in GUI.

More improvement to prime.

Support for USERREADONLY in GUI.

Add that flag to various params in Java classes.

Remove redundant register clauses from several FramsClassAnnotations?.

Automatically gather and register dependant classes.

Add configuration for prime.

Improve Simulator class.

Add prime.xml configuration.

Introduce draft Experiment and Simulator classes.

Add prime experiment tests.

Enclose typical map with listeners into SimpleUniqueList?.

Needfile works in GUI.

Improve needfile handling in Browser.

More improvement with NeedFile?.

Implementing needfile.

Update test.

Rename ChangeEvent? to TestChangeEvent?.

Automatic argument type search in RemoteTree? listeners.

MultiParamLoader? uses AccessProvider?. By default old implementation
enclosed in AccessStash? or Registry.

Minor changes.

Rename SourceInterface? to Source.

Also improve toString of File and ListSource?.

Remove unused SimpleSource? class.

Add clearing in HistoryControl?.

Show entries in table at EventControl?.

Improve EventControl?.

Add listeners registration to EventControl?.

Add foldable table to HistoryControl?.

Add control row to Procedure and Event controls.

Improve layout of controls.

Another minor change to gui layout.

Minor improvement in the SliderControl?.

Minor changes.

Move ReflectionAccess?.Backend to separate file.

It was to cluttered.

Cleanup in ReflectionAccess?.

Move setMin, setMax, setDef to AccessOperations?.

Extract loading operation into AccessOperations?.

Append Framsticks to name of UnsupportedOperationException?.

The java.lang.UnsupportedOperationException? was shadowing this class.

Rename params.Util to params.ParamsUtil?.

Several improvements.

Minor changes.

Implement revert functionality.

Improve local changes management.

Minor improvement.

Remove methods rendered superfluous after SideNoteKey? improvement.

Improve SideNoteKey?.

It is now generic type, so explicit type specification at
call site is no more needed.

Introduce SideNoteKey? interface.

Only Objects implementing that key may be used as side note keys.

Minor improvements.

Use strings instead of ValueControls? in several gui mappings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • java/main/src/main/java/com/framsticks/params/ParamCandidate.java

    r100 r101  
    1010import java.lang.reflect.ParameterizedType;
    1111import java.lang.reflect.Type;
     12import java.util.ArrayList;
    1213import java.util.Arrays;
    1314import java.util.Collection;
     
    1516import java.util.Comparator;
    1617import java.util.HashMap;
     18import java.util.HashSet;
     19import java.util.IdentityHashMap;
    1720import java.util.LinkedList;
    1821import java.util.List;
     
    7578        protected final OneTime<Method> adder = new OneTime<>("adder");
    7679        protected final OneTime<Method> remover = new OneTime<>("remover");
     80        protected int flags = 0;
    7781
    7882        protected final List<ParamAnnotation> annotations = new LinkedList<>();
     
    162166        public List<ParamAnnotation> getAnnotations() {
    163167                return Collections.unmodifiableList(annotations);
     168        }
     169
     170        protected final java.util.Set<Class<?>> dependantClasses = new HashSet<>();
     171
     172        // public void addDependantClass(Class<?> javaClass) {
     173        //      dependantClasses.add(javaClass);
     174        // }
     175
     176        /**
     177         * @return the dependantClasses
     178         */
     179        public java.util.Set<Class<?>> getDependantClasses() {
     180                return Collections.unmodifiableSet(dependantClasses);
    164181        }
    165182
     
    247264                this.name.set(name);
    248265                annotations.add(paramAnnotation);
     266                flags |= paramAnnotation.flags();
    249267                if (member instanceof Field) {
    250268                        field.set((Field) member);
     
    299317
    300318        public int getFlags() {
    301                 int f = 0;
     319                int f = flags;
    302320                if (isReadOnly()) {
    303321                        f |= ParamFlags.READONLY;
     
    341359                protected final Map<String, ParamCandidate> candidates;
    342360                protected final List<ParamCandidate> order;
     361                protected final java.util.Set<Class<?>> dependantClasses = new HashSet<>();
    343362
    344363                /**
     
    364383                        return order;
    365384                }
    366         }
     385
     386                public java.util.Set<Class<?>> getDependentClasses() {
     387                        return dependantClasses;
     388                }
     389        }
     390
     391        protected static final Map<Class<?>, Set> setsCache = Collections.synchronizedMap(new IdentityHashMap<Class<?>, Set>());
    367392
    368393        public static Set getAllCandidates(Class<?> javaClass) throws ConstructionException {
     394                Set result = setsCache.get(javaClass);
     395                if (result != null) {
     396                        return result;
     397                }
    369398
    370399                List<Class<?>> javaClasses = new LinkedList<>();
     
    374403                }
    375404
    376                 Set resultSet = new Set(new HashMap<String, ParamCandidate>(), new LinkedList<ParamCandidate>());
     405                result = new Set(new HashMap<String, ParamCandidate>(), new LinkedList<ParamCandidate>());
    377406
    378407                for (Class<?> j : javaClasses) {
    379                         Set set = new Set(resultSet.getCandidates(), new LinkedList<ParamCandidate>());
     408                        Set set = new Set(result.getCandidates(), new LinkedList<ParamCandidate>());
     409
    380410                        filterParamsCandidates(set, j.getDeclaredFields());
    381411                        filterParamsCandidates(set, j.getDeclaredMethods());
     
    383413                        FramsClassAnnotation fa = j.getAnnotation(FramsClassAnnotation.class);
    384414                        if (fa != null) {
     415
     416                                if (j != javaClass) {
     417                                        result.dependantClasses.add(j);
     418                                }
     419                                for (Class<?> r : fa.register()) {
     420                                        result.dependantClasses.add(r);
     421                                }
     422
     423
    385424                                final List<String> order = Arrays.asList(fa.order());
    386425                                Collections.sort(set.getOrder(), new Comparator<ParamCandidate>() {
     
    396435                                });
    397436                        }
    398                         resultSet.getOrder().addAll(0, set.getOrder());
    399                 }
    400 
    401                 for (ParamCandidate pc : resultSet.getOrder()) {
     437                        result.getOrder().addAll(0, set.getOrder());
     438                }
     439
     440                for (ParamCandidate pc : result.getOrder()) {
    402441                        pc.validate();
    403                 }
    404 
    405                 return resultSet;
     442                        pc.induceParamType(Param.build());
     443                        result.dependantClasses.addAll(pc.getDependantClasses());
     444                }
     445
     446                setsCache.put(javaClass, result);
     447
     448                return result;
    406449        }
    407450
     
    425468        }
    426469
     470        protected ParamBuilder induceParamType(ParamBuilder builder, Type type) {
     471                // if (type.equals(Void.TYPE)) {
     472                //      throw new ConstructionException().msg("void is not a valid type");
     473                // }
     474
     475                if (type instanceof ParameterizedType) {
     476                        ParameterizedType p = (ParameterizedType) type;
     477                        Type rawType = p.getRawType();
     478                        Type containedType = null;
     479                        //TODO make implementation here
     480                        boolean map = false;
     481                        StringBuilder b = new StringBuilder();
     482                        if (rawType.equals(Map.class)) {
     483                                containedType = p.getActualTypeArguments()[1];
     484                                map = true;
     485                                b.append("l");
     486                        } else if (rawType.equals(List.class)) {
     487                                containedType = p.getActualTypeArguments()[0];
     488                                b.append("l");
     489                        } else if (rawType.equals(EventListener.class)) {
     490                                containedType = p.getActualTypeArguments()[0];
     491                                b.append("e");
     492                        }
     493                        if (!(containedType instanceof Class)) {
     494                                return builder;
     495                        }
     496                        b.append(" ");
     497
     498                        Class<?> containedClass = (Class<?>) containedType;
     499                        FramsClassAnnotation fca = containedClass.getAnnotation(FramsClassAnnotation.class);
     500                        if (fca == null) {
     501                                throw new ConstructionException().msg("the contained class is not annotated").arg("class", containedClass);
     502                        }
     503                        dependantClasses.add(containedClass);
     504                        b.append(FramsClassBuilder.getName(fca, containedClass));
     505                        //TODO parameterize this
     506                        if (map) {
     507                                b.append(" uid");
     508                        }
     509
     510                        builder.type(b.toString());
     511                        return builder;
     512                }
     513
     514                if (type instanceof Class) {
     515
     516                        Class<?> cl = (Class<?>) type;
     517
     518                        // TODO: future support for enum
     519                        // if (cl.isEnum()) {
     520                        //      Class<? extends Enum<?>> enumType = (Class<? extends Enum<?>>) cl;
     521                        //      Enum<?>[] enums = enumType.getEnumConstants();
     522                        //      StringBuilder b = new StringBuilder();
     523
     524                        //      b.append("d 0 ").append(enums.length - 1).append(" 0 ");
     525                        //      for (Enum<?> e : enums) {
     526                        //              b.append("~").append(e.name());
     527                        //      }
     528                        //      return b.toString();
     529                        // }
     530                        if (cl.equals(Integer.class) || cl.equals(int.class)) {
     531                                builder.type("d");
     532                                return builder;
     533                        }
     534                        if (cl.equals(String.class)) {
     535                                builder.type("s");
     536                                return builder;
     537                        }
     538                        if (cl.equals(Double.class) || cl.equals(double.class)) {
     539                                builder.type("f");
     540                                return builder;
     541                        }
     542                        if (cl.equals(Boolean.class) || cl.equals(boolean.class)) {
     543                                builder.type( "d 0 1");
     544                                return builder;
     545                        }
     546                        if (cl.equals(Object.class)) {
     547                                builder.type("x");
     548                                return builder;
     549                        }
     550
     551
     552                        // builder.type("o " + (cl).getCanonicalName());
     553                        builder.type("o " + cl.getSimpleName());
     554                        dependantClasses.add(cl);
     555                        builder.fillStorageType(cl);
     556                        return builder;
     557                }
     558
     559                throw new ConstructionException().msg("failed to find framsticks for native type").arg("type", type);
     560        }
     561
     562
     563        public ParamBuilder induceParamType(ParamBuilder builder) {
     564                Method method = getCaller();
     565                if (method == null) {
     566                        return induceParamType(builder, getType());
     567                }
     568
     569                if (!method.getReturnType().equals(Void.TYPE)) {
     570                        builder.resultType(induceParamType(Param.build(), method.getGenericReturnType()).finish(ValueParam.class));
     571                }
     572
     573                List<ValueParam> arguments = new ArrayList<>();
     574                int number = 0;
     575                for (Type arg : method.getGenericParameterTypes()) {
     576                        arguments.add(induceParamType(Param.build(), arg).idAndName("arg" + (number++)).finish(ValueParam.class));
     577                }
     578                builder.argumentsType(arguments);
     579
     580                return builder;
     581        }
     582
    427583};
Note: See TracChangeset for help on using the changeset viewer.