mirror of
https://github.com/corda/corda.git
synced 2025-05-02 08:43:15 +00:00
Minor: add a simple List<T>.indexOfOrThrow() utility and use it in a new LedgerTransaction.outRef helper.
This commit is contained in:
parent
e2deea598e
commit
02e9473201
@ -85,8 +85,15 @@ data class WireTransaction(val inputs: List<StateRef>,
|
|||||||
return SignedTransaction(serialized, withSigs)
|
return SignedTransaction(serialized, withSigs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns a [StateAndRef] for the given output index. */
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
fun <T : ContractState> outRef(index: Int) = StateAndRef(outputs[index] as T, StateRef(id, index))
|
fun <T : ContractState> outRef(index: Int): StateAndRef<T> {
|
||||||
|
require(index >= 0 && index < outputs.size)
|
||||||
|
return StateAndRef(outputs[index] as T, StateRef(id, index))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns a [StateAndRef] for the requested output state, or throws [IllegalArgumentException] if not found. */
|
||||||
|
fun <T : ContractState> outRef(state: ContractState): StateAndRef<T> = outRef(outputs.indexOfOrThrow(state))
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
val buf = StringBuilder()
|
val buf = StringBuilder()
|
||||||
|
@ -64,6 +64,13 @@ fun <T> SettableFuture<T>.setFrom(logger: Logger? = null, block: () -> T): Setta
|
|||||||
// Simple infix function to add back null safety that the JDK lacks: timeA until timeB
|
// Simple infix function to add back null safety that the JDK lacks: timeA until timeB
|
||||||
infix fun Temporal.until(endExclusive: Temporal) = Duration.between(this, endExclusive)
|
infix fun Temporal.until(endExclusive: Temporal) = Duration.between(this, endExclusive)
|
||||||
|
|
||||||
|
/** Returns the index of the given item or throws [IllegalArgumentException] if not found. */
|
||||||
|
fun <T> List<T>.indexOfOrThrow(item: T): Int {
|
||||||
|
val i = indexOf(item)
|
||||||
|
require(i != -1)
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
// An alias that can sometimes make code clearer to read.
|
// An alias that can sometimes make code clearer to read.
|
||||||
val RunOnCallerThread = MoreExecutors.directExecutor()
|
val RunOnCallerThread = MoreExecutors.directExecutor()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user