Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenlan-amzn committed Oct 8, 2020
1 parent ba46528 commit 3210aa0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ out/
*.iws
.DS_Store
*.log
http
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ data class ChangePolicy(
val isSafe: Boolean
) : Writeable, ToXContentObject {

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
policyID = sin.readString(),
state = sin.readOptionalString(),
include = sin.readList(::StateFilter),
isSafe = sin.readBoolean()
)

override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
builder
.startObject()
Expand All @@ -54,6 +62,7 @@ data class ChangePolicy(
return builder
}

@Throws(IOException::class)
override fun writeTo(out: StreamOutput) {
out.writeString(policyID)
out.writeOptionalString(state)
Expand All @@ -68,17 +77,7 @@ data class ChangePolicy(
const val IS_SAFE_FIELD = "is_safe"

fun fromStreamInput(sin: StreamInput): ChangePolicy {
val policyID: String? = sin.readString()
val state: String? = sin.readOptionalString()
val isSafe: Boolean = sin.readBoolean()
val include: MutableList<StateFilter> = sin.readList { StateFilter.fromStreamInput(it) }

return ChangePolicy(
requireNotNull(policyID) { "ChangePolicy policy id is null" },
state,
include.toList(),
isSafe
)
return ChangePolicy(sin)
}

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ import java.io.IOException

data class StateFilter(val state: String) : Writeable {

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
state = String()
)

@Throws(IOException::class)
override fun writeTo(out: StreamOutput) {
out.writeString(state)
}
Expand All @@ -51,9 +57,7 @@ data class StateFilter(val state: String) : Writeable {
}

fun fromStreamInput(sin: StreamInput): StateFilter {
val state: String? = sin.readString()

return StateFilter(requireNotNull(state) { "Must include a state when using include filter" })
return StateFilter(sin)
}
}
}

0 comments on commit 3210aa0

Please sign in to comment.