Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,502 changes: 793 additions & 709 deletions docs/diagrams/Storage.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
362 changes: 362 additions & 0 deletions docs/diagrams/StorageUsagePipeline.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import storage.exceptions.*;
import storage.external_interfaces.Loadable;
import storage.file_editors.*;
import storage.storage_value_adapters.UnsupportedValueException;
import storage.storage_values.StorageValue;
import storage.value_formatters.ValueFormatter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import code_generation.CodeGenerator;
import component_construction.custom_components.*;
import component_construction.storable.dynamic_loading.LoadableBy;
import component_construction.storable.exceptions.NonStorableComponentException;
import component_construction.storable.factories.StorableCustomCompilerFactory;
import component_construction.storable.StorableCustomCompiler;
import lexical_analysis.LexicalAnalyser;
import storage.dynamic_loading.LoadableBy;
import storage.external_interfaces.Storable;
import storage.storage_values.*;
import syntax_analysis.SyntaxAnalyser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

import code_generation.CodeGenerator;
import component_construction.storable.StorableCustomCompiler;
import component_construction.storable.dynamic_loading.*;
import component_construction.storable.exceptions.*;
import component_construction.storable.factories.Factory;
import lexical_analysis.LexicalAnalyser;
import storage.dynamic_loading.*;
import storage.storage_values.*;
import syntax_analysis.SyntaxAnalyser;

Expand Down
35 changes: 35 additions & 0 deletions src/main/java/storage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Dynamic Storage
A system for storing of objects dynamically within Java.

## How it works
Objects can produce a `StroageValue<?>` representation of their state. This state can be passed to the `Storage` helper to be stored to a stream or file (and formatted as required).

Stored state may be loaded through the `Storable` helper, and may be used to hydrate objects through the `Loadable` interface.

```java
Storage storage = new Storage()
.setTargetPath("./testFilepath.bin")
.setFileEditor(new ExampleStreamEditor())
.setFormatter(new ExampleValueFormatter());

storage.store(someStorable);
storage.loadInto(new ExampleLoadable());
```

## Additional Features
The [dynamic_loading](/src/main/java/storage/dynamic_loading/) folder holds helpful features to enable dynamic loading of complex objects.

`Factory` methods may be defined for constructing objects, even if they do not implement `Loadable`. They may be defined as lambdas, making it convenient for users to define and interchange them.

`Loader` classes can be created which are simply `Factory` implementations for instantiating objects of a specific type. It is expected that `Loader` classes contain an empty constructor so they may be instantiated through reflection.

Classes may implement `LoadableBy` to explicitly link them to a specific `Loader`. When correctly defined, a `Loader` object may be instantiated through this reference (via reflection) and used to instantiate objects of the original class.

A class may implement `ReflectivelyLoadable` and a constructor intended for reflective use (see [ReflectiveClassConstructor](/src/main/java/storage/dynamic_loading/ReflectiveClassConstructor.java)). Objects of these classes can be loaded using `ReflectiveClassConstructor`.

## Diagrams
### Usage Pipeline
![Usage Pipeline Diagram](/docs/diagrams/StorageUsagePipeline.drawio.svg)

### Architecture
![Architecture Diagram](/docs/diagrams/Storage.drawio.svg)
1 change: 0 additions & 1 deletion src/main/java/storage/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import storage.exceptions.*;
import storage.file_editors.*;
import storage.external_interfaces.*;
import storage.storage_value_adapters.UnsupportedValueException;
import storage.storage_values.StorageValue;
import storage.value_formatters.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package component_construction.storable.factories;
package storage.dynamic_loading;

import storage.storage_values.StorageValue;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package component_construction.storable.dynamic_loading;
package storage.dynamic_loading;

import java.lang.reflect.*;

import component_construction.storable.exceptions.IncorrectlyFormattedException;
import storage.exceptions.IncorrectlyFormattedException;

