source: java/main/src/main/java/com/framsticks/params/ArrayListAccess.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.3 KB
Line 
1package com.framsticks.params;
2
3import com.framsticks.util.lang.Numbers;
4
5import java.util.ArrayList;
6import java.util.Collection;
7import java.util.LinkedList;
8import java.util.List;
9
10/**
11 * @author Piotr Sniegowski
12 */
13public class ArrayListAccess extends ListAccess {
14
15        List<Object> list;
16
17        public ArrayListAccess(AccessInterface elementAccess) {
18                super(elementAccess);
19        }
20
21        @Override
22        public ArrayListAccess cloneAccess() throws ConstructionException {
23                return new ArrayListAccess(elementAccess.cloneAccess());
24        }
25
26        @Override
27        public List<?> createAccessee() {
28                return new ArrayList<Object>();
29        }
30
31        @Override
32        public Param getParam(int i) {
33                //TODO listAccessParam
34                return Param.build().id(Integer.toString(i)).name(elementAccess.getId()).type("o " + elementAccess.getId()).finish();
35        }
36
37        @Override
38        public Param getParam(String id) {
39                Integer i = Numbers.parse(id, Integer.class);
40                return (i == null ? null : getParam(i));
41        }
42
43        @Override
44        public String getId() {
45                return "l " + elementAccess.getId();
46        }
47
48        @Override
49        public int getParamCount() {
50                return list.size();
51        }
52
53        @Override
54        public <T> T get(int i, Class<T> type) {
55                if (i < list.size()) {
56                        return type.cast(list.get(i));
57                }
58                return null;
59        }
60
61        @Override
62        public <T> T get(String id, Class<T> type) {
63                return get(Integer.parseInt(id), type);
64        }
65
66        @Override
67        public <T> T get(ValueParam param, Class<T> type) {
68                return get(param.getId(), type);
69        }
70
71        @Override
72        public <T> int set(int i, T value) {
73                while (i >= list.size()) {
74                        list.add(null);
75                }
76                list.set(i, value);
77                return 0;
78        }
79
80        @Override
81        public <T> int set(String id, T value) {
82                return set(Integer.parseInt(id), value);
83        }
84
85        @Override
86        public <T> int set(ValueParam param, T value) {
87                return set(param.getId(), value);
88        }
89
90        @Override
91        public void clearValues() {
92                list.clear();
93        }
94
95        /** covariant */
96        @Override
97        public List<Object> getSelected() {
98                return list;
99        }
100
101        @SuppressWarnings("unchecked")
102        @Override
103        public ArrayListAccess select(Object object) {
104                list = (List<Object>) object;
105                return this;
106        }
107
108        @Override
109        public String computeIdentifierFor(Object selected) {
110                return Integer.toString(list.size());
111        }
112
113        @Override
114        public Collection<Param> getParams() {
115                List<Param> result = new LinkedList<Param>();
116                if (list == null) {
117                        return result;
118                }
119                for (int i = 0; i < list.size(); ++i) {
120                        result.add(getParam(i));
121                }
122                return result;
123        }
124
125
126}
Note: See TracBrowser for help on using the repository browser.