source: java/main/src/main/java/com/framsticks/params/types/BinaryParam.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.0 KB
Line 
1package com.framsticks.params.types;
2
3import com.framsticks.params.CastFailure;
4import com.framsticks.params.ParamBuilder;
5import com.framsticks.params.PrimitiveParam;
6import com.framsticks.params.ReassignResult;
7import com.framsticks.util.lang.Numbers;
8
9import javax.annotation.concurrent.Immutable;
10
11/**
12 * @author Piotr Sniegowski
13 */
14@Immutable
15public class BinaryParam extends PrimitiveParam<Integer> {
16
17        /**
18         * @param builder
19         */
20        public BinaryParam(ParamBuilder builder) {
21                super(builder);
22        }
23
24        @Override
25        public Class<?> getStorageType() {
26                return Integer.class;
27        }
28
29        @Override
30        public String getFramsTypeName() {
31                return "db";
32        }
33
34        @Override
35        public ReassignResult<?> reassign(Object newValue, Object oldValue) throws CastFailure {
36                if (newValue instanceof String) {
37                        Integer v = Numbers.parse((String) newValue, Integer.class);
38                        if (v != null) {
39                                return ReassignResult.create(v);
40                        }
41                        throw new CastFailure();
42                }
43                if (newValue instanceof Integer) {
44                        return ReassignResult.create((Integer) newValue);
45                }
46                throw new CastFailure();
47        }
48
49}
Note: See TracBrowser for help on using the repository browser.