net.dschinghis-kahn:objectstore

A data store with size limitation capabilities.

License

License

Categories

Categories

Net
GroupId

GroupId

net.dschinghis-kahn
ArtifactId

ArtifactId

objectstore
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

net.dschinghis-kahn:objectstore
A data store with size limitation capabilities.
Project URL

Project URL

https://github.com/Dschinghis-Kahn/objectstore
Source Code Management

Source Code Management

https://github.com/Dschinghis-Kahn/objectstore

Download objectstore

How to add to project

<!-- https://jarcasting.com/artifacts/net.dschinghis-kahn/objectstore/ -->
<dependency>
    <groupId>net.dschinghis-kahn</groupId>
    <artifactId>objectstore</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/net.dschinghis-kahn/objectstore/
implementation 'net.dschinghis-kahn:objectstore:1.0'
// https://jarcasting.com/artifacts/net.dschinghis-kahn/objectstore/
implementation ("net.dschinghis-kahn:objectstore:1.0")
'net.dschinghis-kahn:objectstore:jar:1.0'
<dependency org="net.dschinghis-kahn" name="objectstore" rev="1.0">
  <artifact name="objectstore" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.dschinghis-kahn', module='objectstore', version='1.0')
)
libraryDependencies += "net.dschinghis-kahn" % "objectstore" % "1.0"
[net.dschinghis-kahn/objectstore "1.0"]

Dependencies

compile (1)

Group / Artifact Type Version
log4j : log4j jar 1.2.17

test (2)

Group / Artifact Type Version
junit : junit jar 4.11
org.apache.maven.plugins : maven-surefire-plugin maven-plugin 2.16

Project Modules

There are no modules declared in this project.

objectstore

A data store with size limitation capabilities.

##Features

  • Easy to use
  • Blocks add method when full
  • Can prioritize its items

##Example

public class TaskStore {

    private ObjectStore<Task> store;

    public static void main(String[] args) {
        TaskStore taskStore = new TaskStore();
        taskStore.addTask(new Task(0));
        taskStore.addTask(new Task(1));
        taskStore.addTask(new Task(3));

        // this task will be sorted to the correct position
        taskStore.addTask(new Task(2));

        taskStore.addTask(new Task(4));

       /*
         * At this point the store holds these tasks in order: 
         * 1. Task(0) 
         * 2. Task(1) 
         * 3. Task(2) 
         * 4. Task(3) 
         * 5. Task(4)
         */

        // this method will block because the store is full now
        taskStore.addTask(new Task(5));
    }

    public TaskStore() {
        // An Object store with maxSize=5 and priorized=true is created
        store = new ObjectStore<Task>(5, true);
    }

    public void addTask(Task task) {
        // Just add the task, the method will block if necessary
        store.add(task);
    }

    public Task getNextTask() {
        return store.get();
    }

}
public class Task implements Comparable<Task> {

    private Integer id;

    public Task(int id) {
        this.id = id;
    }

    @Override
    public int compareTo(Task o) {
        return id.compareTo(o.id);
    }

    @Override
    public String toString() {
        return "Task [id=" + id + "]";
    }
    
}

Versions

Version
1.0