Ignore:
Timestamp:
07/02/13 16:20:07 (11 years ago)
Author:
psniegowski
Message:

HIGHLIGHTS:

CHANGELOG:
Make ProcedureParam? hold only ValueParams?.

Use id instead of names when naming gui components internally.

Basic procedure calling in GUI.

The actual procedure call is currently only backed
by the ObjectInstance?.

Add UnimplementedException?.

Improve naming of various gui elements.

Allow easy navigating in FEST Swing testing.

Add optional explicit order attribute to FramsClassAnnotation?.

That's because java reflection does return declared members
in any specific order. That ordering is needed only for
classes that have no representation in framsticks and need
a deterministic ordering of params.

Add ControlOwner? interface.

Add test for procedure calling in Browser.

First version of ParamAnnotation? for procedures.

Development of ProcedureParam?.

Add draft version of ProcedureParam? implementation in ReflectionAccess?.

Allow viewing FramsClasses? in gui Browser.

Extract ResourceBuilder? from ModelBuilder?.

Remove internalId from Param.

It was currently completely not utilised. Whether it is still needed
after introduction of ParamAnnotation? is arguable.

Add remaining param attributes to ParamAnnotation?.

Change AutoBuilder? semantics.

AutoBuilder? returns list of objects that are to be appended
with methods @AutoAppendAnnotation?.

This allows to omit explicit addition of ModelPackage? to instance
if the instance uses ModelBuilder? (registration of ModelPackage? comes
from schema).

Fix params ordering problem in auto created FramsClasses?.

Improve ObjectInstance?.

Several fixes to ModelBuilder?.

Improve test for ObjectInstance? in Browser.

Make initialization of robot static.

With robot recreated for second browser test, the test hanged
deep in AWT.

Add base convenience base test for Browser tests.

More tests to ObjectInstance?.

Rename Dispatcher.invokeLater() to dispatch().

Add assertDispatch.

It allows assertions in other threads, than TestNGInvoker.
Assertions are gathered after each method invocation and rethrown.

Use timeOut annotation attribute for tests involving some waiting.

Remove firstTask method (merge with joinableStart).

Clean up leftovers.

Remove unused FavouritesXMLFactory (the reading part is already
completely done with generic XmlLoader?, and writing part will be done
based on the same approach if needed).
Move UserFavourite? to the com.framsticks.gui.configuration package.

Remove GenotypeBrowser? as to specific.

This functionality will be available in ObjectInstance?.

Add interface ParamsPackage?.

Package containing registration of Java classes meant to use with
ReflectionAccess? may be in Instance using configuration.

Minor changes.

Make Group immutable.

Add AutoBuilder? interface extending Builder - only those would
be used to automatically build from XML.

Fix groups in FramsClass?.

Minor naming cleanup in Registry.

Add ModelComponent? interface.

All class creating the Model are implementing that interface.

Extract Model.build into ModelBuilder?.

ModelBuilder? will be compatible with other builders
and allow using it from configuration.

Fix NeuroConnection?.

Add synchronous get operation for dispatchers.

Rename JoinableMonitor? to Monitor.

Add ObjectInstance?.

This class is mainly for demonstration
and testing purposes.

Improve FramsServer? runner.

  • improve ExternalProcess? runner,
  • runner can kill the server but also react properly, when the server exists on it's own,
  • set default path to search for framsticks server installation,
  • add LoggingOutputListener?.
File:
1 edited

