First commit

master
Andrea Cavalli 1 year ago
commit e57088c0dd
  1. 50
      .github/workflows/maven-publish.yml
  2. 2
      .gitignore
  3. 3
      README.md
  4. 116
      pom.xml
  5. 13
      src/main/java/it/cavallium/data/generator/CommonField.java
  6. 9
      src/main/java/it/cavallium/data/generator/DataInitializer.java
  7. 13
      src/main/java/it/cavallium/data/generator/DataSerializer.java
  8. 9
      src/main/java/it/cavallium/data/generator/DataUpgrader.java
  9. 50
      src/main/java/it/cavallium/data/generator/Nullable.java
  10. 29
      src/main/java/it/cavallium/data/generator/nativedata/ArrayInt52Serializer.java
  11. 29
      src/main/java/it/cavallium/data/generator/nativedata/ArrayStringSerializer.java
  12. 29
      src/main/java/it/cavallium/data/generator/nativedata/ArraybooleanSerializer.java
  13. 29
      src/main/java/it/cavallium/data/generator/nativedata/ArraybyteSerializer.java
  14. 29
      src/main/java/it/cavallium/data/generator/nativedata/ArraycharSerializer.java
  15. 29
      src/main/java/it/cavallium/data/generator/nativedata/ArraydoubleSerializer.java
  16. 29
      src/main/java/it/cavallium/data/generator/nativedata/ArrayfloatSerializer.java
  17. 29
      src/main/java/it/cavallium/data/generator/nativedata/ArrayintSerializer.java
  18. 29
      src/main/java/it/cavallium/data/generator/nativedata/ArraylongSerializer.java
  19. 29
      src/main/java/it/cavallium/data/generator/nativedata/ArrayshortSerializer.java
  20. 5
      src/main/java/it/cavallium/data/generator/nativedata/IGenericNullable.java
  21. 90
      src/main/java/it/cavallium/data/generator/nativedata/Int52.java
  22. 67
      src/main/java/it/cavallium/data/generator/nativedata/Int52Serializer.java
  23. 102
      src/main/java/it/cavallium/data/generator/nativedata/NullableInt52.java
  24. 37
      src/main/java/it/cavallium/data/generator/nativedata/NullableInt52Serializer.java
  25. 117
      src/main/java/it/cavallium/data/generator/nativedata/NullableString.java
  26. 34
      src/main/java/it/cavallium/data/generator/nativedata/NullableStringSerializer.java
  27. 101
      src/main/java/it/cavallium/data/generator/nativedata/Nullableboolean.java
  28. 34
      src/main/java/it/cavallium/data/generator/nativedata/NullablebooleanSerializer.java
  29. 100
      src/main/java/it/cavallium/data/generator/nativedata/Nullablebyte.java
  30. 34
      src/main/java/it/cavallium/data/generator/nativedata/NullablebyteSerializer.java
  31. 100
      src/main/java/it/cavallium/data/generator/nativedata/Nullablechar.java
  32. 34
      src/main/java/it/cavallium/data/generator/nativedata/NullablecharSerializer.java
  33. 100
      src/main/java/it/cavallium/data/generator/nativedata/Nullabledouble.java
  34. 34
      src/main/java/it/cavallium/data/generator/nativedata/NullabledoubleSerializer.java
  35. 100
      src/main/java/it/cavallium/data/generator/nativedata/Nullablefloat.java
  36. 34
      src/main/java/it/cavallium/data/generator/nativedata/NullablefloatSerializer.java
  37. 100
      src/main/java/it/cavallium/data/generator/nativedata/Nullableint.java
  38. 34
      src/main/java/it/cavallium/data/generator/nativedata/NullableintSerializer.java
  39. 100
      src/main/java/it/cavallium/data/generator/nativedata/Nullablelong.java
  40. 34
      src/main/java/it/cavallium/data/generator/nativedata/NullablelongSerializer.java
  41. 100
      src/main/java/it/cavallium/data/generator/nativedata/Nullableshort.java
  42. 34
      src/main/java/it/cavallium/data/generator/nativedata/NullableshortSerializer.java
  43. 28
      src/main/java/it/cavallium/data/generator/nativedata/StringSerializer.java
  44. 69
      src/test/java/it/cavallium/data/generator/nativedata/TestInt52Serializer.java

