source: java/main/src/main/java/com/framsticks/core/ListChange.java @ 102

Last change on this file since 102 was 102, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

for Joinables running

CHANGELOG:
Add WorkPackageLogic? and classes representing prime experiment state.

Add classes for PrimeExperiment? state.

Extract single netload routine in Simulator.

Working netload with dummy content in PrimeExperiment?.

More development with NetLoadSaveLogic? and PrimeExperiment?.

Improvement around prime.

Improve BufferedDispatcher?.isActive logic.

Add prime-all.xml configuration.

Manual connecting to existing simulators from GUI.

Guard in SimulatorConnector? against expdef mismatch.

Guard against empty target dispatcher in BufferedDispatcher?.

Make BufferedDispatcher? a Dispatcher (and Joinable).

Minor improvements.

Done StackedJoinable?, improve Experiment.

Develop StackedJoinable?.

Add StackedJoinable? utility joinables controller.

Add dependency on apache-commons-lang.

Add ready ListChange? on Simulators.

Improve hints in ListChange?.

Several improvements.

Found bug with dispatching in Experiment.

Minor improvements.

Fix bug with early finishing Server.

Many changes in Dispatching.

Fix bug with connection.

Do not obfuscate log with socket related exceptions.

Add SocketClosedException?.

Add SimulatorConnector?.

Work out conception of experiment composing of logics building blocks.

Rename SinkInterface? to Sink.

Move saving of Accesses into AccessOperations?.

Some improvements to Experiment.

Improve joinables.

Fix issue with joinables closing.

Add direct and managed consoles to popup menu.

File size: 2.5 KB
Line 
1package com.framsticks.core;
2
3import java.util.Arrays;
4import java.util.Set;
5import java.util.TreeSet;
6
7import org.apache.commons.lang.StringUtils;
8
9import com.framsticks.params.annotations.FramsClassAnnotation;
10import com.framsticks.params.annotations.ParamAnnotation;
11import com.framsticks.util.Misc;
12import com.framsticks.util.lang.Strings;
13
14/**
15 * @author Piotr Sniegowski
16 */
17@FramsClassAnnotation(order = {"type", "pos", "id", "hint"})
18public class ListChange {
19
20        public static enum Action {
21                Add,
22                Remove,
23                Modify
24        }
25
26
27        public ListChange(Action action, Integer position, String identifier, Object... hints) {
28                this.action = action;
29                this.position = position;
30                this.identifier = identifier;
31                if (hints.length != 0) {
32                        this.hints = new TreeSet<>();
33                        for (Object h : hints) {
34                                this.hints.add(h.toString());
35                        }
36                }
37        }
38
39        /**
40         *
41         */
42        public ListChange() {
43        }
44
45        public Action getAction() {
46                return action;
47        }
48
49        public Integer getPosition() {
50                return position;
51        }
52
53        public String getIdentifier() {
54                return identifier;
55        }
56
57
58        public boolean hasHint(String hint) {
59                if (hints == null) {
60                        return false;
61                }
62                return hints.contains(hint);
63        }
64
65
66        public Action action = Action.Add;
67        @ParamAnnotation(id = "pos", def = "-1")
68        public Integer position;
69        @ParamAnnotation(id = "id")
70        public String identifier;
71
72        protected Set<String> hints;
73
74        @ParamAnnotation
75        public String getHints() {
76                return StringUtils.join(hints, ",");
77        }
78
79        @ParamAnnotation
80        public void setHints(String hints) {
81                if (!Strings.notEmpty(hints)) {
82                        this.hints = null;
83                        return;
84                }
85                this.hints = new TreeSet<>();
86                this.hints.addAll(Arrays.asList(StringUtils.split(hints, ",")));
87        }
88
89        @ParamAnnotation
90        public Integer getType() { return action.ordinal(); }
91        @ParamAnnotation
92        public void setType(Integer type) { action = Action.values()[type]; }
93
94        public String getBestIdentifier() {
95                if (Strings.notEmpty(identifier)) {
96                        return identifier;
97                }
98                return position.toString();
99        }
100
101        @Override
102        public String toString() {
103                StringBuilder b = new StringBuilder();
104                b.append(action).append(" ").append(identifier).append(" ").append(position);
105                if (hints != null && !hints.isEmpty()) {
106                        b.append(" ").append(getHints());
107                }
108                return b.toString();
109        }
110
111        @Override
112        public boolean equals(Object object) {
113                if (object instanceof ListChange) {
114                        ListChange r = (ListChange) object;
115                        return Misc.equals(action, r.action) && Misc.equals(position, r.position) && Misc.equals(identifier, r.identifier) && Misc.equals(hints, r.hints);
116                }
117                return false;
118        }
119
120}
Note: See TracBrowser for help on using the repository browser.