source: java/main/src/main/java/com/framsticks/params/PropertiesAccess.java @ 87

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

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 size: 2.2 KB
Line 
1package com.framsticks.params;
2
3import java.util.HashMap;
4import java.util.Map;
5
6
7/**
8 * The Class PropertiesAccess.
9 *
10 * @author Jarek Szymczak <name.surname@gmail.com> (please replace name and
11 *         surname with my personal data)
12 *
13 * @author Piotr Śniegowski
14 */
15public class PropertiesAccess extends SimpleAbstractAccess {
16
17        public Map<String, Object> properties;
18
19        @Override
20        public Map<String, Object> createAccessee() {
21                return PropertiesAccess.createPropertiesMap();
22        }
23
24        public static Map<String, Object> createPropertiesMap() {
25                return new HashMap<String, Object>();
26        }
27
28        public PropertiesAccess(FramsClass framsClass) {
29                super(framsClass);
30        }
31
32        @Override
33        public void clearValues() {
34                assert properties != null;
35                properties.clear();
36        }
37
38        @Override
39        public <T> T get(ValueParam param, Class<T> type) {
40                assert properties != null;
41                assert param != null;
42                Object object = properties.get(param.getId());
43                if (object != null) {
44                        try {
45                                return type.cast(object);
46                        } catch (ClassCastException e) {
47                                throw (ClassCastException) new ClassCastException("property " + param + " type is " + object.getClass().getName() + ", not " + type.getName()).initCause(e);
48                        }
49                }
50                try {
51                        return param.getDef(type);
52                } catch (ClassCastException e) {
53                        throw (ClassCastException) new ClassCastException("default value of property " + param + " is not of type " + type.getName()).initCause(e);
54                }
55
56        }
57
58        @Override
59        protected <T> void internalSet(ValueParam param, T value) {
60                properties.put(param.getId(), value);
61        }
62
63        /**
64         * Sets the new values to operate on. It does not check whether the values
65         * which are set through this method are correct. If set values are not
66         * correct exceptions might occurred while getting / setting the parameters
67         * values
68         *
69         * @param object
70         *            the properties with parameters values
71         */
72        @SuppressWarnings("unchecked")
73        @Override
74        public PropertiesAccess select(Object object) {
75                this.properties = (Map<String, Object>)object;
76                return this;
77        }
78
79        /** covariant */
80        @Override
81        public Map<String, Object> getSelected() {
82                return properties;
83        }
84
85        @Override
86        public PropertiesAccess cloneAccess() {
87                return new PropertiesAccess(framsClass);
88        }
89
90        @Override
91        public boolean tryAutoAppend(Object object) {
92                return false;
93        }
94
95}
Note: See TracBrowser for help on using the repository browser.