summaryrefslogtreecommitdiff
path: root/src/main/java/com/p4square/grow/provider/CollectionProvider.java
blob: e4e904063c1ab286ac768a8ae7f47e1eae338797 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * Copyright 2013 Jesse Morgan
 */

package com.p4square.grow.provider;

import java.io.IOException;
import java.util.Map;

/**
 * ListProvider is the logical extension of Provider for dealing with lists of
 * items.
 *
 * @param C The type of the collection key.
 * @param K The type of the item key.
 * @param V The type of the value.
 *
 * @author Jesse Morgan <jesse@jesterpm.net>
 */
public interface CollectionProvider<C, K, V> {
    /**
     * Retrieve a specific object from the collection.
     *
     * @param collection The collection key.
     * @param key The key for the object in the collection.
     * @return The object or null if not found.
     */
    V get(C collection, K key) throws IOException;

    /**
     * Retrieve a collection.
     *
     * The returned map will never be null.
     *
     * @param collection The collection key.
     * @return A Map of keys to values.
     */
    Map<K, V> query(C collection) throws IOException;

    /**
     * Retrieve a portion of a collection.
     *
     * The returned map will never be null.
     *
     * @param collection The collection key.
     * @param limit Max number of items to return.
     * @return A Map of keys to values.
     */
    Map<K, V> query(C collection, int limit) throws IOException;

    /**
     * Persist the object with the given key.
     *
     * @param collection The collection key.
     * @param key The key for the object in the collection.
     * @param obj The object to persist.
     */
    void put(C collection, K key, V obj) throws IOException;
}