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

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

HIGHLIGHTS:

  • FramsClass? and contained Param are now immutable classes (like String),

which allows to refer to them concurrently without synchronization
(which for example in turn simplifies GUI management)

  • also make Path immutable (which was earlier only assumed)
  • add global cache for FramsClasses? created solely and automatically

on base of Java classes.

representations basing on given FramsClass?

  • above changes greatly improved GUI responsivness during browsing
  • furtherly improve Param class hierarchy
  • allow to inject actions on state changes into MultiParamLoader?
  • add more tests

CHANGELOG:

Add StatusListener? to MultiParamLoader?.

Minor refactorization in MultiParamLoader?.

First step with auto append.

Add SchemaTest?.

Improve Registry.

Clean up in Registry.

Work out Registry.

Use annotations for Param.

Fix ListChange?.

Improve fluent interface of the FramsClassBuilder?.

Done caching of ReflectionAccess?.Backend

Fix hashCode of Pair.

A step on a way to cache ReflectionAccess?.Backend

Make SimpleAbstractAccess?.framsClass a final field.

Add static cache for FramsClasses? based on java.

Only classes created strictly and automatically
based on java classes are using this cache.

Make all Params immutable.

Many improvement to make Param immutable.

Make PrimitiveParam? generic type.

Several changes to make Param immutable.

Make FramsClass? immutable.

Another improvement to Path immutability.

Several improvements to Path.

Improve PathTest?.

Configurarable MutabilityDetector?.

File size: 1.3 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.params.SinkInterface;
8
9import javax.annotation.concurrent.Immutable;
10
11/**
12 * @author Piotr Sniegowski
13 */
14@Immutable
15public class StringParam extends PrimitiveParam<String> {
16
17
18
19        /**
20         * @param builder
21         */
22        public StringParam(ParamBuilder builder) {
23                super(builder);
24        }
25
26        @Override
27        public Class<?> getStorageType() {
28                return String.class;
29        }
30
31        @Override
32        public ReassignResult<String> reassign(Object newValue, Object oldValue) throws CastFailure {
33                if (newValue == null) {
34                        return new ReassignResult<String>(null);
35                }
36                if (newValue instanceof String) {
37                        return ReassignResult.create((String) newValue);
38                }
39                return ReassignResult.create(newValue.toString());
40                // return super.reassign(newValue, oldValue);
41        }
42
43        @Override
44        public String getFramsTypeName() {
45                return "s";
46        }
47
48        private static final String SEPARATOR = System.getProperty("line.separator");
49
50        @Override
51        public void save(SinkInterface sink, Object value) {
52                assert value instanceof String;
53                String s = (String)value;
54                sink.print((s.contains(SEPARATOR) ? (s = "~" + SEPARATOR + s + "~") : s));
55        }
56}
Note: See TracBrowser for help on using the repository browser.