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

io.github.amayaframework.di.RepositoryImpl Maven / Gradle / Ivy

package io.github.amayaframework.di;

import com.github.romanqed.jfunc.Function0;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

final class RepositoryImpl implements Repository {
    private final Map> body;

    RepositoryImpl() {
        this.body = new HashMap<>();
    }

    @Override
    public Function0 get(Artifact artifact) {
        return body.get(artifact);
    }

    @Override
    public Iterable getAll() {
        return Collections.unmodifiableCollection(body.keySet());
    }

    @Override
    public boolean contains(Artifact artifact) {
        return body.containsKey(artifact);
    }

    @Override
    public void add(Artifact artifact, Function0 supplier) {
        body.put(artifact, supplier);
    }

    @Override
    public boolean remove(Artifact artifact) {
        return body.remove(artifact) != null;
    }

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