First release

This commit is contained in:
Andrea Cavalli 2023-01-17 16:14:00 +01:00
parent fa3fffc0b8
commit 16e66006b9
72 changed files with 3315 additions and 293 deletions

View File

@ -24,7 +24,7 @@ jobs:
shell: bash shell: bash
run: | run: |
# ====== Variables # ====== Variables
export REVISION=${{ github.run_number }} export REVISION=1.0.${{ github.run_number }}
echo "REVISION=$REVISION" >> $GITHUB_ENV echo "REVISION=$REVISION" >> $GITHUB_ENV
- name: Set up JDK 17 - name: Set up JDK 17

67
.gitignore vendored
View File

@ -1,67 +1,10 @@
/target/ /target/
/database-data-builder.iml *.iml
data-generator.iml
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# PyDev specific (Python IDE for Eclipse)
*.pydevproject
# CDT-specific (C/C++ Development Tooling)
.cproject
# CDT- autotools
.autotools
# Java annotation processor (APT)
.factorypath
# PDT-specific (PHP Development Tools)
.buildpath
# sbteclipse plugin
.target
# Tern plugin
.tern-project
# TeXlipse plugin
.texlipse
# STS (Spring Tool Suite)
.springBeans
# Code Recommenders
.recommenders/
# Annotation Processing
.apt_generated/
.apt_generated_test/
# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet
.project
.classpath
.ci-friendly-pom.xml .ci-friendly-pom.xml
/.classpath
/.project
/.settings/
.flattened-pom.xml .flattened-pom.xml

View File

@ -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 17
if: github.ref == 'refs/heads/master'
uses: actions/setup-java@v1
with:
java-version: 17
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 }}

67
data-generator-plugin/.gitignore vendored Normal file
View File

@ -0,0 +1,67 @@
/target/
/database-data-builder.iml
data-generator.iml
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# PyDev specific (Python IDE for Eclipse)
*.pydevproject
# CDT-specific (C/C++ Development Tooling)
.cproject
# CDT- autotools
.autotools
# Java annotation processor (APT)
.factorypath
# PDT-specific (PHP Development Tools)
.buildpath
# sbteclipse plugin
.target
# Tern plugin
.tern-project
# TeXlipse plugin
.texlipse
# STS (Spring Tool Suite)
.springBeans
# Code Recommenders
.recommenders/
# Annotation Processing
.apt_generated/
.apt_generated_test/
# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet
.project
.classpath
.ci-friendly-pom.xml
.flattened-pom.xml

View File

@ -0,0 +1,15 @@
Data generator
==============
Maven plugin to generate upgradable data classes and serializers from a .yaml definition file.
It can be also executed standalone.
The data is serializable and upgradable from any version to the latest.
The transformations between each version are defined in the .yaml file itself.
Supports custom (external) data types, custom data arrays, custom data optionals,
interfaces with common getters / setters.
The serialized data is very lightweight: it serializes only the data, without any metadata or type specification,
because it's all deducted on compile-time from the definitions file.

View File

@ -0,0 +1,274 @@
<?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</name>
<artifactId>data-generator-plugin</artifactId>
<version>${revision}</version>
<packaging>maven-plugin</packaging>
<parent>
<groupId>it.cavallium</groupId>
<version>${revision}</version>
<artifactId>data-generator</artifactId>
</parent>
<properties>
<revision>1.0.0.0-SNAPSHOT</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</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.git</connection>
<developerConnection>scm:git:https://git.ignuranza.net/andreacavalli/data-generator.git</developerConnection>
<tag>HEAD</tag>
</scm>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.6.1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-tools-annotations</artifactId>
<version>3.6.1</version>
</dependency>
</dependencies>
</plugin>
<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.9.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>17</release>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.1.0</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>oss</flattenMode>
<pomElements>
<dependencyManagement>resolve</dependencyManagement>
<dependencies>resolve</dependencies>
<version>resolve</version>
</pomElements>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-plugin-plugin
</artifactId>
<versionRange>
[3.6.1,)
</versionRange>
<goals>
<goal>descriptor</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
flatten-maven-plugin
</artifactId>
<versionRange>
[1.1.0,)
</versionRange>
<goals>
<goal>flatten</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.33</version>
</dependency>
<dependency>
<groupId>com.squareup</groupId>
<artifactId>javapoet</artifactId>
<version>1.14.0-records</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
</dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
<version>8.5.11</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.8.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.8.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.2.1</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.soabase.record-builder</groupId>
<artifactId>record-builder-core</artifactId>
<version>34</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>2.19.0</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>it.cavallium</groupId>
<artifactId>data-generator-runtime</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>
</project>

