source: java/main/src/main/java/com/framsticks/params/types/BooleanParam.java @ 88

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

HIGHLIGHTS:

  • loading f0 schema with XmlLoader?
  • use XmlLoader? to load configuration
  • introduce unified fork-join model of various entities

(Instances, Connections, GUI Frames, etc.),
all those entities clean up gracefully on
shutdown, which may be initialized by user
or by some entity

  • basing on above, simplify several organizing classes

(Observer, main class)

(to host native frams server process from Java level)

CHANGELOG:
Remove redundant Observer class.

Clean up in AbstractJoinable?.

Update ExternalProcess? class to changes in joining model.

Another sweep through code with FindBugs?.

Find bug with not joining RemoteInstance?.

Joining almost works.

Much improved joining model.

More improvement to joining model.

Add logging messages around joinable operations.

Rename methods in AbstractJoinable?.

Improve Joinable.

Rewrite of entity structure.

More simplifications with entities.

Further improve joinables.

Let Frame compose from JFrame instead of inheriting.

Add join classes.

Improvements of closing.

Add Builder interface.

Add FramsServerTest?.xml

FramsServer? may be configured through xml.

Make Framsticks main class an Observer of Entities.

Make Observer a generic type.

Remove variables regarding to removed endpoint.

Simplify observer (remove endpoints).

More changes to Observer and Endpoint.

Minor improvements.

Add OutputListener? to ExternalProcess?.

Improve testing of ExternalProcess?.

Add ExternalProcess? runner.

Rename the Program class to Framsticks.

Migrate Program to use XmlLoader? configuration.

First steps with configuration using XmlLoader?.

Fix several bugs.

Move all f0 classes to apriopriate package.

XmlLoader? is able to load Schema.

XmlLoader? is loading classes and props.

Add GroupBuilder?.

File size: 1.5 KB
Line 
1package com.framsticks.params.types;
2
3import javax.annotation.concurrent.Immutable;
4
5import com.framsticks.params.CastFailure;
6import com.framsticks.params.ParamBuilder;
7import com.framsticks.params.PrimitiveParam;
8import com.framsticks.params.ReassignResult;
9import com.framsticks.params.SinkInterface;
10import com.framsticks.util.lang.Numbers;
11
12/**
13 * @author Piotr Sniegowski
14 */
15@Immutable
16public class BooleanParam extends PrimitiveParam<Boolean> {
17
18        /**
19         * @param builder
20         */
21        public BooleanParam(ParamBuilder builder) {
22                super(builder.fillDef(false).fillStorageType(Boolean.class));
23        }
24
25        @Override
26        public Class<?> getStorageType() {
27                return Boolean.class;
28        }
29
30        @Override
31        public ReassignResult<Boolean> reassign(Object newValue, Object oldValue) throws CastFailure {
32                if (newValue instanceof Boolean) {
33                        return ReassignResult.create((Boolean) newValue);
34                }
35                if (newValue instanceof Integer) {
36                        return ReassignResult.create(((Integer) newValue) != 0);
37                }
38                if (newValue instanceof String) {
39                        if ("true".equals(newValue)) {
40                                return ReassignResult.create(true);
41                        }
42                        if ("false".equals(newValue)) {
43                                return ReassignResult.create(false);
44                        }
45                        Integer i = Numbers.cast(newValue, Integer.class);
46                        if (i != null) {
47                                return ReassignResult.create(i != 0);
48                        }
49                        throw new CastFailure();
50                }
51                throw new CastFailure();
52        }
53
54        @Override
55        public String getFramsTypeName() {
56                return "d 0 1";
57        }
58
59        @Override
60        public void save(SinkInterface sink, Object value) {
61                assert value instanceof Boolean;
62                sink.print(((Boolean)value) ? "1" : "0");
63        }
64}
Note: See TracBrowser for help on using the repository browser.