Skip to content
This repository has been archived by the owner on Jul 29, 2022. It is now read-only.

kerelape/memoria

Repository files navigation

Warning Functionality of this library is now in reikai

Memoria

Why should an object care about where to store their bytes?

EO principles respected here DevOps By Rultor.com We recommend IntelliJ IDEA

Code quality Code grade

Examples

Basics

RAM can used as a memory storage:

val ram: BytesMemory = RamMemory()

Also a file could:

val cache: BytesMemory = FileMemory(File("//path"))

Restrictions

If you do not want your object to suddenly take to much space:

BoundedBytesMemory(
    min = 0, // might be omitted (0 by default)
    max = 128,
    RamMemory()
)

Thus, once the limit is overflown you'll see IllegalArgumentExcepton

Useful

Primitives

There is a number of adapters to kotlin 'primitives'. These use BytesMemory to store the value, but acts as memory of their type:

  • StringMemory implements MutableMemory<String>, so you can write("Hello, World") instread of working with bytes.
  • IntMemory.

TwinMemory

TwinMemory class allows you to have two different (or the same... why not) memory sources:

val twin = StringMemory(
    TwinMemory(
        RamMemory(),
        FileMemory(
            File("twin.txt")
        )
    )
)

twin.write("twin me!") // -> will write the value to both sources, ram and file
twin.value() // -> returns value stored in ram, the first (origin) argument of the constructor