View File

@ -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 17
if: github.ref == 'refs/heads/master'
uses: actions/setup-java@v1
with:
java-version: 17
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 }}

10
data-generator-runtime/.gitignore vendored Normal file
View File

@ -0,0 +1,10 @@
/target/
*.iml
.ci-friendly-pom.xml
/.classpath
/.project
/.settings/
.flattened-pom.xml

View File

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

View File

@ -0,0 +1,188 @@
<?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>
<artifactId>data-generator-runtime</artifactId>
<version>${revision}</version>
<packaging>jar</packaging>
<parent>
<groupId>it.cavallium</groupId>
<version>${revision}</version>
<artifactId>data-generator</artifactId>
<relativePath>../pom.xml</relativePath>
</parent>
<properties>
<revision>1.0.0.0-SNAPSHOT</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</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.9.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>17</release>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.1.0</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>oss</flattenMode>
<pomElements>
<dependencyManagement>resolve</dependencyManagement>
<dependencies>resolve</dependencies>
<version>resolve</version>
</pomElements>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
flatten-maven-plugin
</artifactId>
<versionRange>
[1.1.0,)
</versionRange>
<goals>
<goal>flatten</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</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>23.0.0</version>
</dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
<version>8.5.11</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.0</version>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
</project>

View File

@ -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;
}
}

View File

@ -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;
}

View File

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

View File

@ -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;
}

View File

@ -0,0 +1,24 @@
package it.cavallium.data.generator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface NativeNullable<T> {
boolean isEmpty();
default boolean isPresent() {
return !isEmpty();
}
@NotNull
T orElse(@NotNull T defaultValue);
@NotNull NativeNullable<? extends T> or(@NotNull NativeNullable<? extends T> fallback);
@Nullable
T getNullable();
@Nullable
T getNullable(@Nullable T defaultValue);
}

View File

@ -0,0 +1,118 @@
package it.cavallium.data.generator;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Stream;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface TypedNullable<T> extends NativeNullable<T> {
@NotNull
default T get() throws NullPointerException {
var value = getNullable();
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
@Override
default @Nullable T getNullable(@Nullable T defaultValue) {
var value = getNullable();
return value == null ? defaultValue : value;
}
@Override
default @NotNull T orElse(@NotNull T defaultValue) {
var value = getNullable();
if (value == null) {
Objects.requireNonNull(defaultValue, "default value must not be null");
return defaultValue;
} else {
return value;
}
}
@Override
default @NotNull NativeNullable<? extends T> or(@NotNull NativeNullable<? extends T> fallback) {
var value = getNullable();
if (value == null) {
return fallback;
} else {
return this;
}
}
@Override
default boolean isPresent() {
return getNullable() != null;
}
@Override
default boolean isEmpty() {
return getNullable() == null;
}
default <U, TN extends TypedNullable<U>> @NotNull TN map(
@NotNull Function<@NotNull T, @NotNull U> value,
@NotNull Function<@Nullable U, @NotNull TN> nullableConstructor) {
var nullable = getNullable();
if (nullable != null) {
var val = value.apply(nullable);
Objects.requireNonNull(val, "Mapped value must not be null");
return nullableConstructor.apply(val);
} else {
return nullableConstructor.apply(null);
}
}
default <U> @NotNull Optional<U> map(@NotNull Function<@NotNull T, @NotNull U> value) {
var nullable = getNullable();
if (nullable != null) {
var val = value.apply(nullable);
return Optional.of(val);
} else {
return Optional.empty();
}
}
@SuppressWarnings("unchecked")
default <TN extends TypedNullable<T>> @NotNull TN filter(
@NotNull Predicate<@NotNull T> value,
@NotNull Supplier<TN> nullableConstructor) {
var nullable = getNullable();
if (nullable != null) {
var filter = value.test(nullable);
if (!filter) {
return nullableConstructor.get();
}
}
return (TN) this;
}
default @NotNull Optional<T> filter(@NotNull Predicate<@NotNull T> value) {
var nullable = getNullable();
if (nullable != null) {
var filter = value.test(nullable);
if (!filter) {
return Optional.empty();
}
}
return Optional.ofNullable(nullable);
}
default @NotNull Optional<T> toOptional() {
var nullable = getNullable();
return Optional.ofNullable(nullable);
}
default @NotNull Stream<T> stream() {
var nullable = getNullable();
return Stream.ofNullable(nullable);
}
}

View File

@ -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 (Int52 datum : data) {
Int52Serializer.INSTANCE.serialize(dataOutput, datum);
}
}
@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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

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

