target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test void checkIdInGroupNull() { assertThrows(NullPointerException.class, () -> StoragePreconditions.checkIdInGroup(null)); }
|
@CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; } }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; } private StoragePreconditions(); }
|
@Test void checkIdInGroupEmpty() { byte[] emptyId = new byte[0]; assertThrows(IllegalArgumentException.class, () -> StoragePreconditions.checkIdInGroup(emptyId)); }
|
@CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; } }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; } private StoragePreconditions(); }
|
@Test void afterTransactions(TestKit testKit) { checkCounter(testKit, AFTER_TXS_COUNTER_NAME, 1L); for (int i = 1; i <= 2; i++) { testKit.createBlock(); checkCounter(testKit, AFTER_TXS_COUNTER_NAME, 1L + i); } }
|
@Override public void afterTransactions(ExecutionContext context) { incrementCounter(AFTER_TXS_COUNTER_NAME, context); }
|
QaServiceImpl extends AbstractService implements QaService { @Override public void afterTransactions(ExecutionContext context) { incrementCounter(AFTER_TXS_COUNTER_NAME, context); } }
|
QaServiceImpl extends AbstractService implements QaService { @Override public void afterTransactions(ExecutionContext context) { incrementCounter(AFTER_TXS_COUNTER_NAME, context); } @Inject QaServiceImpl(ServiceInstanceSpec instanceSpec); }
|
QaServiceImpl extends AbstractService implements QaService { @Override public void afterTransactions(ExecutionContext context) { incrementCounter(AFTER_TXS_COUNTER_NAME, context); } @Inject QaServiceImpl(ServiceInstanceSpec instanceSpec); @Override void initialize(ExecutionContext context, Configuration configuration); @Override void resume(ExecutionContext context, byte[] arguments); @Override void createPublicApiHandlers(Node node, Router router); @Override void beforeTransactions(ExecutionContext context); @Override void afterTransactions(ExecutionContext context); @Override void afterCommit(BlockCommittedEvent event); @Override HashCode submitIncrementCounter(long requestSeed, String counterName); @Override HashCode submitUnknownTx(); @Override @SuppressWarnings("ConstantConditions") // Node is not null. Optional<Counter> getValue(String counterName); @Override Config getConsensusConfiguration(); @Override @SuppressWarnings("ConstantConditions") // Node is not null. Optional<ZonedDateTime> getTime(); @Override @SuppressWarnings("ConstantConditions") // Node is not null. Map<PublicKey, ZonedDateTime> getValidatorsTimes(); @Override void verifyConfiguration(ExecutionContext context, Configuration configuration); @Override void applyConfiguration(ExecutionContext context, Configuration configuration); @Override @Transaction(CREATE_COUNTER_TX_ID) void createCounter(TxMessageProtos.CreateCounterTxBody arguments,
ExecutionContext context); @Override @Transaction(INCREMENT_COUNTER_TX_ID) void incrementCounter(TxMessageProtos.IncrementCounterTxBody arguments,
ExecutionContext context); @Override @Transaction(VALID_THROWING_TX_ID) void throwing(TxMessageProtos.ThrowingTxBody arguments, ExecutionContext context); @Override @Transaction(VALID_ERROR_TX_ID) void error(TxMessageProtos.ErrorTxBody arguments, ExecutionContext context); }
|
QaServiceImpl extends AbstractService implements QaService { @Override public void afterTransactions(ExecutionContext context) { incrementCounter(AFTER_TXS_COUNTER_NAME, context); } @Inject QaServiceImpl(ServiceInstanceSpec instanceSpec); @Override void initialize(ExecutionContext context, Configuration configuration); @Override void resume(ExecutionContext context, byte[] arguments); @Override void createPublicApiHandlers(Node node, Router router); @Override void beforeTransactions(ExecutionContext context); @Override void afterTransactions(ExecutionContext context); @Override void afterCommit(BlockCommittedEvent event); @Override HashCode submitIncrementCounter(long requestSeed, String counterName); @Override HashCode submitUnknownTx(); @Override @SuppressWarnings("ConstantConditions") // Node is not null. Optional<Counter> getValue(String counterName); @Override Config getConsensusConfiguration(); @Override @SuppressWarnings("ConstantConditions") // Node is not null. Optional<ZonedDateTime> getTime(); @Override @SuppressWarnings("ConstantConditions") // Node is not null. Map<PublicKey, ZonedDateTime> getValidatorsTimes(); @Override void verifyConfiguration(ExecutionContext context, Configuration configuration); @Override void applyConfiguration(ExecutionContext context, Configuration configuration); @Override @Transaction(CREATE_COUNTER_TX_ID) void createCounter(TxMessageProtos.CreateCounterTxBody arguments,
ExecutionContext context); @Override @Transaction(INCREMENT_COUNTER_TX_ID) void incrementCounter(TxMessageProtos.IncrementCounterTxBody arguments,
ExecutionContext context); @Override @Transaction(VALID_THROWING_TX_ID) void throwing(TxMessageProtos.ThrowingTxBody arguments, ExecutionContext context); @Override @Transaction(VALID_ERROR_TX_ID) void error(TxMessageProtos.ErrorTxBody arguments, ExecutionContext context); }
|
@Test void checkStorageKeyAcceptsEmpty() { byte[] key = new byte[]{}; assertThat(key, sameInstance(StoragePreconditions.checkStorageKey(key))); }
|
@CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); }
|
@Test void checkStorageKeyAcceptsNonEmpty() { byte[] key = bytes('k'); assertThat(key, sameInstance(StoragePreconditions.checkStorageKey(key))); }
|
@CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); }
|
@Test void checkStorageKeyDoesNotAcceptNull() { assertThrows(NullPointerException.class, () -> StoragePreconditions.checkStorageKey(null)); }
|
@CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); }
|
@Test void checkProofKeyAccepts32ByteZeroKey() { byte[] key = new byte[32]; assertThat(key, sameInstance(StoragePreconditions.checkProofKey(key))); }
|
@CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); }
|
@Test void checkProofKeyAccepts32ByteNonZeroKey() { byte[] key = bytes("0123456789abcdef0123456789abcdef"); assertThat(key, sameInstance(StoragePreconditions.checkProofKey(key))); }
|
@CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); }
|
@Test void checkProofKeyDoesNotAcceptNull() { NullPointerException thrown = assertThrows(NullPointerException.class, () -> StoragePreconditions.checkProofKey(null)); assertThat(thrown.getLocalizedMessage(), containsString("Proof map key is null")); }
|
@CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); }
|
@Test void checkProofKeyDoesNotAcceptSmallerKeys() { byte[] key = new byte[1]; IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> StoragePreconditions.checkProofKey(key)); assertThat(thrown.getLocalizedMessage(), containsString("Proof map key has invalid size (1)")); }
|
@CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); }
|
@Test void checkProofKeyDoesNotAcceptBiggerKeys() { byte[] key = new byte[64]; IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> StoragePreconditions.checkProofKey(key)); assertThat(thrown.getLocalizedMessage(), containsString("Proof map key has invalid size (64)")); }
|
@CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); }
|
@Test void checkStorageValueAcceptsEmpty() { byte[] value = new byte[]{}; assertThat(value, sameInstance(StoragePreconditions.checkStorageValue(value))); }
|
@CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); } }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); } private StoragePreconditions(); }
|
@Test void checkStorageValueAcceptsNonEmpty() { byte[] value = bytes('v'); assertThat(value, sameInstance(StoragePreconditions.checkStorageValue(value))); }
|
@CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); } }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); } private StoragePreconditions(); }
|
@Test void afterCommit(TestKit testKit) { testKit.createBlock(); checkAfterCommitCounter(testKit, 1L); testKit.createBlock(); checkAfterCommitCounter(testKit, 2L); }
|
@Override public void afterCommit(BlockCommittedEvent event) { long seed = event.getHeight(); submitIncrementCounter(seed, AFTER_COMMIT_COUNTER_NAME); }
|
QaServiceImpl extends AbstractService implements QaService { @Override public void afterCommit(BlockCommittedEvent event) { long seed = event.getHeight(); submitIncrementCounter(seed, AFTER_COMMIT_COUNTER_NAME); } }
|
QaServiceImpl extends AbstractService implements QaService { @Override public void afterCommit(BlockCommittedEvent event) { long seed = event.getHeight(); submitIncrementCounter(seed, AFTER_COMMIT_COUNTER_NAME); } @Inject QaServiceImpl(ServiceInstanceSpec instanceSpec); }
|
QaServiceImpl extends AbstractService implements QaService { @Override public void afterCommit(BlockCommittedEvent event) { long seed = event.getHeight(); submitIncrementCounter(seed, AFTER_COMMIT_COUNTER_NAME); } @Inject QaServiceImpl(ServiceInstanceSpec instanceSpec); @Override void initialize(ExecutionContext context, Configuration configuration); @Override void resume(ExecutionContext context, byte[] arguments); @Override void createPublicApiHandlers(Node node, Router router); @Override void beforeTransactions(ExecutionContext context); @Override void afterTransactions(ExecutionContext context); @Override void afterCommit(BlockCommittedEvent event); @Override HashCode submitIncrementCounter(long requestSeed, String counterName); @Override HashCode submitUnknownTx(); @Override @SuppressWarnings("ConstantConditions") // Node is not null. Optional<Counter> getValue(String counterName); @Override Config getConsensusConfiguration(); @Override @SuppressWarnings("ConstantConditions") // Node is not null. Optional<ZonedDateTime> getTime(); @Override @SuppressWarnings("ConstantConditions") // Node is not null. Map<PublicKey, ZonedDateTime> getValidatorsTimes(); @Override void verifyConfiguration(ExecutionContext context, Configuration configuration); @Override void applyConfiguration(ExecutionContext context, Configuration configuration); @Override @Transaction(CREATE_COUNTER_TX_ID) void createCounter(TxMessageProtos.CreateCounterTxBody arguments,
ExecutionContext context); @Override @Transaction(INCREMENT_COUNTER_TX_ID) void incrementCounter(TxMessageProtos.IncrementCounterTxBody arguments,
ExecutionContext context); @Override @Transaction(VALID_THROWING_TX_ID) void throwing(TxMessageProtos.ThrowingTxBody arguments, ExecutionContext context); @Override @Transaction(VALID_ERROR_TX_ID) void error(TxMessageProtos.ErrorTxBody arguments, ExecutionContext context); }
|
QaServiceImpl extends AbstractService implements QaService { @Override public void afterCommit(BlockCommittedEvent event) { long seed = event.getHeight(); submitIncrementCounter(seed, AFTER_COMMIT_COUNTER_NAME); } @Inject QaServiceImpl(ServiceInstanceSpec instanceSpec); @Override void initialize(ExecutionContext context, Configuration configuration); @Override void resume(ExecutionContext context, byte[] arguments); @Override void createPublicApiHandlers(Node node, Router router); @Override void beforeTransactions(ExecutionContext context); @Override void afterTransactions(ExecutionContext context); @Override void afterCommit(BlockCommittedEvent event); @Override HashCode submitIncrementCounter(long requestSeed, String counterName); @Override HashCode submitUnknownTx(); @Override @SuppressWarnings("ConstantConditions") // Node is not null. Optional<Counter> getValue(String counterName); @Override Config getConsensusConfiguration(); @Override @SuppressWarnings("ConstantConditions") // Node is not null. Optional<ZonedDateTime> getTime(); @Override @SuppressWarnings("ConstantConditions") // Node is not null. Map<PublicKey, ZonedDateTime> getValidatorsTimes(); @Override void verifyConfiguration(ExecutionContext context, Configuration configuration); @Override void applyConfiguration(ExecutionContext context, Configuration configuration); @Override @Transaction(CREATE_COUNTER_TX_ID) void createCounter(TxMessageProtos.CreateCounterTxBody arguments,
ExecutionContext context); @Override @Transaction(INCREMENT_COUNTER_TX_ID) void incrementCounter(TxMessageProtos.IncrementCounterTxBody arguments,
ExecutionContext context); @Override @Transaction(VALID_THROWING_TX_ID) void throwing(TxMessageProtos.ThrowingTxBody arguments, ExecutionContext context); @Override @Transaction(VALID_ERROR_TX_ID) void error(TxMessageProtos.ErrorTxBody arguments, ExecutionContext context); }
|
@Test void parseGetTxResponseInPool() { String json = "{\n" + " 'type': 'in-pool',\n" + " 'message': '" + toHex(TRANSACTION_MESSAGE) + "'\n" + "}"; TransactionResponse transactionResponse = ExplorerApiHelper.parseGetTxResponse(json); assertThat(transactionResponse.getStatus(), is(TransactionStatus.IN_POOL)); assertThat(transactionResponse.getMessage(), is(TRANSACTION_MESSAGE)); assertThrows(IllegalStateException.class, transactionResponse::getExecutionResult); assertThrows(IllegalStateException.class, transactionResponse::getLocation); }
|
static TransactionResponse parseGetTxResponse(String json) { GetTxResponse response = JSON.fromJson(json, GetTxResponse.class); ExecutionStatus executionResult = getExecutionStatus(response.getStatus()); return new TransactionResponse( response.getType(), response.getMessage(), executionResult, response.getLocation() ); }
|
ExplorerApiHelper { static TransactionResponse parseGetTxResponse(String json) { GetTxResponse response = JSON.fromJson(json, GetTxResponse.class); ExecutionStatus executionResult = getExecutionStatus(response.getStatus()); return new TransactionResponse( response.getType(), response.getMessage(), executionResult, response.getLocation() ); } }
|
ExplorerApiHelper { static TransactionResponse parseGetTxResponse(String json) { GetTxResponse response = JSON.fromJson(json, GetTxResponse.class); ExecutionStatus executionResult = getExecutionStatus(response.getStatus()); return new TransactionResponse( response.getType(), response.getMessage(), executionResult, response.getLocation() ); } private ExplorerApiHelper(); }
|
ExplorerApiHelper { static TransactionResponse parseGetTxResponse(String json) { GetTxResponse response = JSON.fromJson(json, GetTxResponse.class); ExecutionStatus executionResult = getExecutionStatus(response.getStatus()); return new TransactionResponse( response.getType(), response.getMessage(), executionResult, response.getLocation() ); } private ExplorerApiHelper(); }
|
ExplorerApiHelper { static TransactionResponse parseGetTxResponse(String json) { GetTxResponse response = JSON.fromJson(json, GetTxResponse.class); ExecutionStatus executionResult = getExecutionStatus(response.getStatus()); return new TransactionResponse( response.getType(), response.getMessage(), executionResult, response.getLocation() ); } private ExplorerApiHelper(); }
|
@Test void checkStorageValueDoesNotAcceptNull() { assertThrows(NullPointerException.class, () -> StoragePreconditions.checkStorageKey(null)); }
|
@CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); }
|
@Test void checkNoNulls() { assertThrows(NullPointerException.class, () -> { Collection<String> c = Arrays.asList("hello", null); StoragePreconditions.checkNoNulls(c); }); }
|
static <E> void checkNoNulls(Collection<E> collection) { checkNotNull(collection, "Collection is null"); if (collection.contains(null)) { throw new NullPointerException("Collection contains nulls"); } }
|
StoragePreconditions { static <E> void checkNoNulls(Collection<E> collection) { checkNotNull(collection, "Collection is null"); if (collection.contains(null)) { throw new NullPointerException("Collection contains nulls"); } } }
|
StoragePreconditions { static <E> void checkNoNulls(Collection<E> collection) { checkNotNull(collection, "Collection is null"); if (collection.contains(null)) { throw new NullPointerException("Collection contains nulls"); } } private StoragePreconditions(); }
|
StoragePreconditions { static <E> void checkNoNulls(Collection<E> collection) { checkNotNull(collection, "Collection is null"); if (collection.contains(null)) { throw new NullPointerException("Collection contains nulls"); } } private StoragePreconditions(); }
|
StoragePreconditions { static <E> void checkNoNulls(Collection<E> collection) { checkNotNull(collection, "Collection is null"); if (collection.contains(null)) { throw new NullPointerException("Collection contains nulls"); } } private StoragePreconditions(); }
|
@Test void checkElementIndexNegative() { IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> StoragePreconditions.checkElementIndex(-1, 2)); assertThat(thrown.getLocalizedMessage(), containsString("Index must be in range [0, 2), but: -1")); }
|
@CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
@Test void checkElementIndexEqualToSize() { IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> StoragePreconditions.checkElementIndex(2, 2)); assertThat(thrown.getLocalizedMessage(), containsString("Index must be in range [0, 2), but: 2")); }
|
@CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
@Test void checkElementIndexGreaterThanSize() { IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> StoragePreconditions.checkElementIndex(3, 2)); assertThat(thrown.getLocalizedMessage(), containsString("Index must be in range [0, 2), but: 3")); }
|
@CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
@Test void checkElementIndexMaxLong() { IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> StoragePreconditions.checkElementIndex(Long.MAX_VALUE, 2)); assertThat(thrown.getLocalizedMessage(), containsString("Index must be in range [0, 2), but:")); }
|
@CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
@Test void checkElementIndex0MinValid() { long index = 0; long size = 3; assertThat(StoragePreconditions.checkElementIndex(index, size), equalTo(index)); }
|
@CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
@Test void checkElementIndex1() { long index = 1; long size = 3; assertThat(StoragePreconditions.checkElementIndex(index, size), equalTo(index)); }
|
@CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
@Test void checkElementIndex2MaxValid() { long index = 2; long size = 3; assertThat(StoragePreconditions.checkElementIndex(index, size), equalTo(index)); }
|
@CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); }
|
@Test void checkPositionIndexSize0_Valid() { long index = 0; long size = 0; assertThat(StoragePreconditions.checkPositionIndex(index, size), equalTo(index)); }
|
@CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); }
|
@Test void hasLength() { byte[] bytes = new byte[10]; assertTrue(CryptoUtils.hasLength(bytes, 10)); }
|
static boolean hasLength(byte[] data, int size) { return data.length == size; }
|
CryptoUtils { static boolean hasLength(byte[] data, int size) { return data.length == size; } }
|
CryptoUtils { static boolean hasLength(byte[] data, int size) { return data.length == size; } private CryptoUtils(); }
|
CryptoUtils { static boolean hasLength(byte[] data, int size) { return data.length == size; } private CryptoUtils(); }
|
CryptoUtils { static boolean hasLength(byte[] data, int size) { return data.length == size; } private CryptoUtils(); }
|
@Test void checkPositionIndexSize0_NotValid() { long index = 1; long size = 0; IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> StoragePreconditions.checkPositionIndex(index, size)); assertThat(thrown.getLocalizedMessage(), containsString("index (1) is greater than size (0)")); }
|
@CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); }
|
@Test void checkPositionIndexSize0_NotValidNegative() { long index = -1; long size = 0; IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> StoragePreconditions.checkPositionIndex(index, size)); assertThat(thrown.getLocalizedMessage(), containsString("index (-1) is negative")); }
|
@CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); }
|
@Test void checkPositionIndexSize3_AllValid() { long size = 3; long[] validIndices = {0, 1, 2, 3}; for (long index : validIndices) { assertThat(StoragePreconditions.checkPositionIndex(index, size), equalTo(index)); } }
|
@CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); }
|
@Test void checkPositionIndexSize3_NotValid() { long index = 4; long size = 3; IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> StoragePreconditions.checkPositionIndex(index, size)); assertThat(thrown.getLocalizedMessage(), containsString("index (4) is greater than size (3)")); }
|
@CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); }
|
@Test void checkPositionIndex_NegativeSize() { long index = 0; long size = -1; IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> StoragePreconditions.checkPositionIndex(index, size)); assertThat(thrown.getLocalizedMessage(), containsString("size (-1) is negative")); }
|
@CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); }
|
StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); }
|
@Test void checkRangeFromNegative() { IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> checkRange(-1, 2)); assertThat(thrown.getLocalizedMessage(), containsString("Proof range first element index -1 must be in range [0, 2)")); }
|
static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
@Test void checkRangeFromEqualToTo() { IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> checkRange(2, 2)); assertThat(thrown.getLocalizedMessage(), containsString("Proof range first element index 2 must be in range [0, 2)")); }
|
static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
@Test void checkRangeFromGreaterThanTo() { IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> checkRange(3, 2)); assertThat(thrown.getLocalizedMessage(), containsString("Proof range first element index 3 must be in range [0, 2)")); }
|
static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
@Test void checkRangeFromMaxLong() { IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> checkRange(Long.MAX_VALUE, 2)); assertThat(thrown.getLocalizedMessage(), containsString("Proof range first element index " + Long.MAX_VALUE + " must be in range [0, 2)")); }
|
static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
@Test void checkRangeFrom0MinValid() { long from = 0; long to = 3; checkRange(from, to); }
|
static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
@Test void hexToByteArray() { byte[] bytes = CryptoUtils.hexToByteArray("abcd"); assertEquals(2, bytes.length); assertEquals(-85, bytes[0]); assertEquals(-51, bytes[1]); }
|
static byte[] hexToByteArray(String hex) { return HEX_ENCODING.decode(hex); }
|
CryptoUtils { static byte[] hexToByteArray(String hex) { return HEX_ENCODING.decode(hex); } }
|
CryptoUtils { static byte[] hexToByteArray(String hex) { return HEX_ENCODING.decode(hex); } private CryptoUtils(); }
|
CryptoUtils { static byte[] hexToByteArray(String hex) { return HEX_ENCODING.decode(hex); } private CryptoUtils(); }
|
CryptoUtils { static byte[] hexToByteArray(String hex) { return HEX_ENCODING.decode(hex); } private CryptoUtils(); }
|
@Test void checkRangeFrom1() { long from = 1; long to = 3; checkRange(from, to); }
|
static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
@Test void checkRangeFrom2MaxValid() { long from = 2; long to = 3; checkRange(from, to); }
|
static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); }
|
@Test void trySplit_Empty() { int[] source = new int[0]; Spliterator<Integer> spliterator = createSpliteratorOf(source); assertNull(spliterator.trySplit()); }
|
@Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteristics(IMMUTABLE), nextIndex, mid, initialCounterValue); this.nextIndex = mid; return prefix; }
|
ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteristics(IMMUTABLE), nextIndex, mid, initialCounterValue); this.nextIndex = mid; return prefix; } }
|
ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteristics(IMMUTABLE), nextIndex, mid, initialCounterValue); this.nextIndex = mid; return prefix; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable,
long nextIndex, long fence, Integer initialCounterValue); }
|
ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteristics(IMMUTABLE), nextIndex, mid, initialCounterValue); this.nextIndex = mid; return prefix; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable,
long nextIndex, long fence, Integer initialCounterValue); @Override boolean tryAdvance(Consumer<? super ElementT> action); @Override Spliterator<ElementT> trySplit(); @Override long estimateSize(); @Override int characteristics(); }
|
ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteristics(IMMUTABLE), nextIndex, mid, initialCounterValue); this.nextIndex = mid; return prefix; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable,
long nextIndex, long fence, Integer initialCounterValue); @Override boolean tryAdvance(Consumer<? super ElementT> action); @Override Spliterator<ElementT> trySplit(); @Override long estimateSize(); @Override int characteristics(); }
|
@Test @DisplayName("trySplit if there are less than minimal splittable size (1 element)") void trySplit_OneElement() { Spliterator<Integer> spliterator = createSpliteratorOf(new int[1]); assertNull(spliterator.trySplit()); }
|
@Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteristics(IMMUTABLE), nextIndex, mid, initialCounterValue); this.nextIndex = mid; return prefix; }
|
ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteristics(IMMUTABLE), nextIndex, mid, initialCounterValue); this.nextIndex = mid; return prefix; } }
|
ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteristics(IMMUTABLE), nextIndex, mid, initialCounterValue); this.nextIndex = mid; return prefix; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable,
long nextIndex, long fence, Integer initialCounterValue); }
|
ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteristics(IMMUTABLE), nextIndex, mid, initialCounterValue); this.nextIndex = mid; return prefix; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable,
long nextIndex, long fence, Integer initialCounterValue); @Override boolean tryAdvance(Consumer<? super ElementT> action); @Override Spliterator<ElementT> trySplit(); @Override long estimateSize(); @Override int characteristics(); }
|
ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteristics(IMMUTABLE), nextIndex, mid, initialCounterValue); this.nextIndex = mid; return prefix; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable,
long nextIndex, long fence, Integer initialCounterValue); @Override boolean tryAdvance(Consumer<? super ElementT> action); @Override Spliterator<ElementT> trySplit(); @Override long estimateSize(); @Override int characteristics(); }
|
@Test void spliteratorRemainsBoundToTheSourceAfterSplit() { ListIndex<Integer> list = createListMock(); when(list.size()).thenReturn(10L); ModificationCounter counter = new IncrementalModificationCounter(); Spliterator<Integer> spliterator = new ListSpliterator<>(list, counter, true); Spliterator<Integer> other = spliterator.trySplit(); counter.notifyModified(); assertHasDetectedModification(spliterator); assertHasDetectedModification(other); }
|
@Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteristics(IMMUTABLE), nextIndex, mid, initialCounterValue); this.nextIndex = mid; return prefix; }
|
ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteristics(IMMUTABLE), nextIndex, mid, initialCounterValue); this.nextIndex = mid; return prefix; } }
|
ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteristics(IMMUTABLE), nextIndex, mid, initialCounterValue); this.nextIndex = mid; return prefix; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable,
long nextIndex, long fence, Integer initialCounterValue); }
|
ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteristics(IMMUTABLE), nextIndex, mid, initialCounterValue); this.nextIndex = mid; return prefix; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable,
long nextIndex, long fence, Integer initialCounterValue); @Override boolean tryAdvance(Consumer<? super ElementT> action); @Override Spliterator<ElementT> trySplit(); @Override long estimateSize(); @Override int characteristics(); }
|
ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteristics(IMMUTABLE), nextIndex, mid, initialCounterValue); this.nextIndex = mid; return prefix; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable,
long nextIndex, long fence, Integer initialCounterValue); @Override boolean tryAdvance(Consumer<? super ElementT> action); @Override Spliterator<ElementT> trySplit(); @Override long estimateSize(); @Override int characteristics(); }
|
@Test @DisplayName("spliterator uses the list size at bind time, allowing for structural modifications") void spliteratorIsLateBindingUsesProperSize() { ListIndex<Integer> list = createListMock(); long initialSize = 10; lenient().when(list.size()).thenReturn(initialSize); ModificationCounter counter = new IncrementalModificationCounter(); Spliterator<Integer> spliterator = new ListSpliterator<>(list, counter, true); long size = initialSize + 1; when(list.size()).thenReturn(size); counter.notifyModified(); assertThat(spliterator.estimateSize()).isEqualTo(size); }
|
@Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; }
|
ListSpliterator implements Spliterator<ElementT> { @Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; } }
|
ListSpliterator implements Spliterator<ElementT> { @Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable,
long nextIndex, long fence, Integer initialCounterValue); }
|
ListSpliterator implements Spliterator<ElementT> { @Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable,
long nextIndex, long fence, Integer initialCounterValue); @Override boolean tryAdvance(Consumer<? super ElementT> action); @Override Spliterator<ElementT> trySplit(); @Override long estimateSize(); @Override int characteristics(); }
|
ListSpliterator implements Spliterator<ElementT> { @Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable,
long nextIndex, long fence, Integer initialCounterValue); @Override boolean tryAdvance(Consumer<? super ElementT> action); @Override Spliterator<ElementT> trySplit(); @Override long estimateSize(); @Override int characteristics(); }
|
@Test void estimateSizeIsZeroAfterSpliteratorIsConsumed() { ListIndex<Integer> list = createListMock(); long listSize = 5; when(list.size()).thenReturn(listSize); ModificationCounter counter = mock(ModificationCounter.class); Spliterator<Integer> spliterator = new ListSpliterator<>(list, counter, true); spliterator.forEachRemaining(NULL_CONSUMER); assertThat(spliterator.estimateSize()).isEqualTo(0); }
|
@Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; }
|
ListSpliterator implements Spliterator<ElementT> { @Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; } }
|
ListSpliterator implements Spliterator<ElementT> { @Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable,
long nextIndex, long fence, Integer initialCounterValue); }
|
ListSpliterator implements Spliterator<ElementT> { @Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable,
long nextIndex, long fence, Integer initialCounterValue); @Override boolean tryAdvance(Consumer<? super ElementT> action); @Override Spliterator<ElementT> trySplit(); @Override long estimateSize(); @Override int characteristics(); }
|
ListSpliterator implements Spliterator<ElementT> { @Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable,
long nextIndex, long fence, Integer initialCounterValue); @Override boolean tryAdvance(Consumer<? super ElementT> action); @Override Spliterator<ElementT> trySplit(); @Override long estimateSize(); @Override int characteristics(); }
|
@Test void isEmpty() { Block emptyBlock = Blocks.aBlock() .numTransactions(0) .build(); assertTrue(emptyBlock.isEmpty()); }
|
public final boolean isEmpty() { return getNumTransactions() == 0; }
|
Block { public final boolean isEmpty() { return getNumTransactions() == 0; } }
|
Block { public final boolean isEmpty() { return getNumTransactions() == 0; } }
|
Block { public final boolean isEmpty() { return getNumTransactions() == 0; } abstract HashCode getBlockHash(); abstract int getProposerId(); abstract long getHeight(); final boolean isEmpty(); abstract int getNumTransactions(); abstract HashCode getPreviousBlockHash(); abstract HashCode getTxRootHash(); abstract HashCode getStateHash(); abstract HashCode getErrorHash(); abstract ImmutableMap<String, ByteString> getAdditionalHeaders(); @SuppressWarnings("squid:S1206") @Override int hashCode(); static TypeAdapter<Block> typeAdapter(Gson gson); static Block fromMessage(com.exonum.messages.core.Blockchain.Block blockMessage); static Block parseFrom(byte[] serializedBlock); static Builder builder(); }
|
Block { public final boolean isEmpty() { return getNumTransactions() == 0; } abstract HashCode getBlockHash(); abstract int getProposerId(); abstract long getHeight(); final boolean isEmpty(); abstract int getNumTransactions(); abstract HashCode getPreviousBlockHash(); abstract HashCode getTxRootHash(); abstract HashCode getStateHash(); abstract HashCode getErrorHash(); abstract ImmutableMap<String, ByteString> getAdditionalHeaders(); @SuppressWarnings("squid:S1206") @Override int hashCode(); static TypeAdapter<Block> typeAdapter(Gson gson); static Block fromMessage(com.exonum.messages.core.Blockchain.Block blockMessage); static Block parseFrom(byte[] serializedBlock); static Builder builder(); }
|
@Test void getWallet(VertxTestContext context) { long balance = 200L; Wallet wallet = new Wallet(balance); when(service.getWallet(eq(FROM_KEY))) .thenReturn(Optional.of(wallet)); String getWalletUri = getWalletUri(FROM_KEY); get(getWalletUri) .send(context.succeeding(response -> context.verify(() -> { assertThat(response.statusCode()) .isEqualTo(HTTP_OK); String body = response.bodyAsString(); Wallet actualWallet = json() .fromJson(body, Wallet.class); assertThat(actualWallet.getBalance()).isEqualTo(wallet.getBalance()); context.completeNow(); }))); }
|
private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wallet.get())); } else { rc.response() .setStatusCode(HTTP_NOT_FOUND) .end(); } }
|
ApiController { private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wallet.get())); } else { rc.response() .setStatusCode(HTTP_NOT_FOUND) .end(); } } }
|
ApiController { private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wallet.get())); } else { rc.response() .setStatusCode(HTTP_NOT_FOUND) .end(); } } ApiController(CryptocurrencyService service); }
|
ApiController { private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wallet.get())); } else { rc.response() .setStatusCode(HTTP_NOT_FOUND) .end(); } } ApiController(CryptocurrencyService service); }
|
ApiController { private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wallet.get())); } else { rc.response() .setStatusCode(HTTP_NOT_FOUND) .end(); } } ApiController(CryptocurrencyService service); }
|
@Test void getNonexistentWallet(VertxTestContext context) { when(service.getWallet(FROM_KEY)) .thenReturn(Optional.empty()); String getWalletUri = getWalletUri(FROM_KEY); get(getWalletUri) .send(context.succeeding(response -> context.verify(() -> { assertThat(response.statusCode()).isEqualTo(HTTP_NOT_FOUND); context.completeNow(); }))); }
|
private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wallet.get())); } else { rc.response() .setStatusCode(HTTP_NOT_FOUND) .end(); } }
|
ApiController { private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wallet.get())); } else { rc.response() .setStatusCode(HTTP_NOT_FOUND) .end(); } } }
|
ApiController { private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wallet.get())); } else { rc.response() .setStatusCode(HTTP_NOT_FOUND) .end(); } } ApiController(CryptocurrencyService service); }
|
ApiController { private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wallet.get())); } else { rc.response() .setStatusCode(HTTP_NOT_FOUND) .end(); } } ApiController(CryptocurrencyService service); }
|
ApiController { private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wallet.get())); } else { rc.response() .setStatusCode(HTTP_NOT_FOUND) .end(); } } ApiController(CryptocurrencyService service); }
|
@Test void byteArrayToHex() { String hex = CryptoUtils.byteArrayToHex(new byte[]{-85, -51}); assertEquals("abcd", hex); }
|
static String byteArrayToHex(byte[] bytes) { return HEX_ENCODING.encode(bytes); }
|
CryptoUtils { static String byteArrayToHex(byte[] bytes) { return HEX_ENCODING.encode(bytes); } }
|
CryptoUtils { static String byteArrayToHex(byte[] bytes) { return HEX_ENCODING.encode(bytes); } private CryptoUtils(); }
|
CryptoUtils { static String byteArrayToHex(byte[] bytes) { return HEX_ENCODING.encode(bytes); } private CryptoUtils(); }
|
CryptoUtils { static String byteArrayToHex(byte[] bytes) { return HEX_ENCODING.encode(bytes); } private CryptoUtils(); }
|
@Test void getWalletHistory(VertxTestContext context) { List<HistoryEntity> history = singletonList( HistoryEntity.newBuilder() .setSeed(1L) .setWalletFrom(FROM_KEY) .setWalletTo(TO_KEY) .setAmount(10L) .setTxMessageHash(HashCode.fromString("a0a0a0")) .build() ); when(service.getWalletHistory(FROM_KEY)).thenReturn(history); String uri = getWalletUri(FROM_KEY) + "/history"; get(uri) .send(context.succeeding(response -> context.verify(() -> { assertThat(response.statusCode()).isEqualTo(HTTP_OK); List<HistoryEntity> actualHistory = parseWalletHistory(response); assertThat(actualHistory).isEqualTo(history); context.completeNow(); }))); }
|
private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(walletHistory)); }
|
ApiController { private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(walletHistory)); } }
|
ApiController { private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(walletHistory)); } ApiController(CryptocurrencyService service); }
|
ApiController { private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(walletHistory)); } ApiController(CryptocurrencyService service); }
|
ApiController { private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(walletHistory)); } ApiController(CryptocurrencyService service); }
|
@Test void getWalletHistoryNonexistentWallet(VertxTestContext context) { when(service.getWalletHistory(FROM_KEY)).thenReturn(emptyList()); String uri = getWalletUri(FROM_KEY) + "/history"; get(uri) .send(context.succeeding(response -> context.verify(() -> { assertThat(response.statusCode()).isEqualTo(HTTP_OK); assertThat(parseWalletHistory(response)).isEmpty(); context.completeNow(); }))); }
|
private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(walletHistory)); }
|
ApiController { private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(walletHistory)); } }
|
ApiController { private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(walletHistory)); } ApiController(CryptocurrencyService service); }
|
ApiController { private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(walletHistory)); } ApiController(CryptocurrencyService service); }
|
ApiController { private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(walletHistory)); } ApiController(CryptocurrencyService service); }
|
@Test void parseFromWrongMessage() { byte[] message = bytes("Not a signed message"); assertThrows(InvalidProtocolBufferException.class, () -> SignedMessage.parseFrom(message)); }
|
public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); }
|
SignedMessage { public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); } }
|
SignedMessage { public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); } private SignedMessage(CoreMessage payload, PublicKey authorPk,
ByteString signature, HashCode hash); }
|
SignedMessage { public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); } private SignedMessage(CoreMessage payload, PublicKey authorPk,
ByteString signature, HashCode hash); static SignedMessage parseFrom(byte[] messageBytes); static SignedMessage fromProto(Messages.SignedMessage message); Messages.CoreMessage getPayload(); PublicKey getAuthorPk(); byte[] getSignature(); HashCode hash(); }
|
SignedMessage { public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); } private SignedMessage(CoreMessage payload, PublicKey authorPk,
ByteString signature, HashCode hash); static SignedMessage parseFrom(byte[] messageBytes); static SignedMessage fromProto(Messages.SignedMessage message); Messages.CoreMessage getPayload(); PublicKey getAuthorPk(); byte[] getSignature(); HashCode hash(); }
|
@Test void parseFromPayloadNotExonumMessage() { ByteString invalidPayload = ByteString.copyFrom( bytes("Invalid payload: not an ExonumMessage")); Types.PublicKey authorPk = aPublicKey().build(); Types.Signature signature = aSignature().build(); byte[] message = Messages.SignedMessage.newBuilder() .setPayload(invalidPayload) .setAuthor(authorPk) .setSignature(signature) .build() .toByteArray(); assertThrows(InvalidProtocolBufferException.class, () -> SignedMessage.parseFrom(message)); }
|
public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); }
|
SignedMessage { public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); } }
|
SignedMessage { public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); } private SignedMessage(CoreMessage payload, PublicKey authorPk,
ByteString signature, HashCode hash); }
|
SignedMessage { public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); } private SignedMessage(CoreMessage payload, PublicKey authorPk,
ByteString signature, HashCode hash); static SignedMessage parseFrom(byte[] messageBytes); static SignedMessage fromProto(Messages.SignedMessage message); Messages.CoreMessage getPayload(); PublicKey getAuthorPk(); byte[] getSignature(); HashCode hash(); }
|
SignedMessage { public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); } private SignedMessage(CoreMessage payload, PublicKey authorPk,
ByteString signature, HashCode hash); static SignedMessage parseFrom(byte[] messageBytes); static SignedMessage fromProto(Messages.SignedMessage message); Messages.CoreMessage getPayload(); PublicKey getAuthorPk(); byte[] getSignature(); HashCode hash(); }
|
@Test void testEquals() throws InvalidProtocolBufferException { String red = "Red"; String black = "Black"; EqualsVerifier.forClass(ParsedTransactionMessage.class) .suppress(Warning.NULL_FIELDS) .withOnlyTheseFields("signedMessage") .withPrefabValues(Messages.SignedMessage.class, signedConsensusMessage(red), signedConsensusMessage(black)) .withPrefabValues(SignedMessage.class, signedMessage(red), signedMessage(black)) .withPrefabValues(AnyTx.class, anyTx(red), anyTx(black)) .verify(); }
|
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof ParsedTransactionMessage)) { return false; } ParsedTransactionMessage that = (ParsedTransactionMessage) o; return signedMessage.equals(that.signedMessage); }
|
ParsedTransactionMessage implements TransactionMessage { @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof ParsedTransactionMessage)) { return false; } ParsedTransactionMessage that = (ParsedTransactionMessage) o; return signedMessage.equals(that.signedMessage); } }
|
ParsedTransactionMessage implements TransactionMessage { @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof ParsedTransactionMessage)) { return false; } ParsedTransactionMessage that = (ParsedTransactionMessage) o; return signedMessage.equals(that.signedMessage); } ParsedTransactionMessage(Messages.SignedMessage signedMessage); }
|
ParsedTransactionMessage implements TransactionMessage { @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof ParsedTransactionMessage)) { return false; } ParsedTransactionMessage that = (ParsedTransactionMessage) o; return signedMessage.equals(that.signedMessage); } ParsedTransactionMessage(Messages.SignedMessage signedMessage); @Override PublicKey getAuthor(); @Override int getServiceId(); @Override int getTransactionId(); @Override ByteString getPayload(); @Override HashCode hash(); @Override byte[] getSignature(); @Override byte[] toBytes(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); }
|
ParsedTransactionMessage implements TransactionMessage { @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof ParsedTransactionMessage)) { return false; } ParsedTransactionMessage that = (ParsedTransactionMessage) o; return signedMessage.equals(that.signedMessage); } ParsedTransactionMessage(Messages.SignedMessage signedMessage); @Override PublicKey getAuthor(); @Override int getServiceId(); @Override int getTransactionId(); @Override ByteString getPayload(); @Override HashCode hash(); @Override byte[] getSignature(); @Override byte[] toBytes(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); }
|
@Test void longSerializesAsText() { long value = 10L; String json = json().toJson(new Wrapper<>(value)); assertJsonValue(json, "10"); }
|
public static Gson json() { return INSTANCE; }
|
JsonSerializer { public static Gson json() { return INSTANCE; } }
|
JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); }
|
JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); static GsonBuilder builder(); static Gson json(); }
|
JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); static GsonBuilder builder(); static Gson json(); }
|
@Test void publicKeySerializesAsHexValue() { PublicKey value = PublicKey.fromBytes(bytes(0x00, 0x01, 0x02)); String json = json().toJson(new Wrapper<>(value)); assertJsonValue(json, "000102"); }
|
public static Gson json() { return INSTANCE; }
|
JsonSerializer { public static Gson json() { return INSTANCE; } }
|
JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); }
|
JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); static GsonBuilder builder(); static Gson json(); }
|
JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); static GsonBuilder builder(); static Gson json(); }
|
@Test void hashCodeSerializesAsValue() { HashCode value = HashCode.fromBytes(bytes(0x00, 0x01, 0x02)); String json = json().toJson(new Wrapper<>(value)); assertJsonValue(json, "000102"); }
|
public static Gson json() { return INSTANCE; }
|
JsonSerializer { public static Gson json() { return INSTANCE; } }
|
JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); }
|
JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); static GsonBuilder builder(); static Gson json(); }
|
JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); static GsonBuilder builder(); static Gson json(); }
|
@Test void transactionMessageSerializesAsValue() { TransactionMessage value = aMessage(); String json = json().toJson(new Wrapper<>(value)); String expectedValue = Bytes.toHexString(value.toBytes()); assertJsonValue(json, expectedValue); }
|
public static Gson json() { return INSTANCE; }
|
JsonSerializer { public static Gson json() { return INSTANCE; } }
|
JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); }
|
JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); static GsonBuilder builder(); static Gson json(); }
|
JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); static GsonBuilder builder(); static Gson json(); }
|
@Test void parseGetBlockResponse() { String prevHash = "81abde95"; String txHash = "c6c0aa07"; String stateHash = "2eab5971"; String tx1 = "336a4acb"; String tx2 = "12345678"; String commitTime = "2019-10-01T17:07:45.663021Z"; String json = "{\n" + " \"proposer_id\": 0,\n" + " \"height\": 2,\n" + " \"tx_count\": 1,\n" + " \"prev_hash\": \"" + prevHash + "\",\n" + " \"tx_hash\": \"" + txHash + "\",\n" + " \"state_hash\": \"" + stateHash + "\",\n" + " \"precommits\": [\n" + " \"bc13da11\"\n" + " ],\n" + " \"txs\": [\n" + " {\"service_id\": 0, \"tx_hash\": \"" + tx1 + "\"},\n" + " {\"service_id\": 128, \"tx_hash\": \"" + tx2 + "\"}\n" + " ],\n" + " \"time\": \"" + commitTime + "\"\n" + "}"; BlockResponse response = ExplorerApiHelper.parseGetBlockResponse(json); Block expectedBlock = Block.builder() .proposerId(0) .height(2) .numTransactions(1) .previousBlockHash(HashCode.fromString(prevHash)) .txRootHash(HashCode.fromString(txHash)) .stateHash(HashCode.fromString(stateHash)) .commitTime(ZonedDateTime.parse(commitTime)) .build(); assertThat(response.getBlock(), is(expectedBlock)); assertThat(response.getTransactionHashes(), contains(HashCode.fromString(tx1), HashCode.fromString(tx2))); }
|
static BlockResponse parseGetBlockResponse(String json) { GetBlockResponse response = JSON.fromJson(json, GetBlockResponse.class); List<HashCode> txs = response.getTxs().stream() .map(IndexedTxHash::getTxHash) .collect(toList()); return new BlockResponse(response.getAsBlock(), txs); }
|
ExplorerApiHelper { static BlockResponse parseGetBlockResponse(String json) { GetBlockResponse response = JSON.fromJson(json, GetBlockResponse.class); List<HashCode> txs = response.getTxs().stream() .map(IndexedTxHash::getTxHash) .collect(toList()); return new BlockResponse(response.getAsBlock(), txs); } }
|
ExplorerApiHelper { static BlockResponse parseGetBlockResponse(String json) { GetBlockResponse response = JSON.fromJson(json, GetBlockResponse.class); List<HashCode> txs = response.getTxs().stream() .map(IndexedTxHash::getTxHash) .collect(toList()); return new BlockResponse(response.getAsBlock(), txs); } private ExplorerApiHelper(); }
|
ExplorerApiHelper { static BlockResponse parseGetBlockResponse(String json) { GetBlockResponse response = JSON.fromJson(json, GetBlockResponse.class); List<HashCode> txs = response.getTxs().stream() .map(IndexedTxHash::getTxHash) .collect(toList()); return new BlockResponse(response.getAsBlock(), txs); } private ExplorerApiHelper(); }
|
ExplorerApiHelper { static BlockResponse parseGetBlockResponse(String json) { GetBlockResponse response = JSON.fromJson(json, GetBlockResponse.class); List<HashCode> txs = response.getTxs().stream() .map(IndexedTxHash::getTxHash) .collect(toList()); return new BlockResponse(response.getAsBlock(), txs); } private ExplorerApiHelper(); }
|
@Test void toBytes() { Point p = createPoint(-1, 1); assertThat(serializer.toBytes(p), equalTo(p.toByteArray())); }
|
@Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpaceLeft(); return result; } catch (IOException e) { throw new AssertionError("Failed to serialize " + value + " to a byte array (should never happen)", e); } }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpaceLeft(); return result; } catch (IOException e) { throw new AssertionError("Failed to serialize " + value + " to a byte array (should never happen)", e); } } }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpaceLeft(); return result; } catch (IOException e) { throw new AssertionError("Failed to serialize " + value + " to a byte array (should never happen)", e); } } ProtobufReflectiveSerializer(Class<MessageT> messageType); }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpaceLeft(); return result; } catch (IOException e) { throw new AssertionError("Failed to serialize " + value + " to a byte array (should never happen)", e); } } ProtobufReflectiveSerializer(Class<MessageT> messageType); @Override byte[] toBytes(MessageT value); @SuppressWarnings("unchecked") @Override MessageT fromBytes(byte[] serializedValue); }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpaceLeft(); return result; } catch (IOException e) { throw new AssertionError("Failed to serialize " + value + " to a byte array (should never happen)", e); } } ProtobufReflectiveSerializer(Class<MessageT> messageType); @Override byte[] toBytes(MessageT value); @SuppressWarnings("unchecked") @Override MessageT fromBytes(byte[] serializedValue); }
|
@Test void toBytesIsDeterministic() { Point p1 = createPoint(-1, -1); Point p2 = createPoint(1, 1); Point p3 = createPoint(Integer.MIN_VALUE, Integer.MAX_VALUE); Targets t1 = pointsAsTargetsInOrder(p1, p2, p3); Targets t2 = pointsAsTargetsInOrder(p3, p2, p1); ProtobufReflectiveSerializer<Targets> serializer = new ProtobufReflectiveSerializer<>(Targets.class); assertThat("The protobuf serializer is not deterministic:", serializer.toBytes(t1), equalTo(serializer.toBytes(t2))); }
|
@Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpaceLeft(); return result; } catch (IOException e) { throw new AssertionError("Failed to serialize " + value + " to a byte array (should never happen)", e); } }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpaceLeft(); return result; } catch (IOException e) { throw new AssertionError("Failed to serialize " + value + " to a byte array (should never happen)", e); } } }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpaceLeft(); return result; } catch (IOException e) { throw new AssertionError("Failed to serialize " + value + " to a byte array (should never happen)", e); } } ProtobufReflectiveSerializer(Class<MessageT> messageType); }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpaceLeft(); return result; } catch (IOException e) { throw new AssertionError("Failed to serialize " + value + " to a byte array (should never happen)", e); } } ProtobufReflectiveSerializer(Class<MessageT> messageType); @Override byte[] toBytes(MessageT value); @SuppressWarnings("unchecked") @Override MessageT fromBytes(byte[] serializedValue); }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpaceLeft(); return result; } catch (IOException e) { throw new AssertionError("Failed to serialize " + value + " to a byte array (should never happen)", e); } } ProtobufReflectiveSerializer(Class<MessageT> messageType); @Override byte[] toBytes(MessageT value); @SuppressWarnings("unchecked") @Override MessageT fromBytes(byte[] serializedValue); }
|
@Test void toBytesNullMessage() { assertThrows(NullPointerException.class, () -> serializer.toBytes(null)); }
|
@Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpaceLeft(); return result; } catch (IOException e) { throw new AssertionError("Failed to serialize " + value + " to a byte array (should never happen)", e); } }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpaceLeft(); return result; } catch (IOException e) { throw new AssertionError("Failed to serialize " + value + " to a byte array (should never happen)", e); } } }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpaceLeft(); return result; } catch (IOException e) { throw new AssertionError("Failed to serialize " + value + " to a byte array (should never happen)", e); } } ProtobufReflectiveSerializer(Class<MessageT> messageType); }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpaceLeft(); return result; } catch (IOException e) { throw new AssertionError("Failed to serialize " + value + " to a byte array (should never happen)", e); } } ProtobufReflectiveSerializer(Class<MessageT> messageType); @Override byte[] toBytes(MessageT value); @SuppressWarnings("unchecked") @Override MessageT fromBytes(byte[] serializedValue); }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpaceLeft(); return result; } catch (IOException e) { throw new AssertionError("Failed to serialize " + value + " to a byte array (should never happen)", e); } } ProtobufReflectiveSerializer(Class<MessageT> messageType); @Override byte[] toBytes(MessageT value); @SuppressWarnings("unchecked") @Override MessageT fromBytes(byte[] serializedValue); }
|
@Test void fromBytesNull() { assertThrows(NullPointerException.class, () -> serializer.fromBytes(null)); }
|
@SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException(e); } catch (Throwable throwable) { throw new AssertionError("Unexpected exception in MessageT#parseFrom", throwable); } }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException(e); } catch (Throwable throwable) { throw new AssertionError("Unexpected exception in MessageT#parseFrom", throwable); } } }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException(e); } catch (Throwable throwable) { throw new AssertionError("Unexpected exception in MessageT#parseFrom", throwable); } } ProtobufReflectiveSerializer(Class<MessageT> messageType); }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException(e); } catch (Throwable throwable) { throw new AssertionError("Unexpected exception in MessageT#parseFrom", throwable); } } ProtobufReflectiveSerializer(Class<MessageT> messageType); @Override byte[] toBytes(MessageT value); @SuppressWarnings("unchecked") @Override MessageT fromBytes(byte[] serializedValue); }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException(e); } catch (Throwable throwable) { throw new AssertionError("Unexpected exception in MessageT#parseFrom", throwable); } } ProtobufReflectiveSerializer(Class<MessageT> messageType); @Override byte[] toBytes(MessageT value); @SuppressWarnings("unchecked") @Override MessageT fromBytes(byte[] serializedValue); }
|
@Test void fromBytesInvalidInput() { byte[] invalidBuffer = new byte[32]; assertThrows(IllegalArgumentException.class, () -> serializer.fromBytes(invalidBuffer)); }
|
@SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException(e); } catch (Throwable throwable) { throw new AssertionError("Unexpected exception in MessageT#parseFrom", throwable); } }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException(e); } catch (Throwable throwable) { throw new AssertionError("Unexpected exception in MessageT#parseFrom", throwable); } } }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException(e); } catch (Throwable throwable) { throw new AssertionError("Unexpected exception in MessageT#parseFrom", throwable); } } ProtobufReflectiveSerializer(Class<MessageT> messageType); }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException(e); } catch (Throwable throwable) { throw new AssertionError("Unexpected exception in MessageT#parseFrom", throwable); } } ProtobufReflectiveSerializer(Class<MessageT> messageType); @Override byte[] toBytes(MessageT value); @SuppressWarnings("unchecked") @Override MessageT fromBytes(byte[] serializedValue); }
|
ProtobufReflectiveSerializer implements Serializer<MessageT> { @SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException(e); } catch (Throwable throwable) { throw new AssertionError("Unexpected exception in MessageT#parseFrom", throwable); } } ProtobufReflectiveSerializer(Class<MessageT> messageType); @Override byte[] toBytes(MessageT value); @SuppressWarnings("unchecked") @Override MessageT fromBytes(byte[] serializedValue); }
|
@Test void fromSelf() { assertThat(CheckingSerializerDecorator.from(decorator), sameInstance(decorator)); }
|
public static <T> CheckingSerializerDecorator<T> from(Serializer<T> serializer) { if (serializer instanceof CheckingSerializerDecorator) { return (CheckingSerializerDecorator<T>) serializer; } return new CheckingSerializerDecorator<>(serializer); }
|
CheckingSerializerDecorator implements Serializer<T> { public static <T> CheckingSerializerDecorator<T> from(Serializer<T> serializer) { if (serializer instanceof CheckingSerializerDecorator) { return (CheckingSerializerDecorator<T>) serializer; } return new CheckingSerializerDecorator<>(serializer); } }
|
CheckingSerializerDecorator implements Serializer<T> { public static <T> CheckingSerializerDecorator<T> from(Serializer<T> serializer) { if (serializer instanceof CheckingSerializerDecorator) { return (CheckingSerializerDecorator<T>) serializer; } return new CheckingSerializerDecorator<>(serializer); } private CheckingSerializerDecorator(Serializer<T> delegate); }
|
CheckingSerializerDecorator implements Serializer<T> { public static <T> CheckingSerializerDecorator<T> from(Serializer<T> serializer) { if (serializer instanceof CheckingSerializerDecorator) { return (CheckingSerializerDecorator<T>) serializer; } return new CheckingSerializerDecorator<>(serializer); } private CheckingSerializerDecorator(Serializer<T> delegate); static CheckingSerializerDecorator<T> from(Serializer<T> serializer); @Override byte[] toBytes(T value); @Override T fromBytes(byte[] serializedValue); }
|
CheckingSerializerDecorator implements Serializer<T> { public static <T> CheckingSerializerDecorator<T> from(Serializer<T> serializer) { if (serializer instanceof CheckingSerializerDecorator) { return (CheckingSerializerDecorator<T>) serializer; } return new CheckingSerializerDecorator<>(serializer); } private CheckingSerializerDecorator(Serializer<T> delegate); static CheckingSerializerDecorator<T> from(Serializer<T> serializer); @Override byte[] toBytes(T value); @Override T fromBytes(byte[] serializedValue); }
|
@Test void toBytes() { Object value = new Object(); byte[] valueBytes = new byte[0]; when(delegateMock.toBytes(value)).thenReturn(valueBytes); assertThat(decorator.toBytes(value), equalTo(valueBytes)); }
|
@Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private CheckingSerializerDecorator(Serializer<T> delegate); }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private CheckingSerializerDecorator(Serializer<T> delegate); static CheckingSerializerDecorator<T> from(Serializer<T> serializer); @Override byte[] toBytes(T value); @Override T fromBytes(byte[] serializedValue); }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private CheckingSerializerDecorator(Serializer<T> delegate); static CheckingSerializerDecorator<T> from(Serializer<T> serializer); @Override byte[] toBytes(T value); @Override T fromBytes(byte[] serializedValue); }
|
@Test void toBytes_NullValue() { assertThrows(NullPointerException.class, () -> decorator.toBytes(null)); }
|
@Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private CheckingSerializerDecorator(Serializer<T> delegate); }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private CheckingSerializerDecorator(Serializer<T> delegate); static CheckingSerializerDecorator<T> from(Serializer<T> serializer); @Override byte[] toBytes(T value); @Override T fromBytes(byte[] serializedValue); }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private CheckingSerializerDecorator(Serializer<T> delegate); static CheckingSerializerDecorator<T> from(Serializer<T> serializer); @Override byte[] toBytes(T value); @Override T fromBytes(byte[] serializedValue); }
|
@Test void toBytes_NullFromDelegate() { when(delegateMock.toBytes(any())).thenReturn(null); expectBrokenSerializerException(() -> decorator.toBytes(new Object())); }
|
@Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private CheckingSerializerDecorator(Serializer<T> delegate); }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private CheckingSerializerDecorator(Serializer<T> delegate); static CheckingSerializerDecorator<T> from(Serializer<T> serializer); @Override byte[] toBytes(T value); @Override T fromBytes(byte[] serializedValue); }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private CheckingSerializerDecorator(Serializer<T> delegate); static CheckingSerializerDecorator<T> from(Serializer<T> serializer); @Override byte[] toBytes(T value); @Override T fromBytes(byte[] serializedValue); }
|
@Test void fromBytes() { Object value = new Object(); byte[] valueBytes = new byte[0]; when(delegateMock.fromBytes(valueBytes)).thenReturn(value); assertThat(decorator.fromBytes(valueBytes), equalTo(value)); }
|
@Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exception if a serialized value cannot be converted " + "to an instance of the given type.", delegate); return value; }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exception if a serialized value cannot be converted " + "to an instance of the given type.", delegate); return value; } }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exception if a serialized value cannot be converted " + "to an instance of the given type.", delegate); return value; } private CheckingSerializerDecorator(Serializer<T> delegate); }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exception if a serialized value cannot be converted " + "to an instance of the given type.", delegate); return value; } private CheckingSerializerDecorator(Serializer<T> delegate); static CheckingSerializerDecorator<T> from(Serializer<T> serializer); @Override byte[] toBytes(T value); @Override T fromBytes(byte[] serializedValue); }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exception if a serialized value cannot be converted " + "to an instance of the given type.", delegate); return value; } private CheckingSerializerDecorator(Serializer<T> delegate); static CheckingSerializerDecorator<T> from(Serializer<T> serializer); @Override byte[] toBytes(T value); @Override T fromBytes(byte[] serializedValue); }
|
@Test void parseGetBlocksResponse() { String json = "{\n" + " 'range': {\n" + " 'start': 6,\n" + " 'end': 288\n" + " },\n" + " 'blocks': [ " + BLOCK_1_JSON + "," + BLOCK_2_JSON + "," + BLOCK_3_JSON + "]\n" + "}\n"; BlocksResponse response = ExplorerApiHelper.parseGetBlocksResponse(json); assertThat(response.getBlocks(), contains(BLOCK_1, BLOCK_2, BLOCK_3)); assertThat(response.getBlocksRangeStart(), is(6L)); assertThat(response.getBlocksRangeEnd(), is(288L)); }
|
static BlocksResponse parseGetBlocksResponse(String json) { GetBlocksResponse response = JSON.fromJson(json, GetBlocksResponse.class); return new BlocksResponse( response.getBlocks(), response.getRange().getStart(), response.getRange().getEnd() ); }
|
ExplorerApiHelper { static BlocksResponse parseGetBlocksResponse(String json) { GetBlocksResponse response = JSON.fromJson(json, GetBlocksResponse.class); return new BlocksResponse( response.getBlocks(), response.getRange().getStart(), response.getRange().getEnd() ); } }
|
ExplorerApiHelper { static BlocksResponse parseGetBlocksResponse(String json) { GetBlocksResponse response = JSON.fromJson(json, GetBlocksResponse.class); return new BlocksResponse( response.getBlocks(), response.getRange().getStart(), response.getRange().getEnd() ); } private ExplorerApiHelper(); }
|
ExplorerApiHelper { static BlocksResponse parseGetBlocksResponse(String json) { GetBlocksResponse response = JSON.fromJson(json, GetBlocksResponse.class); return new BlocksResponse( response.getBlocks(), response.getRange().getStart(), response.getRange().getEnd() ); } private ExplorerApiHelper(); }
|
ExplorerApiHelper { static BlocksResponse parseGetBlocksResponse(String json) { GetBlocksResponse response = JSON.fromJson(json, GetBlocksResponse.class); return new BlocksResponse( response.getBlocks(), response.getRange().getStart(), response.getRange().getEnd() ); } private ExplorerApiHelper(); }
|
@Test void fromBytes_NullValue() { assertThrows(NullPointerException.class, () -> decorator.toBytes(null)); }
|
@Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private CheckingSerializerDecorator(Serializer<T> delegate); }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private CheckingSerializerDecorator(Serializer<T> delegate); static CheckingSerializerDecorator<T> from(Serializer<T> serializer); @Override byte[] toBytes(T value); @Override T fromBytes(byte[] serializedValue); }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private CheckingSerializerDecorator(Serializer<T> delegate); static CheckingSerializerDecorator<T> from(Serializer<T> serializer); @Override byte[] toBytes(T value); @Override T fromBytes(byte[] serializedValue); }
|
@Test void fromBytes_NullFromDelegate() { when(delegateMock.fromBytes(any())).thenReturn(null); expectBrokenSerializerException(() -> decorator.fromBytes(new byte[0])); }
|
@Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exception if a serialized value cannot be converted " + "to an instance of the given type.", delegate); return value; }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exception if a serialized value cannot be converted " + "to an instance of the given type.", delegate); return value; } }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exception if a serialized value cannot be converted " + "to an instance of the given type.", delegate); return value; } private CheckingSerializerDecorator(Serializer<T> delegate); }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exception if a serialized value cannot be converted " + "to an instance of the given type.", delegate); return value; } private CheckingSerializerDecorator(Serializer<T> delegate); static CheckingSerializerDecorator<T> from(Serializer<T> serializer); @Override byte[] toBytes(T value); @Override T fromBytes(byte[] serializedValue); }
|
CheckingSerializerDecorator implements Serializer<T> { @Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exception if a serialized value cannot be converted " + "to an instance of the given type.", delegate); return value; } private CheckingSerializerDecorator(Serializer<T> delegate); static CheckingSerializerDecorator<T> from(Serializer<T> serializer); @Override byte[] toBytes(T value); @Override T fromBytes(byte[] serializedValue); }
|
@Test void checkArtifactWithNoForbiddenCharacters() { String name = "com.acme/foo:1.0"; checkNoForbiddenChars(name); }
|
static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(), matcher.start())); } }
|
JavaArtifactUtils { static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(), matcher.start())); } } }
|
JavaArtifactUtils { static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(), matcher.start())); } } private JavaArtifactUtils(); }
|
JavaArtifactUtils { static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(), matcher.start())); } } private JavaArtifactUtils(); }
|
JavaArtifactUtils { static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(), matcher.start())); } } private JavaArtifactUtils(); }
|
@Test void checkArtifactWithForbiddenCharacters() { String name = "com.acme foo:1.0"; assertThrows(IllegalArgumentException.class, () -> checkNoForbiddenChars(name)); }
|
static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(), matcher.start())); } }
|
JavaArtifactUtils { static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(), matcher.start())); } } }
|
JavaArtifactUtils { static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(), matcher.start())); } } private JavaArtifactUtils(); }
|
JavaArtifactUtils { static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(), matcher.start())); } } private JavaArtifactUtils(); }
|
JavaArtifactUtils { static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(), matcher.start())); } } private JavaArtifactUtils(); }
|
@Test void valueOf() { int runtimeId = 1; String name = "test-service"; String version = "0.1"; ServiceArtifactId id = ServiceArtifactId.valueOf(runtimeId, name, version); assertThat(id.getRuntimeId()).isEqualTo(runtimeId); assertThat(id.getName()).isEqualTo(name); assertThat(id.getVersion()).isEqualTo(version); }
|
public static ServiceArtifactId valueOf(int runtimeId, String name, String version) { checkArgument(isNotBlank(name), "name is blank: '%s'", name); checkArgument(isNotBlank(version), "version is blank: '%s'", version); return new AutoValue_ServiceArtifactId(runtimeId, name, version); }
|
ServiceArtifactId { public static ServiceArtifactId valueOf(int runtimeId, String name, String version) { checkArgument(isNotBlank(name), "name is blank: '%s'", name); checkArgument(isNotBlank(version), "version is blank: '%s'", version); return new AutoValue_ServiceArtifactId(runtimeId, name, version); } }
|
ServiceArtifactId { public static ServiceArtifactId valueOf(int runtimeId, String name, String version) { checkArgument(isNotBlank(name), "name is blank: '%s'", name); checkArgument(isNotBlank(version), "version is blank: '%s'", version); return new AutoValue_ServiceArtifactId(runtimeId, name, version); } }
|
ServiceArtifactId { public static ServiceArtifactId valueOf(int runtimeId, String name, String version) { checkArgument(isNotBlank(name), "name is blank: '%s'", name); checkArgument(isNotBlank(version), "version is blank: '%s'", version); return new AutoValue_ServiceArtifactId(runtimeId, name, version); } abstract int getRuntimeId(); abstract String getName(); abstract String getVersion(); static ServiceArtifactId parseFrom(String serviceArtifactId); static ServiceArtifactId newJavaId(String name, String version); static ServiceArtifactId valueOf(int runtimeId, String name, String version); static ServiceArtifactId fromProto(ArtifactId artifactId); @Override final String toString(); }
|
ServiceArtifactId { public static ServiceArtifactId valueOf(int runtimeId, String name, String version) { checkArgument(isNotBlank(name), "name is blank: '%s'", name); checkArgument(isNotBlank(version), "version is blank: '%s'", version); return new AutoValue_ServiceArtifactId(runtimeId, name, version); } abstract int getRuntimeId(); abstract String getName(); abstract String getVersion(); static ServiceArtifactId parseFrom(String serviceArtifactId); static ServiceArtifactId newJavaId(String name, String version); static ServiceArtifactId valueOf(int runtimeId, String name, String version); static ServiceArtifactId fromProto(ArtifactId artifactId); @Override final String toString(); }
|
@Test void newJavaId() { String name = "test-service"; String version = "test-version"; ServiceArtifactId id = ServiceArtifactId.newJavaId(name, version); assertThat(id.getRuntimeId()).isEqualTo(RuntimeId.JAVA.getId()); assertThat(id.getName()).isEqualTo(name); }
|
public static ServiceArtifactId newJavaId(String name, String version) { return valueOf(JAVA.getId(), name, version); }
|
ServiceArtifactId { public static ServiceArtifactId newJavaId(String name, String version) { return valueOf(JAVA.getId(), name, version); } }
|
ServiceArtifactId { public static ServiceArtifactId newJavaId(String name, String version) { return valueOf(JAVA.getId(), name, version); } }
|
ServiceArtifactId { public static ServiceArtifactId newJavaId(String name, String version) { return valueOf(JAVA.getId(), name, version); } abstract int getRuntimeId(); abstract String getName(); abstract String getVersion(); static ServiceArtifactId parseFrom(String serviceArtifactId); static ServiceArtifactId newJavaId(String name, String version); static ServiceArtifactId valueOf(int runtimeId, String name, String version); static ServiceArtifactId fromProto(ArtifactId artifactId); @Override final String toString(); }
|
ServiceArtifactId { public static ServiceArtifactId newJavaId(String name, String version) { return valueOf(JAVA.getId(), name, version); } abstract int getRuntimeId(); abstract String getName(); abstract String getVersion(); static ServiceArtifactId parseFrom(String serviceArtifactId); static ServiceArtifactId newJavaId(String name, String version); static ServiceArtifactId valueOf(int runtimeId, String name, String version); static ServiceArtifactId fromProto(ArtifactId artifactId); @Override final String toString(); }
|
@Test void fromProto() { ArtifactId artifactId = ARTIFACT_ID; ServiceArtifactId serviceArtifactId = ServiceArtifactId.fromProto(artifactId); assertThat(serviceArtifactId.getRuntimeId()).isEqualTo(artifactId.getRuntimeId()); assertThat(serviceArtifactId.getName()).isEqualTo(artifactId.getName()); assertThat(serviceArtifactId.getVersion()).isEqualTo(artifactId.getVersion()); }
|
public static ServiceArtifactId fromProto(ArtifactId artifactId) { return valueOf(artifactId.getRuntimeId(), artifactId.getName(), artifactId.getVersion()); }
|
ServiceArtifactId { public static ServiceArtifactId fromProto(ArtifactId artifactId) { return valueOf(artifactId.getRuntimeId(), artifactId.getName(), artifactId.getVersion()); } }
|
ServiceArtifactId { public static ServiceArtifactId fromProto(ArtifactId artifactId) { return valueOf(artifactId.getRuntimeId(), artifactId.getName(), artifactId.getVersion()); } }
|
ServiceArtifactId { public static ServiceArtifactId fromProto(ArtifactId artifactId) { return valueOf(artifactId.getRuntimeId(), artifactId.getName(), artifactId.getVersion()); } abstract int getRuntimeId(); abstract String getName(); abstract String getVersion(); static ServiceArtifactId parseFrom(String serviceArtifactId); static ServiceArtifactId newJavaId(String name, String version); static ServiceArtifactId valueOf(int runtimeId, String name, String version); static ServiceArtifactId fromProto(ArtifactId artifactId); @Override final String toString(); }
|
ServiceArtifactId { public static ServiceArtifactId fromProto(ArtifactId artifactId) { return valueOf(artifactId.getRuntimeId(), artifactId.getName(), artifactId.getVersion()); } abstract int getRuntimeId(); abstract String getName(); abstract String getVersion(); static ServiceArtifactId parseFrom(String serviceArtifactId); static ServiceArtifactId newJavaId(String name, String version); static ServiceArtifactId valueOf(int runtimeId, String name, String version); static ServiceArtifactId fromProto(ArtifactId artifactId); @Override final String toString(); }
|
@Test void toStringTest() { ServiceArtifactId id = ServiceArtifactId.valueOf(0, "full-name", "0.1"); assertThat(id.toString()).isEqualTo("0:full-name:0.1"); }
|
@Override public final String toString() { return getRuntimeId() + DELIMITER + getName() + DELIMITER + getVersion(); }
|
ServiceArtifactId { @Override public final String toString() { return getRuntimeId() + DELIMITER + getName() + DELIMITER + getVersion(); } }
|
ServiceArtifactId { @Override public final String toString() { return getRuntimeId() + DELIMITER + getName() + DELIMITER + getVersion(); } }
|
ServiceArtifactId { @Override public final String toString() { return getRuntimeId() + DELIMITER + getName() + DELIMITER + getVersion(); } abstract int getRuntimeId(); abstract String getName(); abstract String getVersion(); static ServiceArtifactId parseFrom(String serviceArtifactId); static ServiceArtifactId newJavaId(String name, String version); static ServiceArtifactId valueOf(int runtimeId, String name, String version); static ServiceArtifactId fromProto(ArtifactId artifactId); @Override final String toString(); }
|
ServiceArtifactId { @Override public final String toString() { return getRuntimeId() + DELIMITER + getName() + DELIMITER + getVersion(); } abstract int getRuntimeId(); abstract String getName(); abstract String getVersion(); static ServiceArtifactId parseFrom(String serviceArtifactId); static ServiceArtifactId newJavaId(String name, String version); static ServiceArtifactId valueOf(int runtimeId, String name, String version); static ServiceArtifactId fromProto(ArtifactId artifactId); @Override final String toString(); }
|
@Test void emptyListValidProof() { FlatListProof proof = new FlatListProof(emptyList(), emptyList(), 0L); CheckedListProof<byte[]> checked = proof.verify(); assertTrue(checked.isValid()); assertThat(checked.size()).isZero(); assertThat(checked.getIndexHash()).isEqualTo(EMPTY_LIST_INDEX_HASH); }
|
CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
@Test void singletonListValidProof() { int index = 0; ListProofElementEntry element = ELEMENT_ENTRIES.get(index); long size = 1L; FlatListProof proof = new FlatListProof(singletonList(element), emptyList(), size); CheckedListProof<byte[]> checked = proof.verify(); assertTrue(checked.isValid()); assertThat(checked.size()).isEqualTo(size); byte[] e0Value = ELEMENTS.get(index); assertThat(checked.getElements()).containsExactly(entry((long) index, e0Value)); HashCode rootHash = getLeafHashCode(e0Value); HashCode expectedListHash = getProofListHash(rootHash, size); assertThat(checked.getIndexHash()).isEqualTo(expectedListHash); }
|
CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
@Test void parseServicesResponse() { String serviceName1 = "service-name-1"; String serviceName2 = "service-name-2"; int serviceId1 = 1; int serviceId2 = 2; ServiceInstanceInfo serviceInstanceInfo1 = new ServiceInstanceInfo(serviceName1, serviceId1); ServiceInstanceInfo serviceInstanceInfo2 = new ServiceInstanceInfo(serviceName2, serviceId2); List<ServiceInstanceInfo> expected = Arrays.asList(serviceInstanceInfo1, serviceInstanceInfo2); String json = "{\n" + " \"services\": [{\n" + " \"spec\": {\n" + " \"name\": \"" + serviceName1 + "\",\n" + " \"id\": " + serviceId1 + "\n" + " },\n" + " \"status\": \"Active\"\n" + " },\n" + " {\n" + " \"spec\": {\n" + " \"name\": \"" + serviceName2 + "\",\n" + " \"id\": " + serviceId2 + "\n" + " },\n" + " \"status\": \"Active\"\n" + " }\n" + " ]\n" + "}"; List<ServiceInstanceInfo> actual = ExplorerApiHelper.parseServicesResponse(json); assertThat(actual, contains(expected.toArray())); }
|
static List<ServiceInstanceInfo> parseServicesResponse(String json) { ServicesResponse servicesResponse = JSON.fromJson(json, ServicesResponse.class); return servicesResponse.getServices().stream() .map(ServiceInstanceState::getSpec) .collect(toList()); }
|
ExplorerApiHelper { static List<ServiceInstanceInfo> parseServicesResponse(String json) { ServicesResponse servicesResponse = JSON.fromJson(json, ServicesResponse.class); return servicesResponse.getServices().stream() .map(ServiceInstanceState::getSpec) .collect(toList()); } }
|
ExplorerApiHelper { static List<ServiceInstanceInfo> parseServicesResponse(String json) { ServicesResponse servicesResponse = JSON.fromJson(json, ServicesResponse.class); return servicesResponse.getServices().stream() .map(ServiceInstanceState::getSpec) .collect(toList()); } private ExplorerApiHelper(); }
|
ExplorerApiHelper { static List<ServiceInstanceInfo> parseServicesResponse(String json) { ServicesResponse servicesResponse = JSON.fromJson(json, ServicesResponse.class); return servicesResponse.getServices().stream() .map(ServiceInstanceState::getSpec) .collect(toList()); } private ExplorerApiHelper(); }
|
ExplorerApiHelper { static List<ServiceInstanceInfo> parseServicesResponse(String json) { ServicesResponse servicesResponse = JSON.fromJson(json, ServicesResponse.class); return servicesResponse.getServices().stream() .map(ServiceInstanceState::getSpec) .collect(toList()); } private ExplorerApiHelper(); }
|
@Test void twoElementListValidProofE0() { int index = 0; long size = 2L; ListProofHashedEntry h1 = hashedEntry(1, 0); FlatListProof proof = new FlatListProofBuilder() .size(size) .addElement(ELEMENT_ENTRIES.get(index)) .addProofEntry(h1) .build(); CheckedListProof<byte[]> checked = proof.verify(); assertTrue(checked.isValid()); assertThat(checked.size()).isEqualTo(size); byte[] e0value = ELEMENTS.get(index); assertThat(checked.getElements()).containsExactly(entry((long) index, e0value)); HashCode node0Hash = getLeafHashCode(e0value); HashCode node1Hash = h1.getHash(); HashCode rootHash = getBranchHashCode(node0Hash, node1Hash); HashCode expectedListHash = getProofListHash(rootHash, size); assertThat(checked.getIndexHash()).isEqualTo(expectedListHash); }
|
CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
@Test void twoElementListValidProofE1() { int index = 1; long size = 2L; ListProofHashedEntry h0 = hashedEntry(0, 0); FlatListProof proof = new FlatListProofBuilder() .size(size) .addElement(ELEMENT_ENTRIES.get(index)) .addProofEntry(h0) .build(); CheckedListProof<byte[]> checked = proof.verify(); assertTrue(checked.isValid()); assertThat(checked.size()).isEqualTo(size); byte[] e1value = ELEMENTS.get(index); assertThat(checked.getElements()).containsExactly(entry((long) index, e1value)); HashCode node0Hash = h0.getHash(); HashCode node1Hash = getLeafHashCode(e1value); HashCode rootHash = getBranchHashCode(node0Hash, node1Hash); HashCode expectedListHash = getProofListHash(rootHash, size); assertThat(checked.getIndexHash()).isEqualTo(expectedListHash); }
|
CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
@Test void twoElementListValidProofFullProof() { long size = 2L; FlatListProof proof = new FlatListProofBuilder() .size(size) .addElements(ELEMENT_ENTRIES.subList(0, (int) size)) .build(); CheckedListProof<byte[]> checked = proof.verify(); assertTrue(checked.isValid()); assertThat(checked.size()).isEqualTo(size); assertThat(checked.getElements()).containsExactly( entry(0L, ELEMENTS.get(0)), entry(1L, ELEMENTS.get(1))); HashCode node0Hash = getLeafHashCode(ELEMENTS.get(0)); HashCode node1Hash = getLeafHashCode(ELEMENTS.get(1)); HashCode rootHash = getBranchHashCode(node0Hash, node1Hash); HashCode expectedListHash = getProofListHash(rootHash, size); assertThat(checked.getIndexHash()).isEqualTo(expectedListHash); }
|
CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
@Test void twoElementListValidProofAt0() { FlatListProof proof = twoElementListAt0().build(); CheckedListProof<byte[]> checked = proof.verify(); assertTrue(checked.isValid()); }
|
CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
@Test void threeElementListValidProofE2() { int index = 2; ListProofElementEntry elementEntry = ELEMENT_ENTRIES.get(index); long size = 3; ListProofHashedEntry h0 = hashedEntry(0, 1); FlatListProof proof = new FlatListProofBuilder() .size(size) .addElement(elementEntry) .addProofEntry(h0) .build(); CheckedListProof<byte[]> checked = proof.verify(); assertThat(checked.size()).isEqualTo(size); assertThat(checked.getElements()) .containsExactly(entry((long) index, ELEMENTS.get(index))); HashCode leafHash = getLeafHashCode(ELEMENTS.get(index)); HashCode node0Hash = h0.getHash(); HashCode node1Hash = getBranchHashCode(leafHash, null); HashCode rootHash = getBranchHashCode(node0Hash, node1Hash); HashCode expectedListHash = getProofListHash(rootHash, size); assertThat(checked.getIndexHash()).isEqualTo(expectedListHash); }
|
CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
@Test void fiveElementListValidProofAt4() { FlatListProof proof = fiveElementListAt4().build(); CheckedListProof<byte[]> checked = proof.verify(); assertTrue(checked.isValid()); assertThat(checked.getElements()).containsExactly(entry(4L, ELEMENTS.get(4))); }
|
CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { return verifyNonEmptyListProof(); } } FlatListProof(List<ListProofElementEntry> elements,
List<ListProofHashedEntry> proof, long size); }
|
@Test void checkValidSha256Hash() { HashCode hash = HashCode.fromBytes(new byte[32]); assertDoesNotThrow(() -> ProofHashes.checkSha256Hash(hash)); }
|
public static void checkSha256Hash(HashCode hash) { int size = hash.bits(); if (size != Hashing.DEFAULT_HASH_SIZE_BITS) { String message = String.format("Invalid hash size (%s), must be 256 bits", size); throw new InvalidProofException(message); } }
|
ProofHashes { public static void checkSha256Hash(HashCode hash) { int size = hash.bits(); if (size != Hashing.DEFAULT_HASH_SIZE_BITS) { String message = String.format("Invalid hash size (%s), must be 256 bits", size); throw new InvalidProofException(message); } } }
|
ProofHashes { public static void checkSha256Hash(HashCode hash) { int size = hash.bits(); if (size != Hashing.DEFAULT_HASH_SIZE_BITS) { String message = String.format("Invalid hash size (%s), must be 256 bits", size); throw new InvalidProofException(message); } } private ProofHashes(); }
|
ProofHashes { public static void checkSha256Hash(HashCode hash) { int size = hash.bits(); if (size != Hashing.DEFAULT_HASH_SIZE_BITS) { String message = String.format("Invalid hash size (%s), must be 256 bits", size); throw new InvalidProofException(message); } } private ProofHashes(); static void checkSha256Hash(HashCode hash); }
|
ProofHashes { public static void checkSha256Hash(HashCode hash) { int size = hash.bits(); if (size != Hashing.DEFAULT_HASH_SIZE_BITS) { String message = String.format("Invalid hash size (%s), must be 256 bits", size); throw new InvalidProofException(message); } } private ProofHashes(); static void checkSha256Hash(HashCode hash); }
|
@Test void throwsIfNull() { assertThrows(NullPointerException.class, () -> DbKey.fromBytes(null)); }
|
public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKey newLeafKey(byte[] keySlice); static DbKey newBranchKey(byte[] keySlice, int numSignificantBits); Type getNodeType(); byte[] getKeySlice(); int getNumSignificantBits(); byte[] getRawDbKey(); KeyBitSet keyBits(); DbKey commonPrefix(DbKey other); boolean isPrefixOf(DbKey other); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(DbKey other); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKey newLeafKey(byte[] keySlice); static DbKey newBranchKey(byte[] keySlice, int numSignificantBits); Type getNodeType(); byte[] getKeySlice(); int getNumSignificantBits(); byte[] getRawDbKey(); KeyBitSet keyBits(); DbKey commonPrefix(DbKey other); boolean isPrefixOf(DbKey other); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(DbKey other); static final int KEY_SIZE; static final int KEY_SIZE_BITS; static final int DB_KEY_SIZE; }
|
@Test void throwsIfInvalidNodeTypeCode() { byte[] rawDbKey = createDbKey(2, bytes("a"), 8); assertThrows(IllegalArgumentException.class, () -> { DbKey dbKey = DbKey.fromBytes(rawDbKey); }); }
|
public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKey newLeafKey(byte[] keySlice); static DbKey newBranchKey(byte[] keySlice, int numSignificantBits); Type getNodeType(); byte[] getKeySlice(); int getNumSignificantBits(); byte[] getRawDbKey(); KeyBitSet keyBits(); DbKey commonPrefix(DbKey other); boolean isPrefixOf(DbKey other); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(DbKey other); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKey newLeafKey(byte[] keySlice); static DbKey newBranchKey(byte[] keySlice, int numSignificantBits); Type getNodeType(); byte[] getKeySlice(); int getNumSignificantBits(); byte[] getRawDbKey(); KeyBitSet keyBits(); DbKey commonPrefix(DbKey other); boolean isPrefixOf(DbKey other); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(DbKey other); static final int KEY_SIZE; static final int KEY_SIZE_BITS; static final int DB_KEY_SIZE; }
|
@Test void throwsIfLeafHasInvalidSize() { int invalidNumBits = 10; byte[] rawDbKey = createDbKey(Type.LEAF.code, bytes("a"), invalidNumBits); assertThrows(IllegalArgumentException.class, () -> { DbKey dbKey = DbKey.fromBytes(rawDbKey); }); }
|
public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKey newLeafKey(byte[] keySlice); static DbKey newBranchKey(byte[] keySlice, int numSignificantBits); Type getNodeType(); byte[] getKeySlice(); int getNumSignificantBits(); byte[] getRawDbKey(); KeyBitSet keyBits(); DbKey commonPrefix(DbKey other); boolean isPrefixOf(DbKey other); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(DbKey other); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKey newLeafKey(byte[] keySlice); static DbKey newBranchKey(byte[] keySlice, int numSignificantBits); Type getNodeType(); byte[] getKeySlice(); int getNumSignificantBits(); byte[] getRawDbKey(); KeyBitSet keyBits(); DbKey commonPrefix(DbKey other); boolean isPrefixOf(DbKey other); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(DbKey other); static final int KEY_SIZE; static final int KEY_SIZE_BITS; static final int DB_KEY_SIZE; }
|
@Test void indexOfFindsTheFirst() { List<Integer> l = ImmutableList.of(-1, 1, 2, 3); Predicate<Integer> positiveInt = i -> i > 0; assertThat(ExonumIterables.indexOf(l, positiveInt), equalTo(OptionalInt.of(1))); }
|
static <T> OptionalInt indexOf(Iterable<T> list, Predicate<? super T> p) { int i = Iterables.indexOf(list, p::test); if (i == -1) { return OptionalInt.empty(); } return OptionalInt.of(i); }
|
ExonumIterables { static <T> OptionalInt indexOf(Iterable<T> list, Predicate<? super T> p) { int i = Iterables.indexOf(list, p::test); if (i == -1) { return OptionalInt.empty(); } return OptionalInt.of(i); } }
|
ExonumIterables { static <T> OptionalInt indexOf(Iterable<T> list, Predicate<? super T> p) { int i = Iterables.indexOf(list, p::test); if (i == -1) { return OptionalInt.empty(); } return OptionalInt.of(i); } private ExonumIterables(); }
|
ExonumIterables { static <T> OptionalInt indexOf(Iterable<T> list, Predicate<? super T> p) { int i = Iterables.indexOf(list, p::test); if (i == -1) { return OptionalInt.empty(); } return OptionalInt.of(i); } private ExonumIterables(); }
|
ExonumIterables { static <T> OptionalInt indexOf(Iterable<T> list, Predicate<? super T> p) { int i = Iterables.indexOf(list, p::test); if (i == -1) { return OptionalInt.empty(); } return OptionalInt.of(i); } private ExonumIterables(); }
|
@Test void throwsIfBranchKeySliceHasBitsAfterSignificantPart0Bits() { int numSignificantBits = 0; byte[] rawDbKey = createDbKey(Type.BRANCH.code, bytes(0x01), numSignificantBits); assertThrows(IllegalArgumentException.class, () -> { DbKey dbKey = DbKey.fromBytes(rawDbKey); }); }
|
public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKey newLeafKey(byte[] keySlice); static DbKey newBranchKey(byte[] keySlice, int numSignificantBits); Type getNodeType(); byte[] getKeySlice(); int getNumSignificantBits(); byte[] getRawDbKey(); KeyBitSet keyBits(); DbKey commonPrefix(DbKey other); boolean isPrefixOf(DbKey other); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(DbKey other); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKey newLeafKey(byte[] keySlice); static DbKey newBranchKey(byte[] keySlice, int numSignificantBits); Type getNodeType(); byte[] getKeySlice(); int getNumSignificantBits(); byte[] getRawDbKey(); KeyBitSet keyBits(); DbKey commonPrefix(DbKey other); boolean isPrefixOf(DbKey other); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(DbKey other); static final int KEY_SIZE; static final int KEY_SIZE_BITS; static final int DB_KEY_SIZE; }
|
@Test void throwsIfBranchKeySliceHasBitsAfterSignificantPart1Bit() { int numSignificantBits = 1; byte[] rawDbKey = createDbKey(Type.BRANCH.code, bytes(0x03), numSignificantBits); assertThrows(IllegalArgumentException.class, () -> { DbKey dbKey = DbKey.fromBytes(rawDbKey); }); }
|
public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKey newLeafKey(byte[] keySlice); static DbKey newBranchKey(byte[] keySlice, int numSignificantBits); Type getNodeType(); byte[] getKeySlice(); int getNumSignificantBits(); byte[] getRawDbKey(); KeyBitSet keyBits(); DbKey commonPrefix(DbKey other); boolean isPrefixOf(DbKey other); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(DbKey other); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKey newLeafKey(byte[] keySlice); static DbKey newBranchKey(byte[] keySlice, int numSignificantBits); Type getNodeType(); byte[] getKeySlice(); int getNumSignificantBits(); byte[] getRawDbKey(); KeyBitSet keyBits(); DbKey commonPrefix(DbKey other); boolean isPrefixOf(DbKey other); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(DbKey other); static final int KEY_SIZE; static final int KEY_SIZE_BITS; static final int DB_KEY_SIZE; }
|
@Test void throwsIfBranchKeySliceHasBitsAfterSignificantPart7Bit() { int numSignificantBits = 7; byte[] rawDbKey = createDbKey(Type.BRANCH.code, bytes(0x80), numSignificantBits); assertThrows(IllegalArgumentException.class, () -> { DbKey dbKey = DbKey.fromBytes(rawDbKey); }); }
|
public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKey newLeafKey(byte[] keySlice); static DbKey newBranchKey(byte[] keySlice, int numSignificantBits); Type getNodeType(); byte[] getKeySlice(); int getNumSignificantBits(); byte[] getRawDbKey(); KeyBitSet keyBits(); DbKey commonPrefix(DbKey other); boolean isPrefixOf(DbKey other); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(DbKey other); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKey newLeafKey(byte[] keySlice); static DbKey newBranchKey(byte[] keySlice, int numSignificantBits); Type getNodeType(); byte[] getKeySlice(); int getNumSignificantBits(); byte[] getRawDbKey(); KeyBitSet keyBits(); DbKey commonPrefix(DbKey other); boolean isPrefixOf(DbKey other); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(DbKey other); static final int KEY_SIZE; static final int KEY_SIZE_BITS; static final int DB_KEY_SIZE; }
|
@Test void throwsIfBranchKeySliceHasBitsAfterSignificantPart8Bit() { int numSignificantBits = 8; byte[] rawDbKey = createDbKey(Type.BRANCH.code, bytes(0xFF, 0x01), numSignificantBits); assertThrows(IllegalArgumentException.class, () -> { DbKey dbKey = DbKey.fromBytes(rawDbKey); }); }
|
public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKey newLeafKey(byte[] keySlice); static DbKey newBranchKey(byte[] keySlice, int numSignificantBits); Type getNodeType(); byte[] getKeySlice(); int getNumSignificantBits(); byte[] getRawDbKey(); KeyBitSet keyBits(); DbKey commonPrefix(DbKey other); boolean isPrefixOf(DbKey other); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(DbKey other); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKey newLeafKey(byte[] keySlice); static DbKey newBranchKey(byte[] keySlice, int numSignificantBits); Type getNodeType(); byte[] getKeySlice(); int getNumSignificantBits(); byte[] getRawDbKey(); KeyBitSet keyBits(); DbKey commonPrefix(DbKey other); boolean isPrefixOf(DbKey other); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(DbKey other); static final int KEY_SIZE; static final int KEY_SIZE_BITS; static final int DB_KEY_SIZE; }
|
@Test void throwsIfBranchKeySliceHasBitsAfterSignificantPart12Bit() { int numSignificantBits = 12; byte[] rawDbKey = createDbKey(Type.BRANCH.code, bytes(0xFF, 0x1F), numSignificantBits); assertThrows(IllegalArgumentException.class, () -> { DbKey dbKey = DbKey.fromBytes(rawDbKey); }); }
|
public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKey newLeafKey(byte[] keySlice); static DbKey newBranchKey(byte[] keySlice, int numSignificantBits); Type getNodeType(); byte[] getKeySlice(); int getNumSignificantBits(); byte[] getRawDbKey(); KeyBitSet keyBits(); DbKey commonPrefix(DbKey other); boolean isPrefixOf(DbKey other); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(DbKey other); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKey newLeafKey(byte[] keySlice); static DbKey newBranchKey(byte[] keySlice, int numSignificantBits); Type getNodeType(); byte[] getKeySlice(); int getNumSignificantBits(); byte[] getRawDbKey(); KeyBitSet keyBits(); DbKey commonPrefix(DbKey other); boolean isPrefixOf(DbKey other); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(DbKey other); static final int KEY_SIZE; static final int KEY_SIZE_BITS; static final int DB_KEY_SIZE; }
|
@Test void throwsIfBranchKeySliceHasBitsAfterSignificantPart16Bit() { int numSignificantBits = 16; byte[] rawDbKey = createDbKey(Type.BRANCH.code, bytes(0xFF, 0xFF, 0x01), numSignificantBits); assertThrows(IllegalArgumentException.class, () -> { DbKey dbKey = DbKey.fromBytes(rawDbKey); }); }
|
public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKey newLeafKey(byte[] keySlice); static DbKey newBranchKey(byte[] keySlice, int numSignificantBits); Type getNodeType(); byte[] getKeySlice(); int getNumSignificantBits(); byte[] getRawDbKey(); KeyBitSet keyBits(); DbKey commonPrefix(DbKey other); boolean isPrefixOf(DbKey other); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(DbKey other); }
|
DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKey newLeafKey(byte[] keySlice); static DbKey newBranchKey(byte[] keySlice, int numSignificantBits); Type getNodeType(); byte[] getKeySlice(); int getNumSignificantBits(); byte[] getRawDbKey(); KeyBitSet keyBits(); DbKey commonPrefix(DbKey other); boolean isPrefixOf(DbKey other); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(DbKey other); static final int KEY_SIZE; static final int KEY_SIZE_BITS; static final int DB_KEY_SIZE; }
|
@Test void mapProofShouldBeCorrect() { DbKey firstDbKey = DbKeyTestUtils.branchKeyFromPrefix("101100"); ByteString valueKey = DbKeyTestUtils.keyByteStringFromString("101110"); DbKey thirdDbKey = DbKeyTestUtils.branchKeyFromPrefix("1011111"); MapEntry<ByteString, ByteString> leaf = createMapEntry(valueKey, FIRST_VALUE); List<MapProofEntry> branches = Arrays.asList( createMapProofEntry(firstDbKey), createMapProofEntry(thirdDbKey) ); UncheckedMapProof uncheckedFlatMapProof = new UncheckedFlatMapProof(branches, singletonList(leaf), emptyList()); CheckedMapProof checkedMapProof = uncheckedFlatMapProof.check(); MapEntry<ByteString, ByteString> expectedEntry = MapEntry.valueOf(valueKey, FIRST_VALUE); assertThat(checkedMapProof.getEntries(), equalTo(singleton(expectedEntry))); assertTrue(checkedMapProof.containsKey(valueKey)); assertThat(checkedMapProof.get(valueKey), equalTo(FIRST_VALUE)); }
|
@Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapProofStatus.INVALID_HASH_SIZE); } if (prefixesIncluded()) { return CheckedFlatMapProof.invalid(MapProofStatus.EMBEDDED_PATH); } if (isEmptyProof()) { return checkEmptyProof(); } else if (isSingletonProof()) { return checkSingletonProof(); } else { return checkProof(); } }
|
UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapProofStatus.INVALID_HASH_SIZE); } if (prefixesIncluded()) { return CheckedFlatMapProof.invalid(MapProofStatus.EMBEDDED_PATH); } if (isEmptyProof()) { return checkEmptyProof(); } else if (isSingletonProof()) { return checkSingletonProof(); } else { return checkProof(); } } }
|
UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapProofStatus.INVALID_HASH_SIZE); } if (prefixesIncluded()) { return CheckedFlatMapProof.invalid(MapProofStatus.EMBEDDED_PATH); } if (isEmptyProof()) { return checkEmptyProof(); } else if (isSingletonProof()) { return checkSingletonProof(); } else { return checkProof(); } } UncheckedFlatMapProof(
List<MapProofEntry> proof,
List<MapEntry<ByteString, ByteString>> entries,
List<byte[]> missingKeys); }
|
UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapProofStatus.INVALID_HASH_SIZE); } if (prefixesIncluded()) { return CheckedFlatMapProof.invalid(MapProofStatus.EMBEDDED_PATH); } if (isEmptyProof()) { return checkEmptyProof(); } else if (isSingletonProof()) { return checkSingletonProof(); } else { return checkProof(); } } UncheckedFlatMapProof(
List<MapProofEntry> proof,
List<MapEntry<ByteString, ByteString>> entries,
List<byte[]> missingKeys); @Override CheckedMapProof check(); }
|
UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapProofStatus.INVALID_HASH_SIZE); } if (prefixesIncluded()) { return CheckedFlatMapProof.invalid(MapProofStatus.EMBEDDED_PATH); } if (isEmptyProof()) { return checkEmptyProof(); } else if (isSingletonProof()) { return checkSingletonProof(); } else { return checkProof(); } } UncheckedFlatMapProof(
List<MapProofEntry> proof,
List<MapEntry<ByteString, ByteString>> entries,
List<byte[]> missingKeys); @Override CheckedMapProof check(); }
|
@Test void mapProofWithSeveralLeafsShouldBeCorrect() { ByteString firstKey = DbKeyTestUtils.keyByteStringFromString("0011_0101"); ByteString secondKey = DbKeyTestUtils.keyByteStringFromString("0011_0110"); DbKey thirdDbKey = DbKeyTestUtils.branchKeyFromPrefix("0100_0000"); ByteString fourthKey = DbKeyTestUtils.keyByteStringFromString("1000_1101"); List<MapEntry<ByteString, ByteString>> leaves = Arrays.asList( createMapEntry(firstKey, FIRST_VALUE), createMapEntry(secondKey, SECOND_VALUE), createMapEntry(fourthKey, THIRD_VALUE) ); UncheckedMapProof uncheckedFlatMapProof = new UncheckedFlatMapProof( singletonList(createMapProofEntry(thirdDbKey)), leaves, emptyList()); CheckedMapProof checkedMapProof = uncheckedFlatMapProof.check(); Set<MapEntry<ByteString, ByteString>> actualCheckedEntries = checkedMapProof.getEntries(); assertThat(actualCheckedEntries, containsInAnyOrder(leaves.toArray())); assertTrue(checkedMapProof.containsKey(firstKey)); assertThat(checkedMapProof.get(firstKey), equalTo(FIRST_VALUE)); assertThat(checkedMapProof.get(secondKey), equalTo(SECOND_VALUE)); assertThat(checkedMapProof.get(fourthKey), equalTo(THIRD_VALUE)); assertThrows(IllegalArgumentException.class, () -> checkedMapProof.containsKey(ByteString.copyFromUtf8("not required key"))); }
|
@Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapProofStatus.INVALID_HASH_SIZE); } if (prefixesIncluded()) { return CheckedFlatMapProof.invalid(MapProofStatus.EMBEDDED_PATH); } if (isEmptyProof()) { return checkEmptyProof(); } else if (isSingletonProof()) { return checkSingletonProof(); } else { return checkProof(); } }
|
UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapProofStatus.INVALID_HASH_SIZE); } if (prefixesIncluded()) { return CheckedFlatMapProof.invalid(MapProofStatus.EMBEDDED_PATH); } if (isEmptyProof()) { return checkEmptyProof(); } else if (isSingletonProof()) { return checkSingletonProof(); } else { return checkProof(); } } }
|
UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapProofStatus.INVALID_HASH_SIZE); } if (prefixesIncluded()) { return CheckedFlatMapProof.invalid(MapProofStatus.EMBEDDED_PATH); } if (isEmptyProof()) { return checkEmptyProof(); } else if (isSingletonProof()) { return checkSingletonProof(); } else { return checkProof(); } } UncheckedFlatMapProof(
List<MapProofEntry> proof,
List<MapEntry<ByteString, ByteString>> entries,
List<byte[]> missingKeys); }
|
UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapProofStatus.INVALID_HASH_SIZE); } if (prefixesIncluded()) { return CheckedFlatMapProof.invalid(MapProofStatus.EMBEDDED_PATH); } if (isEmptyProof()) { return checkEmptyProof(); } else if (isSingletonProof()) { return checkSingletonProof(); } else { return checkProof(); } } UncheckedFlatMapProof(
List<MapProofEntry> proof,
List<MapEntry<ByteString, ByteString>> entries,
List<byte[]> missingKeys); @Override CheckedMapProof check(); }
|
UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapProofStatus.INVALID_HASH_SIZE); } if (prefixesIncluded()) { return CheckedFlatMapProof.invalid(MapProofStatus.EMBEDDED_PATH); } if (isEmptyProof()) { return checkEmptyProof(); } else if (isSingletonProof()) { return checkSingletonProof(); } else { return checkProof(); } } UncheckedFlatMapProof(
List<MapProofEntry> proof,
List<MapEntry<ByteString, ByteString>> entries,
List<byte[]> missingKeys); @Override CheckedMapProof check(); }
|
@Test void mapProofWithEqualEntriesOrderShouldBeInvalid() { DbKey firstDbKey = DbKeyTestUtils.branchKeyFromPrefix("101100"); DbKey secondKey = DbKeyTestUtils.branchKeyFromPrefix("101100"); List<MapProofEntry> entries = Arrays.asList( createMapProofEntry(firstDbKey), createMapProofEntry(secondKey) ); UncheckedMapProof uncheckedFlatMapProof = new UncheckedFlatMapProof(entries, emptyList(), emptyList()); CheckedMapProof checkedMapProof = uncheckedFlatMapProof.check(); assertThat(checkedMapProof.getProofStatus(), equalTo(MapProofStatus.DUPLICATE_PATH)); }
|
@Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapProofStatus.INVALID_HASH_SIZE); } if (prefixesIncluded()) { return CheckedFlatMapProof.invalid(MapProofStatus.EMBEDDED_PATH); } if (isEmptyProof()) { return checkEmptyProof(); } else if (isSingletonProof()) { return checkSingletonProof(); } else { return checkProof(); } }
|
UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapProofStatus.INVALID_HASH_SIZE); } if (prefixesIncluded()) { return CheckedFlatMapProof.invalid(MapProofStatus.EMBEDDED_PATH); } if (isEmptyProof()) { return checkEmptyProof(); } else if (isSingletonProof()) { return checkSingletonProof(); } else { return checkProof(); } } }
|
UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapProofStatus.INVALID_HASH_SIZE); } if (prefixesIncluded()) { return CheckedFlatMapProof.invalid(MapProofStatus.EMBEDDED_PATH); } if (isEmptyProof()) { return checkEmptyProof(); } else if (isSingletonProof()) { return checkSingletonProof(); } else { return checkProof(); } } UncheckedFlatMapProof(
List<MapProofEntry> proof,
List<MapEntry<ByteString, ByteString>> entries,
List<byte[]> missingKeys); }
|
UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapProofStatus.INVALID_HASH_SIZE); } if (prefixesIncluded()) { return CheckedFlatMapProof.invalid(MapProofStatus.EMBEDDED_PATH); } if (isEmptyProof()) { return checkEmptyProof(); } else if (isSingletonProof()) { return checkSingletonProof(); } else { return checkProof(); } } UncheckedFlatMapProof(
List<MapProofEntry> proof,
List<MapEntry<ByteString, ByteString>> entries,
List<byte[]> missingKeys); @Override CheckedMapProof check(); }
|
UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapProofStatus.INVALID_HASH_SIZE); } if (prefixesIncluded()) { return CheckedFlatMapProof.invalid(MapProofStatus.EMBEDDED_PATH); } if (isEmptyProof()) { return checkEmptyProof(); } else if (isSingletonProof()) { return checkSingletonProof(); } else { return checkProof(); } } UncheckedFlatMapProof(
List<MapProofEntry> proof,
List<MapEntry<ByteString, ByteString>> entries,
List<byte[]> missingKeys); @Override CheckedMapProof check(); }
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.