-/*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
+/*******************************************************************************
+ * Copyright (c) 2010 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
package org.simantics.databoard.example.old;
-import java.awt.geom.Rectangle2D;\r
-import java.io.IOException;\r
-\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.Datatypes;\r
-import org.simantics.databoard.binding.Binding;\r
-import org.simantics.databoard.binding.RecordBinding;\r
-import org.simantics.databoard.binding.error.BindingException;\r
-import org.simantics.databoard.type.Datatype;\r
+import java.awt.geom.Rectangle2D;
+import java.io.IOException;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.databoard.Datatypes;
+import org.simantics.databoard.binding.Binding;
+import org.simantics.databoard.binding.RecordBinding;
+import org.simantics.databoard.binding.error.BindingException;
+import org.simantics.databoard.type.Datatype;
/**
* {@link Binding} is a link between an instance and a {@link Datatype}.
@Override
public boolean isInstance(Object obj) {
return obj instanceof Rectangle2D;
- }\r
- \r
- @Override\r
- public void setDouble(Object r, int index, double x)\r
- throws BindingException {\r
- Rectangle2D.Double rect = (Rectangle2D.Double) r;\r
- switch (index) {\r
- case 0: rect.x = x; break;\r
- case 1: rect.y = x; break;\r
- case 2: rect.width = x; break;\r
- case 3: rect.height = x; break;\r
- default: throw new IllegalArgumentException("index out of range, expected 0..3, got "+index);\r
- }\r
- }\r
- \r
- @Override\r
- public double getDouble(Object r, int index) throws BindingException {\r
- Rectangle2D.Double rect = (Rectangle2D.Double) r;\r
- switch (index) {\r
- case 0: return rect.x; \r
- case 1: return rect.y;\r
- case 2: return rect.width;\r
- case 3: return rect.height;\r
- default: throw new IllegalArgumentException("index out of range, expected 0..3, got "+index);\r
- }\r
+ }
+
+ @Override
+ public void setDouble(Object r, int index, double x)
+ throws BindingException {
+ Rectangle2D.Double rect = (Rectangle2D.Double) r;
+ switch (index) {
+ case 0: rect.x = x; break;
+ case 1: rect.y = x; break;
+ case 2: rect.width = x; break;
+ case 3: rect.height = x; break;
+ default: throw new IllegalArgumentException("index out of range, expected 0..3, got "+index);
+ }
+ }
+
+ @Override
+ public double getDouble(Object r, int index) throws BindingException {
+ Rectangle2D.Double rect = (Rectangle2D.Double) r;
+ switch (index) {
+ case 0: return rect.x;
+ case 1: return rect.y;
+ case 2: return rect.width;
+ case 3: return rect.height;
+ default: throw new IllegalArgumentException("index out of range, expected 0..3, got "+index);
+ }
}
}
System.out.println("Lets measure performance... (4,000,000 reads and 1,000,000 writes*4)");
Rectangle2D rect = new Rectangle2D.Double(5, 5, 100, 200);
- \r
+
for ( int i=0; i<10; i++ ) {
long time1 = testBinding(reflectionBinding, rect);
long time2 = testBinding(handWrittenBinding, rect);
- time1 = testBinding(reflectionBinding, rect);\r
- time2 = testBinding(handWrittenBinding, rect);\r
- \r
+ time1 = testBinding(reflectionBinding, rect);
+ time2 = testBinding(handWrittenBinding, rect);
+
System.out.println("Time of reflection based binding: "+time1+" ms");
- System.out.println("Time of Hand-Written binding: "+time2+" ms");\r
+ System.out.println("Time of Hand-Written binding: "+time2+" ms");
}
}