View File

@ -0,0 +1,101 @@
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(0L);
public static final Int52 ONE = new Int52(1L);
public static final Int52 TWO = new Int52(2L);
public static final Int52 TEN = new Int52(10L);
private final long value;
private Int52(long value) {
this.value = value;
}
public static Int52 fromLong(long value) {
if (value == 0) {
return ZERO;
} else if (value == 1) {
return ONE;
} else if (value == 2) {
return TWO;
} else if (value == 10) {
return TEN;
} else if (value <= 0) {
throw new IllegalArgumentException("Only positive values are supported");
} else if (value > 0x0F_FF_FF_FF_FF_FF_FFL) {
throw new IllegalArgumentException("Only values below or equal to " + 0xFFFFFFFFFFFFFL + " are supported");
} else {
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 Long.hashCode(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);
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,137 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.NativeNullable;
import it.cavallium.data.generator.TypedNullable;
import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class NullableInt52 implements Serializable, IGenericNullable, TypedNullable<Int52> {
@Serial
private static final long serialVersionUID = 1L;
private static final NullableInt52 NULL = new NullableInt52(null);
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) {
if (value == null) {
return NULL;
} else {
return new NullableInt52(value);
}
}
public static NullableInt52 ofNullableNumber(@Nullable Number value) {
if (value == null) {
return NULL;
} else {
return new NullableInt52(Int52.fromLong(value.longValue()));
}
}
public static NullableInt52 empty() {
return NULL;
}
@Override
public boolean isEmpty() {
return value == null;
}
@Override
public boolean isPresent() {
return value != null;
}
@Override
@NotNull
public Int52 get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
@Override
public @NotNull NullableInt52 or(@NotNull NativeNullable<? extends Int52> fallback) {
if (value == null) {
if (fallback.getClass() == NullableInt52.class) {
return (NullableInt52) fallback;
} else {
return ofNullable(fallback.getNullable());
}
} else {
return this;
}
}
@NotNull
public NullableInt52 or(NullableInt52 fallback) {
if (value == null) {
return fallback;
} else {
return this;
}
}
@Override
public Object $getNullable() {
return this.getNullable();
}
@Nullable
public Int52 getNullable() {
return value;
}
@Override
@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 value == null ? 0 : value.hashCode();
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}

View File

@ -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)));
}
}
}

View File

