• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

link-intersystems / lis-commons / #243

22 Sep 2023 01:08PM UTC coverage: 89.793% (-0.3%) from 90.043%
#243

push

renelink
Added longest common sequence implementation.

74 of 74 new or added lines in 2 files covered. (100.0%)

7495 of 8347 relevant lines covered (89.79%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.78
/lis-commons-util/src/main/java/com/link_intersystems/util/ArrayTable.java
1
package com.link_intersystems.util;
2

3
import java.lang.reflect.Array;
4

5
import static java.util.Objects.*;
6

7
/**
8
 * Resizable-array implementation of the {@code Table} interface.
9
 *
10
 * @param <E>
11
 */
12
public class ArrayTable<E> implements Table<E> {
13

14
    private final Class<E> elementType;
15
    private E[][] table;
16
    private E defaultCellValue;
17
    private int rowGrowSize = 16;
1✔
18
    private int columnGrowSize = 16;
1✔
19

20
    public ArrayTable(Class<E> elementType) {
21
        this(elementType, null);
1✔
22
    }
1✔
23

24
    public ArrayTable(Class<E> elementType, E defaultCellValue) {
1✔
25
        this.elementType = requireNonNull(elementType);
1✔
26
        table = (E[][]) Array.newInstance(elementType, 0, 0);
1✔
27
        this.defaultCellValue = defaultCellValue;
1✔
28
    }
1✔
29

30
    public void setRowGrowSize(int rowGrowSize) {
31
        if (rowGrowSize < 1) {
×
32
            throw new IllegalArgumentException();
×
33
        }
34
        this.rowGrowSize = rowGrowSize;
×
35
    }
×
36

37
    public void setColumnGrowSize(int columnGrowSize) {
38
        if (columnGrowSize < 1) {
×
39
            throw new IllegalArgumentException();
×
40
        }
41
        this.columnGrowSize = columnGrowSize;
×
42
    }
×
43

44
    @Override
45
    public E getCell(int row, int column) {
46
        E cellValue = null;
1✔
47

48
        if (table != null && row < table.length && column < table[row].length) {
1✔
49
            cellValue = table[row][column];
1✔
50
        }
51

52
        if (cellValue == null) {
1✔
53
            cellValue = defaultCellValue;
1✔
54
        }
55

56
        return cellValue;
1✔
57
    }
58

59
    @Override
60
    public E setCell(int row, int column, E element) {
61
        ensureCapacity(row, column);
1✔
62

63
        E previousElement = table[row][column];
1✔
64
        table[row][column] = element;
1✔
65
        return previousElement;
1✔
66
    }
67

68
    private void ensureCapacity(int row, int column) {
69
        if (row >= table.length) {
1✔
70
            E[][] newTable = growRows(row);
1✔
71

72
            for (int i = 0; i < table.length; i++) {
1✔
73
                newTable[i] = table[i];
1✔
74
            }
75

76
            table = newTable;
1✔
77
        }
78

79
        if (column >= table[row].length) {
1✔
80
            E[] newColumns = growColumns(row, column);
1✔
81
            System.arraycopy(table[row], 0, newColumns, 0, table[row].length);
1✔
82
            table[row] = newColumns;
1✔
83
        }
84
    }
1✔
85

86
    protected E[] growColumns(int row, int column) {
87
        int newSize = column + 1 + columnGrowSize;
1✔
88
        if (newSize < 0) {
1✔
89
            newSize = Integer.MAX_VALUE;
×
90
        }
91
        return (E[]) Array.newInstance(elementType, newSize);
1✔
92
    }
93

94
    protected E[][] growRows(int minRows) {
95
        int newSize = minRows + 1 + rowGrowSize;
1✔
96
        if (newSize < 0) {
1✔
97
            newSize = Integer.MAX_VALUE;
×
98
        }
99
        return (E[][]) Array.newInstance(elementType, newSize, 0);
1✔
100
    }
101

102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc