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

COVERAGE SUMMARY FOR SOURCE FILE [ConcurrentArrayList.java]

nameclass, %method, %block, %line, %
ConcurrentArrayList.java100% (2/2)91%  (10/11)98%  (139/142)96%  (26/27)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ConcurrentArrayList$1100% (1/1)75%  (3/4)91%  (32/35)80%  (4/5)
remove (): void 0%   (0/1)0%   (0/3)0%   (0/1)
ConcurrentArrayList$1 (ConcurrentArrayList): void 100% (1/1)100% (11/11)100% (2/2)
hasNext (): boolean 100% (1/1)100% (10/10)100% (1/1)
next (): Object 100% (1/1)100% (11/11)100% (1/1)
     
class ConcurrentArrayList100% (1/1)100% (7/7)100% (107/107)100% (23/23)
ConcurrentArrayList (): void 100% (1/1)100% (8/8)100% (2/2)
add (Object): void 100% (1/1)100% (18/18)100% (4/4)
iterator (): Iterator 100% (1/1)100% (5/5)100% (1/1)
peekFirst (): Object 100% (1/1)100% (12/12)100% (2/2)
peekLast (): Object 100% (1/1)100% (16/16)100% (3/3)
removeFirst (Object): boolean 100% (1/1)100% (30/30)100% (7/7)
removeLast (Object): boolean 100% (1/1)100% (18/18)100% (4/4)

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.mvstore;
7 
8import java.util.Arrays;
9import java.util.Iterator;
10 
11/**
12 * A very simple array list that supports concurrent access.
13 * Internally, it uses immutable objects.
14 *
15 * @param <K> the key type
16 */
17public class ConcurrentArrayList<K> {
18 
19    /**
20     * The array.
21     */
22    @SuppressWarnings("unchecked")
23    K[] array = (K[]) new Object[0];
24 
25    /**
26     * Get the first element, or null if none.
27     *
28     * @return the first element
29     */
30    public K peekFirst() {
31        K[] a = array;
32        return a.length == 0 ? null : a[0];
33    }
34 
35    /**
36     * Get the last element, or null if none.
37     *
38     * @return the last element
39     */
40    public K peekLast() {
41        K[] a = array;
42        int len = a.length;
43        return len == 0 ? null : a[len - 1];
44    }
45 
46    /**
47     * Add an element at the end.
48     *
49     * @param obj the element
50     */
51    public synchronized void add(K obj) {
52        int len = array.length;
53        array = Arrays.copyOf(array, len + 1);
54        array[len] = obj;
55    }
56 
57    /**
58     * Remove the first element, if it matches.
59     *
60     * @param obj the element to remove
61     * @return true if the element matched and was removed
62     */
63    public synchronized boolean removeFirst(K obj) {
64        if (peekFirst() != obj) {
65            return false;
66        }
67        int len = array.length;
68        @SuppressWarnings("unchecked")
69        K[] a = (K[]) new Object[len - 1];
70        System.arraycopy(array, 1, a, 0, len - 1);
71        array = a;
72        return true;
73    }
74 
75    /**
76     * Remove the last element, if it matches.
77     *
78     * @param obj the element to remove
79     * @return true if the element matched and was removed
80     */
81    public synchronized boolean removeLast(K obj) {
82        if (peekLast() != obj) {
83            return false;
84        }
85        array = Arrays.copyOf(array, array.length - 1);
86        return true;
87    }
88 
89    /**
90     * Get an iterator over all entries.
91     *
92     * @return the iterator
93     */
94    public Iterator<K> iterator() {
95        return new Iterator<K>() {
96 
97            K[] a = array;
98            int index;
99 
100            @Override
101            public boolean hasNext() {
102                return index < a.length;
103            }
104 
105            @Override
106            public K next() {
107                return a[index++];
108            }
109 
110            @Override
111            public void remove() {
112                throw DataUtils.newUnsupportedOperationException("remove");
113            }
114 
115        };
116    }
117 
118}

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