@ -0,0 +1,170 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.NativeNullable;
import it.cavallium.data.generator.TypedNullable;
import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class NullableString implements Serializable, IGenericNullable, TypedNullable<String> {
@Serial
private static final long serialVersionUID = 1L;
private static final NullableString NULL = new NullableString(null);
private final String value;
public NullableString(String value) {
this.value = value;
}
@SuppressWarnings("ConstantConditions")
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) {
if (value == null) {
return NULL;
} else {
return new NullableString(value);
}
}
public static NullableString ofNullableBlank(@Nullable String value) {
if (value == null || value.isBlank()) {
return NULL;
}
return new NullableString(value);
}
public static NullableString empty() {
return NULL;
}
@Override
public boolean isEmpty() {
return value == null;
}
@Override
public boolean isPresent() {
return value != null;
}
public boolean isContentful() {
return value != null && !value.isBlank();
}
public boolean isBlank() {
return value == null || value.isBlank();
}
@Override
@NotNull
public String get() {
if (value == null) {
throw new NullPointerException();
} else {
return value;
}
}
@Override
public @NotNull NullableString or(@NotNull NativeNullable<? extends String> fallback) {
if (value == null) {
if (fallback.getClass() == NullableString.class) {
return (NullableString) fallback;
} else {
return ofNullable(fallback.getNullable());
}
} else {
return this;
}
}
@NotNull
public NullableString or(NullableString fallback) {
if (value == null) {
return fallback;
} else {
return this;
}
}
public @NotNull NullableString orIfBlank(@NotNull NativeNullable<? extends String> fallback) {
if (isBlank()) {
if (fallback.getClass() == NullableString.class) {
return (NullableString) fallback;
} else {
return ofNullable(fallback.getNullable());
}
} else {
return this;
}
}
@NotNull
public NullableString orIfBlank(NullableString fallback) {
if (isBlank()) {
return fallback;
} else {
return this;
}
}
@Override
public String $getNullable() {
return this.getNullable();
}
@Nullable
public String getNullable() {
return value;
}
@Override
@Nullable
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 value == null ? 0 : value.hashCode();
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}

View File

@ -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());
}
}
}

View File

@ -0,0 +1,145 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.NativeNullable;
import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Nullableboolean implements Serializable, IGenericNullable, NativeNullable<Boolean> {
@Serial
private static final long serialVersionUID = 1L;
private static final Nullableboolean NULL = new Nullableboolean(null);
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) {
if (value == null) {
return NULL;
} else {
return new Nullableboolean(value);
}
}
public static Nullableboolean empty() {
return NULL;
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
@Override
public @NotNull Boolean orElse(@NotNull Boolean defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override
public @NotNull Nullableboolean or(@NotNull NativeNullable<? extends Boolean> fallback) {
if (value == null) {
if (fallback.getClass() == Nullableboolean.class) {
return (Nullableboolean) fallback;
} else {
return ofNullable(fallback.getNullable());
}
} else {
return this;
}
}
@NotNull
public Nullableboolean or(Nullableboolean fallback) {
if (value == null) {
return fallback;
} else {
return this;
}
}
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;
}
@Override
public @Nullable Boolean getNullable(@Nullable Boolean defaultValue) {
return value != null ? value : defaultValue;
}
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 value == null ? 0 : value.hashCode();
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}

View File

@ -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());
}
}
}

View File

@ -0,0 +1,152 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.NativeNullable;
import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Nullablebyte implements Serializable, IGenericNullable, NativeNullable<Byte> {
@Serial
private static final long serialVersionUID = 1L;
private static final Nullablebyte NULL = new Nullablebyte(null);
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) {
if (value == null) {
return NULL;
} else {
return new Nullablebyte(value);
}
}
public static Nullablebyte ofNullableNumber(@Nullable Number value) {
if (value == null) {
return NULL;
} else {
return new Nullablebyte(value.byteValue());
}
}
public static Nullablebyte empty() {
return NULL;
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
@Override
public @NotNull Byte orElse(@NotNull Byte defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override
public @NotNull Nullablebyte or(@NotNull NativeNullable<? extends Byte> fallback) {
if (value == null) {
if (fallback.getClass() == Nullablebyte.class) {
return (Nullablebyte) fallback;
} else {
return ofNullable(fallback.getNullable());
}
} else {
return this;
}
}
@NotNull
public Nullablebyte or(Nullablebyte fallback) {
if (value == null) {
return fallback;
} else {
return this;
}
}
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;
}
@Override
public @Nullable Byte getNullable(@Nullable Byte defaultValue) {
return value != null ? value : defaultValue;
}
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 value == null ? 0 : value.hashCode();
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}

View File

@ -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());
}
}
}

View File

