Line | |
---|
1 | package com.framsticks.params.types; |
---|
2 | |
---|
3 | import com.framsticks.params.AccessInterface; |
---|
4 | import com.framsticks.params.ArrayListAccess; |
---|
5 | import com.framsticks.params.CastFailure; |
---|
6 | import com.framsticks.util.Casting; |
---|
7 | import com.framsticks.util.Containers; |
---|
8 | import com.framsticks.util.Numbers; |
---|
9 | |
---|
10 | import java.util.ArrayList; |
---|
11 | import java.util.List; |
---|
12 | |
---|
13 | /** |
---|
14 | * @author Piotr Sniegowski |
---|
15 | */ |
---|
16 | public class ArrayListParam extends ListParam { |
---|
17 | |
---|
18 | public ArrayListParam(String containedTypeName) { |
---|
19 | super(containedTypeName); |
---|
20 | } |
---|
21 | |
---|
22 | |
---|
23 | @Override |
---|
24 | public Class getStorageType() { |
---|
25 | return List.class; |
---|
26 | } |
---|
27 | |
---|
28 | @Override |
---|
29 | public AccessInterface prepareAccessInterface(AccessInterface access) { |
---|
30 | return new ArrayListAccess(access); |
---|
31 | } |
---|
32 | |
---|
33 | @Override |
---|
34 | public String computeAccessId() { |
---|
35 | return "l " + containedTypeName; |
---|
36 | } |
---|
37 | |
---|
38 | @Override |
---|
39 | public Object reassign(Object newValue, Object oldValue) throws CastFailure { |
---|
40 | if (newValue == null) { |
---|
41 | throw new CastFailure(); |
---|
42 | } |
---|
43 | Integer size = Numbers.cast(newValue, Integer.class); |
---|
44 | if (size != null) { |
---|
45 | //return oldValue; |
---|
46 | List list; |
---|
47 | if (oldValue == null) { |
---|
48 | list = new ArrayList(); |
---|
49 | } else { |
---|
50 | list = Casting.tryCast(List.class, oldValue); |
---|
51 | if (list == null) { |
---|
52 | throw new CastFailure(); |
---|
53 | } |
---|
54 | } |
---|
55 | Containers.resizeList(list, size); |
---|
56 | return list; |
---|
57 | } |
---|
58 | if (oldValue != null) { |
---|
59 | return oldValue; |
---|
60 | } |
---|
61 | return newValue; |
---|
62 | } |
---|
63 | |
---|
64 | @Override |
---|
65 | public String getType() { |
---|
66 | return "l " + getContainedTypeName(); |
---|
67 | } |
---|
68 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.