Skip to content

Commit ef9c426

Browse files
committed
small additions
1 parent 3d8112a commit ef9c426

File tree

13 files changed

+66
-20
lines changed

13 files changed

+66
-20
lines changed

abi-parser-simple/src/main/java/com/openelements/hiero/smartcontract/abi/simple/GsonAbiParser.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public GsonAbiParser() {
1818
this.gson = new GsonBuilder()
1919
.registerTypeAdapterFactory(new AbiTypeAdapterFactory())
2020
.create();
21-
2221
}
2322

2423
public @NonNull AbiModel parse(@NonNull Reader abiReader) throws AbiParserException {

abi-parser-simple/src/main/java/com/openelements/hiero/smartcontract/abi/simple/implementation/AbiEntryTypeAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.ArrayList;
1313
import java.util.Collections;
1414
import java.util.List;
15+
import org.jspecify.annotations.NonNull;
1516

1617
public class AbiEntryTypeAdapter extends BasicTypeAdapter<AbiEntry> {
1718

@@ -20,7 +21,7 @@ public AbiEntryTypeAdapter(Gson gson) {
2021
}
2122

2223
@Override
23-
public AbiEntry read(JsonReader in) throws IOException {
24+
public AbiEntry read(@NonNull final JsonReader in) throws IOException {
2425
final JsonObject abiEntryObject = readObject(in);
2526
final AbiEntryType type = getStringValue(abiEntryObject, "type")
2627
.map(AbiEntryType::of)

abi-parser-simple/src/main/java/com/openelements/hiero/smartcontract/abi/simple/implementation/AbiModelTypeAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public AbiModelTypeAdapter(@NonNull Gson gson) {
1818
}
1919

2020
@Override
21-
public AbiModel read(JsonReader in) throws IOException {
21+
public AbiModel read(@NonNull final JsonReader in) throws IOException {
2222
JsonArray array = readArray(in);
2323
final List<AbiEntry> entries = new ArrayList<>();
2424
array.forEach(jsonElement -> {

abi-parser-simple/src/main/java/com/openelements/hiero/smartcontract/abi/simple/implementation/AbiParameterTypeAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.ArrayList;
1010
import java.util.Collections;
1111
import java.util.List;
12+
import org.jspecify.annotations.NonNull;
1213

1314
public class AbiParameterTypeAdapter extends BasicTypeAdapter<AbiParameter> {
1415

@@ -17,7 +18,7 @@ public AbiParameterTypeAdapter(Gson gson) {
1718
}
1819

1920
@Override
20-
public AbiParameter read(JsonReader in) throws IOException {
21+
public AbiParameter read(@NonNull final JsonReader in) throws IOException {
2122
final JsonObject parameterObject = readObject(in);
2223

2324
final String name = getStringValue(parameterObject, "name")

abi-parser-simple/src/main/java/com/openelements/hiero/smartcontract/abi/simple/implementation/AbiTypeAdapterFactory.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
import com.openelements.hiero.smartcontract.abi.model.AbiEntry;
88
import com.openelements.hiero.smartcontract.abi.model.AbiModel;
99
import com.openelements.hiero.smartcontract.abi.model.AbiParameter;
10+
import java.util.Objects;
11+
import org.jspecify.annotations.NonNull;
1012

1113
public class AbiTypeAdapterFactory implements TypeAdapterFactory {
1214

1315
@Override
14-
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
16+
public <T> TypeAdapter<T> create(@NonNull final Gson gson, @NonNull final TypeToken<T> type) {
17+
Objects.requireNonNull(type, "type must not be null");
1518
if (type.getRawType().equals(AbiModel.class)) {
1619
return (TypeAdapter<T>) new AbiModelTypeAdapter(gson);
1720
}

abi-parser-simple/src/main/java/com/openelements/hiero/smartcontract/abi/simple/implementation/BasicTypeAdapter.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,30 @@ public abstract class BasicTypeAdapter<T> extends TypeAdapter<T> {
2121

2222
private final TypeAdapter<JsonArray> arrayTypeAdapter;
2323

24-
25-
public BasicTypeAdapter(final Gson gson) {
24+
public BasicTypeAdapter(@NonNull final Gson gson) {
2625
this.gson = Objects.requireNonNull(gson, "gson");
2726
objectTypeAdapter = gson.getAdapter(JsonObject.class);
2827
arrayTypeAdapter = gson.getAdapter(JsonArray.class);
2928
}
3029

31-
protected JsonObject readObject(JsonReader in) throws IOException {
30+
protected JsonObject readObject(@NonNull final JsonReader in) throws IOException {
3231
return objectTypeAdapter.read(in);
3332
}
3433

35-
protected JsonArray readArray(JsonReader in) throws IOException {
34+
protected JsonArray readArray(@NonNull final JsonReader in) throws IOException {
3635
return arrayTypeAdapter.read(in);
3736
}
3837

39-
40-
protected <T> T fromJson(JsonElement json, Class<T> classOfT) throws JsonSyntaxException {
38+
protected <T> T fromJson(@NonNull final JsonElement json, @NonNull final Class<T> classOfT) throws JsonSyntaxException {
4139
return gson.fromJson(json, classOfT);
4240
}
4341

44-
42+
@NonNull
4543
protected Gson getGson() {
4644
return gson;
4745
}
4846

47+
@NonNull
4948
protected TypeAdapter<JsonObject> getObjectTypeAdapter() {
5049
return objectTypeAdapter;
5150
}
@@ -55,6 +54,7 @@ public void write(JsonWriter out, T value) throws IOException {
5554
throw new UnsupportedOperationException("Not supported yet.");
5655
}
5756

57+
@NonNull
5858
protected JsonArray getArray(@NonNull final JsonObject jsonObject, @NonNull final String key) {
5959
Objects.requireNonNull(jsonObject, "jsonObject");
6060
Objects.requireNonNull(key, "key");
@@ -69,6 +69,7 @@ protected JsonArray getArray(@NonNull final JsonObject jsonObject, @NonNull fina
6969
return new JsonArray();
7070
}
7171

72+
@NonNull
7273
protected Optional<String> getStringValue(@NonNull final JsonObject jsonObject, @NonNull final String key) {
7374
Objects.requireNonNull(jsonObject, "jsonObject");
7475
Objects.requireNonNull(key, "key");
@@ -82,6 +83,7 @@ protected Optional<String> getStringValue(@NonNull final JsonObject jsonObject,
8283
return Optional.empty();
8384
}
8485

86+
@NonNull
8587
protected Optional<Boolean> getBooleanValue(@NonNull final JsonObject jsonObject, @NonNull final String key) {
8688
Objects.requireNonNull(jsonObject, "jsonObject");
8789
Objects.requireNonNull(key, "key");

abi-parser/src/main/java/com/openelements/hiero/smartcontract/abi/model/AbiFunction.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,5 @@ public record AbiFunction(@NonNull AbiEntryType type, @Nullable String name, @No
3636
Objects.requireNonNull(inputs, "inputs");
3737
Objects.requireNonNull(outputs, "outputs");
3838
Objects.requireNonNull(stateMutability, "stateMutability");
39-
4039
}
4140
}

abi-parser/src/main/java/com/openelements/hiero/smartcontract/abi/model/AbiModel.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,24 @@ public record AbiModel(@NonNull List<AbiEntry> entries) {
1010
Objects.requireNonNull(entries, "entries");
1111
}
1212

13+
@NonNull
1314
public List<AbiFunction> getFunctions() {
1415
return getEntriesOfType(AbiFunction.class);
1516
}
1617

18+
@NonNull
1719
public List<AbiEvent> getEvents() {
1820
return getEntriesOfType(AbiEvent.class);
1921
}
2022

23+
@NonNull
2124
public List<AbiError> getErrors() {
2225
return getEntriesOfType(AbiError.class);
2326
}
2427

25-
private <T extends AbiEntry> List<T> getEntriesOfType(Class<T> type) {
28+
@NonNull
29+
private <T extends AbiEntry> List<T> getEntriesOfType(@NonNull final Class<T> type) {
30+
Objects.requireNonNull(type, "type must not be null");
2631
return entries.stream()
2732
.filter(type::isInstance)
2833
.map(type::cast)

abi-parser/src/main/java/com/openelements/hiero/smartcontract/abi/util/HexConverter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class HexConverter {
1111
@NonNull
1212
public static String bytesToHex(@NonNull final byte[] bytes) {
1313
//see https://stackoverflow.com/questions/9655181/java-convert-a-byte-array-to-a-hex-string
14-
Objects.requireNonNull(bytes, "bytes");
14+
Objects.requireNonNull(bytes, "bytes must not be null");
1515
final byte[] hexChars = new byte[bytes.length * 2];
1616
for (int j = 0; j < bytes.length; j++) {
1717
int v = bytes[j] & 0xFF;
@@ -21,7 +21,9 @@ public static String bytesToHex(@NonNull final byte[] bytes) {
2121
return new String(hexChars, StandardCharsets.UTF_8).toLowerCase();
2222
}
2323

24+
@NonNull
2425
public static byte[] hexToBytes(@NonNull final String hex) {
26+
Objects.requireNonNull(hex, "hex must not be null");
2527
int len = hex.length();
2628
byte[] data = new byte[len / 2];
2729
for (int i = 0; i < len; i += 2) {

abi-parser/src/main/java/com/openelements/hiero/smartcontract/abi/util/KeccakUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package com.openelements.hiero.smartcontract.abi.util;
22

33
import org.bouncycastle.jcajce.provider.digest.Keccak;
4+
import org.jspecify.annotations.NonNull;
45

56
public class KeccakUtil {
67

7-
public static byte[] keccak256(final byte[] data) {
8-
Keccak.DigestKeccak kecc = new Keccak.Digest256();
8+
public static byte[] keccak256(@NonNull final byte[] data) {
9+
final Keccak.DigestKeccak kecc = new Keccak.Digest256();
910
kecc.update(data);
1011
return kecc.digest();
1112
}

0 commit comments

Comments
 (0)