All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.leeonky.jfactory.MemoryDataRepository Maven / Gradle / Ivy

There is a newer version: 0.7.2
Show newest version
package com.github.leeonky.jfactory;

import java.util.*;

public class MemoryDataRepository implements DataRepository {
    private Map, Set> repo = new HashMap<>();

    @Override
    public void save(Object object) {
        if (object != null)
            repo.computeIfAbsent(object.getClass(), c -> new LinkedHashSet<>()).add(object);
    }

    @Override
    @SuppressWarnings("unchecked")
    public  Collection queryAll(Class type) {
        return (Collection) repo.getOrDefault(type, Collections.emptySet());
    }

    @Override
    public void clear() {
        repo.clear();
    }
}