implement cap table builder and reader
This commit is contained in:
parent
0d03705cfc
commit
59c2859881
2 changed files with 51 additions and 0 deletions
|
@ -0,0 +1,34 @@
|
||||||
|
package org.capnproto;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
class BuilderCapabilityTable implements CapTableBuilder {
|
||||||
|
|
||||||
|
private final List<ClientHook> table = new ArrayList<>();
|
||||||
|
|
||||||
|
BuilderCapabilityTable() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClientHook extractCap(int index) {
|
||||||
|
return table.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int injectCap(ClientHook cap) {
|
||||||
|
int index = table.size();
|
||||||
|
table.add(cap);
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dropCap(int index) {
|
||||||
|
table.set(index, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClientHook[] getTable() {
|
||||||
|
return table.toArray(new ClientHook[0]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package org.capnproto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
class ReaderCapabilityTable implements CapTableReader {
|
||||||
|
|
||||||
|
final List<ClientHook> table;
|
||||||
|
|
||||||
|
ReaderCapabilityTable(List<ClientHook> table) {
|
||||||
|
this.table = table;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClientHook extractCap(int index) {
|
||||||
|
return index < table.size() ? table.get(index) : null;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue