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/parsers/MultiParamLoader.java

    r86 r87  
    99
    1010public class MultiParamLoader {
     11
     12        public interface StatusListener {
     13                void onStatusChange();
     14        }
     15
    1116        private final static Logger log = Logger.getLogger(MultiParamLoader.class);
    1217
     
    2732        }
    2833
     34        protected final Map<Status, List<StatusListener>> listeners = new HashMap<>();
     35
    2936        /**
    3037         * Specifies the action that should be taken inside loops.
     
    3643        protected AccessInterface lastAccessInterface;
    3744
     45        protected static FramsClass emptyFramsClass = FramsClass.build().idAndName("<empty>").finish();
    3846        /**
    3947         * Empty Param representing unknown classes - used to omit unknown
    4048         * objects in the file.
    4149         */
    42         protected AccessInterface emptyParam = new PropertiesAccess(new FramsClass());
     50        protected AccessInterface emptyParam = new PropertiesAccess(emptyFramsClass);
    4351
    4452        /**
     
    5765        private Status status = Status.None;
    5866
    59         private void setStatus(Status status) {
    60                 log.trace("changing status: " + this.status.toString() + " -> " + status.toString());
    61                 this.status = status;
    62         }
    6367
    6468        /**
     
    176180                        lastAccessInterface.load(currentSource);
    177181
    178                         if (isBreakCondition(Status.AfterObject)) {
    179                                 // break after object creation
     182                        if (changeStatus(Status.AfterObject)) {
    180183                                return LoopAction.Break;
    181184                        }
    182 
    183185                        return LoopAction.Continue;
    184186                } else if (status == Status.BeforeUnknown) {
     
    187189                        // found unknown object
    188190                        emptyParam.load(currentSource);
    189                         setStatus(Status.AfterObject);
    190 
     191                        if (changeStatus(Status.AfterObject)) {
     192                                return LoopAction.Break;
     193                        }
    191194                        return LoopAction.Continue;
    192195                }
     
    236239         */
    237240        private LoopAction isCommentLine(String line) {
    238                 if (line.charAt(0) == '#' && isBreakCondition(Status.OnComment)) {
    239                         // it's a simple comment - maybe we should break?
     241                if (line.charAt(0) == '#') {
    240242                        lastComment = line;
    241                         return LoopAction.Break;
    242                 }
    243 
     243                        if (changeStatus(Status.OnComment)) {
     244                                // it's a simple comment - maybe we should break?
     245                                return LoopAction.Break;
     246                        }
     247                }
    244248                return LoopAction.Nothing;
    245249        }
     
    255259
    256260                        if (lastAccessInterface != null) {
    257                                 if (isBreakCondition(Status.BeforeObject)) {
    258                                         log.debug("breaking before object");
     261                                if (changeStatus(Status.BeforeObject)) {
    259262                                        return LoopAction.Break;
    260263                                } else {
     
    263266                        } else {
    264267                                lastUnknownObjectName = typeName;
    265                                 if (isBreakCondition(Status.BeforeUnknown)) {
    266                                         log.debug("breaking before unknown");
     268                                if (changeStatus(Status.BeforeUnknown)) {
    267269                                        return LoopAction.Break;
    268270                                } else {
     
    309311                }
    310312
    311                 setStatus(Status.Finished);
     313                changeStatus(Status.Finished);
    312314        }
    313315
     
    320322
    321323                currentSource = source;
    322                 setStatus(Status.Loading);
     324                changeStatus(Status.Loading);
    323325
    324326                return true;
     
    391393         * Checks whether execution should break on selected condition.
    392394         */
    393         private boolean isBreakCondition(Status condition) {
    394                 setStatus(condition);
    395                 return breakConditions.contains(condition);
     395        private boolean changeStatus(Status status) {
     396                log.trace("changing status: " + this.status.toString() + " -> " + status.toString());
     397                this.status = status;
     398                if (listeners.containsKey(status)) {
     399                        for (StatusListener l : listeners.get(status)) {
     400                                l.onStatusChange();
     401                        }
     402                }
     403                return breakConditions.contains(status);
    396404        }
    397405
     
    405413                return result;
    406414        }
     415
     416        public void addListener(Status status, StatusListener listener) {
     417                if (!listeners.containsKey(status)) {
     418                        listeners.put(status, new LinkedList<StatusListener>());
     419                }
     420                listeners.get(status).add(listener);
     421        }
    407422}
Note: See TracChangeset for help on using the changeset viewer.