source: java/main/src/main/java/com/framsticks/params/types/UniqueListParam.java @ 77

Last change on this file since 77 was 77, checked in by psniegowski, 11 years ago

Add new java codebase.

File size: 1.7 KB
Line 
1package com.framsticks.params.types;
2
3import com.framsticks.params.AccessInterface;
4import com.framsticks.params.CastFailure;
5import com.framsticks.params.UniqueListAccess;
6import com.framsticks.util.Numbers;
7
8import java.util.HashMap;
9import java.util.List;
10import java.util.Map;
11
12/**
13 * @author Piotr Sniegowski
14 */
15public class UniqueListParam extends ListParam {
16
17    final String uidName;
18
19    public UniqueListParam(String containedTypeName, String uidName) {
20        super(containedTypeName);
21        this.uidName = uidName;
22    }
23
24    @Override
25    public String computeAccessId() {
26        return "l " + containedTypeName + " " + uidName;
27    }
28
29
30    @Override
31    public Class getStorageType() {
32        return Map.class;
33    }
34
35    @Override
36    public AccessInterface prepareAccessInterface(AccessInterface access) {
37        return new UniqueListAccess(access, uidName);
38    }
39
40
41    @Override
42    public Object reassign(Object newValue, Object oldValue) throws CastFailure {
43        if (newValue instanceof Map) {
44            return newValue;
45        }
46        Integer size = Numbers.cast(newValue, Integer.class);
47        if (size != null) {
48            //return oldValue;
49            /*
50            the integer value should be ignored, because this may cause, that object is created before
51            information about it's elements is available, which would break resolution flow
52            */
53            if (oldValue != null) {
54                return oldValue;
55            }
56            return new HashMap();
57        }
58
59        throw new CastFailure();
60    }
61
62    @Override
63    public String getType() {
64        return "l " + containedTypeName + " " + uidName;
65    }
66
67
68}
Note: See TracBrowser for help on using the repository browser.