Skip to content

Commit 80f8c33

Browse files
author
Andrew Louth
committed
Refactors isEmpty() methods to empty()
The presence of isEmpty() causes some kotlin JSON parsers (e.g. fasterxml as used by AWS Lambda) to generate a field labelled 'empty' because isEmpty() follows the pattern of a boolean accessor.
1 parent e744dff commit 80f8c33

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

sdk/src/main/java/com/tmsdurham/actions/DialogflowApp.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ class DialogflowApp : AssistantApp<DialogflowRequest, DialogflowResponse> {
434434
*/
435435
fun ask(inputPrompt: RichResponse, noInputs: MutableList<String>? = null): ResponseWrapper<DialogflowResponse>? {
436436
debug("ask: inputPrompt=$inputPrompt, noInputs=$noInputs")
437-
if (inputPrompt.isEmpty()) {
437+
if (inputPrompt.empty()) {
438438
handleError("Invalid input prompt")
439439
return null
440440
}
@@ -655,7 +655,7 @@ class DialogflowApp : AssistantApp<DialogflowRequest, DialogflowResponse> {
655655
*/
656656
fun askWithCarousel(inputPrompt: RichResponse, carousel: Carousel): ResponseWrapper<DialogflowResponse>? {
657657
debug("askWithCarousel: inputPrompt=$inputPrompt, carousel=$carousel")
658-
if (inputPrompt.isEmpty()) {
658+
if (inputPrompt.empty()) {
659659
handleError("Invalid input prompt")
660660
return null
661661
}
@@ -774,7 +774,7 @@ class DialogflowApp : AssistantApp<DialogflowRequest, DialogflowResponse> {
774774
*/
775775
override fun tell(richResponse: RichResponse?): ResponseWrapper<DialogflowResponse>? {
776776
debug("tell: richResponse=$richResponse")
777-
if (richResponse == null || richResponse.isEmpty()) {
777+
if (richResponse == null || richResponse.empty()) {
778778
handleError("Invalid rich response")
779779
return null
780780
}
@@ -784,7 +784,7 @@ class DialogflowApp : AssistantApp<DialogflowRequest, DialogflowResponse> {
784784

785785
override fun tell(simpleResponse: SimpleResponse): ResponseWrapper<DialogflowResponse>? {
786786
debug("tell: speechResponse=$simpleResponse")
787-
if (simpleResponse.isEmpty()) {
787+
if (simpleResponse.empty()) {
788788
handleError("Invalid speech response")
789789
return null
790790
}
@@ -1217,7 +1217,7 @@ class DialogflowApp : AssistantApp<DialogflowRequest, DialogflowResponse> {
12171217
*/
12181218
fun buildResponse(simpleResponse: SimpleResponse, expectUserResponse: Boolean, noInputs: MutableList<String>? = null): ResponseWrapper<DialogflowResponse>? {
12191219
debug("buildResponse_: simpleResponse=$simpleResponse, expectUserResponse=$expectUserResponse, noInputs=$noInputs")
1220-
if (simpleResponse.isEmpty()) {
1220+
if (simpleResponse.empty()) {
12211221
handleError("Invalid text to speech")
12221222
return null
12231223
}
@@ -1237,7 +1237,7 @@ class DialogflowApp : AssistantApp<DialogflowRequest, DialogflowResponse> {
12371237
*/
12381238
fun buildResponse(richResponse: RichResponse, expectUserResponse: Boolean, noInputs: MutableList<String>? = null): ResponseWrapper<DialogflowResponse>? {
12391239
debug("buildResponse_: textToSpeech=$richResponse, expectUserResponse=$expectUserResponse, noInputs=$noInputs")
1240-
if (richResponse.isEmpty()) {
1240+
if (richResponse.empty()) {
12411241
handleError("Invalid text to speech")
12421242
return null
12431243
}

sdk/src/main/java/com/tmsdurham/actions/ResponseBuilder.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ data class SimpleResponse(
3939
var textToSpeech: String? = null,
4040
var ssml: String? = null,
4141
var displayText: String? = null) {
42-
fun isEmpty() = textToSpeech.isNullOrBlank() && ssml.isNullOrBlank() && displayText.isNullOrBlank()
42+
fun empty() = textToSpeech.isNullOrBlank() && ssml.isNullOrBlank() && displayText.isNullOrBlank()
4343
}
4444

4545
/**
@@ -109,7 +109,7 @@ data class RichResponse(
109109
var altLinkSuggestion: AltLinkSuggestion? = null,
110110
var linkOutSuggestion: LinkOutSuggestion? = null) {
111111

112-
fun isEmpty() = (items.isEmpty() &&
112+
fun empty() = (items.isEmpty() &&
113113
(suggestions == null || suggestions!!.isEmpty()) &&
114114
(altLinkSuggestion == null) &&
115115
(linkOutSuggestion == null))
@@ -123,7 +123,7 @@ data class RichResponse(
123123
*/
124124
fun addSimpleResponse(speech: String, displayText: String? = null): RichResponse {
125125
val simpleResponse = SimpleResponse(textToSpeech = speech, displayText = displayText)
126-
if (simpleResponse.isEmpty()) {
126+
if (simpleResponse.empty()) {
127127
error("Invalid simpleResponse")
128128
return this
129129
}

0 commit comments

Comments
 (0)