Skip to content

Commit 44637d9

Browse files
committed
Added toArray method to PGbit
1 parent b7bb910 commit 44637d9

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/main/java/com/pgvector/PGbit.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,19 @@ public void toBytes(byte[] bytes, int offset) {
112112
}
113113
}
114114

115+
/**
116+
* Returns an array
117+
*
118+
* @return an array
119+
*/
120+
public boolean[] toArray() {
121+
boolean[] bits = new boolean[length];
122+
for (int i = 0; i < length; i++) {
123+
bits[i] = ((data[i / 8] >> (7 - (i % 8))) & 1) == 1;
124+
}
125+
return bits;
126+
}
127+
115128
/**
116129
* Registers the bit type
117130
*

src/test/java/com/pgvector/PGbitTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ public class PGbitTest {
1212
@Test
1313
void testArrayConstructor() {
1414
PGbit vec = new PGbit(new boolean[] {true, false, true});
15-
assertEquals("101", vec.getValue());
15+
assertArrayEquals(new boolean[] {true, false, true}, vec.toArray());
1616
}
1717

1818
@Test
1919
void testStringConstructor() throws SQLException {
2020
PGbit vec = new PGbit("101");
21+
assertArrayEquals(new boolean[] {true, false, true}, vec.toArray());
22+
}
23+
24+
@Test
25+
void testGetValue() {
26+
PGbit vec = new PGbit(new boolean[] {true, false, true});
2127
assertEquals("101", vec.getValue());
2228
}
2329
}

0 commit comments

Comments
 (0)