Skip to content

Commit f73fecb

Browse files
committed
Tweaks.
1 parent 731f995 commit f73fecb

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

src/main/java/com/stringcompressor/AsciiCompressor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ public AsciiCompressor(byte[] supportedCharset) {
5656

5757
// Protected interface:
5858

59-
protected void standardCharsetValidation(byte[] supportedCharset, int numBits, int maxChars) {
59+
protected void standardCharsetValidation(byte[] supportedCharset, int numBits) {
6060
int len = supportedCharset.length;
61+
int maxChars = (int) Math.pow(2, numBits);
6162

6263
if (len != maxChars)
6364
throw new CharacterNotSupportedException(

src/main/java/com/stringcompressor/FiveBitAsciiCompressor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public final byte[] decompress(final byte[] compressed) {
104104

105105
@Override
106106
protected void validateSupportedCharset(byte[] supportedCharset) {
107-
standardCharsetValidation(supportedCharset, 5, 32);
107+
standardCharsetValidation(supportedCharset, 5);
108108
}
109109

110110
}

src/main/java/com/stringcompressor/FourBitAsciiCompressor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,30 @@ public final byte[] compress(byte[] str) {
6060
*/
6161
@Override
6262
public final byte[] decompress(final byte[] compressed) {
63-
int cLen = compressed.length - 1;
63+
int cLenMinus = compressed.length - 1;
6464

65-
if (cLen <= 0)
65+
if (cLenMinus <= 0)
6666
return new byte[0];
6767

68-
final int odd = compressed[cLen];
69-
final int dLen = odd == 1 ? (--cLen << 1) + 1 : cLen << 1;
68+
final int odd = compressed[cLenMinus];
69+
final int dLen = odd == 1 ? (--cLenMinus << 1) + 1 : cLenMinus << 1;
7070
final byte[] decompressed = new byte[dLen];
7171

72-
for (int i = 0, j = 0; i < cLen; i++) {
72+
for (int i = 0, j = 0; i < cLenMinus; i++) {
7373
final byte bite = compressed[i];
7474
decompressed[j++] = supportedCharset[(bite & 0xF0) >> 4];
7575
decompressed[j++] = supportedCharset[bite & 0x0F];
7676
}
7777

7878
if (odd == 1)
79-
decompressed[dLen - 1] = supportedCharset[compressed[cLen]];
79+
decompressed[dLen - 1] = supportedCharset[compressed[cLenMinus]];
8080

8181
return decompressed;
8282
}
8383

8484
@Override
8585
protected void validateSupportedCharset(byte[] supportedCharset) {
86-
standardCharsetValidation(supportedCharset, 4, 16);
86+
standardCharsetValidation(supportedCharset, 4);
8787
}
8888

8989
}

src/main/java/com/stringcompressor/SixBitAsciiCompressor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public final byte[] decompress(final byte[] compressed) {
112112

113113
@Override
114114
protected void validateSupportedCharset(byte[] supportedCharset) {
115-
standardCharsetValidation(supportedCharset, 6, 64);
115+
standardCharsetValidation(supportedCharset, 6);
116116
}
117117

118118
}

0 commit comments

Comments
 (0)