Created
February 25, 2020 15:01
-
-
Save rnaufal/cfaadb809840c2408297a9c44e948287 to your computer and use it in GitHub Desktop.
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 CharSummaryStatistics { | |
private long totalDigits = 0; | |
private long totalUppercaseChars = 0; | |
private long totalLowercaseChars = 0; | |
private long totalInvalidChars = 0; | |
public CharSummaryStatistics() { | |
} | |
public CharSummaryStatistics(final long totalDigits, | |
final long totalUppercaseChars, | |
final long totalLowercaseChars, | |
final long totalInvalidChars) { | |
this.totalDigits = totalDigits; | |
this.totalUppercaseChars = totalUppercaseChars; | |
this.totalLowercaseChars = totalLowercaseChars; | |
this.totalInvalidChars = totalInvalidChars; | |
} | |
public void accept(final int currentChar) { | |
if (Character.isDigit(currentChar)) { | |
totalDigits += 1; | |
} else if (Character.isUpperCase(currentChar)) { | |
totalUppercaseChars += 1; | |
} else if (Character.isLowerCase(currentChar)) { | |
totalLowercaseChars += 1; | |
} else { | |
totalInvalidChars += 1; | |
} | |
} | |
public void combine(final CharSummaryStatistics other) { | |
this.totalDigits += other.totalDigits; | |
this.totalUppercaseChars += other.totalUppercaseChars; | |
this.totalLowercaseChars += other.totalLowercaseChars; | |
} | |
// getters and setters omitted | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment