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