@ -0,0 +1,50 @@
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java#apache-maven-with-a-settings-path
name: Maven Package
on:
push:
pull_request:
schedule:
- cron: '0 0 * * 0' # weekly
jobs:
build:
strategy:
matrix:
include:
- { os: ubuntu-20.04, arch: "linux/amd64" }
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
with:
submodules: "recursive"
- name: Setup variables
shell: bash
run: |
# ====== Variables
export REVISION=${{ github.run_number }}
echo "REVISION=$REVISION" >> $GITHUB_ENV
- name: Set up JDK 16
if: github.ref == 'refs/heads/master'
uses: actions/setup-java@v1
with:
java-version: 16
server-id: mchv-release-distribution
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
env:
MAVEN_USERNAME: ${{ secrets.MCHV_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MCHV_TOKEN }}
- name: Deploy to Maven (Release)
if: github.ref == 'refs/heads/master'
shell: bash
run: |
echo "REVISION: $REVISION"
mvn -B -Drevision=${REVISION} clean deploy
env:
MAVEN_USERNAME: ${{ secrets.MCHV_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MCHV_TOKEN }}

2
.gitignore vendored

@ -0,0 +1,2 @@
/target/
*.iml

@ -0,0 +1,3 @@
Data generator runtime
======================
Dependency of data-generator

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>Data generator runtime</name>
<groupId>it.cavallium</groupId>
<artifactId>data-generator-runtime</artifactId>
<version>1.0.${revision}</version>
<packaging>jar</packaging>
<properties>
<revision>0-SNAPSHOT</revision>
</properties>
<repositories>
<repository>
<id>mchv-release</id>
<name>MCHV Release Apache Maven Packages</name>
<url>https://mvn.mchv.eu/repository/mchv</url>
</repository>
<repository>
<id>mchv-snapshot</id>
<name>MCHV Snapshot Apache Maven Packages</name>
<url>https://mvn.mchv.eu/repository/mchv-snapshot</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>mchv-release-distribution</id>
<name>MCHV Release Apache Maven Packages Distribution</name>
<url>https://mvn.mchv.eu/repository/mchv</url>
</repository>
<snapshotRepository>
<id>mchv-snapshot-distribution</id>
<name>MCHV Snapshot Apache Maven Packages Distribution</name>
<url>https://mvn.mchv.eu/repository/mchv-snapshot</url>
</snapshotRepository>
</distributionManagement>
<scm>
<connection>scm:git:https://git.ignuranza.net/andreacavalli/data-generator-runtime.git</connection>
<developerConnection>scm:git:https://git.ignuranza.net/andreacavalli/data-generator-runtime.git</developerConnection>
<tag>HEAD</tag>
</scm>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.0-M1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>16</release>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
</dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>20.1.0</version>
</dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
<version>8.5.4</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.0-M1</version>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
</project>

@ -0,0 +1,13 @@
package it.cavallium.data.generator;
public class CommonField {
public final String fieldName;
public final String fieldType;
public final boolean hasSetter;
public CommonField(String fieldName, String fieldType, boolean hasSetter) {
this.fieldName = fieldName;
this.fieldType = fieldType;
this.hasSetter = hasSetter;
}
}

@ -0,0 +1,9 @@
package it.cavallium.data.generator;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public interface DataInitializer<T> {
@NotNull T initialize() throws IOException;
}

@ -0,0 +1,13 @@
package it.cavallium.data.generator;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public interface DataSerializer<T> {
void serialize(DataOutput dataOutput, @NotNull T data) throws IOException;
@NotNull T deserialize(DataInput dataInput) throws IOException;
}

@ -0,0 +1,9 @@
package it.cavallium.data.generator;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public interface DataUpgrader<T, U> {
@NotNull U upgrade(@NotNull T data) throws IOException;
}

