1 /*******************************************************************************
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.databoard.tests;
14 import java.util.UUID;
16 import org.simantics.databoard.Bindings;
17 import org.simantics.databoard.binding.Binding;
18 import org.simantics.databoard.binding.RecordBinding;
19 import org.simantics.databoard.serialization.Serializer;
21 public class TestPrimitiveSetters {
23 public static class X {
25 public boolean z; // 0
26 public Boolean zz;// 1
32 public Integer ii;// 5
40 public double d; // 10
41 public Double dd; // 11
43 private boolean z_; // 12
44 private Boolean zz_;// 13
46 private byte b_; // 14
47 private Byte bb_; // 15
50 private Integer ii_;// 17
52 private long l_; // 18
53 private Long ll_; // 19
55 private float f_; // 20
56 private Float ff_; // 21
58 private double d_; // 22
59 private Double dd_; // 23
61 public void setZ_(boolean z) {this.z_ = z;}
62 public boolean getZ_() {return z_;}
64 public void setZz_(Boolean z) {this.zz_ = z;}
65 public Boolean getZz_() {return zz_;}
67 public void setB_(byte z) {this.b_ = z;}
68 public byte getB_() {return b_;}
70 public void setBb_(Byte z) {this.bb_ = z;}
71 public Byte getBb_() {return bb_;}
75 public static void main(String[] args) throws Exception {
76 // DONE Add primitive support for Deserialization
78 // TODO Remove validator from AsmBindingClassLoader
81 RecordBinding b = Bindings.getBinding( X.class );
84 b.setBoolean(x, 0, true);
85 b.setBoolean(x, 1, true);
87 b.setByte(x, 2, (byte)3);
88 b.setByte(x, 3, (byte)3);
96 b.setFloat(x, 8, 3.f);
97 b.setFloat(x, 9, 3.f);
99 b.setDouble(x, 10, 3.2);
100 b.setDouble(x, 11, 3.4);
102 b.setBoolean(x, 12, true);
103 b.setBoolean(x, 13, true);
105 b.setByte(x, 14, (byte)3);
106 b.setByte(x, 15, (byte)3);
108 System.out.println( b.getBoolean(x, 0) );
109 System.out.println( b.getBoolean(x, 1) );
111 System.out.println( b.getByte(x, 2) );
112 System.out.println( b.getByte(x, 3) );
114 System.out.println( b.getInt(x, 4) );
115 System.out.println( b.getInt(x, 5) );
117 System.out.println( b.getLong(x, 6) );
118 System.out.println( b.getLong(x, 7) );
120 System.out.println( b.getFloat(x, 8) );
121 System.out.println( b.getFloat(x, 9) );
123 System.out.println( b.getDouble(x, 10) );
124 System.out.println( b.getDouble(x, 11) );
126 System.out.println( b.getBoolean(x, 12) );
127 System.out.println( b.getBoolean(x, 13) );
129 System.out.println( b.getByte(x, 14) );
130 System.out.println( b.getByte(x, 15) );
132 System.out.println(b.toString(x));
134 UUID guid = UUID.randomUUID();
135 Binding binding = Bindings.getBinding(UUID.class);
136 Serializer s = Bindings.getSerializer(binding);
137 byte[] data = s.serialize( guid );
139 guid = (UUID) s.deserialize( data );