@ -0,0 +1,144 @@
package it.cavallium.data.generator.nativedata;
import it.cavallium.data.generator.NativeNullable;
import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Nullablechar implements Serializable, IGenericNullable, NativeNullable<Character> {
@Serial
private static final long serialVersionUID = 1L;
private static final Nullablechar NULL = new Nullablechar(null);
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) {
if (value == null) {
return NULL;
} else {
return new Nullablechar(value);
}
}
public static Nullablechar empty() {
return NULL;
}
public boolean isEmpty() {
return value == null;
}
public boolean isPresent() {
return value != null;
}
@Override
public @NotNull Character orElse(@NotNull Character defaultValue) {
if (value == null) {
return defaultValue;
} else {
return value;
}
}
@Override
public @NotNull Nullablechar or(@NotNull NativeNullable<? extends Character> fallback) {
if (value == null) {
if (fallback.getClass() == Nullablechar.class) {
return (Nullablechar) fallback;
} else {
return ofNullable(fallback.getNullable());
}
} else {
return this;
}
}
@NotNull
public Nullablechar or(Nullablechar fallback) {
if (value == null) {
return fallback;
} else {
return this;
}
}
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;
}
@Override
public @Nullable Character getNullable(@Nullable Character defaultValue) {
return value != null ? value : defaultValue;
}
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 (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
var that = (Nullablechar) o;
return Objects.equals(value, that.value);
}
@Override
public int hashCode() {
return value == null ? 0 : value.hashCode();
}
@Override
public String toString() {
if (value == null) return "null";
return "" + value;
}
}

View File

@ -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 NullablecharSerializer implements DataSerializer<Nullablechar> {
public static final NullablecharSerializer INSTANCE = new NullablecharSerializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull Nullablechar data) throws IOException {
if (data.isEmpty()) {
dataOutput.writeBoolean(false);
} else {
dataOutput.writeBoolean(true);
char dataContent = data.get();
dataOutput.writeChar(dataContent);
}
}
@NotNull
@Override
public Nullablechar deserialize(DataInput dataInput) throws IOException {
var isPresent = dataInput.readBoolean();
if (!isPresent) {
return Nullablechar.empty();
} else {
return Nullablechar.of(dataInput.readChar());
}
}
}

View File

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

View File

@ -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 NullabledoubleSerializer implements DataSerializer<Nullabledouble> {
public static final NullabledoubleSerializer INSTANCE = new NullabledoubleSerializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull Nullabledouble data) throws IOException {
if (data.isEmpty()) {
dataOutput.writeBoolean(false);
} else {
dataOutput.writeBoolean(true);
double dataContent = data.get();
dataOutput.writeDouble(dataContent);
}
}
@NotNull
@Override
public Nullabledouble deserialize(DataInput dataInput) throws IOException {
var isPresent = dataInput.readBoolean();
if (!isPresent) {
return Nullabledouble.empty();
} else {
return Nullabledouble.of(dataInput.readDouble());
}
}
}

View File

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

View File

@ -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 NullablefloatSerializer implements DataSerializer<Nullablefloat> {
public static final NullablefloatSerializer INSTANCE = new NullablefloatSerializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull Nullablefloat data) throws IOException {
if (data.isEmpty()) {
dataOutput.writeBoolean(false);
} else {
dataOutput.writeBoolean(true);
float dataContent = data.get();
dataOutput.writeFloat(dataContent);
}
}
@NotNull
@Override
public Nullablefloat deserialize(DataInput dataInput) throws IOException {
var isPresent = dataInput.readBoolean();
if (!isPresent) {
return Nullablefloat.empty();
} else {
return Nullablefloat.of(dataInput.readFloat());
}
}
}

View File

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

View File

@ -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 NullableintSerializer implements DataSerializer<Nullableint> {
public static final NullableintSerializer INSTANCE = new NullableintSerializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull Nullableint data) throws IOException {
if (data.isEmpty()) {
dataOutput.writeBoolean(false);
} else {
dataOutput.writeBoolean(true);
int dataContent = data.get();
dataOutput.writeInt(dataContent);
}
}
@NotNull
@Override
public Nullableint deserialize(DataInput dataInput) throws IOException {
var isPresent = dataInput.readBoolean();
if (!isPresent) {
return Nullableint.empty();
} else {
return Nullableint.of(dataInput.readInt());
}
}
}

