mirror of
https://github.com/corda/corda.git
synced 2024-12-22 14:22:28 +00:00
[M10 Fixes] - fixes enum - json conversion problem in kotlin 1.1.1 (#495)
(cherry picked from commit 3327517
)
This commit is contained in:
parent
f1a168046d
commit
072cea4923
@ -46,7 +46,7 @@ interface TokenizableAssetInfo {
|
|||||||
* TODO Proper lookup of currencies in a locale and context sensitive fashion is not supported and is left to the application.
|
* TODO Proper lookup of currencies in a locale and context sensitive fashion is not supported and is left to the application.
|
||||||
*/
|
*/
|
||||||
@CordaSerializable
|
@CordaSerializable
|
||||||
data class Amount<T: Any>(val quantity: Long, val displayTokenSize: BigDecimal,val token: T) : Comparable<Amount<T>> {
|
data class Amount<T : Any>(val quantity: Long, val displayTokenSize: BigDecimal, val token: T) : Comparable<Amount<T>> {
|
||||||
companion object {
|
companion object {
|
||||||
/**
|
/**
|
||||||
* Build an Amount from a decimal representation. For example, with an input of "12.34 GBP",
|
* Build an Amount from a decimal representation. For example, with an input of "12.34 GBP",
|
||||||
@ -253,10 +253,9 @@ data class Amount<T: Any>(val quantity: Long, val displayTokenSize: BigDecimal,v
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun <T : Any> Iterable<Amount<T>>.sumOrNull() = if (!iterator().hasNext()) null else sumOrThrow()
|
||||||
fun <T: Any> Iterable<Amount<T>>.sumOrNull() = if (!iterator().hasNext()) null else sumOrThrow()
|
fun <T : Any> Iterable<Amount<T>>.sumOrThrow() = reduce { left, right -> left + right }
|
||||||
fun <T: Any> Iterable<Amount<T>>.sumOrThrow() = reduce { left, right -> left + right }
|
fun <T : Any> Iterable<Amount<T>>.sumOrZero(token: T) = if (iterator().hasNext()) sumOrThrow() else Amount.zero(token)
|
||||||
fun <T: Any> Iterable<Amount<T>>.sumOrZero(token: T) = if (iterator().hasNext()) sumOrThrow() else Amount.zero(token)
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -550,43 +549,25 @@ enum class DateRollDirection(val value: Long) { FORWARD(1), BACKWARD(-1) }
|
|||||||
* There are some additional rules which are explained in the individual cases below.
|
* There are some additional rules which are explained in the individual cases below.
|
||||||
*/
|
*/
|
||||||
@CordaSerializable
|
@CordaSerializable
|
||||||
enum class DateRollConvention {
|
enum class DateRollConvention(val direction: () -> DateRollDirection, val isModified: Boolean) {
|
||||||
// direction() cannot be a val due to the throw in the Actual instance
|
// direction() cannot be a val due to the throw in the Actual instance
|
||||||
|
|
||||||
/** Don't roll the date, use the one supplied. */
|
/** Don't roll the date, use the one supplied. */
|
||||||
Actual {
|
Actual({ throw UnsupportedOperationException("Direction is not relevant for convention Actual") }, false),
|
||||||
override fun direction(): DateRollDirection = throw UnsupportedOperationException("Direction is not relevant for convention Actual")
|
|
||||||
override val isModified: Boolean = false
|
|
||||||
},
|
|
||||||
/** Following is the next business date from this one. */
|
/** Following is the next business date from this one. */
|
||||||
Following {
|
Following({ DateRollDirection.FORWARD }, false),
|
||||||
override fun direction(): DateRollDirection = DateRollDirection.FORWARD
|
|
||||||
override val isModified: Boolean = false
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* "Modified following" is the next business date, unless it's in the next month, in which case use the preceeding
|
* "Modified following" is the next business date, unless it's in the next month, in which case use the preceeding
|
||||||
* business date.
|
* business date.
|
||||||
*/
|
*/
|
||||||
ModifiedFollowing {
|
ModifiedFollowing({ DateRollDirection.FORWARD }, true),
|
||||||
override fun direction(): DateRollDirection = DateRollDirection.FORWARD
|
|
||||||
override val isModified: Boolean = true
|
|
||||||
},
|
|
||||||
/** Previous is the previous business date from this one. */
|
/** Previous is the previous business date from this one. */
|
||||||
Previous {
|
Previous({ DateRollDirection.BACKWARD }, false),
|
||||||
override fun direction(): DateRollDirection = DateRollDirection.BACKWARD
|
|
||||||
override val isModified: Boolean = false
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* Modified previous is the previous business date, unless it's in the previous month, in which case use the next
|
* Modified previous is the previous business date, unless it's in the previous month, in which case use the next
|
||||||
* business date.
|
* business date.
|
||||||
*/
|
*/
|
||||||
ModifiedPrevious {
|
ModifiedPrevious({ DateRollDirection.BACKWARD }, true);
|
||||||
override fun direction(): DateRollDirection = DateRollDirection.BACKWARD
|
|
||||||
override val isModified: Boolean = true
|
|
||||||
};
|
|
||||||
|
|
||||||
abstract fun direction(): DateRollDirection
|
|
||||||
abstract val isModified: Boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -630,31 +611,14 @@ enum class PaymentRule {
|
|||||||
*/
|
*/
|
||||||
@Suppress("unused") // TODO: Revisit post-Vega and see if annualCompoundCount is still needed.
|
@Suppress("unused") // TODO: Revisit post-Vega and see if annualCompoundCount is still needed.
|
||||||
@CordaSerializable
|
@CordaSerializable
|
||||||
enum class Frequency(val annualCompoundCount: Int) {
|
enum class Frequency(val annualCompoundCount: Int, val offset: LocalDate.(Long) -> LocalDate) {
|
||||||
Annual(1) {
|
Annual(1, { plusYears(1 * it) }),
|
||||||
override fun offset(d: LocalDate, n: Long) = d.plusYears(1 * n)
|
SemiAnnual(2, { plusMonths(6 * it) }),
|
||||||
},
|
Quarterly(4, { plusMonths(3 * it) }),
|
||||||
SemiAnnual(2) {
|
Monthly(12, { plusMonths(1 * it) }),
|
||||||
override fun offset(d: LocalDate, n: Long) = d.plusMonths(6 * n)
|
Weekly(52, { plusWeeks(1 * it) }),
|
||||||
},
|
BiWeekly(26, { plusWeeks(2 * it) }),
|
||||||
Quarterly(4) {
|
Daily(365, { plusDays(1 * it) });
|
||||||
override fun offset(d: LocalDate, n: Long) = d.plusMonths(3 * n)
|
|
||||||
},
|
|
||||||
Monthly(12) {
|
|
||||||
override fun offset(d: LocalDate, n: Long) = d.plusMonths(1 * n)
|
|
||||||
},
|
|
||||||
Weekly(52) {
|
|
||||||
override fun offset(d: LocalDate, n: Long) = d.plusWeeks(1 * n)
|
|
||||||
},
|
|
||||||
BiWeekly(26) {
|
|
||||||
override fun offset(d: LocalDate, n: Long) = d.plusWeeks(2 * n)
|
|
||||||
},
|
|
||||||
Daily(365) {
|
|
||||||
override fun offset(d: LocalDate, n: Long) = d.plusDays(1 * n)
|
|
||||||
};
|
|
||||||
|
|
||||||
abstract fun offset(d: LocalDate, n: Long = 1): LocalDate
|
|
||||||
// Daily() // Let's not worry about this for now.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user