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

com.lyncode.xoai.dataprovider.repository.InMemoryItemRepository Maven / Gradle / Ivy

package com.lyncode.xoai.dataprovider.repository;

import com.lyncode.xoai.dataprovider.exceptions.IdDoesNotExistException;
import com.lyncode.xoai.dataprovider.exceptions.OAIException;
import com.lyncode.xoai.dataprovider.filter.ScopedFilter;
import com.lyncode.xoai.dataprovider.handlers.results.ListItemIdentifiersResult;
import com.lyncode.xoai.dataprovider.handlers.results.ListItemsResults;
import com.lyncode.xoai.dataprovider.model.InMemoryItem;
import com.lyncode.xoai.dataprovider.model.Item;
import com.lyncode.xoai.dataprovider.model.ItemIdentifier;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static java.lang.Math.min;
import static java.util.Arrays.asList;

public class InMemoryItemRepository implements ItemRepository {
    private List list = new ArrayList();

    public InMemoryItemRepository withNoItems() {
        return this;
    }

    public InMemoryItemRepository withItem(InMemoryItem item) {
        list.add(item);
        return this;
    }

    public InMemoryItemRepository withItems(InMemoryItem... item) {
        list.addAll(asList(item));
        return this;
    }

    public InMemoryItemRepository withRandomItems(int number) {
        for (int i = 0; i < number; i++)
            list.add(InMemoryItem.randomItem());
        return this;
    }

    @Override
    public Item getItem(String identifier) throws IdDoesNotExistException, OAIException {
        for (InMemoryItem item : this.list) {
            if (item.getIdentifier().equals(identifier))
                return item;
        }
        throw new IdDoesNotExistException();
    }

    @Override
    public ListItemIdentifiersResult getItemIdentifiers(List filters, int offset, int length) throws OAIException {
        return new ListItemIdentifiersResult(offset + length < list.size(), new ArrayList(list.subList(offset, min(offset + length, list.size()))));
    }

    @Override
    public ListItemIdentifiersResult getItemIdentifiers(List filters, int offset, int length, Date from) throws OAIException {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public ListItemIdentifiersResult getItemIdentifiersUntil(List filters, int offset, int length, Date until) throws OAIException {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public ListItemIdentifiersResult getItemIdentifiers(List filters, int offset, int length, Date from, Date until) throws OAIException {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public ListItemIdentifiersResult getItemIdentifiers(List filters, int offset, int length, String setSpec) throws OAIException {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public ListItemIdentifiersResult getItemIdentifiers(List filters, int offset, int length, String setSpec, Date from) throws OAIException {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public ListItemIdentifiersResult getItemIdentifiersUntil(List filters, int offset, int length, String setSpec, Date until) throws OAIException {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public ListItemIdentifiersResult getItemIdentifiers(List filters, int offset, int length, String setSpec, Date from, Date until) throws OAIException {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public ListItemsResults getItems(List filters, int offset, int length) throws OAIException {
        return new ListItemsResults(offset + length < list.size(), new ArrayList(list.subList(offset, min(offset + length, list.size()))));
    }

    @Override
    public ListItemsResults getItems(List filters, int offset, int length, Date from) throws OAIException {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public ListItemsResults getItemsUntil(List filters, int offset, int length, Date until) throws OAIException {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public ListItemsResults getItems(List filters, int offset, int length, Date from, Date until) throws OAIException {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public ListItemsResults getItems(List filters, int offset, int length, String setSpec) throws OAIException {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public ListItemsResults getItems(List filters, int offset, int length, String setSpec, Date from) throws OAIException {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public ListItemsResults getItemsUntil(List filters, int offset, int length, String setSpec, Date until) throws OAIException {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public ListItemsResults getItems(List filters, int offset, int length, String setSpec, Date from, Date until) throws OAIException {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy