]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/serialization/impl/DoubleSerializer.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / serialization / impl / DoubleSerializer.java
1 package org.simantics.databoard.serialization.impl;
2
3 import java.io.DataInput;
4 import java.io.DataOutput;
5 import java.io.IOException;
6
7 import org.simantics.databoard.binding.DoubleBinding;
8 import org.simantics.databoard.binding.error.BindingException;
9 import org.simantics.databoard.serialization.Serializer.NonRecursiveSerializer;
10
11 public class DoubleSerializer extends NonRecursiveSerializer {
12
13         DoubleBinding binding;
14         
15         public DoubleSerializer(DoubleBinding binding) {this.binding = binding;}
16         
17         @Override
18         public Object deserialize(DataInput in) throws IOException {
19                 try {
20                         double value = in.readDouble();
21                         return binding.create(value);
22                 } catch (BindingException e) {
23                         throw new IOException( e ); 
24                 }
25         }
26         
27         @Override
28         public void deserializeTo(DataInput in, Object obj) throws IOException {
29                 try {
30                         double value = in.readDouble();
31                         binding.setValue(obj, value);
32                 } catch (BindingException e) {
33                         throw new IOException( e ); 
34                 }
35         }
36
37         @Override
38         public void skip(DataInput in)
39                         throws IOException {
40                 in.skipBytes(8);                        
41         }
42         
43         @Override
44         public void serialize(DataOutput out, Object obj) throws IOException {
45                 try {
46                         double value = binding.getValue_(obj);
47                         out.writeDouble(value);
48                 } catch (BindingException e) {
49                         throw new IOException( e ); 
50                 }
51         }
52
53         @Override
54         public Integer getConstantSize() {
55                 return 8;
56         }
57
58         @Override
59         public int getSize(Object obj) {
60                 return 8;
61         }
62         
63         @Override
64         public int getMinSize() {
65                 return 8;
66         }
67         
68         public double getDouble(DataInput in) throws IOException
69         {
70                 return in.readDouble();
71         }
72         
73         public void putDouble(DataOutput out, double x) throws IOException
74         {
75                 out.writeDouble(x);
76         }
77         
78 }