@ -0,0 +1,50 @@
package it.cavallium.data.generator;
public class Nullable<T> {
private static final long serialVersionUID = 1L;
private final T value;
public Nullable(T value) {
this.value = value;
}
public static <T> Nullable<T> of(T value) {
if (value == null) {
throw new NullPointerException();
} else {
return new Nullable<>(value);
}
}
public static <T> Nullable<T> ofNullable(T value) {
return new Nullable<>(value);
}
public static <T> Nullable<T> empty() {
return new Nullable<>(null);
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
@org.jetbrains.annotations.NotNull
public T get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
@org.jetbrains.annotations.Nullable
public T getNullable() {
return value;
}
}

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.List;
import org.jetbrains.annotations.NotNull;
public class ArrayInt52Serializer implements DataSerializer< List<Int52>> {
@Override
public void serialize(DataOutput dataOutput, List<Int52> data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
Int52Serializer.INSTANCE.serialize(dataOutput, data.get(i));
}
}
@NotNull
@Override
public List<Int52> deserialize(DataInput dataInput) throws IOException {
var data = new Int52[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = Int52Serializer.INSTANCE.deserialize(dataInput);
}
return List.of(data);
}
}

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.List;
import org.jetbrains.annotations.NotNull;
public class ArrayStringSerializer implements DataSerializer<List<String>> {
@Override
public void serialize(DataOutput dataOutput, @NotNull List<String> data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
dataOutput.writeUTF(data.get(i));
}
}
@NotNull
@Override
public List<String> deserialize(DataInput dataInput) throws IOException {
var data = new String[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = dataInput.readUTF();
}
return List.of(data);
}
}

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import it.unimi.dsi.fastutil.booleans.BooleanList;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class ArraybooleanSerializer implements DataSerializer<BooleanList> {
@Override
public void serialize(DataOutput dataOutput, @NotNull BooleanList data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
dataOutput.writeBoolean(data.getBoolean(i));
}
}
@NotNull
@Override
public BooleanList deserialize(DataInput dataInput) throws IOException {
var data = new boolean[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = dataInput.readBoolean();
}
return BooleanList.of(data);
}
}

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import it.unimi.dsi.fastutil.bytes.ByteList;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class ArraybyteSerializer implements DataSerializer<ByteList> {
@Override
public void serialize(DataOutput dataOutput, @NotNull ByteList data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
dataOutput.writeByte(data.getByte(i));
}
}
@NotNull
@Override
public ByteList deserialize(DataInput dataInput) throws IOException {
var data = new byte[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = dataInput.readByte();
}
return ByteList.of(data);
}
}

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import it.unimi.dsi.fastutil.chars.CharList;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class ArraycharSerializer implements DataSerializer<CharList> {
@Override
public void serialize(DataOutput dataOutput, @NotNull CharList data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
dataOutput.writeChar(data.getChar(i));
}
}
@NotNull
@Override
public CharList deserialize(DataInput dataInput) throws IOException {
var data = new char[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = dataInput.readChar();
}
return CharList.of(data);
}
}

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import it.unimi.dsi.fastutil.doubles.DoubleList;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class ArraydoubleSerializer implements DataSerializer<DoubleList> {
@Override
public void serialize(DataOutput dataOutput, @NotNull DoubleList data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
dataOutput.writeDouble(data.getDouble(i));
}
}
@NotNull
@Override
public DoubleList deserialize(DataInput dataInput) throws IOException {
var data = new double[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = dataInput.readDouble();
}
return DoubleList.of(data);
}
}

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import it.unimi.dsi.fastutil.floats.FloatList;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class ArrayfloatSerializer implements DataSerializer<FloatList> {
@Override
public void serialize(DataOutput dataOutput, @NotNull FloatList data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
dataOutput.writeFloat(data.getFloat(i));
}
}
@NotNull
@Override
public FloatList deserialize(DataInput dataInput) throws IOException {
var data = new float[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = dataInput.readFloat();
}
return FloatList.of(data);
}
}

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import it.unimi.dsi.fastutil.ints.IntList;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class ArrayintSerializer implements DataSerializer<IntList> {
@Override
public void serialize(DataOutput dataOutput, @NotNull IntList data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
dataOutput.writeInt(data.getInt(i));
}
}
@NotNull
@Override
public IntList deserialize(DataInput dataInput) throws IOException {
var data = new int[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = dataInput.readInt();
}
return IntList.of(data);
}
}

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import it.unimi.dsi.fastutil.longs.LongList;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class ArraylongSerializer implements DataSerializer<LongList> {
@Override
public void serialize(DataOutput dataOutput, @NotNull LongList data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
dataOutput.writeLong(data.getLong(i));
}
}
@NotNull
@Override
public LongList deserialize(DataInput dataInput) throws IOException {
var data = new long[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = dataInput.readLong();
}
return LongList.of(data);
}
}

