source: java/main/src/main/java/com/framsticks/params/types/ArrayListParam.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.8 KB
Line 
1package com.framsticks.params.types;
2
3import com.framsticks.params.Access;
4import com.framsticks.params.ArrayListAccess;
5import com.framsticks.params.CastFailure;
6import com.framsticks.params.ParamBuilder;
7import com.framsticks.params.ReassignResult;
8import com.framsticks.util.lang.Casting;
9import com.framsticks.util.lang.Numbers;
10
11import java.util.List;
12
13import javax.annotation.concurrent.Immutable;
14
15/**
16 * @author Piotr Sniegowski
17 */
18@Immutable
19public 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}
Note: See TracBrowser for help on using the repository browser.