1 | package com.framsticks.params.types; |
---|
2 | |
---|
3 | import com.framsticks.params.Access; |
---|
4 | import com.framsticks.params.ArrayListAccess; |
---|
5 | import com.framsticks.params.CastFailure; |
---|
6 | import com.framsticks.params.ParamBuilder; |
---|
7 | import com.framsticks.params.ReassignResult; |
---|
8 | import com.framsticks.util.lang.Casting; |
---|
9 | import com.framsticks.util.lang.Numbers; |
---|
10 | |
---|
11 | import java.util.List; |
---|
12 | |
---|
13 | import javax.annotation.concurrent.Immutable; |
---|
14 | |
---|
15 | /** |
---|
16 | * @author Piotr Sniegowski |
---|
17 | */ |
---|
18 | @Immutable |
---|
19 | public class ArrayListParam extends ListParam { |
---|
20 | |
---|
21 | public ArrayListParam(ParamBuilder builder) { |
---|
22 | super(builder); |
---|
23 | } |
---|
24 | |
---|
25 | |
---|
26 | @Override |
---|
27 | public Class<?> getStorageType() { |
---|
28 | return List.class; |
---|
29 | } |
---|
30 | |
---|
31 | @Override |
---|
32 | public Access prepareAccess(Access access) { |
---|
33 | return new ArrayListAccess(access); |
---|
34 | } |
---|
35 | |
---|
36 | @Override |
---|
37 | public String computeAccessId() { |
---|
38 | return "l " + containedTypeName; |
---|
39 | } |
---|
40 | |
---|
41 | @Override |
---|
42 | public ReassignResult<List<?>> reassign(Object newValue, Object oldValue) throws CastFailure { |
---|
43 | if (newValue == null) { |
---|
44 | throw new CastFailure(); |
---|
45 | } |
---|
46 | Integer size = Numbers.cast(newValue, Integer.class); |
---|
47 | if (size != null) { |
---|
48 | //return oldValue; |
---|
49 | // List<?> list; |
---|
50 | // if (oldValue == null) { |
---|
51 | // list = new ArrayList<Object>(); |
---|
52 | // } else { |
---|
53 | // list = Casting.tryCast(List.class, oldValue); |
---|
54 | // if (list == null) { |
---|
55 | // throw new CastFailure(); |
---|
56 | // } |
---|
57 | // } |
---|
58 | // Containers.resizeList(list, size); |
---|
59 | return new ReassignResult<List<?>>(Casting.tryCast(List.class, oldValue)); |
---|
60 | // return new ReassignResult<List<?>>(list); |
---|
61 | } |
---|
62 | // if (oldValue != null) { |
---|
63 | // return new ReassignResult<List<?>>(Casting.throwCast(List.class, oldValue)); |
---|
64 | // } |
---|
65 | return new ReassignResult<List<?>>(Casting.throwCast(List.class, newValue)); |
---|
66 | } |
---|
67 | |
---|
68 | @Override |
---|
69 | public String getFramsTypeName() { |
---|
70 | return "l " + getContainedTypeName(); |
---|
71 | } |
---|
72 | |
---|
73 | // return (value == null) ? "0" : Integer.toString(Casting.throwCast(List.class, value).size()); |
---|
74 | } |
---|