/**
* A class specifying a designated loader for the current class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package component_construction.storable.dynamic_loading;
package storage.dynamic_loading;

import java.lang.reflect.InvocationTargetException;

import component_construction.storable.exceptions.MissingEmptyConstructorException;
import component_construction.storable.factories.Factory;
import storage.exceptions.MissingEmptyConstructorException;

/**
* An interface defining the ability construct objects of the specified type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package component_construction.storable.dynamic_loading;
package storage.dynamic_loading;

import java.lang.reflect.InvocationTargetException;
import java.util.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package component_construction.storable.dynamic_loading;
package storage.dynamic_loading;

import storage.external_interfaces.Loadable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package component_construction.storable.exceptions;
package storage.exceptions;

public class IncorrectlyFormattedException extends RuntimeException {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package component_construction.storable.exceptions;
package storage.exceptions;

import component_construction.storable.dynamic_loading.Loader;
import storage.dynamic_loading.Loader;

public class MissingEmptyConstructorException extends RuntimeException {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package storage.storage_value_adapters;
package storage.exceptions;

import storage.storage_values.StorageValue;

Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/storage/value_formatters/ValueFormatter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package storage.value_formatters;

import storage.storage_value_adapters.UnsupportedValueException;
import storage.exceptions.UnsupportedValueException;
import storage.storage_values.StorageValue;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.*;
import java.util.Map.Entry;

import storage.storage_value_adapters.UnsupportedValueException;
import storage.exceptions.UnsupportedValueException;
import storage.storage_values.*;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import code_generation.CodeGenerator;
import component_construction.storable.exceptions.*;
import lexical_analysis.LexicalAnalyser;
import storage.dynamic_loading.Factory;
import storage.storage_values.*;
import syntax_analysis.SyntaxAnalyser;
import test_aids.storage_entities.custom_components.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package component_construction.storable.dynamic_loading;
package storage.dynamic_loading;

import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;

import component_construction.storable.exceptions.IncorrectlyFormattedException;
import storage.exceptions.IncorrectlyFormattedException;
import test_aids.storage_entities.loadableby_entities.*;

public class LoadableByTests {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package component_construction.storable.dynamic_loading;
package storage.dynamic_loading;

import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;

import component_construction.storable.exceptions.MissingEmptyConstructorException;
import storage.exceptions.MissingEmptyConstructorException;
import test_aids.storage_entities.*;

public class LoaderTests {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package component_construction.storable.dynamic_loading;
package storage.dynamic_loading;

import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.junit.jupiter.api.Test;

import helper_objects.*;
import storage.storage_value_adapters.UnsupportedValueException;
import storage.exceptions.UnsupportedValueException;
import storage.storage_values.*;

public class ValueToStringFormatterTests {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package test_aids.storage_entities;

import component_construction.storable.dynamic_loading.Loader;
import storage.dynamic_loading.Loader;
import storage.storage_values.StorageValue;

public class IncorrectlyFormedLoader implements Loader<Boolean> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package test_aids.storage_entities;

import component_construction.storable.dynamic_loading.Loader;
import storage.dynamic_loading.Loader;
import storage.storage_values.StorageValue;

public class TestObjectLoader implements Loader<TestObject> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package test_aids.storage_entities.custom_components.loadable;

import code_generation.CodeGenerator;
import component_construction.storable.dynamic_loading.ReflectivelyLoadable;
import storage.dynamic_loading.ReflectivelyLoadable;
import storage.external_interfaces.*;
import storage.storage_values.*;
import syntax_analysis.parsing.ParseState;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package test_aids.storage_entities.custom_components.loadable;

import component_construction.storable.dynamic_loading.ReflectivelyLoadable;
import grammar_objects.Token;
import lexical_analysis.LexicalAnalyser;
import storage.dynamic_loading.ReflectivelyLoadable;
import storage.external_interfaces.Storable;
import storage.storage_values.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package test_aids.storage_entities.custom_components.loadable;

import component_construction.storable.dynamic_loading.ReflectivelyLoadable;
import grammar_objects.Token;
import storage.dynamic_loading.ReflectivelyLoadable;
import storage.external_interfaces.*;
import storage.storage_values.*;
import syntax_analysis.SyntaxAnalyser;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package test_aids.storage_entities.custom_components.loadableBy;

import component_construction.storable.dynamic_loading.Loader;
import storage.dynamic_loading.Loader;
import storage.storage_values.StorageValue;

public class LoadableByCustomLexicalAnalyserLoader implements Loader<LoadableByStorableCustomLexicalAnalyser> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package test_aids.storage_entities.custom_components.loadableBy;

import component_construction.storable.dynamic_loading.LoadableBy;
import grammar_objects.Token;
import lexical_analysis.LexicalAnalyser;
import storage.dynamic_loading.LoadableBy;
import storage.external_interfaces.Storable;
import storage.storage_values.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package test_aids.storage_entities.loadableby_entities;

import component_construction.storable.dynamic_loading.LoadableBy;
import storage.dynamic_loading.LoadableBy;

public class ConcretisedGenericTestLoadableObject <T> extends StandardLoader implements GenercicTestInterface<Boolean>, LoadableBy<StandardLoader> {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package test_aids.storage_entities.loadableby_entities;

import component_construction.storable.dynamic_loading.Loader;
import storage.dynamic_loading.Loader;
import storage.storage_values.StorageValue;

public class GenericLoader <T> implements Loader<T> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package test_aids.storage_entities.loadableby_entities;

import component_construction.storable.dynamic_loading.LoadableBy;
import storage.dynamic_loading.LoadableBy;

public class GenericTestLoadableObject <T> extends StandardLoader implements GenercicTestInterface<T>, LoadableBy<StandardLoader> {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package test_aids.storage_entities.loadableby_entities;

import component_construction.storable.dynamic_loading.LoadableBy;
import storage.dynamic_loading.LoadableBy;

public record GenericallyLoadableObject(int a) implements LoadableBy<GenericLoader<GenericallyLoadableObject>> {}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package test_aids.storage_entities.loadableby_entities;

import component_construction.storable.dynamic_loading.LoadableBy;
import storage.dynamic_loading.LoadableBy;

public record LoadableObject(int a) implements LoadableBy<StandardLoader> {}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package test_aids.storage_entities.loadableby_entities;

import component_construction.storable.dynamic_loading.Loader;
import storage.dynamic_loading.Loader;
import storage.storage_values.StorageValue;

public class StandardLoader implements Loader<LoadableObject> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package test_aids.storage_entities.loadableby_entities;

import component_construction.storable.dynamic_loading.LoadableBy;
import storage.dynamic_loading.LoadableBy;

public class TestLoadableObject extends StandardLoader implements TestInterface, LoadableBy<StandardLoader> {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package test_aids.storage_entities.loadableby_entities;

import component_construction.storable.dynamic_loading.*;
import storage.dynamic_loading.*;

public record WildcardLoadableObject(int a) implements LoadableBy<Loader<?>> {}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package test_aids.test_storage;

import storage.storage_value_adapters.UnsupportedValueException;
import storage.exceptions.UnsupportedValueException;
import storage.storage_values.StorageValue;
import storage.value_formatters.ValueFormatter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package test_aids.test_storage;

import storage.storage_value_adapters.UnsupportedValueException;
import storage.exceptions.UnsupportedValueException;
import storage.storage_values.StorageValue;
import storage.value_formatters.ValueFormatter;
import test_aids.exceptions.ExampleException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package test_aids.test_storage;

import storage.storage_value_adapters.UnsupportedValueException;
import storage.exceptions.UnsupportedValueException;
import storage.storage_values.StorageValue;
import storage.value_formatters.ValueFormatter;

Expand Down
Loading