View File

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

View File

@ -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 NullablelongSerializer implements DataSerializer<Nullablelong> {
public static final NullablelongSerializer INSTANCE = new NullablelongSerializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull Nullablelong data) throws IOException {
if (data.isEmpty()) {
dataOutput.writeBoolean(false);
} else {
dataOutput.writeBoolean(true);
long dataContent = data.get();
dataOutput.writeLong(dataContent);
}
}
@NotNull
@Override
public Nullablelong deserialize(DataInput dataInput) throws IOException {
var isPresent = dataInput.readBoolean();
if (!isPresent) {
return Nullablelong.empty();
} else {
return Nullablelong.of(dataInput.readLong());
}
}
}

View File

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

View File

@ -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 NullableshortSerializer implements DataSerializer<Nullableshort> {
public static final NullableshortSerializer INSTANCE = new NullableshortSerializer();
@Override
public void serialize(DataOutput dataOutput, @NotNull Nullableshort data) throws IOException {
if (data.isEmpty()) {
dataOutput.writeBoolean(false);
} else {
dataOutput.writeBoolean(true);
short dataContent = data.get();
dataOutput.writeShort(dataContent);
}
}
@NotNull
@Override
public Nullableshort deserialize(DataInput dataInput) throws IOException {
var isPresent = dataInput.readBoolean();
if (!isPresent) {
return Nullableshort.empty();
} else {
return Nullableshort.of(dataInput.readShort());
}
}
}

View File

@ -0,0 +1,63 @@
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.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.Channels;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CodingErrorAction;
import java.nio.charset.MalformedInputException;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnmappableCharacterException;
import org.jetbrains.annotations.NotNull;
public class StringSerializer implements DataSerializer<String> {
public static final StringSerializer INSTANCE = new StringSerializer();
private static final ThreadLocal<CharsetEncoder> UTF8_ENCODER = ThreadLocal.withInitial(() -> StandardCharsets.UTF_8
.newEncoder()
.onUnmappableCharacter(CodingErrorAction.REPORT)
.onMalformedInput(CodingErrorAction.REPORT)
);
private static final ThreadLocal<CharsetDecoder> UTF8_DECODER = ThreadLocal.withInitial(() -> StandardCharsets.UTF_8
.newDecoder()
.onUnmappableCharacter(CodingErrorAction.REPORT)
.onMalformedInput(CodingErrorAction.REPORT)
);
@Override
public void serialize(DataOutput dataOutput, @NotNull String data) throws IOException {
try {
var bytes = UTF8_ENCODER.get().reset().encode(CharBuffer.wrap(data));
dataOutput.writeInt(bytes.limit());
if (bytes.hasArray()) {
dataOutput.write(bytes.array(), bytes.arrayOffset(), bytes.limit());
} else {
while (bytes.hasRemaining()) {
dataOutput.writeByte(bytes.get());
}
}
} catch (IllegalStateException | CharacterCodingException ex) {
throw new IOException("Can't encode this UTF-8 string", ex);
}
}
@NotNull
@Override
public String deserialize(DataInput dataInput) throws IOException {
byte[] bytes = new byte[dataInput.readInt()];
dataInput.readFully(bytes);
try {
CharBuffer decoded = UTF8_DECODER.get().reset().decode(ByteBuffer.wrap(bytes));
return decoded.toString();
} catch (IllegalStateException | CharacterCodingException ex) {
throw new IOException("Can't decode this UTF-8 string", ex);
}
}
}

View File

@ -0,0 +1,6 @@
module data.generator.runtime {
exports it.cavallium.data.generator.nativedata;
exports it.cavallium.data.generator;
requires org.jetbrains.annotations;
requires it.unimi.dsi.fastutil;
}

View File

