source: java/main/src/main/java/com/framsticks/params/types/StringParam.java

Last change on this file 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.3 KB
RevLine 
[77]1package com.framsticks.params.types;
2
3import com.framsticks.params.CastFailure;
[87]4import com.framsticks.params.ParamBuilder;
[84]5import com.framsticks.params.PrimitiveParam;
6import com.framsticks.params.ReassignResult;
[77]7
[87]8import javax.annotation.concurrent.Immutable;
9
[77]10/**
11 * @author Piotr Sniegowski
12 */
[87]13@Immutable
14public class StringParam extends PrimitiveParam<String> {
15
16
17
18        /**
19         * @param builder
20         */
21        public StringParam(ParamBuilder builder) {
22                super(builder);
23        }
24
[77]25        @Override
[84]26        public Class<?> getStorageType() {
[77]27                return String.class;
28        }
29
30        @Override
[84]31        public ReassignResult<String> reassign(Object newValue, Object oldValue) throws CastFailure {
32                if (newValue == null) {
33                        return new ReassignResult<String>(null);
34                }
35                if (newValue instanceof String) {
36                        return ReassignResult.create((String) newValue);
37                }
38                return ReassignResult.create(newValue.toString());
39                // return super.reassign(newValue, oldValue);
[77]40        }
41
[84]42        @Override
43        public String getFramsTypeName() {
44                return "s";
45        }
[77]46
[84]47        private static final String SEPARATOR = System.getProperty("line.separator");
[77]48
[84]49        @Override
[105]50        public String serialize(Object value) {
[107]51                if (value == null) {
52                        return "";
53                }
[84]54                assert value instanceof String;
[105]55                String s = (String) value;
56                return (s.contains(SEPARATOR) ? (s = "~" + SEPARATOR + s + "~") : s);
[84]57        }
[77]58}
Note: See TracBrowser for help on using the repository browser.