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