EMMA Coverage Report (generated Sun Mar 01 22:06:14 CET 2015)
[all classes][org.h2.value]

COVERAGE SUMMARY FOR SOURCE FILE [ValueByte.java]

nameclass, %method, %block, %line, %
ValueByte.java100% (1/1)90%  (19/21)76%  (119/156)80%  (28.9/36)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ValueByte100% (1/1)90%  (19/21)76%  (119/156)80%  (28.9/36)
compareSecure (Value, CompareMode): int 0%   (0/1)0%   (0/9)0%   (0/2)
modulus (Value): Value 0%   (0/1)0%   (0/19)0%   (0/4)
divide (Value): Value 100% (1/1)58%  (11/19)75%  (3/4)
equals (Object): boolean 100% (1/1)92%  (12/13)92%  (0.9/1)
ValueByte (byte): void 100% (1/1)100% (6/6)100% (3/3)
add (Value): Value 100% (1/1)100% (10/10)100% (2/2)
checkRange (int): ValueByte 100% (1/1)100% (15/15)100% (3/3)
get (byte): ValueByte 100% (1/1)100% (7/7)100% (1/1)
getByte (): byte 100% (1/1)100% (3/3)100% (1/1)
getDisplaySize (): int 100% (1/1)100% (2/2)100% (1/1)
getObject (): Object 100% (1/1)100% (4/4)100% (1/1)
getPrecision (): long 100% (1/1)100% (2/2)100% (1/1)
getSQL (): String 100% (1/1)100% (3/3)100% (1/1)
getSignum (): int 100% (1/1)100% (4/4)100% (1/1)
getString (): String 100% (1/1)100% (4/4)100% (1/1)
getType (): int 100% (1/1)100% (2/2)100% (1/1)
hashCode (): int 100% (1/1)100% (3/3)100% (1/1)
multiply (Value): Value 100% (1/1)100% (10/10)100% (2/2)
negate (): Value 100% (1/1)100% (5/5)100% (1/1)
set (PreparedStatement, int): void 100% (1/1)100% (6/6)100% (2/2)
subtract (Value): Value 100% (1/1)100% (10/10)100% (2/2)

1/*
2 * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (http://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6package org.h2.value;
7 
8import java.sql.PreparedStatement;
9import java.sql.SQLException;
10 
11import org.h2.api.ErrorCode;
12import org.h2.message.DbException;
13import org.h2.util.MathUtils;
14 
15/**
16 * Implementation of the BYTE data type.
17 */
18public class ValueByte extends Value {
19 
20    /**
21     * The precision in digits.
22     */
23    static final int PRECISION = 3;
24 
25    /**
26     * The display size for a byte.
27     * Example: -127
28     */
29    static final int DISPLAY_SIZE = 4;
30 
31    private final byte value;
32 
33    private ValueByte(byte value) {
34        this.value = value;
35    }
36 
37    @Override
38    public Value add(Value v) {
39        ValueByte other = (ValueByte) v;
40        return checkRange(value + other.value);
41    }
42 
43    private static ValueByte checkRange(int x) {
44        if (x < Byte.MIN_VALUE || x > Byte.MAX_VALUE) {
45            throw DbException.get(ErrorCode.NUMERIC_VALUE_OUT_OF_RANGE_1,
46                    Integer.toString(x));
47        }
48        return ValueByte.get((byte) x);
49    }
50 
51    @Override
52    public int getSignum() {
53        return Integer.signum(value);
54    }
55 
56    @Override
57    public Value negate() {
58        return checkRange(-(int) value);
59    }
60 
61    @Override
62    public Value subtract(Value v) {
63        ValueByte other = (ValueByte) v;
64        return checkRange(value - other.value);
65    }
66 
67    @Override
68    public Value multiply(Value v) {
69        ValueByte other = (ValueByte) v;
70        return checkRange(value * other.value);
71    }
72 
73    @Override
74    public Value divide(Value v) {
75        ValueByte other = (ValueByte) v;
76        if (other.value == 0) {
77            throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getSQL());
78        }
79        return ValueByte.get((byte) (value / other.value));
80    }
81 
82    @Override
83    public Value modulus(Value v) {
84        ValueByte other = (ValueByte) v;
85        if (other.value == 0) {
86            throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getSQL());
87        }
88        return ValueByte.get((byte) (value % other.value));
89    }
90 
91    @Override
92    public String getSQL() {
93        return getString();
94    }
95 
96    @Override
97    public int getType() {
98        return Value.BYTE;
99    }
100 
101    @Override
102    public byte getByte() {
103        return value;
104    }
105 
106    @Override
107    protected int compareSecure(Value o, CompareMode mode) {
108        ValueByte v = (ValueByte) o;
109        return MathUtils.compareInt(value, v.value);
110    }
111 
112    @Override
113    public String getString() {
114        return String.valueOf(value);
115    }
116 
117    @Override
118    public long getPrecision() {
119        return PRECISION;
120    }
121 
122    @Override
123    public int hashCode() {
124        return value;
125    }
126 
127    @Override
128    public Object getObject() {
129        return Byte.valueOf(value);
130    }
131 
132    @Override
133    public void set(PreparedStatement prep, int parameterIndex)
134            throws SQLException {
135        prep.setByte(parameterIndex, value);
136    }
137 
138    /**
139     * Get or create byte value for the given byte.
140     *
141     * @param i the byte
142     * @return the value
143     */
144    public static ValueByte get(byte i) {
145        return (ValueByte) Value.cache(new ValueByte(i));
146    }
147 
148    @Override
149    public int getDisplaySize() {
150        return DISPLAY_SIZE;
151    }
152 
153    @Override
154    public boolean equals(Object other) {
155        return other instanceof ValueByte && value == ((ValueByte) other).value;
156    }
157 
158}

[all classes][org.h2.value]
EMMA 2.0.5312 (C) Vladimir Roubtsov