Cosmetic refactor: add final keyword where possible
This commit is contained in:
parent
dd286c6e17
commit
d5e0a8c02d
17 changed files with 58 additions and 62 deletions
|
@ -1,9 +1,9 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public class AnyPointer {
|
public final class AnyPointer {
|
||||||
|
|
||||||
public static class Reader {
|
public final static class Reader {
|
||||||
public PointerReader reader;
|
public final PointerReader reader;
|
||||||
|
|
||||||
public Reader(PointerReader reader) {
|
public Reader(PointerReader reader) {
|
||||||
this.reader = reader;
|
this.reader = reader;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public class DecodeException extends RuntimeException {
|
public final class DecodeException extends RuntimeException {
|
||||||
public DecodeException(String message) {
|
public DecodeException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public class FieldSize {
|
public final class FieldSize {
|
||||||
public static final byte VOID = 0;
|
public static final byte VOID = 0;
|
||||||
public static final byte BIT = 1;
|
public static final byte BIT = 1;
|
||||||
public static final byte BYTE = 2;
|
public static final byte BYTE = 2;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public interface FromStructBuilder<T> {
|
public interface FromStructBuilder<T> {
|
||||||
public abstract T fromStructBuilder(StructBuilder builder);
|
T fromStructBuilder(StructBuilder builder);
|
||||||
public abstract StructSize structSize();
|
StructSize structSize();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public interface FromStructReader<T> {
|
public interface FromStructReader<T> {
|
||||||
public abstract T fromStructReader(StructReader reader);
|
T fromStructReader(StructReader reader);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
|
public final class InputStreamMessageReader {
|
||||||
public class InputStreamMessageReader {
|
|
||||||
|
|
||||||
static byte[] readExact(InputStream is, int length) throws IOException {
|
static byte[] readExact(InputStream is, int length) throws IOException {
|
||||||
byte[] bytes = new byte[length];
|
byte[] bytes = new byte[length];
|
||||||
|
@ -52,7 +51,7 @@ public class InputStreamMessageReader {
|
||||||
|
|
||||||
if (segmentCount > 1) {
|
if (segmentCount > 1) {
|
||||||
ByteBuffer moreSizesRaw = makeByteBuffer(readExact(is, 4 * (segmentCount & ~1)));
|
ByteBuffer moreSizesRaw = makeByteBuffer(readExact(is, 4 * (segmentCount & ~1)));
|
||||||
for(int ii = 0; ii < segmentCount - 1; ++ii) {
|
for (int ii = 0; ii < segmentCount - 1; ++ii) {
|
||||||
int size = moreSizesRaw.getInt(ii * 4);
|
int size = moreSizesRaw.getInt(ii * 4);
|
||||||
moreSizes.add(size);
|
moreSizes.add(size);
|
||||||
totalWords += size;
|
totalWords += size;
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public final class ListBuilder {
|
public final class ListBuilder {
|
||||||
SegmentBuilder segment;
|
final SegmentBuilder segment;
|
||||||
int ptr; // byte offset to front of list
|
final int ptr; // byte offset to front of list
|
||||||
int elementCount;
|
final int elementCount;
|
||||||
int step; // in bits
|
final int step; // in bits
|
||||||
int structDataSize; // in bits
|
final int structDataSize; // in bits
|
||||||
short structPointerCount;
|
final short structPointerCount;
|
||||||
|
|
||||||
public ListBuilder(SegmentBuilder segment, int ptr,
|
public ListBuilder(SegmentBuilder segment, int ptr,
|
||||||
int elementCount, int step,
|
int elementCount, int step,
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public class ListReader {
|
public final class ListReader {
|
||||||
SegmentReader segment;
|
final SegmentReader segment;
|
||||||
int ptr; // byte offset to front of list
|
final int ptr; // byte offset to front of list
|
||||||
int elementCount;
|
final int elementCount;
|
||||||
int step; // in bits
|
final int step; // in bits
|
||||||
int structDataSize; // in bits
|
final int structDataSize; // in bits
|
||||||
short structPointerCount;
|
final short structPointerCount;
|
||||||
int nestingLimit;
|
final int nestingLimit;
|
||||||
|
|
||||||
|
public ListReader() {
|
||||||
public ListReader () {
|
|
||||||
this.segment = null;
|
this.segment = null;
|
||||||
this.ptr = 0;
|
this.ptr = 0;
|
||||||
this.elementCount = 0;
|
this.elementCount = 0;
|
||||||
|
@ -47,6 +46,6 @@ public class ListReader {
|
||||||
int structPointers = structData + (this.structDataSize / 8);
|
int structPointers = structData + (this.structDataSize / 8);
|
||||||
|
|
||||||
return new StructReader(this.segment, structData, structPointers / 8, this.structDataSize,
|
return new StructReader(this.segment, structData, structPointers / 8, this.structDataSize,
|
||||||
this.structPointerCount, (byte)(indexBit % 8), this.nestingLimit - 1);
|
this.structPointerCount, (byte) (indexBit % 8), this.nestingLimit - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@ package org.capnproto;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public class MessageReader {
|
public final class MessageReader {
|
||||||
ByteBuffer[] segmentSlices;
|
final ByteBuffer[] segmentSlices;
|
||||||
|
|
||||||
public MessageReader(ByteBuffer[] segmentSlices) {
|
public MessageReader(ByteBuffer[] segmentSlices) {
|
||||||
this.segmentSlices = segmentSlices;
|
this.segmentSlices = segmentSlices;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public final class PointerBuilder {
|
public final class PointerBuilder {
|
||||||
public SegmentBuilder segment;
|
public final SegmentBuilder segment;
|
||||||
public int pointer; // word offset
|
public final int pointer; // word offset
|
||||||
|
|
||||||
public PointerBuilder(SegmentBuilder segment, int pointer) {
|
public PointerBuilder(SegmentBuilder segment, int pointer) {
|
||||||
this.segment = segment;
|
this.segment = segment;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public class PointerReader {
|
public final class PointerReader {
|
||||||
public SegmentReader segment;
|
public final SegmentReader segment;
|
||||||
public int pointer; // word offset
|
public final int pointer; // word offset
|
||||||
public int nestingLimit;
|
public final int nestingLimit;
|
||||||
|
|
||||||
public PointerReader() {
|
public PointerReader() {
|
||||||
this.segment = null;
|
this.segment = null;
|
||||||
|
|
|
@ -2,11 +2,11 @@ package org.capnproto;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public class SegmentBuilder extends SegmentReader {
|
public final class SegmentBuilder extends SegmentReader {
|
||||||
public int pos = 0; // in words
|
|
||||||
|
|
||||||
public static final int FAILED_ALLOCATION = -1;
|
public static final int FAILED_ALLOCATION = -1;
|
||||||
|
|
||||||
|
public int pos = 0; // in words
|
||||||
|
|
||||||
public SegmentBuilder(ByteBuffer buf) {
|
public SegmentBuilder(ByteBuffer buf) {
|
||||||
super(buf);
|
super(buf);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package org.capnproto;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public class SegmentReader {
|
public class SegmentReader {
|
||||||
ByteBuffer buffer;
|
final ByteBuffer buffer;
|
||||||
|
|
||||||
public SegmentReader(ByteBuffer buffer) {
|
public SegmentReader(ByteBuffer buffer) {
|
||||||
this.buffer = buffer;
|
this.buffer = buffer;
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public final class StructBuilder {
|
public final class StructBuilder {
|
||||||
public SegmentBuilder segment;
|
public final SegmentBuilder segment;
|
||||||
public int data; //byte offset to data section
|
public final int data; //byte offset to data section
|
||||||
public int pointers; // word offset of pointer section
|
public final int pointers; // word offset of pointer section
|
||||||
public int dataSize; // in bits
|
public final int dataSize; // in bits
|
||||||
public short pointerCount;
|
public final short pointerCount;
|
||||||
public byte bit0Offset;
|
public final byte bit0Offset;
|
||||||
|
|
||||||
public StructBuilder(SegmentBuilder segment, int data,
|
public StructBuilder(SegmentBuilder segment, int data,
|
||||||
int pointers, int dataSize, short pointerCount,
|
int pointers, int dataSize, short pointerCount,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
|
|
||||||
public final class StructList {
|
public final class StructList {
|
||||||
public static final class Reader<T> {
|
public static final class Reader<T> {
|
||||||
public ListReader reader;
|
public ListReader reader;
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public final class StructReader {
|
public final class StructReader {
|
||||||
public SegmentReader segment;
|
public final SegmentReader segment;
|
||||||
public int data; //byte offset to data section
|
public final int data; //byte offset to data section
|
||||||
public int pointers; // word offset of pointer section
|
public final int pointers; // word offset of pointer section
|
||||||
public int dataSize; // in bits
|
public final int dataSize; // in bits
|
||||||
public short pointerCount;
|
public final short pointerCount;
|
||||||
public byte bit0Offset;
|
public final byte bit0Offset;
|
||||||
public int nestingLimit;
|
public final int nestingLimit;
|
||||||
|
|
||||||
|
|
||||||
public StructReader(SegmentReader segment, int data,
|
public StructReader(SegmentReader segment, int data,
|
||||||
int pointers, int dataSize, short pointerCount,
|
int pointers, int dataSize, short pointerCount,
|
||||||
|
|
|
@ -2,7 +2,7 @@ package org.capnproto;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public class Text {
|
public final class Text {
|
||||||
|
|
||||||
public static final class Reader {
|
public static final class Reader {
|
||||||
public final ByteBuffer buffer;
|
public final ByteBuffer buffer;
|
||||||
|
@ -35,7 +35,7 @@ public class Text {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new String(bytes, "UTF-8");
|
return new String(bytes, "UTF-8");
|
||||||
} catch(java.io.UnsupportedEncodingException e) {
|
} catch (java.io.UnsupportedEncodingException e) {
|
||||||
return "unsupported encoding"; // XXX
|
return "unsupported encoding"; // XXX
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue