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

COVERAGE SUMMARY FOR SOURCE FILE [IntArray.java]

nameclass, %method, %block, %line, %
IntArray.java100% (1/1)85%  (11/13)68%  (210/309)78%  (46/59)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class IntArray100% (1/1)85%  (11/13)68%  (210/309)78%  (46/59)
toArray (int []): void 0%   (0/1)0%   (0/9)0%   (0/2)
toString (): String 0%   (0/1)0%   (0/29)0%   (0/5)
get (int): int 100% (1/1)39%  (11/28)75%  (3/4)
removeRange (int, int): void 100% (1/1)58%  (29/50)83%  (5/6)
remove (int): void 100% (1/1)62%  (28/45)83%  (5/6)
equals (Object): boolean 100% (1/1)85%  (35/41)67%  (6/9)
IntArray (): void 100% (1/1)100% (4/4)100% (2/2)
IntArray (int []): void 100% (1/1)100% (10/10)100% (4/4)
IntArray (int): void 100% (1/1)100% (7/7)100% (3/3)
add (int): void 100% (1/1)100% (25/25)100% (4/4)
ensureCapacity (int): void 100% (1/1)100% (25/25)100% (6/6)
hashCode (): int 100% (1/1)100% (33/33)100% (7/7)
size (): int 100% (1/1)100% (3/3)100% (1/1)

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.util;
7 
8import org.h2.engine.SysProperties;
9 
10/**
11 * An array with integer element.
12 */
13public class IntArray {
14 
15    private int[] data;
16    private int size;
17    private int hash;
18 
19    /**
20     * Create an int array with the default initial capacity.
21     */
22    public IntArray() {
23        this(10);
24    }
25 
26    /**
27     * Create an int array with specified initial capacity.
28     *
29     * @param capacity the initial capacity
30     */
31    public IntArray(int capacity) {
32        data = new int[capacity];
33    }
34 
35    /**
36     * Create an int array with the given values and size.
37     *
38     * @param data the int array
39     */
40    public IntArray(int[] data) {
41        this.data = data;
42        size = data.length;
43    }
44 
45    /**
46     * Append a value.
47     *
48     * @param value the value to append
49     */
50    public void add(int value) {
51        if (size >= data.length) {
52            ensureCapacity(size + size);
53        }
54        data[size++] = value;
55    }
56 
57    /**
58     * Get the value at the given index.
59     *
60     * @param index the index
61     * @return the value
62     */
63    public int get(int index) {
64        if (SysProperties.CHECK) {
65            if (index >= size) {
66                throw new ArrayIndexOutOfBoundsException("i=" + index + " size=" + size);
67            }
68        }
69        return data[index];
70    }
71 
72    /**
73     * Remove the value at the given index.
74     *
75     * @param index the index
76     */
77    public void remove(int index) {
78        if (SysProperties.CHECK) {
79            if (index >= size) {
80                throw new ArrayIndexOutOfBoundsException("i=" + index + " size=" + size);
81            }
82        }
83        System.arraycopy(data, index + 1, data, index, size - index - 1);
84        size--;
85    }
86 
87    /**
88     * Ensure the the underlying array is large enough for the given number of
89     * entries.
90     *
91     * @param minCapacity the minimum capacity
92     */
93    public void ensureCapacity(int minCapacity) {
94        minCapacity = Math.max(4, minCapacity);
95        if (minCapacity >= data.length) {
96            int[] d = new int[minCapacity];
97            System.arraycopy(data, 0, d, 0, data.length);
98            data = d;
99        }
100    }
101 
102    @Override
103    public boolean equals(Object obj) {
104        if (!(obj instanceof IntArray)) {
105            return false;
106        }
107        IntArray other = (IntArray) obj;
108        if (hashCode() != other.hashCode() || size != other.size) {
109            return false;
110        }
111        for (int i = 0; i < size; i++) {
112            if (data[i] != other.data[i]) {
113                return false;
114            }
115        }
116        return true;
117    }
118 
119    @Override
120    public int hashCode() {
121        if (hash != 0) {
122            return hash;
123        }
124        int h = size + 1;
125        for (int i = 0; i < size; i++) {
126            h = h * 31 + data[i];
127        }
128        hash = h;
129        return h;
130    }
131 
132    /**
133     * Get the size of the list.
134     *
135     * @return the size
136     */
137    public int size() {
138        return size;
139    }
140 
141    /**
142     * Convert this list to an array. The target array must be big enough.
143     *
144     * @param array the target array
145     */
146    public void toArray(int[] array) {
147        System.arraycopy(data, 0, array, 0, size);
148    }
149 
150    @Override
151    public String toString() {
152        StatementBuilder buff = new StatementBuilder("{");
153        for (int i = 0; i < size; i++) {
154            buff.appendExceptFirst(", ");
155            buff.append(data[i]);
156        }
157        return buff.append('}').toString();
158    }
159 
160    /**
161     * Remove a number of elements.
162     *
163     * @param fromIndex the index of the first item to remove
164     * @param toIndex upper bound (exclusive)
165     */
166    public void removeRange(int fromIndex, int toIndex) {
167        if (SysProperties.CHECK) {
168            if (fromIndex > toIndex || toIndex > size) {
169                throw new ArrayIndexOutOfBoundsException("from=" + fromIndex +
170                        " to=" + toIndex + " size=" + size);
171            }
172        }
173        System.arraycopy(data, toIndex, data, fromIndex, size - toIndex);
174        size -= toIndex - fromIndex;
175    }
176 
177}

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