Skip to content

Conversation

@rlaope
Copy link
Contributor

@rlaope rlaope commented Sep 20, 2023

Please understand that I am not good at grammar because I am not an English speaker..

Hello, I am a 16-year-old developer who lives in Korea., I was looking at the spring docs part developed by Kotlin and saw MyHealth Metrics ExportConfiguration's private fun getStatusCode(). It was using the if statement to return it, so I suggest using a when statement while using Kotlin!


Before

private fun getStatusCode(health: HealthEndpoint): Int {
		val status = health.health().status
		if (Status.UP == status) {
			return 3
		}
		if (Status.OUT_OF_SERVICE == status) {
			return 2
		}
		if (Status.DOWN == status) {
			return 1
		}
		return 0
	}

After

private fun getStatusCode(health: HealthEndpoint): Int {
    	return when (health.health().status) {
        	Status.UP -> 3
        	Status.OUT_OF_SERVICE -> 2
        	Status.DOWN -> 1
        	else -> 0
    	}
}

or

private fun getStatusCode(health: HealthEndpoint) = when (health.health().status) {
    Status.UP -> 3
    Status.OUT_OF_SERVICE -> 2
    Status.DOWN -> 1
    else -> 0
}

If you want to apply the second option, please leave a comment I'll change it.

Thank you :)

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 20, 2023
@wilkinsona wilkinsona changed the title Simplify MyHealthMetricsExportConfiguration's private fun getStatusCode() Use more idiomatic Kotlin in example for "Map Health Indicators to Micrometer Metrics" Sep 20, 2023
@wilkinsona wilkinsona added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 20, 2023
@wilkinsona wilkinsona added this to the 2.7.x milestone Sep 20, 2023
@wilkinsona
Copy link
Member

This is great. Thanks very much, @esperar.

@mhalbritter
Copy link
Contributor

Thank you very much and congratulations on your first contribution 🎉!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: documentation A documentation update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants