mirror of
https://github.com/corda/corda.git
synced 2025-01-23 21:08:48 +00:00
Remove kotlin.Pair from Public APIs
This commit is contained in:
parent
fa7c2b71f7
commit
bc4223712b
@ -391,10 +391,10 @@ class AmountTransfer<T : Any, P : Any>(val quantityDelta: Long,
|
||||
* relative asset exchange happens, but with each party exchanging versus a central counterparty, or clearing house.
|
||||
*
|
||||
* @param centralParty The central party to face the exchange against.
|
||||
* @return Returns two new AmountTransfers each between one of the original parties and the centralParty.
|
||||
* @return Returns a list of two new AmountTransfers each between one of the original parties and the centralParty.
|
||||
* The net total exchange is the same as in the original input.
|
||||
*/
|
||||
fun novate(centralParty: P): Pair<AmountTransfer<T, P>, AmountTransfer<T, P>> = Pair(copy(destination = centralParty), copy(source = centralParty))
|
||||
fun novate(centralParty: P): List<AmountTransfer<T, P>> = listOf(copy(destination = centralParty), copy(source = centralParty))
|
||||
|
||||
/**
|
||||
* Applies this AmountTransfer to a list of [SourceAndAmount] objects representing balances.
|
||||
|
@ -147,6 +147,12 @@ data class Issued<out P : Any>(val issuer: PartyAndReference, val product: P) {
|
||||
fun <T : Any> Amount<Issued<T>>.withoutIssuer(): Amount<T> = Amount(quantity, token.product)
|
||||
|
||||
// DOCSTART 3
|
||||
|
||||
/**
|
||||
* Return structure for [OwnableState.withNewOwner]
|
||||
*/
|
||||
data class CommandAndState(val command: CommandData, val ownableState: OwnableState)
|
||||
|
||||
/**
|
||||
* A contract state that can have a single owner.
|
||||
*/
|
||||
@ -155,7 +161,7 @@ interface OwnableState : ContractState {
|
||||
val owner: AbstractParty
|
||||
|
||||
/** Copies the underlying data structure, replacing the owner field with this new value and leaving the rest alone */
|
||||
fun withNewOwner(newOwner: AbstractParty): Pair<CommandData, OwnableState>
|
||||
fun withNewOwner(newOwner: AbstractParty): CommandAndState
|
||||
}
|
||||
// DOCEND 3
|
||||
|
||||
|
@ -3,6 +3,8 @@ package net.corda.core.node
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
import java.util.*
|
||||
|
||||
data class ScreenCoordinate(val screenX: Double, val screenY: Double)
|
||||
|
||||
/** A latitude/longitude pair. */
|
||||
@CordaSerializable
|
||||
data class WorldCoordinate(val latitude: Double, val longitude: Double) {
|
||||
@ -21,7 +23,7 @@ data class WorldCoordinate(val latitude: Double, val longitude: Double) {
|
||||
*/
|
||||
@Suppress("unused") // Used from the visualiser GUI.
|
||||
fun project(screenWidth: Double, screenHeight: Double, topLatitude: Double, bottomLatitude: Double,
|
||||
leftLongitude: Double, rightLongitude: Double): Pair<Double, Double> {
|
||||
leftLongitude: Double, rightLongitude: Double): ScreenCoordinate {
|
||||
require(latitude in bottomLatitude..topLatitude)
|
||||
require(longitude in leftLongitude..rightLongitude)
|
||||
|
||||
@ -33,7 +35,7 @@ data class WorldCoordinate(val latitude: Double, val longitude: Double) {
|
||||
val topLatRel = screenYRelative(topLatitude)
|
||||
val bottomLatRel = screenYRelative(bottomLatitude)
|
||||
fun latitudeToScreenY(lat: Double) = screenHeight * (screenYRelative(lat) - topLatRel) / (bottomLatRel - topLatRel)
|
||||
return Pair(longitudeToScreenX(longitude), latitudeToScreenY(latitude))
|
||||
return ScreenCoordinate(longitudeToScreenX(longitude), latitudeToScreenY(latitude))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,7 +202,7 @@ class ContractUpgradeFlowTest {
|
||||
|
||||
override fun move(newAmount: Amount<Issued<Currency>>, newOwner: AbstractParty) = copy(amount = amount.copy(newAmount.quantity), owners = listOf(newOwner))
|
||||
override fun toString() = "${Emoji.bagOfCash}New Cash($amount at ${amount.token.issuer} owned by $owner)"
|
||||
override fun withNewOwner(newOwner: AbstractParty) = Pair(Cash.Commands.Move(), copy(owners = listOf(newOwner)))
|
||||
override fun withNewOwner(newOwner: AbstractParty) = CommandAndState(Cash.Commands.Move(), copy(owners = listOf(newOwner)))
|
||||
}
|
||||
|
||||
override fun upgrade(state: Cash.State) = CashV2.State(state.amount.times(1000), listOf(state.owner))
|
||||
|
@ -32,7 +32,7 @@ class TransactionSerializationTests : TestDependencyInjectionBase() {
|
||||
override val participants: List<AbstractParty>
|
||||
get() = listOf(owner)
|
||||
|
||||
override fun withNewOwner(newOwner: AbstractParty) = Pair(Commands.Move(), copy(owner = newOwner))
|
||||
override fun withNewOwner(newOwner: AbstractParty) = CommandAndState(Commands.Move(), copy(owner = newOwner))
|
||||
}
|
||||
|
||||
interface Commands : CommandData {
|
||||
|
@ -68,8 +68,8 @@ public class JavaCommercialPaper implements Contract {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Pair<CommandData, OwnableState> withNewOwner(@NotNull AbstractParty newOwner) {
|
||||
return new Pair<>(new Commands.Move(), new State(this.issuance, newOwner, this.faceValue, this.maturityDate));
|
||||
public CommandAndState withNewOwner(@NotNull AbstractParty newOwner) {
|
||||
return new CommandAndState(new Commands.Move(), new State(this.issuance, newOwner, this.faceValue, this.maturityDate));
|
||||
}
|
||||
|
||||
public ICommercialPaperState withFaceValue(Amount<Issued<Currency>> newFaceValue) {
|
||||
|
@ -73,7 +73,7 @@ class CommercialPaper : Contract {
|
||||
val token: Issued<Terms>
|
||||
get() = Issued(issuance, Terms(faceValue.token, maturityDate))
|
||||
|
||||
override fun withNewOwner(newOwner: AbstractParty) = Pair(Commands.Move(), copy(owner = newOwner))
|
||||
override fun withNewOwner(newOwner: AbstractParty) = CommandAndState(Commands.Move(), copy(owner = newOwner))
|
||||
override fun toString() = "${Emoji.newspaper}CommercialPaper(of $faceValue redeemable on $maturityDate by '$issuance', owned by $owner)"
|
||||
|
||||
// Although kotlin is smart enough not to need these, as we are using the ICommercialPaperState, we need to declare them explicitly for use later,
|
||||
|
@ -36,7 +36,7 @@ class CommercialPaperLegacy : Contract {
|
||||
override val participants = listOf(owner)
|
||||
|
||||
fun withoutOwner() = copy(owner = NULL_PARTY)
|
||||
override fun withNewOwner(newOwner: AbstractParty) = Pair(Commands.Move(), copy(owner = newOwner))
|
||||
override fun withNewOwner(newOwner: AbstractParty) = CommandAndState(Commands.Move(), copy(owner = newOwner))
|
||||
override fun toString() = "${Emoji.newspaper}CommercialPaper(of $faceValue redeemable on $maturityDate by '$issuance', owned by $owner)"
|
||||
|
||||
// Although kotlin is smart enough not to need these, as we are using the ICommercialPaperState, we need to declare them explicitly for use later,
|
||||
|
@ -108,7 +108,7 @@ class Cash : OnLedgerAsset<Currency, Cash.Commands, Cash.State>() {
|
||||
|
||||
override fun toString() = "${Emoji.bagOfCash}Cash($amount at ${amount.token.issuer} owned by $owner)"
|
||||
|
||||
override fun withNewOwner(newOwner: AbstractParty) = Pair(Commands.Move(), copy(owner = newOwner))
|
||||
override fun withNewOwner(newOwner: AbstractParty) = CommandAndState(Commands.Move(), copy(owner = newOwner))
|
||||
|
||||
/** Object Relational Mapping support. */
|
||||
override fun generateMappedObject(schema: MappedSchema): PersistentState {
|
||||
|
@ -110,7 +110,7 @@ class CommodityContract : OnLedgerAsset<Commodity, CommodityContract.Commands, C
|
||||
|
||||
override fun toString() = "Commodity($amount at ${amount.token.issuer} owned by $owner)"
|
||||
|
||||
override fun withNewOwner(newOwner: AbstractParty) = Pair(Commands.Move(), copy(owner = newOwner))
|
||||
override fun withNewOwner(newOwner: AbstractParty) = CommandAndState(Commands.Move(), copy(owner = newOwner))
|
||||
}
|
||||
|
||||
// Just for grouping
|
||||
|
@ -333,7 +333,7 @@ class Obligation<P : Any> : Contract {
|
||||
}
|
||||
}
|
||||
|
||||
override fun withNewOwner(newOwner: AbstractParty) = Pair(Commands.Move(), copy(beneficiary = newOwner))
|
||||
override fun withNewOwner(newOwner: AbstractParty) = CommandAndState(Commands.Move(), copy(beneficiary = newOwner))
|
||||
}
|
||||
|
||||
// Just for grouping
|
||||
|
@ -71,7 +71,7 @@ class DummyFungibleContract : OnLedgerAsset<Currency, DummyFungibleContract.Comm
|
||||
|
||||
override fun toString() = "${Emoji.bagOfCash}Cash($amount at ${amount.token.issuer} owned by $owner)"
|
||||
|
||||
override fun withNewOwner(newOwner: AbstractParty) = Pair(Commands.Move(), copy(owner = newOwner))
|
||||
override fun withNewOwner(newOwner: AbstractParty) = CommandAndState(Commands.Move(), copy(owner = newOwner))
|
||||
|
||||
/** Object Relational Mapping support. */
|
||||
override fun generateMappedObject(schema: MappedSchema): PersistentState {
|
||||
|
@ -87,7 +87,7 @@ class VaultSchemaTest : TestDependencyInjectionBase() {
|
||||
override val participants: List<AbstractParty>
|
||||
get() = listOf(owner)
|
||||
|
||||
override fun withNewOwner(newOwner: AbstractParty) = Pair(Commands.Create(), copy(owner = newOwner))
|
||||
override fun withNewOwner(newOwner: AbstractParty) = CommandAndState(Commands.Create(), copy(owner = newOwner))
|
||||
}
|
||||
|
||||
interface Commands : CommandData {
|
||||
|
@ -8,6 +8,7 @@ import javafx.scene.shape.Circle
|
||||
import javafx.scene.shape.Line
|
||||
import javafx.util.Duration
|
||||
import net.corda.core.crypto.commonName
|
||||
import net.corda.core.node.ScreenCoordinate
|
||||
import net.corda.core.utilities.ProgressTracker
|
||||
import net.corda.netmap.simulation.IRSSimulation
|
||||
import net.corda.testing.node.MockNetwork
|
||||
@ -26,7 +27,7 @@ class VisualiserViewModel {
|
||||
inner class NodeWidget(val node: MockNetwork.MockNode, val innerDot: Circle, val outerDot: Circle, val longPulseDot: Circle,
|
||||
val pulseAnim: Animation, val longPulseAnim: Animation,
|
||||
val nameLabel: Label, val statusLabel: Label) {
|
||||
fun position(nodeCoords: (node: MockNetwork.MockNode) -> Pair<Double, Double>) {
|
||||
fun position(nodeCoords: (node: MockNetwork.MockNode) -> ScreenCoordinate) {
|
||||
val (x, y) = nodeCoords(node)
|
||||
innerDot.centerX = x
|
||||
innerDot.centerY = y
|
||||
@ -76,7 +77,7 @@ class VisualiserViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
fun nodeMapCoords(node: MockNetwork.MockNode): Pair<Double, Double> {
|
||||
fun nodeMapCoords(node: MockNetwork.MockNode): ScreenCoordinate {
|
||||
// For an image of the whole world, we use:
|
||||
// return node.place.coordinate.project(mapImage.fitWidth, mapImage.fitHeight, 85.0511, -85.0511, -180.0, 180.0)
|
||||
|
||||
@ -90,7 +91,7 @@ class VisualiserViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
fun nodeCircleCoords(type: NetworkMapVisualiser.NodeType, index: Int): Pair<Double, Double> {
|
||||
fun nodeCircleCoords(type: NetworkMapVisualiser.NodeType, index: Int): ScreenCoordinate {
|
||||
val stepRad: Double = when (type) {
|
||||
NetworkMapVisualiser.NodeType.BANK -> 2 * Math.PI / bankCount
|
||||
NetworkMapVisualiser.NodeType.SERVICE -> (2 * Math.PI / serviceCount)
|
||||
@ -109,7 +110,7 @@ class VisualiserViewModel {
|
||||
val circleY = view.stageHeight / 2 + yOffset
|
||||
val x: Double = radius * Math.cos(tangentRad) + circleX
|
||||
val y: Double = radius * Math.sin(tangentRad) + circleY
|
||||
return Pair(x, y)
|
||||
return ScreenCoordinate(x, y)
|
||||
}
|
||||
|
||||
fun createNodes() {
|
||||
|
@ -21,7 +21,7 @@ data class DummyContract(override val legalContractReference: SecureHash = Secur
|
||||
override val participants: List<AbstractParty>
|
||||
get() = listOf(owner)
|
||||
|
||||
override fun withNewOwner(newOwner: AbstractParty) = Pair(Commands.Move(), copy(owner = newOwner))
|
||||
override fun withNewOwner(newOwner: AbstractParty) = CommandAndState(Commands.Move(), copy(owner = newOwner))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,6 +30,7 @@ import net.corda.core.contracts.ContractState
|
||||
import net.corda.core.crypto.toBase58String
|
||||
import net.corda.core.identity.Party
|
||||
import net.corda.core.node.NodeInfo
|
||||
import net.corda.core.node.ScreenCoordinate
|
||||
import net.corda.explorer.formatters.PartyNameFormatter
|
||||
import net.corda.explorer.model.CordaView
|
||||
import tornadofx.*
|
||||
@ -122,11 +123,11 @@ class Network : CordaView() {
|
||||
contentDisplay = ContentDisplay.TOP
|
||||
val coordinate = Bindings.createObjectBinding({
|
||||
// These coordinates are obtained when we generate the map using TileMill.
|
||||
node.worldMapLocation?.coordinate?.project(mapPane.width, mapPane.height, 85.0511, -85.0511, -180.0, 180.0) ?: Pair(0.0, 0.0)
|
||||
node.worldMapLocation?.coordinate?.project(mapPane.width, mapPane.height, 85.0511, -85.0511, -180.0, 180.0) ?: ScreenCoordinate(0.0, 0.0)
|
||||
}, arrayOf(mapPane.widthProperty(), mapPane.heightProperty()))
|
||||
// Center point of the label.
|
||||
layoutXProperty().bind(coordinate.map { it.first - width / 2 })
|
||||
layoutYProperty().bind(coordinate.map { it.second - height / 4 })
|
||||
layoutXProperty().bind(coordinate.map { it.screenX - width / 2 })
|
||||
layoutYProperty().bind(coordinate.map { it.screenY - height / 4 })
|
||||
}
|
||||
|
||||
val button = node.renderButton(mapLabel)
|
||||
|
Loading…
Reference in New Issue
Block a user