Skip to content

Commit 6af44ca

Browse files
awalter17imagejan
authored andcommitted
Create and implement PrimitiveColumn, and update tests
1 parent 447c4ef commit 6af44ca

35 files changed

+222
-311
lines changed

src/main/java/net/imagej/table/BoolColumn.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
*
3939
* @author Alison Walter
4040
*/
41-
public class BoolColumn extends BoolArray implements Column<Boolean> {
41+
public class BoolColumn extends BoolArray implements
42+
PrimitiveColumn<boolean[], Boolean>
43+
{
4244

4345
/** The column header. */
4446
private String header;
@@ -66,31 +68,20 @@ public Class<Boolean> getType() {
6668
return Boolean.class;
6769
}
6870

71+
// -- PrimitiveColumn methods --
72+
6973
@Override
70-
public void fill(final Boolean[] values) {
71-
final boolean[] prim = toPrimitive(values);
72-
this.setArray(prim);
74+
public void fill(final boolean[] values) {
75+
setArray(values.clone());
7376
}
7477

7578
@Override
76-
public void fill(final Boolean[] values, final int offset) {
77-
final boolean[] prim = toPrimitive(values);
78-
79+
public void fill(final boolean[] values, final int offset) {
7980
// Check if array has been initialized
80-
if (this.getArray() == null) this.setArray(prim);
81+
if (getArray() == null) setArray(values.clone());
8182
else {
82-
System.arraycopy(prim, 0, this.getArray(), offset, prim.length);
83-
}
84-
}
85-
86-
// -- Helper methods --
87-
88-
private boolean[] toPrimitive(final Boolean[] values) {
89-
final boolean[] prim = new boolean[values.length];
90-
for (int i = 0; i < prim.length; i++) {
91-
prim[i] = values[i].booleanValue();
83+
System.arraycopy(values, 0, getArray(), offset, values.length);
9284
}
93-
return prim;
9485
}
9586

9687
}

src/main/java/net/imagej/table/BoolTable.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@
3939
public interface BoolTable extends Table<BoolColumn, Boolean> {
4040

4141
/** Gets the value of the given table cell. */
42-
boolean getValue(int col, int row);
42+
default boolean getValue(final int col, final int row) {
43+
return get(col).getValue(row);
44+
}
4345

4446
/** Sets the value of the given table cell. */
45-
void setValue(int col, int row, boolean value);
47+
default void setValue(final int col, final int row, final boolean value) {
48+
get(col).setValue(row, value);
49+
}
4650

4751
}

src/main/java/net/imagej/table/ByteColumn.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
*
3939
* @author Alison Walter
4040
*/
41-
public class ByteColumn extends ByteArray implements Column<Byte> {
41+
public class ByteColumn extends ByteArray implements
42+
PrimitiveColumn<byte[], Byte>
43+
{
4244

4345
/** The column header. */
4446
private String header;
@@ -66,31 +68,20 @@ public Class<Byte> getType() {
6668
return Byte.class;
6769
}
6870

71+
// -- PrimitiveColumn methods --
72+
6973
@Override
70-
public void fill(final Byte[] values) {
71-
final byte[] prim = toPrimitive(values);
72-
this.setArray(prim);
74+
public void fill(final byte[] values) {
75+
setArray(values.clone());
7376
}
7477

7578
@Override
76-
public void fill(final Byte[] values, final int offset) {
77-
final byte[] prim = toPrimitive(values);
78-
79+
public void fill(final byte[] values, final int offset) {
7980
// Check if array has been initialized
80-
if (this.getArray() == null) this.setArray(prim);
81+
if (getArray() == null) setArray(values.clone());
8182
else {
82-
System.arraycopy(prim, 0, this.getArray(), offset, prim.length);
83-
}
84-
}
85-
86-
// -- Helper methods --
87-
88-
private byte[] toPrimitive(final Byte[] values) {
89-
final byte[] prim = new byte[values.length];
90-
for (int i = 0; i < prim.length; i++) {
91-
prim[i] = values[i].byteValue();
83+
System.arraycopy(values, 0, getArray(), offset, values.length);
9284
}
93-
return prim;
9485
}
9586

9687
}

src/main/java/net/imagej/table/ByteTable.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@
3939
public interface ByteTable extends Table<ByteColumn, Byte> {
4040

4141
/** Gets the value of the given table cell. */
42-
byte getValue(int col, int row);
42+
default byte getValue(int col, int row) {
43+
return get(col).getValue(row);
44+
}
4345

4446
/** Sets the value of the given table cell. */
45-
void setValue(int col, int row, byte value);
47+
default void setValue(int col, int row, byte value) {
48+
get(col).setValue(row, value);
49+
}
4650

4751
}

src/main/java/net/imagej/table/CharColumn.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
*
3939
* @author Alison Walter
4040
*/
41-
public class CharColumn extends CharArray implements Column<Character> {
41+
public class CharColumn extends CharArray implements
42+
PrimitiveColumn<char[], Character>
43+
{
4244

4345
/** The column header. */
4446
private String header;
@@ -66,31 +68,20 @@ public Class<Character> getType() {
6668
return Character.class;
6769
}
6870

71+
// -- PrimitiveColumn methods --
72+
6973
@Override
70-
public void fill(final Character[] values) {
71-
final char[] prim = toPrimitive(values);
72-
this.setArray(prim);
74+
public void fill(final char[] values) {
75+
setArray(values.clone());
7376
}
7477

7578
@Override
76-
public void fill(final Character[] values, final int offset) {
77-
final char[] prim = toPrimitive(values);
78-
79+
public void fill(final char[] values, final int offset) {
7980
// Check if array has been initialized
80-
if (this.getArray() == null) this.setArray(prim);
81+
if (getArray() == null) setArray(values.clone());
8182
else {
82-
System.arraycopy(prim, 0, this.getArray(), offset, prim.length);
83-
}
84-
}
85-
86-
// -- Helper methods --
87-
88-
private char[] toPrimitive(final Character[] values) {
89-
final char[] prim = new char[values.length];
90-
for (int i = 0; i < prim.length; i++) {
91-
prim[i] = values[i].charValue();
83+
System.arraycopy(values, 0, getArray(), offset, values.length);
9284
}
93-
return prim;
9485
}
9586

9687
}

src/main/java/net/imagej/table/CharTable.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@
3939
public interface CharTable extends Table<CharColumn, Character> {
4040

4141
/** Gets the value of the given table cell. */
42-
char getValue(int col, int row);
42+
default char getValue(final int col, final int row) {
43+
return get(col).getValue(row);
44+
}
4345

4446
/** Sets the value of the given table cell. */
45-
void setValue(int col, int row, char value);
47+
default void setValue(final int col, final int row, final char value) {
48+
get(col).setValue(row, value);
49+
}
4650

4751
}

src/main/java/net/imagej/table/Column.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,4 @@ public interface Column<T> extends List<T>, Sizable {
6060
/** Returns the actual type of data stored in the column. */
6161
Class<T> getType();
6262

63-
/** Fills the column with the values in the given array. */
64-
void fill(T[] values);
65-
66-
/** Fills the column with the values in the given array. */
67-
void fill(T[] values, int offset);
68-
6963
}

src/main/java/net/imagej/table/DefaultBoolTable.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
* @author Alison Walter
3838
*/
3939
public class DefaultBoolTable extends AbstractTable<BoolColumn, Boolean>
40-
implements BoolTable {
40+
implements BoolTable
41+
{
4142

4243
/** Creates an empty boolean table. */
4344
public DefaultBoolTable() {
@@ -49,18 +50,6 @@ public DefaultBoolTable(final int columnCount, final int rowCount) {
4950
super(columnCount, rowCount);
5051
}
5152

52-
// -- BoolTable methods --
53-
54-
@Override
55-
public boolean getValue(final int col, final int row) {
56-
return get(col).getValue(row);
57-
}
58-
59-
@Override
60-
public void setValue(final int col, final int row, final boolean value) {
61-
get(col).setValue(row, value);
62-
}
63-
6453
// -- Internal methods --
6554

6655
@Override

src/main/java/net/imagej/table/DefaultByteTable.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
* @author Alison Walter
3838
*/
3939
public class DefaultByteTable extends AbstractTable<ByteColumn, Byte>
40-
implements ByteTable {
40+
implements ByteTable
41+
{
4142

4243
/** Creates an empty byte table. */
4344
public DefaultByteTable() {
@@ -49,18 +50,6 @@ public DefaultByteTable(final int columnCount, final int rowCount) {
4950
super(columnCount, rowCount);
5051
}
5152

52-
// -- ByteTable methods --
53-
54-
@Override
55-
public byte getValue(final int col, final int row) {
56-
return get(col).getValue(row);
57-
}
58-
59-
@Override
60-
public void setValue(final int col, final int row, final byte value) {
61-
get(col).setValue(row, value);
62-
}
63-
6453
// -- Internal methods --
6554

6655
@Override

src/main/java/net/imagej/table/DefaultCharTable.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
* @author Alison Walter
3838
*/
3939
public class DefaultCharTable extends AbstractTable<CharColumn, Character>
40-
implements CharTable {
40+
implements CharTable
41+
{
4142

4243
/** Creates an empty char table. */
4344
public DefaultCharTable() {
@@ -49,18 +50,6 @@ public DefaultCharTable(final int columnCount, final int rowCount) {
4950
super(columnCount, rowCount);
5051
}
5152

52-
// -- CharTable methods --
53-
54-
@Override
55-
public char getValue(final int col, final int row) {
56-
return get(col).getValue(row);
57-
}
58-
59-
@Override
60-
public void setValue(final int col, final int row, final char value) {
61-
get(col).setValue(row, value);
62-
}
63-
6453
// -- Internal methods --
6554

6655
@Override

0 commit comments

Comments
 (0)