@ -0,0 +1,29 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import it.unimi.dsi.fastutil.shorts.ShortList;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class ArrayshortSerializer implements DataSerializer<ShortList> {
@Override
public void serialize(DataOutput dataOutput, @NotNull ShortList data) throws IOException {
dataOutput.writeInt(data.size());
for (int i = 0; i < data.size(); i++) {
dataOutput.writeShort(data.getShort(i));
}
}
@NotNull
@Override
public ShortList deserialize(DataInput dataInput) throws IOException {
var data = new short[dataInput.readInt()];
for (int i = 0; i < data.length; i++) {
data[i] = dataInput.readShort();
}
return ShortList.of(data);
}
}

@ -0,0 +1,5 @@
package it.cavallium.data.generator.nativedata;
public interface IGenericNullable {
Object $getNullable();
}

@ -0,0 +1,90 @@
package it.cavallium.data.generator.nativedata;
import java.lang.annotation.Native;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
public class Int52 extends Number implements Comparable<Int52> {
/**
* The number of bits used to represent a {@code Int52} value in two's
* complement binary form.
*/
@Native
public static final int SIZE = 52;
/**
* The number of bytes used to represent a {@code Int52} value in two's
* complement binary form.
*/
public static final int BYTES = 7;
public static final Int52 ZERO = new Int52(0);
private final long value;
private Int52(long value) {
this.value = value;
}
public static Int52 fromLong(long value) {
if (value < 0) {
throw new IllegalArgumentException("Only positive values are supported");
}
if (value > 0x0F_FF_FF_FF_FF_FF_FFL) {
throw new IllegalArgumentException("Only values below or equal to " + 0xFFFFFFFFFFFFFL + " are supported");
}
return new Int52(value);
}
long getValue() {
return value;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Int52 int52 = (Int52) o;
return value == int52.value;
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
return Long.toString(value);
}
@Override
public int intValue() {
return (int) value;
}
@Override
public long longValue() {
return value;
}
@Override
public float floatValue() {
return (float) value;
}
@Override
public double doubleValue() {
return (double) value;
}
@Override
public int compareTo(@NotNull Int52 o) {
return Long.compareUnsigned(this.value, o.value);
}
}

@ -0,0 +1,67 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class Int52Serializer implements DataSerializer<Int52> {
public static final Int52Serializer INSTANCE = new Int52Serializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull Int52 data) throws IOException {
serializeValue(dataOutput, data);
}
@NotNull
@Override
public Int52 deserialize(DataInput dataInput) throws IOException {
return deserializeValue(dataInput);
}
public static void serializeValue(DataOutput dataOutput, @NotNull Int52 data) throws IOException {
long value = data.getValue();
for(int i = 0; i < 7; i++) {
dataOutput.writeByte(((int)((value >> (6 - i) * 8) & (i == 0 ? 0b00001111L : 255L))));
}
}
public static Int52 deserializeValue(DataInput dataInput) throws IOException {
long value = 0;
return Int52.fromLong(
((long) dataInput.readUnsignedByte() & 0b00001111) << 48
| ((long) dataInput.readUnsignedByte()) << 40
| ((long) dataInput.readUnsignedByte() << 32)
| ((long) dataInput.readUnsignedByte() << 24)
| ((long) dataInput.readUnsignedByte()) << 16
| ((long) dataInput.readUnsignedByte()) << 8
| ((long) dataInput.readUnsignedByte())
);
}
public static byte[] toByteArray(long value) {
byte[] result = new byte[7];
for(int i = 6; i >= 0; --i) {
result[i] = (byte)((int)(value & (i == 0 ? 0b00001111L : 255L)));
value >>= 8;
}
return result;
}
public static long fromByteArray(byte[] bytes) {
if (bytes.length != 7) {
throw new IllegalArgumentException("Size must be 7, got " + bytes.length + " instead");
}
return fromBytes((byte) (bytes[0] & 0b00001111), bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6]);
}
public static long fromBytes(byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7) {
return ((long)b1 & 0b00001111) << 48 | ((long)b2 & 255L) << 40 | ((long)b3 & 255L) << 32 | ((long)b4 & 255L) << 24 | ((long)b5 & 255L) << 16 | ((long)b6 & 255L) << 8 | (long)b7 & 255L;
}
}

