source: java/main/src/main/java/com/framsticks/params/SimplePrimitive.java @ 193

Last change on this file since 193 was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
File size: 962 bytes
Line 
1package com.framsticks.params;
2
3import com.framsticks.structure.messages.ValueChange;
4import com.framsticks.util.lang.Strings;
5
6public class SimplePrimitive<T> {
7
8        protected T value;
9        protected final EventListeners<ValueChange> listeners = new EventListeners<>();
10
11        /**
12         * @param value
13         */
14        public SimplePrimitive(T value) {
15                this.value = value;
16        }
17
18        /**
19         * @param value
20         */
21        public SimplePrimitive() {
22                this(null);
23        }
24
25        /**
26         * @return the value
27         */
28        public T get() {
29                return value;
30        }
31
32        /**
33         * @param value the value to set
34         */
35        public void set(T value) {
36                this.value = value;
37                listeners.actionForAll(new ValueChange(value != null ? value.toString() : null));
38        }
39
40        public void addListener(EventListener<ValueChange> listener) {
41                listeners.add(listener);
42        }
43
44        public void removeListener(EventListener<ValueChange> listener) {
45                listeners.remove(listener);
46        }
47
48        @Override
49        public String toString() {
50                return Strings.toStringNullProof(value);
51        }
52
53}
Note: See TracBrowser for help on using the repository browser.