Skip to content

Commit 4eb6216

Browse files
authored
Merge pull request #62 from sebthom/updates
minor code cleanup
2 parents 14b093e + 076fff9 commit 4eb6216

32 files changed

+75
-31
lines changed

src/org/jcodings/MultiByteEncoding.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ protected final boolean mb4IsCodeCType(int code, int ctype) {
201201
}
202202

203203
/* onigenc_strlen */
204+
@Override
204205
public int strLength(byte[]bytes, int p, int end) {
205206
int n = 0;
206207
int q = p;
@@ -211,6 +212,7 @@ public int strLength(byte[]bytes, int p, int end) {
211212
return n;
212213
}
213214

215+
@Override
214216
public int strCodeAt(byte[]bytes, int p, int end, int index) {
215217
int n = 0;
216218
int q = p;

src/org/jcodings/exception/CharacterPropertyException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121

2222
public class CharacterPropertyException extends EncodingException {
2323

24-
public CharacterPropertyException(EncodingError error) {
24+
private static final long serialVersionUID = 1L;
25+
26+
public CharacterPropertyException(EncodingError error) {
2527
super(error);
2628
}
2729

src/org/jcodings/exception/EncodingException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
package org.jcodings.exception;
2121

2222
public class EncodingException extends JCodingsException {
23+
24+
private static final long serialVersionUID = 1L;
25+
2326
private final EncodingError error;
2427

2528
public EncodingException(EncodingError error) {

src/org/jcodings/exception/JCodingsException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
package org.jcodings.exception;
2121

2222
public class JCodingsException extends RuntimeException {
23+
24+
private static final long serialVersionUID = 1L;
25+
2326
public JCodingsException(String message) {
2427
super(message);
2528
}

src/org/jcodings/exception/TranscoderException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
package org.jcodings.exception;
2121

2222
public class TranscoderException extends JCodingsException {
23+
24+
private static final long serialVersionUID = 1L;
25+
2326
public TranscoderException(String message) {
2427
super(message);
2528
}

src/org/jcodings/specific/BaseEUCJPEncoding.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public int mbcCaseFold(int flag, byte[]bytes, IntHolder pp, int end, byte[]lower
9292
}
9393
}
9494

95+
@Override
9596
protected boolean isLead(int c) {
9697
return ((c - 0xa1) & 0xff) > 0xfe - 0xa1;
9798
}

src/org/jcodings/specific/EUCKREncoding.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public boolean isCodeCType(int code, int ctype) {
6969
}
7070

7171
// euckr_islead
72+
@Override
7273
protected boolean isLead(int c) {
7374
return ((c) < 0xa1 || (c) == 0xff);
7475
}

src/org/jcodings/specific/EmacsMuleEncoding.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public int leftAdjustCharHead(byte[] bytes, int p, int s, int end) {
9999
int p_ = s;
100100
while (!islead(bytes[p_] & 0xff) && p_ > p) p_--;
101101
return p_;
102-
};
102+
}
103103

104104
@Override
105105
public boolean isReverseMatchAllowed(byte[]bytes, int p, int end) {

src/org/jcodings/specific/GB18030Encoding.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private enum State {
120120
Odd_CM_Odd_C4CM,
121121
Even_CM_Even_C4CM,
122122
Odd_CM_Even_C4CM
123-
};
123+
}
124124

125125
@Override
126126
public int leftAdjustCharHead(byte[]bytes, int start, int s, int end) {

src/org/jcodings/specific/Windows_1251Encoding.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import org.jcodings.CaseFoldMapEncoding;
2323
import org.jcodings.Config;
24-
import org.jcodings.ISOEncoding;
2524
import org.jcodings.IntHolder;
2625
import org.jcodings.constants.CharacterType;
2726

src/org/jcodings/spi/Charsets.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
*/
1111
public class Charsets extends java.nio.charset.spi.CharsetProvider {
1212
private static final List<Charset> charsets = Collections.singletonList((Charset) ISO_8859_16.INSTANCE);
13+
14+
@Override
1315
public Iterator<Charset> charsets() {
1416
return charsets.iterator();
1517
}
1618

19+
@Override
1720
public Charset charsetForName(String charsetName) {
1821
if ("ISO-8859-16".equals(charsetName) || ISO_8859_16.INSTANCE.aliases().contains(charsetName)) {
1922
return ISO_8859_16.INSTANCE;

src/org/jcodings/transcode/EConv.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,6 @@ public boolean equals(Object other) {
851851
EConv ec2 = (EConv)other;
852852
int i;
853853

854-
if (ec2 == null) return false;
855854
if (ec1.source != ec2.source &&
856855
!Arrays.equals(ec1.source, ec2.source))
857856
return false;

src/org/jcodings/transcode/TranscoderDB.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ private static EConv open0(byte[] source, byte[] destination, int ecflags) {
219219
numTrans = searchPath(source, destination, new SearchPathCallback() {
220220
int additional = 0;
221221

222+
@Override
222223
public void call(byte[] source, byte[] destination, int depth) {
223224
if (lentries.p == null) lentries.p = new Entry[depth + 1 + additional];
224225
lentries.p[depth] = getEntry(source, destination);

src/org/jcodings/transcode/TranscoderList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static void load() {
223223
TranscoderDB.declare("UTF-32", "UTF-8", "From_UTF_32");
224224
TranscoderDB.declare("UTF-8", "UTF-16", "To_UTF_16");
225225
TranscoderDB.declare("UTF-8", "UTF-32", "To_UTF_32");
226-
};
226+
}
227227

228228
static final GenericTranscoderEntry[] GENERIC_LIST = new GenericTranscoderEntry[] {
229229
new GenericTranscoderEntry("Big5", "UTF-8", 57100, "Big5", 1, 2, 1, AsciiCompatibility.CONVERTER, 0),

src/org/jcodings/transcode/specific/Cp50220_decoder_Transcoder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public int stateFinish(byte[] state) {
4040
return TranscodeFunctions.iso2022jpInit(state);
4141
}
4242

43+
@Override
4344
public int startToInfo(byte[] statep, byte[] s, int sStart, int l) {
4445
return TranscodeFunctions.funSiCp50221Decoder(statep, s, sStart, l);
4546
}

src/org/jcodings/transcode/specific/Cp50221_decoder_Transcoder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public int stateFinish(byte[] state) {
4040
return TranscodeFunctions.iso2022jpInit(state);
4141
}
4242

43+
@Override
4344
public int startToInfo(byte[] statep, byte[] s, int sStart, int l) {
4445
return TranscodeFunctions.funSiCp50221Decoder(statep, s, sStart, l);
4546
}

src/org/jcodings/transcode/specific/Iso2022jp_decoder_Transcoder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public int stateFinish(byte[] state) {
4040
return TranscodeFunctions.iso2022jpInit(state);
4141
}
4242

43+
@Override
4344
public int startToInfo(byte[] statep, byte[] s, int sStart, int l) {
4445
return TranscodeFunctions.funSiIso50220jpDecoder(statep, s, sStart, l);
4546
}

src/org/jcodings/transcode/specific/Iso2022jp_kddi_decoder_Transcoder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public int stateFinish(byte[] state) {
4040
return TranscodeFunctions.iso2022jpKddiInit(state);
4141
}
4242

43+
@Override
4344
public int startToInfo(byte[] statep, byte[] s, int sStart, int l) {
4445
return TranscodeFunctions.funSiIso2022jpKddiDecoder(statep, s, sStart, l);
4546
}

src/org/jcodings/util/ArrayReader.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,17 @@ public static byte[] readByteArray(String name) {
4444
bytes[i] = dis.readByte();
4545
}
4646
checkAvailable(dis, name);
47-
dis.close();
4847
return bytes;
4948
} catch (IOException ioe) {
5049
decorate(ioe, name);
51-
return null;
50+
} finally {
51+
try {
52+
dis.close();
53+
} catch (IOException ex) {
54+
// ignore
55+
}
5256
}
57+
return null;
5358
}
5459

5560
public static int[] readIntArray(String name) {
@@ -61,12 +66,17 @@ public static int[] readIntArray(String name) {
6166
ints[i] = dis.readInt();
6267
}
6368
checkAvailable(dis, name);
64-
dis.close();
6569
return ints;
6670
} catch (IOException ioe) {
6771
decorate(ioe, name);
68-
return null;
69-
}
72+
} finally {
73+
try {
74+
dis.close();
75+
} catch (IOException ex) {
76+
// ignore
77+
}
78+
}
79+
return null;
7080
}
7181

7282
public static int[][] readNestedIntArray(String name) {
@@ -82,14 +92,18 @@ public static int[][] readNestedIntArray(String name) {
8292
iints[k] = dis.readInt();
8393
}
8494
}
85-
8695
checkAvailable(dis, name);
87-
dis.close();
8896
return ints;
8997
} catch (IOException ioe) {
9098
decorate(ioe, name);
91-
return null;
99+
} finally {
100+
try {
101+
dis.close();
102+
} catch (IOException ex) {
103+
// ignore
104+
}
92105
}
106+
return null;
93107
}
94108

95109
static void checkAvailable(DataInputStream dis, String name) throws IOException {

src/org/jcodings/util/BytesHash.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public BytesHash(int size) {
2929
super(size);
3030
}
3131

32+
@Override
3233
protected void init() {
3334
head = new BytesHashEntry<V>();
3435
}
@@ -62,7 +63,7 @@ public boolean equals(byte[]bytes, int p, int end) {
6263

6364
public static int hashCode(byte[]bytes, int p, int end) {
6465
int key = 0;
65-
while (p < end) key = ((key << 16) + (key << 6) - key) + (int)(bytes[p++]); // & 0xff ? we have to match jruby string hash
66+
while (p < end) key = ((key << 16) + (key << 6) - key) + bytes[p++]; // & 0xff ? we have to match jruby string hash
6667
key = key + (key >> 5);
6768
return key;
6869
}

src/org/jcodings/util/CaseInsensitiveBytesHash.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public CaseInsensitiveBytesHash(int size) {
3131
super(size);
3232
}
3333

34+
@Override
3435
protected void init() {
3536
head = new CaseInsensitiveBytesHashEntry<V>();
3637
}
@@ -60,7 +61,7 @@ public boolean equals(byte[]bytes, int p, int end) {
6061

6162
public static int hashCode(byte[]bytes, int p, int end) {
6263
int key = 0;
63-
while (p < end) key = ((key << 16) + (key << 6) - key) + (int)(ToLowerCaseTable[bytes[p++] & 0xff]); // & 0xff ? we have to match jruby string hash
64+
while (p < end) key = ((key << 16) + (key << 6) - key) + ToLowerCaseTable[bytes[p++] & 0xff]; // & 0xff ? we have to match jruby string hash
6465
key = key + (key >> 5);
6566
return key;
6667
}

src/org/jcodings/util/Hash.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ protected static int hashValue(int h) {
133133
return h & HASH_SIGN_BIT_MASK;
134134
}
135135

136+
@Override
136137
public Iterator<V> iterator() {
137138
return new HashIterator();
138139
}
@@ -144,16 +145,19 @@ public HashIterator() {
144145
next = head.after;
145146
}
146147

148+
@Override
147149
public boolean hasNext() {
148150
return next != head;
149151
}
150152

153+
@Override
151154
public V next() {
152155
HashEntry<V> e = next;
153156
next = e.after;
154157
return e.value;
155158
}
156159

160+
@Override
157161
public void remove() {
158162
throw new InternalException("not supported operation exception");
159163
}
@@ -170,20 +174,24 @@ public HashEntryIterator() {
170174
next = head.after;
171175
}
172176

177+
@Override
173178
public Iterator<HashEntry<V>> iterator() {
174179
return this;
175180
}
176181

182+
@Override
177183
public boolean hasNext() {
178184
return next != head;
179185
}
180186

187+
@Override
181188
public HashEntry<V> next() {
182189
HashEntry<V> e = next;
183190
next = e.after;
184191
return e;
185192
}
186193

194+
@Override
187195
public void remove() {
188196
throw new InternalException("not supported operation exception");
189197
}

src/org/jcodings/util/IntArrayHash.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public IntArrayHash(int size) {
2929
super(size);
3030
}
3131

32+
@Override
3233
protected void init() {
3334
head = new IntArrayHashEntry<V>();
3435
}

src/org/jcodings/util/IntHash.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public IntHash(int size) {
2929
super(size);
3030
}
3131

32+
@Override
3233
protected void init() {
3334
head = new IntHashEntry<V>();
3435
}

src/org/jcodings/util/ObjHash.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
public final class ObjHash<K, V> extends Hash<V> {
2323

24+
@Override
2425
protected void init() {
2526
head = new ObjHashEntry<K, V>();
2627
}
@@ -38,6 +39,7 @@ public ObjHashEntry() {
3839
key = null;
3940
}
4041

42+
@Override
4143
public boolean equals(Object key) {
4244
if (this.key == key) return true;
4345
return this.key.equals(key);

test/org/jcodings/specific/TestBig5.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import java.nio.charset.Charset;
77

8-
import org.jcodings.specific.BIG5Encoding;
98
import org.junit.Test;
109

1110
public class TestBig5 {

test/org/jcodings/specific/TestCESU8.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package org.jcodings.specific;
22

3-
import static junit.framework.Assert.assertEquals;
4-
import static junit.framework.Assert.assertTrue;
3+
import static org.junit.Assert.assertEquals;
54

65
import org.jcodings.Encoding;
7-
import org.jcodings.constants.CharacterType;
8-
import java.nio.charset.StandardCharsets;
96
import org.junit.Test;
107

118
public class TestCESU8 {

test/org/jcodings/specific/TestCaseMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.jcodings.specific;
22

3-
import static junit.framework.Assert.assertTrue;
3+
import static org.junit.Assert.assertTrue;
44

55
import java.util.Arrays;
66
import java.util.List;

0 commit comments

Comments
 (0)