Skip to content

minor code cleanup #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/org/jcodings/MultiByteEncoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ protected final boolean mb4IsCodeCType(int code, int ctype) {
}

/* onigenc_strlen */
@Override
public int strLength(byte[]bytes, int p, int end) {
int n = 0;
int q = p;
Expand All @@ -211,6 +212,7 @@ public int strLength(byte[]bytes, int p, int end) {
return n;
}

@Override
public int strCodeAt(byte[]bytes, int p, int end, int index) {
int n = 0;
int q = p;
Expand Down
4 changes: 3 additions & 1 deletion src/org/jcodings/exception/CharacterPropertyException.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

public class CharacterPropertyException extends EncodingException {

public CharacterPropertyException(EncodingError error) {
private static final long serialVersionUID = 1L;

public CharacterPropertyException(EncodingError error) {
super(error);
}

Expand Down
3 changes: 3 additions & 0 deletions src/org/jcodings/exception/EncodingException.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
package org.jcodings.exception;

public class EncodingException extends JCodingsException {

private static final long serialVersionUID = 1L;

private final EncodingError error;

public EncodingException(EncodingError error) {
Expand Down
3 changes: 3 additions & 0 deletions src/org/jcodings/exception/JCodingsException.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
package org.jcodings.exception;

public class JCodingsException extends RuntimeException {

private static final long serialVersionUID = 1L;

public JCodingsException(String message) {
super(message);
}
Expand Down
3 changes: 3 additions & 0 deletions src/org/jcodings/exception/TranscoderException.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
package org.jcodings.exception;

public class TranscoderException extends JCodingsException {

private static final long serialVersionUID = 1L;

public TranscoderException(String message) {
super(message);
}
Expand Down
1 change: 1 addition & 0 deletions src/org/jcodings/specific/BaseEUCJPEncoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public int mbcCaseFold(int flag, byte[]bytes, IntHolder pp, int end, byte[]lower
}
}

@Override
protected boolean isLead(int c) {
return ((c - 0xa1) & 0xff) > 0xfe - 0xa1;
}
Expand Down
1 change: 1 addition & 0 deletions src/org/jcodings/specific/EUCKREncoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public boolean isCodeCType(int code, int ctype) {
}

// euckr_islead
@Override
protected boolean isLead(int c) {
return ((c) < 0xa1 || (c) == 0xff);
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/jcodings/specific/EmacsMuleEncoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public int leftAdjustCharHead(byte[] bytes, int p, int s, int end) {
int p_ = s;
while (!islead(bytes[p_] & 0xff) && p_ > p) p_--;
return p_;
};
}

@Override
public boolean isReverseMatchAllowed(byte[]bytes, int p, int end) {
Expand Down
2 changes: 1 addition & 1 deletion src/org/jcodings/specific/GB18030Encoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private enum State {
Odd_CM_Odd_C4CM,
Even_CM_Even_C4CM,
Odd_CM_Even_C4CM
};
}

@Override
public int leftAdjustCharHead(byte[]bytes, int start, int s, int end) {
Expand Down
1 change: 0 additions & 1 deletion src/org/jcodings/specific/Windows_1251Encoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.jcodings.CaseFoldMapEncoding;
import org.jcodings.Config;
import org.jcodings.ISOEncoding;
import org.jcodings.IntHolder;
import org.jcodings.constants.CharacterType;

Expand Down
3 changes: 3 additions & 0 deletions src/org/jcodings/spi/Charsets.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
*/
public class Charsets extends java.nio.charset.spi.CharsetProvider {
private static final List<Charset> charsets = Collections.singletonList((Charset) ISO_8859_16.INSTANCE);

@Override
public Iterator<Charset> charsets() {
return charsets.iterator();
}

@Override
public Charset charsetForName(String charsetName) {
if ("ISO-8859-16".equals(charsetName) || ISO_8859_16.INSTANCE.aliases().contains(charsetName)) {
return ISO_8859_16.INSTANCE;
Expand Down
1 change: 0 additions & 1 deletion src/org/jcodings/transcode/EConv.java
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,6 @@ public boolean equals(Object other) {
EConv ec2 = (EConv)other;
int i;

if (ec2 == null) return false;
if (ec1.source != ec2.source &&
!Arrays.equals(ec1.source, ec2.source))
return false;
Expand Down
1 change: 1 addition & 0 deletions src/org/jcodings/transcode/TranscoderDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ private static EConv open0(byte[] source, byte[] destination, int ecflags) {
numTrans = searchPath(source, destination, new SearchPathCallback() {
int additional = 0;

@Override
public void call(byte[] source, byte[] destination, int depth) {
if (lentries.p == null) lentries.p = new Entry[depth + 1 + additional];
lentries.p[depth] = getEntry(source, destination);
Expand Down
2 changes: 1 addition & 1 deletion src/org/jcodings/transcode/TranscoderList.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static void load() {
TranscoderDB.declare("UTF-32", "UTF-8", "From_UTF_32");
TranscoderDB.declare("UTF-8", "UTF-16", "To_UTF_16");
TranscoderDB.declare("UTF-8", "UTF-32", "To_UTF_32");
};
}

static final GenericTranscoderEntry[] GENERIC_LIST = new GenericTranscoderEntry[] {
new GenericTranscoderEntry("Big5", "UTF-8", 57100, "Big5", 1, 2, 1, AsciiCompatibility.CONVERTER, 0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public int stateFinish(byte[] state) {
return TranscodeFunctions.iso2022jpInit(state);
}

@Override
public int startToInfo(byte[] statep, byte[] s, int sStart, int l) {
return TranscodeFunctions.funSiCp50221Decoder(statep, s, sStart, l);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public int stateFinish(byte[] state) {
return TranscodeFunctions.iso2022jpInit(state);
}

@Override
public int startToInfo(byte[] statep, byte[] s, int sStart, int l) {
return TranscodeFunctions.funSiCp50221Decoder(statep, s, sStart, l);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public int stateFinish(byte[] state) {
return TranscodeFunctions.iso2022jpInit(state);
}

@Override
public int startToInfo(byte[] statep, byte[] s, int sStart, int l) {
return TranscodeFunctions.funSiIso50220jpDecoder(statep, s, sStart, l);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public int stateFinish(byte[] state) {
return TranscodeFunctions.iso2022jpKddiInit(state);
}

@Override
public int startToInfo(byte[] statep, byte[] s, int sStart, int l) {
return TranscodeFunctions.funSiIso2022jpKddiDecoder(statep, s, sStart, l);
}
Expand Down
30 changes: 22 additions & 8 deletions src/org/jcodings/util/ArrayReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,17 @@ public static byte[] readByteArray(String name) {
bytes[i] = dis.readByte();
}
checkAvailable(dis, name);
dis.close();
return bytes;
} catch (IOException ioe) {
decorate(ioe, name);
return null;
} finally {
try {
dis.close();
} catch (IOException ex) {
// ignore
}
}
return null;
}

public static int[] readIntArray(String name) {
Expand All @@ -61,12 +66,17 @@ public static int[] readIntArray(String name) {
ints[i] = dis.readInt();
}
checkAvailable(dis, name);
dis.close();
return ints;
} catch (IOException ioe) {
decorate(ioe, name);
return null;
}
} finally {
try {
dis.close();
} catch (IOException ex) {
// ignore
}
}
return null;
}

public static int[][] readNestedIntArray(String name) {
Expand All @@ -82,14 +92,18 @@ public static int[][] readNestedIntArray(String name) {
iints[k] = dis.readInt();
}
}

checkAvailable(dis, name);
dis.close();
return ints;
} catch (IOException ioe) {
decorate(ioe, name);
return null;
} finally {
try {
dis.close();
} catch (IOException ex) {
// ignore
}
}
return null;
}

static void checkAvailable(DataInputStream dis, String name) throws IOException {
Expand Down
3 changes: 2 additions & 1 deletion src/org/jcodings/util/BytesHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public BytesHash(int size) {
super(size);
}

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

public static int hashCode(byte[]bytes, int p, int end) {
int key = 0;
while (p < end) key = ((key << 16) + (key << 6) - key) + (int)(bytes[p++]); // & 0xff ? we have to match jruby string hash
while (p < end) key = ((key << 16) + (key << 6) - key) + bytes[p++]; // & 0xff ? we have to match jruby string hash
key = key + (key >> 5);
return key;
}
Expand Down
3 changes: 2 additions & 1 deletion src/org/jcodings/util/CaseInsensitiveBytesHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public CaseInsensitiveBytesHash(int size) {
super(size);
}

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

public static int hashCode(byte[]bytes, int p, int end) {
int key = 0;
while (p < end) key = ((key << 16) + (key << 6) - key) + (int)(ToLowerCaseTable[bytes[p++] & 0xff]); // & 0xff ? we have to match jruby string hash
while (p < end) key = ((key << 16) + (key << 6) - key) + ToLowerCaseTable[bytes[p++] & 0xff]; // & 0xff ? we have to match jruby string hash
key = key + (key >> 5);
return key;
}
Expand Down
8 changes: 8 additions & 0 deletions src/org/jcodings/util/Hash.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ protected static int hashValue(int h) {
return h & HASH_SIGN_BIT_MASK;
}

@Override
public Iterator<V> iterator() {
return new HashIterator();
}
Expand All @@ -144,16 +145,19 @@ public HashIterator() {
next = head.after;
}

@Override
public boolean hasNext() {
return next != head;
}

@Override
public V next() {
HashEntry<V> e = next;
next = e.after;
return e.value;
}

@Override
public void remove() {
throw new InternalException("not supported operation exception");
}
Expand All @@ -170,20 +174,24 @@ public HashEntryIterator() {
next = head.after;
}

@Override
public Iterator<HashEntry<V>> iterator() {
return this;
}

@Override
public boolean hasNext() {
return next != head;
}

@Override
public HashEntry<V> next() {
HashEntry<V> e = next;
next = e.after;
return e;
}

@Override
public void remove() {
throw new InternalException("not supported operation exception");
}
Expand Down
1 change: 1 addition & 0 deletions src/org/jcodings/util/IntArrayHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public IntArrayHash(int size) {
super(size);
}

@Override
protected void init() {
head = new IntArrayHashEntry<V>();
}
Expand Down
1 change: 1 addition & 0 deletions src/org/jcodings/util/IntHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public IntHash(int size) {
super(size);
}

@Override
protected void init() {
head = new IntHashEntry<V>();
}
Expand Down
2 changes: 2 additions & 0 deletions src/org/jcodings/util/ObjHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

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

@Override
protected void init() {
head = new ObjHashEntry<K, V>();
}
Expand All @@ -38,6 +39,7 @@ public ObjHashEntry() {
key = null;
}

@Override
public boolean equals(Object key) {
if (this.key == key) return true;
return this.key.equals(key);
Expand Down
1 change: 0 additions & 1 deletion test/org/jcodings/specific/TestBig5.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import java.nio.charset.Charset;

import org.jcodings.specific.BIG5Encoding;
import org.junit.Test;

public class TestBig5 {
Expand Down
5 changes: 1 addition & 4 deletions test/org/jcodings/specific/TestCESU8.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package org.jcodings.specific;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;

import org.jcodings.Encoding;
import org.jcodings.constants.CharacterType;
import java.nio.charset.StandardCharsets;
import org.junit.Test;

public class TestCESU8 {
Expand Down
2 changes: 1 addition & 1 deletion test/org/jcodings/specific/TestCaseMap.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jcodings.specific;

import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertTrue;

import java.util.Arrays;
import java.util.List;
Expand Down
Loading