@ -0,0 +1,71 @@
package it.cavallium.data.generator.nativedata;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class TestInt52Serializer {
@Test
public void testInt52Serialization() throws IOException {
for (int i = 0; i <= 300; i++) {
testInt52Serialization(i);
}
testInt52Serialization(0xF_FF_FF_FF_FF_FF_FFL);
testInt52Serialization(1099511627775L);
testInt52Serialization(999619292661L);
}
public void testInt52Serialization(long n) throws IOException {
var serializer = new Int52Serializer();
byte[] out;
try (var baos = new ByteArrayOutputStream()) {
try (var dos = new DataOutputStream(baos)) {
serializer.serialize(dos, Int52.fromLong(n));
}
out = baos.toByteArray();
}
var bais = new ByteArrayInputStream(out);
var dis = new DataInputStream(bais);
Assertions.assertEquals(n, serializer.deserialize(dis).longValue(), "Deserialized number differ");
}
@Test
public void testInt52OptionalSerialization() throws IOException {
testInt52OptionalSerialization(null);
for (long i = 0; i <= 300; i++) {
testInt52OptionalSerialization(i);
}
testInt52OptionalSerialization(0xF_FF_FF_FF_FF_FF_FFL);
}
public void testInt52OptionalSerialization(@Nullable Long n) throws IOException {
var serializer = new NullableInt52Serializer();
byte[] out;
try (var baos = new ByteArrayOutputStream()) {
try (var dos = new DataOutputStream(baos)) {
if (n == null) {
serializer.serialize(dos, NullableInt52.empty());
} else {
serializer.serialize(dos, NullableInt52.of(Int52.fromLong(n)));
}
}
out = baos.toByteArray();
}
var bais = new ByteArrayInputStream(out);
var dis = new DataInputStream(bais);
if (n == null) {
Assertions.assertNull(serializer.deserialize(dis).getNullable(), "Deserialized number is not empty");
} else {
Assertions.assertEquals(n, serializer.deserialize(dis).get().longValue(), "Deserialized number differ");
}
}
}

237
pom.xml
View File

@ -1,82 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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"> 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> <modelVersion>4.0.0</modelVersion>
<name>Data generator</name>
<groupId>it.cavallium</groupId>
<artifactId>data-generator</artifactId> <artifactId>data-generator</artifactId>
<version>0.9.${revision}</version> <groupId>it.cavallium</groupId>
<packaging>maven-plugin</packaging> <version>${revision}</version>
<packaging>pom</packaging>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <revision>1.0.0.0-SNAPSHOT</revision>
<revision>0-SNAPSHOT</revision>
</properties> </properties>
<repositories> <modules>
<repository> <module>data-generator-plugin</module>
<id>mchv-release</id> <module>data-generator-runtime</module>
<name>MCHV Release Apache Maven Packages</name> </modules>
<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.git</connection>
<developerConnection>scm:git:https://git.ignuranza.net/andreacavalli/data-generator.git</developerConnection>
<tag>HEAD</tag>
</scm>
<build> <build>
<plugins> <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.6.1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-tools-annotations</artifactId>
<version>3.6.1</version>
</dependency>
</dependencies>
</plugin>
<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.9.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>17</release>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.codehaus.mojo</groupId> <groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId> <artifactId>flatten-maven-plugin</artifactId>
@ -103,163 +42,5 @@
</executions> </executions>
</plugin> </plugin>
</plugins> </plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-plugin-plugin
</artifactId>
<versionRange>
[3.6.1,)
</versionRange>
<goals>
<goal>descriptor</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
flatten-maven-plugin
</artifactId>
<versionRange>
[1.1.0,)
</versionRange>
<goals>
<goal>flatten</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build> </build>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.33</version>
</dependency>
<dependency>
<groupId>com.squareup</groupId>
<artifactId>javapoet</artifactId>
<version>1.14.0-records</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
</dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
<version>8.5.11</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.8.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.8.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.2.1</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.soabase.record-builder</groupId>
<artifactId>record-builder-core</artifactId>
<version>34</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>2.19.0</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>it.cavallium</groupId>
<artifactId>data-generator-runtime</artifactId>
<version>1.0.77</version>
</dependency>
</dependencies>
</project> </project>