vm/src/test/java/org/apidesign/vm4brwsr/Instance.java
changeset 22 b9318fe303cd
parent 16 6e8e00258234
child 24 a82e89aae050
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Instance.java	Mon Sep 24 11:07:38 2012 +0200
     1.3 @@ -0,0 +1,69 @@
     1.4 +/*
     1.5 + * To change this template, choose Tools | Templates
     1.6 + * and open the template in the editor.
     1.7 + */
     1.8 +package org.apidesign.vm4brwsr;
     1.9 +
    1.10 +/**
    1.11 + *
    1.12 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.13 + */
    1.14 +public class Instance {
    1.15 +    private int i;
    1.16 +    protected short s;
    1.17 +    public double d;
    1.18 +    private float f;
    1.19 +    protected byte b = (byte)31;
    1.20 +    
    1.21 +    private Instance() {
    1.22 +    }
    1.23 +
    1.24 +    public Instance(int i, double d) {
    1.25 +        this.i = i;
    1.26 +        this.d = d;
    1.27 +    }
    1.28 +    public byte getByte() {
    1.29 +        return b;
    1.30 +    }
    1.31 +    
    1.32 +    public void setByte(byte b) {
    1.33 +        this.b = b;
    1.34 +    }
    1.35 +    public static double defaultDblValue() {
    1.36 +        Instance create = new Instance();
    1.37 +        return create.d;
    1.38 +    }
    1.39 +    
    1.40 +    public static byte assignedByteValue() {
    1.41 +        return new Instance().b;
    1.42 +    }
    1.43 +    public static double magicOne() {
    1.44 +        Instance i = new Instance(10, 3.3d);
    1.45 +        i.b = (byte)0x09;
    1.46 +        return (i.i - i.b) * i.d;
    1.47 +    }
    1.48 +    public static int virtualBytes() {
    1.49 +        Instance i = new InstanceSub(7, 2.2d);
    1.50 +        i.setByte((byte)0x0a);
    1.51 +        Instance i2 = new Instance(3, 333.0d);
    1.52 +        i2.setByte((byte)44);
    1.53 +        return i.getByte() + i2.getByte();
    1.54 +    }
    1.55 +    public static float interfaceBytes() {
    1.56 +        GetByte i = new InstanceSub(7, 2.2d);
    1.57 +        return i.getByte();
    1.58 +    }
    1.59 +    public static boolean instanceOf(boolean sub) {
    1.60 +        Instance i = createInstance(sub);
    1.61 +        return isInstanceSubOf(i);
    1.62 +    }
    1.63 +    private static boolean isInstanceSubOf(Instance instance) {
    1.64 +        return instance instanceof InstanceSub;
    1.65 +    }
    1.66 +    private static Instance createInstance(boolean sub) {
    1.67 +        return sub ? new InstanceSub(3, 0) : new Instance();
    1.68 +    }
    1.69 +    private static boolean isNull() {
    1.70 +        return createInstance(true) == null;
    1.71 +    }
    1.72 +}