Legend:

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

    r88 r90  
    1111
    1212import java.lang.reflect.InvocationTargetException;
     13import java.util.ArrayList;
    1314import java.util.Arrays;
    1415import java.util.List;
     16import java.util.regex.Matcher;
     17import java.util.regex.Pattern;
     18
     19import javax.annotation.Nonnull;
    1520
    1621/**
     
    3742        private String id;
    3843
    39         /**
    40          * The parameter internal id. It's set by a user to use user's own id in
    41          * code
    42          */
    43         private String internalId;
    44 
    4544        /** The number of group, that parameter belongs to. */
    46         private Integer group = 0;
     45        private Integer group;
    4746
    4847        /** The flags stored as a bit sum. */
     
    7675        }
    7776
     77        protected ValueParam resultType;
     78
     79        protected List<ValueParam> argumentsType;
    7880
    7981        /**
     
    114116
    115117        /**
     118         * @return the resultType
     119         */
     120        public ValueParam getResultType() {
     121                return resultType;
     122        }
     123
     124
     125        /**
     126         * @param resultType the resultType to set
     127         */
     128        public ParamBuilder resultType(ValueParam resultType) {
     129                this.resultType = resultType;
     130                return this;
     131        }
     132
     133        /**
     134         * @return the argumentsType
     135         */
     136        public List<ValueParam> getArgumentsType() {
     137                return argumentsType;
     138        }
     139
     140
     141        /**
     142         * @param argumentsType the argumentsType to set
     143         */
     144        public ParamBuilder argumentsType(List<ValueParam> argumentsType) {
     145                this.argumentsType = argumentsType;
     146                return this;
     147        }
     148
     149        /**
    116150         * @return the enumValues
    117151         */
     
    121155
    122156        /**
    123          * @return the procedureSignature
    124          */
    125         public String getProcedureSignature() {
    126                 return procedureSignature;
    127         }
    128 
    129         /**
    130157         * @return the uid
    131158         */
    132159        public String getUid() {
    133160                return uid;
     161        }
     162
     163        public @Nonnull <T extends Param> T finish(Class<T> requested) {
     164                Param param = finish();
     165                if (!requested.isInstance(param)) {
     166                        throw new FramsticksException().msg("param is of wrong type").arg("requested", requested).arg("actual", param.getClass());
     167                }
     168                return requested.cast(param);
    134169        }
    135170
     
    141176         *             when Param getType is not defined
    142177         */
    143         public Param finish() {
     178        public @Nonnull Param finish() {
    144179                try {
    145180                        if (paramType == null) {
    146181                                throw new FramsticksException().msg("trying to finish incomplete param");
    147182                        }
    148 
    149183                        return paramType.getConstructor(ParamBuilder.class).newInstance(this);
    150184                } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | FramsticksException e) {
     
    165199        }
    166200
    167         // public <T extends Param> ParamBuilder type(T param) {
    168         //      return internalSetType(param.getClass(), param);
    169         // }
    170 
    171 
    172201        /**
    173202         * @return the id
     
    178207        }
    179208
    180         /**
    181          * @return the internalId
    182          */
    183         public String getInternalId() {
    184                 return internalId;
    185         }
    186 
    187         public ParamBuilder setInternalId(String internalId) {
    188                 this.internalId = internalId;
    189                 return this;
    190         }
    191 
    192209        @ParamAnnotation
    193210        public ParamBuilder group(Integer group) {
     
    208225        }
    209226
    210         protected <T extends Number> void parseMinMaxDefNumber(Class<T> type, String second, String third) {
     227        protected <T extends Number> void parseMinMaxDefNumber(Class<T> type, String second, String third, String fourth) {
    211228                if (second != null) {
    212229                        min = second;
     
    214231                if (third != null) {
    215232                        max = third;
     233                }
     234                if (fourth != null) {
     235                        def = fourth;
    216236                }
    217237        }
     
    223243                return type(EnumParam.class);
    224244        }
    225 
    226         protected String procedureSignature;
    227245
    228246        protected String uid;
     
    239257                String second = typeSplitted.length > 1 ? typeSplitted[1] : null;
    240258                String third = typeSplitted.length > 2 ? typeSplitted[2] : null;
     259                String fourth = typeSplitted.length > 3 ? typeSplitted[3] : null;
    241260
    242261                switch (first.charAt(0)) {
     
    247266                        }
    248267                        case 'p': {
    249                                 procedureSignature = type.substring(1);
    250268                                type(ProcedureParam.class);
     269                                signature(type.substring(1));
    251270                                break;
    252271                        }
     
    281300                                }
    282301                                if (DecimalParam.class.isAssignableFrom(this.paramType)) {
    283                                         parseMinMaxDefNumber(Integer.class, second, third);
     302                                        parseMinMaxDefNumber(Integer.class, second, third, fourth);
    284303                                }
    285304                                break;
     
    287306                        case 'f': {
    288307                                type(FloatParam.class);
    289                                 parseMinMaxDefNumber(Double.class, second, third);
     308                                parseMinMaxDefNumber(Double.class, second, third, fourth);
    290309                                break;
    291310                        }
     
    472491        }
    473492
    474 
    475493        public Class<?> getStorageType() {
    476494                return storageType;
    477495        }
     496
     497        public ParamBuilder forAccess(AccessInterface access) {
     498                return name(access.getId()).type("o " + access.getId());
     499        }
     500
     501        protected static ValueParam parseProcedureTypePart(String type, String name) {
     502                return Param.build().type(type).name(name).id(name).finish(ValueParam.class);
     503        }
     504
     505        private static Pattern addressPattern = Pattern.compile("^([^\\(]+)?\\(([^\\)]*)\\)$");
     506
     507        public ParamBuilder signature(String signature) {
     508                argumentsType = new ArrayList<>();
     509
     510                if (!Strings.notEmpty(signature)) {
     511                        resultType = null;
     512                        return this;
     513                }
     514                Matcher matcher = addressPattern.matcher(signature);
     515                if (!matcher.matches()) {
     516                        throw new FramsticksException().msg("invalid signature");
     517                }
     518                String result = Strings.collapse(matcher.group(1));
     519                resultType = (result != null) ? parseProcedureTypePart(result, null) : null;
     520                String arguments = matcher.group(2);
     521                if (!Strings.notEmpty(arguments)) {
     522                        return this;
     523                }
     524                int number = 0;
     525                for (String a : arguments.split(",")) {
     526                        int space = a.indexOf(' ');
     527                        String type;
     528                        String name;
     529                        if (space == -1) {
     530                                type = a;
     531                                name = "arg" + number;
     532                        } else {
     533                                type = a.substring(0, space);
     534                                name = a.substring(space + 1);
     535                        }
     536                        argumentsType.add(parseProcedureTypePart(type, name));
     537                        ++number;
     538                }
     539                return this;
     540        }
     541
     542
     543        public ParamBuilder idAndName(String name) {
     544                id(name);
     545                name(name);
     546                return this;
     547        }
    478548}
    479549
Note: See TracChangeset for help on using the changeset viewer.