com.robrua.orianna.store.DataStore Maven / Gradle / Ivy
package com.robrua.orianna.store;
import java.util.Collections;
import java.util.List;
import com.robrua.orianna.type.core.OriannaObject;
/**
* Interface for local storage, be it in-memory, on disk, or otherwise
*
* @author Rob Rua (FatalElement - NA) ([email protected])
*/
public abstract class DataStore {
/**
* @return true if this DataStore doesn't need key information to store data
*/
protected abstract boolean allowsNullStoreKeys();
/**
* @param
* the type of object to check for
* @param type
* the type of object to check for
* @return whether the data store contains the full set of possible objects
* of this type
*/
protected abstract > boolean checkHasAll(Class type);
/**
* @param
* the type of object to delete
* @param type
* the type of object to delete
* @param keys
* the keys to delete
*/
public > void delete(final Class type, final List> keys) {
if(type == null || keys == null || keys.isEmpty()) {
return;
}
doDelete(type, keys);
}
/**
* @param
* the type of object to delete
* @param type
* the type of object to delete
* @param key
* the key to delete
*/
public > void delete(final Class type, final Object key) {
if(type == null || key == null) {
return;
}
doDelete(type, key);
}
/**
* @param
* the type of object to delete
* @param type
* the type of object to delete
* @param keys
* the keys to delete
*/
protected abstract > void doDelete(Class type, List> keys);
/**
* @param
* the type of object to delete
* @param type
* the type of object to delete
* @param key
* the key to delete
*/
protected abstract > void doDelete(Class type, Object key);
/**
* @param
* the type of object to get
* @param type
* the type of object to get
* @param keys
* the keys to get
* @return a list of retrieved objects (same length as keys list, with null
* entries if not found)
*/
protected abstract > List doGet(Class type, List> keys);
/**
* @param
* the type of object to get
* @param type
* the type of object to get
* @param key
* the key to get
* @return the retrieved object (null if not found)
*/
protected abstract > T doGet(Class type, Object key);
/**
* @param
* the type of object to get
* @param type
* the type of object to get
* @return all objects of that type in the data store
*/
protected abstract > List doGetAll(Class type);
/**
* @param
* the type of object to get
* @param type
* the type of object to get
* @return an iterator over objects of that type in the data store
*/
protected abstract > CloseableIterator doGetIterator(final Class type);
/**
* @param
* the type of object to store
* @param objs
* the objects to store
* @param keys
* the keys to store them with
* @param isFullSet
* whether these are all the objects of that type that can exist
*/
protected abstract > void doStore(List objs, List> keys, boolean isFullSet);
/**
* @param
* the type of object to store
* @param obj
* the object to store
* @param key
* the key to store it with
*/
protected abstract > void doStore(T obj, Object key);
/**
* @param
* the type of object to get
* @param type
* the type of object to get
* @param keys
* the keys to get
* @return a list of retrieved objects (same length as keys list, with null
* entries if not found)
*/
public > List get(final Class type, final List> keys) {
if(type == null || keys == null || keys.isEmpty()) {
return Collections.emptyList();
}
return doGet(type, keys);
}
/**
* @param
* the type of object to get
* @param type
* the type of object to get
* @param key
* the key to get
* @return the retrieved object (null if not found)
*/
public > T get(final Class type, final Object key) {
if(type == null || key == null) {
return null;
}
return doGet(type, key);
}
/**
* @param
* the type of object to get
* @param type
* the type of object to get
* @return all objects of that type in the data store
*/
public > List getAll(final Class type) {
if(type == null) {
return Collections.emptyList();
}
return doGetAll(type);
}
/**
* @param
* the type of object to get
* @param type
* the type of object to get
* @return an iterator over objects of that type in the data store
*/
public > CloseableIterator getIterator(final Class type) {
if(type == null) {
return CloseableIterator.emptyIterator();
}
return doGetIterator(type);
}
/**
* @param
* the type of object to check for
* @param type
* the type of object to check for
* @return whether the data store contains the full set of possible objects
* of this type
*/
public > boolean hasAll(final Class type) {
if(type == null) {
return false;
}
return checkHasAll(type);
}
/**
* @param
* the type of object to store
* @param objs
* the objects to store
* @param keys
* the keys to store them with
* @param isFullSet
* whether these are all the objects of that type that can exist
*/
public > void store(final List objs, final List> keys, final boolean isFullSet) {
if(objs == null || !allowsNullStoreKeys() && (keys == null || objs.size() != keys.size()) || objs.isEmpty()) {
return;
}
doStore(objs, keys, isFullSet);
}
/**
* @param
* the type of object to store
* @param obj
* the object to store
* @param key
* the key to store it with
*/
public > void store(final T obj, final Object key) {
if(obj == null || !allowsNullStoreKeys() && key == null) {
return;
}
doStore(obj, key);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy