Ignore:
Timestamp:
06/28/13 11:56:03 (11 years ago)
Author:
psniegowski
Message:

HIGHLIGHTS:

  • FramsClass? and contained Param are now immutable classes (like String),

which allows to refer to them concurrently without synchronization
(which for example in turn simplifies GUI management)

  • also make Path immutable (which was earlier only assumed)
  • add global cache for FramsClasses? created solely and automatically

on base of Java classes.

representations basing on given FramsClass?

  • above changes greatly improved GUI responsivness during browsing
  • furtherly improve Param class hierarchy
  • allow to inject actions on state changes into MultiParamLoader?
  • add more tests

CHANGELOG:

Add StatusListener? to MultiParamLoader?.

Minor refactorization in MultiParamLoader?.

First step with auto append.

Add SchemaTest?.

Improve Registry.

Clean up in Registry.

Work out Registry.

Use annotations for Param.

Fix ListChange?.

Improve fluent interface of the FramsClassBuilder?.

Done caching of ReflectionAccess?.Backend

Fix hashCode of Pair.

A step on a way to cache ReflectionAccess?.Backend

Make SimpleAbstractAccess?.framsClass a final field.

Add static cache for FramsClasses? based on java.

Only classes created strictly and automatically
based on java classes are using this cache.

Make all Params immutable.

Many improvement to make Param immutable.

Make PrimitiveParam? generic type.

Several changes to make Param immutable.

Make FramsClass? immutable.

Another improvement to Path immutability.

Several improvements to Path.

Improve PathTest?.

Configurarable MutabilityDetector?.

File:
1 edited

Legend:

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

    r84 r87  
    11package com.framsticks.params;
    22
     3import com.framsticks.util.FramsticksException;
     4import com.framsticks.util.lang.Numbers;
     5
     6import javax.annotation.concurrent.Immutable;
    37
    48/**
    59 * @author Piotr Sniegowski
    610 */
    7 public abstract class PrimitiveParam extends ValueParam {
     11@Immutable
     12public abstract class PrimitiveParam<S> extends ValueParam {
    813
    914        /** The minimum allowed value of parameter. */
    10         protected Object min;
     15        protected final Object min;
    1116
    1217        /** The maximum allowed value of parameter. */
    13         protected Object max;
     18        protected final Object max;
    1419
    1520        /** The default value of parameter. */
    16         protected Object def;
     21        protected final Object def;
     22
     23        /**
     24         * @param builder
     25         */
     26        public PrimitiveParam(ParamBuilder builder) {
     27                super(builder);
     28                min = builder.getMin();
     29                max = builder.getMax();
     30                def = builder.getDef();
     31        }
    1732
    1833        public void save(SinkInterface sink, Object value) {
     
    2136
    2237        protected <T> T tryCastAndReturn(Object value, Class<T> type) {
    23                 if (value == null)
     38                if (value == null) {
    2439                        return null;
     40                }
    2541                try {
    26                         return type.cast(value);
     42                        if (type.equals(Object.class)) {
     43                                return type.cast(value);
     44                        }
     45                        if (value instanceof String) {
     46                                if (type.equals(String.class)) {
     47                                        return type.cast(value);
     48                                }
     49                                // if (Number.class.isAssignableFrom(type)) {
     50                                return Numbers.parse((String) value, type);
     51                                // }
     52                                // return null;
     53                        } else {
     54                                return type.cast(value);
     55                        }
    2756                } catch (ClassCastException e) {
    28                         throw new ClassCastException("property \"" + name
    29                                         + "\" type is \"" + value.getClass().getName()
    30                                         + "\", not \"" + type.getName() + "\"");
     57                        throw new FramsticksException().msg("failed to cast").cause(e).arg("param", this).arg("actual", value.getClass()).arg("requested", type);
    3158                }
    3259        }
     
    6491         * @throws ClassCastException the class cast exception, thrown when given getType is incorrect
    6592         */
    66         public <T> T getDef(Class<T> type) throws ClassCastException {
     93        public <T> T getDef(Class<T> type) {
    6794                return tryCastAndReturn(def, type);
    6895        }
Note: See TracChangeset for help on using the changeset viewer.