source: java/main/src/main/java/com/framsticks/params/types/UniqueListParam.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: 1.7 KB
Line 
1package com.framsticks.params.types;
2
3import com.framsticks.params.Access;
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.Casting;
9import com.framsticks.util.lang.Numbers;
10
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 Access prepareAccess(Access 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                        return new ReassignResult<Map<?,?>>(Casting.tryCast(Map.class, oldValue));
57                        // return ReassignResult.create(new TreeMap<Object, Object>());
58                }
59
60                throw new CastFailure();
61        }
62
63        @Override
64        public String getFramsTypeName() {
65                return "l " + containedTypeName + " " + uidName;
66        }
67
68
69}
Note: See TracBrowser for help on using the repository browser.