Last active
August 7, 2021 05:27
-
-
Save spullara/4532118 to your computer and use it in GitHub Desktop.
Output a star rating using Java backing code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Rated { | |
public Rated(JsonNode node) { | |
starRating = node.get("rating").intValue(); | |
} | |
int starRating; | |
class Star { | |
boolean active; | |
int num; | |
} | |
List<Star> stars() { | |
List<Star> stars = new ArrayList<Star>(); | |
for (int i = 1; i <= 5; i++) { | |
Star star = new Star(); | |
star.active = starRating >= i; | |
star.num = i; | |
stars.add(star); | |
} | |
return stars; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{#stars}} | |
<span class="star {{#active}}activeStar{{/active}}">{{num}}</span> | |
{{/stars}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment