Skip to content

Commit

Permalink
More final
Browse files Browse the repository at this point in the history
  • Loading branch information
travisbrown committed Apr 18, 2020
1 parent dfeaa22 commit d5a9da7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
44 changes: 22 additions & 22 deletions modules/core/src/main/java/org/dhallj/cbor/Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public abstract class Reader {

/** Only allow symbols that correspond to entire encoded Dhall expressions. */
public <R> R nextSymbol(Visitor<R> visitor) {
public final <R> R nextSymbol(Visitor<R> visitor) {
skip55799();
byte b = this.read();
switch (MajorType.fromByte(b)) {
Expand Down Expand Up @@ -43,12 +43,12 @@ public <R> R nextSymbol(Visitor<R> visitor) {

protected abstract byte[] read(int count);

public BigInteger readUnsignedInteger() {
public final BigInteger readUnsignedInteger() {
skip55799();
return readUnsignedInteger(read());
}

public BigInteger readPositiveBigNum() {
public final BigInteger readPositiveBigNum() {
skip55799();
BigInteger result = readBigNum();
if (result.compareTo(BigInteger.ZERO) < 0) {
Expand All @@ -58,7 +58,7 @@ public BigInteger readPositiveBigNum() {
}
}

public BigInteger readBigNum() {
public final BigInteger readBigNum() {
skip55799();
byte next = read();
switch (MajorType.fromByte(next)) {
Expand All @@ -85,7 +85,7 @@ public BigInteger readBigNum() {
}
}

public String readNullableTextString() {
public final String readNullableTextString() {
skip55799();
byte next = read();
switch (MajorType.fromByte(next)) {
Expand All @@ -98,7 +98,7 @@ public String readNullableTextString() {
}
}

public byte[] readNullableByteString() {
public final byte[] readNullableByteString() {
skip55799();
byte next = read();
switch (MajorType.fromByte(next)) {
Expand All @@ -118,7 +118,7 @@ public byte[] readNullableByteString() {
* CBOR representation where we don't know simply from the length of the array and the first
* element what type of expression we're decoding - could be projection or projection by type
*/
public String tryReadTextString() {
public final String tryReadTextString() {
skip55799();
byte next = peek();
switch (MajorType.fromByte(next)) {
Expand All @@ -129,7 +129,7 @@ public String tryReadTextString() {
}
}

public BigInteger readArrayStart() {
public final BigInteger readArrayStart() {
skip55799();
byte next = read();
switch (MajorType.fromByte(next)) {
Expand All @@ -146,14 +146,14 @@ public BigInteger readArrayStart() {
}
}

public <R> Map<String, R> readMap(Visitor<R> visitor) {
public final <R> Map<String, R> readMap(Visitor<R> visitor) {
skip55799();
byte b = this.read();
switch (MajorType.fromByte(b)) {
case MAP:
BigInteger length = readMapStart(b);
Map<String, R> entries = new HashMap<>();
for (int i = 0; i < length.longValue(); i++) {
int length = readMapStart(b).intValue();
Map<String, R> entries = new HashMap<>(length);
for (int i = 0; i < length; i++) {
String key = readNullableTextString();
R value = nextSymbol(visitor);
entries.put(key, value);
Expand All @@ -165,17 +165,17 @@ public <R> Map<String, R> readMap(Visitor<R> visitor) {
}
}

private BigInteger readUnsignedInteger(byte b) {
private final BigInteger readUnsignedInteger(byte b) {
AdditionalInfo info = AdditionalInfo.fromByte(b);
return readBigInteger(info, b);
}

private BigInteger readNegativeInteger(byte b) {
private final BigInteger readNegativeInteger(byte b) {
AdditionalInfo info = AdditionalInfo.fromByte(b);
return BigInteger.valueOf(-1).subtract(readBigInteger(info, b));
}

private byte[] readByteString(byte b) {
private final byte[] readByteString(byte b) {
AdditionalInfo info = AdditionalInfo.fromByte(b);
BigInteger length = readBigInteger(info, b);
if (length.compareTo(BigInteger.ZERO) < 0) {
Expand All @@ -186,7 +186,7 @@ private byte[] readByteString(byte b) {
}
}

private String readTextString(byte b) {
private final String readTextString(byte b) {
AdditionalInfo info = AdditionalInfo.fromByte(b);
BigInteger length = readBigInteger(info, b);
if (length.compareTo(BigInteger.ZERO) < 0) {
Expand All @@ -198,7 +198,7 @@ private String readTextString(byte b) {
}
}

private <R> R readArrayStart(byte b, Visitor<R> visitor) {
private final <R> R readArrayStart(byte b, Visitor<R> visitor) {
AdditionalInfo info = AdditionalInfo.fromByte(b);
BigInteger length = readBigInteger(info, b);
if (length.compareTo(BigInteger.ZERO) < 0) {
Expand All @@ -220,7 +220,7 @@ private <R> R readArrayStart(byte b, Visitor<R> visitor) {
}
}

private BigInteger readMapStart(byte b) {
private final BigInteger readMapStart(byte b) {
AdditionalInfo info = AdditionalInfo.fromByte(b);
BigInteger length = readBigInteger(info, b);
if (length.compareTo(BigInteger.ZERO) < 0) {
Expand All @@ -230,7 +230,7 @@ private BigInteger readMapStart(byte b) {
}
}

private <R> R readPrimitive(byte b, Visitor<R> visitor) {
private final <R> R readPrimitive(byte b, Visitor<R> visitor) {
int value = b & 31;
if (0 <= value && value <= 19) {
throw new CBORException(String.format("Primitive %d is unassigned", value));
Expand Down Expand Up @@ -291,7 +291,7 @@ private <R> R readPrimitive(byte b, Visitor<R> visitor) {
}
}

private void skip55799() {
private final void skip55799() {
byte next = peek();
switch (MajorType.fromByte(next)) {
case SEMANTIC_TAG:
Expand All @@ -312,7 +312,7 @@ private void skip55799() {
}
}

private BigInteger readBigInteger(AdditionalInfo info, byte first) {
private final BigInteger readBigInteger(AdditionalInfo info, byte first) {
switch (info) {
case DIRECT:
return BigInteger.valueOf(first & 31);
Expand All @@ -333,7 +333,7 @@ private BigInteger readBigInteger(AdditionalInfo info, byte first) {
}
}

private BigInteger readBigInteger(long numBytes) {
private final BigInteger readBigInteger(long numBytes) {
BigInteger result = BigInteger.ZERO;
for (long i = 0; i < numBytes; i++) {
int next = this.read() & 0xff;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.dhallj.core.Expr;

public class Decode {
public static Expr decode(byte[] bytes) {
public static final Expr decode(byte[] bytes) {
Reader reader = new Reader.ByteArrayReader(bytes);
// TODO check: if identifier then must be builtin using Expr.Constants.isBuiltInConstant
Expr e = reader.nextSymbol(new CBORDecodingVisitor(reader));
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/main/java/org/dhallj/core/binary/Encode.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ private final int modeLabel(Expr.ImportMode mode) {
}
}

private static byte[] multihash(byte[] hash) {
private static final byte[] multihash(byte[] hash) {
byte[] bytes = new byte[34];
// The label for SHA-256.
bytes[0] = 18;
Expand Down Expand Up @@ -434,7 +434,7 @@ public Void onEnvImport(final String value, final Expr.ImportMode mode, final by
return null;
}

private static int pathLabel(Path path) {
private static final int pathLabel(Path path) {
if (path.isAbsolute()) {
return Label.IMPORT_TYPE_LOCAL_ABSOLUTE;
} else {
Expand Down

0 comments on commit d5a9da7

Please sign in to comment.