source: java/main/src/main/java/com/framsticks/params/types/UniqueListParam.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: 1.7 KB
Line 
1package com.framsticks.params.types;
2
3import com.framsticks.params.AccessInterface;
4import com.framsticks.params.CastFailure;
5import com.framsticks.params.ParamBuilder;
6import com.framsticks.params.ReassignResult;
7import com.framsticks.params.UniqueListAccess;
8import com.framsticks.util.lang.Numbers;
9
10import java.util.HashMap;
11import java.util.Map;
12
13import javax.annotation.concurrent.Immutable;
14
15/**
16 * @author Piotr Sniegowski
17 */
18@Immutable
19public class UniqueListParam extends ListParam {
20
21        final String uidName;
22
23        public UniqueListParam(ParamBuilder builder) {
24                super(builder);
25                this.uidName = builder.getUid();
26        }
27
28        @Override
29        public String computeAccessId() {
30                return "l " + containedTypeName + " " + uidName;
31        }
32
33
34        @Override
35        public Class<?> getStorageType() {
36                return Map.class;
37        }
38
39        @Override
40        public AccessInterface prepareAccessInterface(AccessInterface access) {
41                return new UniqueListAccess(access, uidName);
42        }
43
44        @Override
45        public ReassignResult<? extends Map<?,?>> reassign(Object newValue, Object oldValue) throws CastFailure {
46                if (newValue instanceof Map) {
47                        return new ReassignResult<Map<?,?>>((Map<?,?>) newValue);
48                }
49                Integer size = Numbers.cast(newValue, Integer.class);
50                if (size != null) {
51                        //return oldValue;
52                        /*
53                        the integer value should be ignored, because this may cause, that object is created before
54                        information about it's elements is available, which would break resolution flow
55                        */
56                        if (oldValue != null) {
57                                return new ReassignResult<Map<?,?>>((Map<?,?>) oldValue);
58                        }
59                        return ReassignResult.create(new HashMap<Object, Object>());
60                }
61
62                throw new CastFailure();
63        }
64
65        @Override
66        public String getFramsTypeName() {
67                return "l " + containedTypeName + " " + uidName;
68        }
69
70
71}
Note: See TracBrowser for help on using the repository browser.