@ -0,0 +1,102 @@
package it.cavallium.data.generator.nativedata;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class NullableInt52 implements Serializable, IGenericNullable {
private static final long serialVersionUID = 1L;
private final Int52 value;
public NullableInt52(Int52 value) {
this.value = value;
}
public static NullableInt52 of(@NotNull Int52 value) {
return new NullableInt52(value);
}
public static NullableInt52 ofNullable(@Nullable Int52 value) {
return new NullableInt52(value);
}
public static <T> NullableInt52 empty() {
return new NullableInt52(null);
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
@NotNull
public Int52 get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
public Int52 orElse(Int52 defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override
public Object $getNullable() {
return this.getNullable();
}
@Nullable
public Int52 getNullable() {
return value;
}
@Nullable
public Int52 getNullable(Int52 defaultValue) {
return value == null ? defaultValue : value;
}
@NotNull
@Override
public NullableInt52 clone() {
if (value != null) {
return NullableInt52.of(value);
} else {
return NullableInt52.empty();
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
var that = (NullableInt52) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}

@ -0,0 +1,37 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class NullableInt52Serializer implements DataSerializer<NullableInt52> {
public static final NullableInt52Serializer INSTANCE = new NullableInt52Serializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull NullableInt52 data) throws IOException {
// 0b10000000 = empty, 0b00000000 = with value
if (data.isEmpty()) {
dataOutput.writeByte(0b10000000);
} else {
dataOutput.write(Int52Serializer.toByteArray(data.get().getValue()));
}
}
@NotNull
@Override
public NullableInt52 deserialize(DataInput dataInput) throws IOException {
// 0b10000000 = empty, 0b00000000 = with value
byte firstByteAndIsPresent = dataInput.readByte();
if ((firstByteAndIsPresent & 0b10000000) != 0) {
return NullableInt52.empty();
} else {
byte[] secondPart = new byte[7];
secondPart[0] = (byte) (firstByteAndIsPresent & 0b00001111);
dataInput.readFully(secondPart, 1, secondPart.length - 1);
return NullableInt52.of(Int52.fromLong(Int52Serializer.fromByteArray(secondPart)));
}
}
}

@ -0,0 +1,117 @@
package it.cavallium.data.generator.nativedata;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class NullableString implements Serializable, IGenericNullable {
private static final long serialVersionUID = 1L;
private final String value;
public NullableString(String value) {
this.value = value;
}
public static NullableString of(@NotNull String value) {
if (value == null) {
throw new NullPointerException();
} else {
return new NullableString(value);
}
}
public static NullableString ofNullable(@Nullable String value) {
return new NullableString(value);
}
public static NullableString ofNullableBlank(@Nullable String value) {
if (value == null || value.isBlank()) {
return empty();
}
return new NullableString(value);
}
public static <T> NullableString empty() {
return new NullableString(null);
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
public boolean isContentful() {
return value != null && !value.isBlank();
}
@NotNull
public String get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
public String orElse(String defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override
public String $getNullable() {
return this.getNullable();
}
@Nullable
public String getNullable() {
return value;
}
@NotNull
public String getNullable(String defaultValue) {
return value == null ? defaultValue : value;
}
@NotNull
@Override
public NullableString clone() {
if (value != null) {
return NullableString.of(value);
} else {
return NullableString.empty();
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
var that = (NullableString) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}

@ -0,0 +1,34 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class NullableStringSerializer implements DataSerializer<NullableString> {
public static final NullableStringSerializer INSTANCE = new NullableStringSerializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull NullableString data) throws IOException {
if (data.isEmpty()) {
dataOutput.writeBoolean(false);
} else {
dataOutput.writeBoolean(true);
String dataContent = data.get();
dataOutput.writeUTF(dataContent);
}
}
@NotNull
@Override
public NullableString deserialize(DataInput dataInput) throws IOException {
var isPresent = dataInput.readBoolean();
if (!isPresent) {
return NullableString.empty();
} else {
return NullableString.of(dataInput.readUTF());
}
}
}

@ -0,0 +1,101 @@
package it.cavallium.data.generator.nativedata;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Nullableboolean implements Serializable, IGenericNullable {
private static final long serialVersionUID = 1L;
private final Boolean value;
public Nullableboolean(Boolean value) {
this.value = value;
}
public static Nullableboolean of(boolean value) {
return new Nullableboolean(value);
}
public static Nullableboolean ofNullable(@Nullable Boolean value) {
return new Nullableboolean(value);
}
public static <T> Nullableboolean empty() {
return new Nullableboolean(null);
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
public boolean get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
public boolean orElse(boolean defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override
public Boolean $getNullable() {
return this.getNullable();
}
@Nullable
public Boolean getNullable() {
return value;
}
public boolean getNullable(boolean defaultValue) {
return value == null ? defaultValue : value;
}
@NotNull
@Override
public Nullableboolean clone() {
if (value != null) {
return Nullableboolean.of(value);
} else {
return Nullableboolean.empty();
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Nullableboolean that = (Nullableboolean) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}

@ -0,0 +1,34 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class NullablebooleanSerializer implements DataSerializer<Nullableboolean> {
public static final NullablebooleanSerializer INSTANCE = new NullablebooleanSerializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull Nullableboolean data) throws IOException {
if (data.isEmpty()) {
dataOutput.writeBoolean(false);
} else {
dataOutput.writeBoolean(true);
boolean dataContent = data.get();
dataOutput.writeBoolean(dataContent);
}
}
@NotNull
@Override
public Nullableboolean deserialize(DataInput dataInput) throws IOException {
var isPresent = dataInput.readBoolean();
if (!isPresent) {
return Nullableboolean.empty();
} else {
return Nullableboolean.of(dataInput.readBoolean());
}
}
}

@ -0,0 +1,100 @@
package it.cavallium.data.generator.nativedata;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Nullablebyte implements Serializable, IGenericNullable {
private static final long serialVersionUID = 1L;
private final Byte value;
public Nullablebyte(Byte value) {
this.value = value;
}
public static Nullablebyte of(byte value) {
return new Nullablebyte(value);
}
public static Nullablebyte ofNullable(@Nullable Byte value) {
return new Nullablebyte(value);
}
public static <T> Nullablebyte empty() {
return new Nullablebyte(null);
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
public byte get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
public byte orElse(byte defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override
public Byte $getNullable() {
return this.getNullable();
}
@Nullable
public Byte getNullable() {
return value;
}
public byte getNullable(byte defaultValue) {
return value == null ? defaultValue : value;
}
@NotNull
@Override
public Nullablebyte clone() {
if (value != null) {
return Nullablebyte.of(value);
} else {
return Nullablebyte.empty();
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Nullablebyte that = (Nullablebyte) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}

@ -0,0 +1,34 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.DataSerializer;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
public class NullablebyteSerializer implements DataSerializer<Nullablebyte> {
public static final NullablebyteSerializer INSTANCE = new NullablebyteSerializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull Nullablebyte data) throws IOException {
if (data.isEmpty()) {
dataOutput.writeBoolean(false);
} else {
dataOutput.writeBoolean(true);
byte dataContent = data.get();
dataOutput.writeByte(dataContent);
}
}
@NotNull
@Override
public Nullablebyte deserialize(DataInput dataInput) throws IOException {
var isPresent = dataInput.readBoolean();
if (!isPresent) {
return Nullablebyte.empty();
} else {
return Nullablebyte.of(dataInput.readByte());
}
}
}

@ -0,0 +1,100 @@
package it.cavallium.data.generator.nativedata;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Nullablechar implements Serializable, IGenericNullable {
private static final long serialVersionUID = 1L;
private final Character value;
public Nullablechar(Character value) {
this.value = value;
}
public static Nullablechar of(char value) {
return new Nullablechar(value);
}
public static Nullablechar ofNullable(@Nullable Character value) {
return new Nullablechar(value);
}
public static <T> Nullablechar empty() {
return new Nullablechar(null);
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
public char get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
public char orElse(char defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override
public Character $getNullable() {
return this.getNullable();
}
@Nullable
public Character getNullable() {
return value;
}
public char getNullable(char defaultValue) {
return value == null ? defaultValue : value;
}
@NotNull
@Override
public Nullablechar clone() {
if (value != null) {
return Nullablechar.of(value);
} else {
return Nullablechar.empty();
}
}
@Override
public boolean equals(Object o) {
if (<