|
1 | 1 | package com.oneandone.typedrest; |
2 | 2 |
|
| 3 | +import java.io.FileNotFoundException; |
| 4 | +import java.io.IOException; |
| 5 | + |
3 | 6 | /** |
4 | 7 | * REST endpoint that represents a collection of <code>TEntity</code>s as |
5 | 8 | * {@link ElementEndpoint}s. |
|
8 | 11 | */ |
9 | 12 | public interface CollectionEndpoint<TEntity> |
10 | 13 | extends GenericCollectionEndpoint<TEntity, ElementEndpoint<TEntity>> { |
| 14 | + |
| 15 | + /** |
| 16 | + * Determines whether the collection contains a specific entity. |
| 17 | + * |
| 18 | + * @param id The ID identifying the entity in the collection. |
| 19 | + * @return <code>true</code> if the entity currently exists, |
| 20 | + * <code>false</code> if it does not. |
| 21 | + * |
| 22 | + * @throws IOException Network communication failed. |
| 23 | + * @throws IllegalAccessException {@link HttpStatus#SC_UNAUTHORIZED} or |
| 24 | + * {@link HttpStatus#SC_FORBIDDEN} |
| 25 | + * @throws RuntimeException Other non-success status code. |
| 26 | + */ |
| 27 | + default boolean contains(String id) |
| 28 | + throws IOException, IllegalAccessException { |
| 29 | + return get(id).exists(); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Determines whether the collection contains a specific entity. |
| 34 | + * |
| 35 | + * @param element The element to be checked. |
| 36 | + * @return <code>true</code> if the entity currently exists, |
| 37 | + * <code>false</code> if it does not. |
| 38 | + * |
| 39 | + * @throws IOException Network communication failed. |
| 40 | + * @throws IllegalAccessException {@link HttpStatus#SC_UNAUTHORIZED} or |
| 41 | + * {@link HttpStatus#SC_FORBIDDEN} |
| 42 | + * @throws RuntimeException Other non-success status code. |
| 43 | + */ |
| 44 | + default boolean contains(TEntity element) |
| 45 | + throws IOException, IllegalAccessException { |
| 46 | + return get(element).exists(); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Sets/replaces an existing element in the collection. |
| 51 | + * |
| 52 | + * @param element The new state of the element. |
| 53 | + * @return The <code>TEntity</code> as returned by the server, possibly with |
| 54 | + * additional fields set. <code>null</code> if the server does not respond |
| 55 | + * with a result entity. |
| 56 | + * @throws IOException Network communication failed. |
| 57 | + * @throws IllegalArgumentException {@link HttpStatus#SC_BAD_REQUEST} |
| 58 | + * @throws IllegalAccessException {@link HttpStatus#SC_UNAUTHORIZED} or |
| 59 | + * {@link HttpStatus#SC_FORBIDDEN} |
| 60 | + * @throws FileNotFoundException {@link HttpStatus#SC_NOT_FOUND} or |
| 61 | + * {@link HttpStatus#SC_GONE} |
| 62 | + * @throws IllegalStateException The entity has changed since it was last |
| 63 | + * retrieved with {@link #read()}. Your changes were rejected to prevent a |
| 64 | + * lost update. |
| 65 | + * @throws RuntimeException Other non-success status code. |
| 66 | + */ |
| 67 | + default TEntity set(TEntity element) |
| 68 | + throws IOException, IllegalArgumentException, IllegalAccessException, FileNotFoundException, IllegalStateException { |
| 69 | + return get(element).set(element); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Modifies an existing element in the collection by merging changes. |
| 74 | + * |
| 75 | + * @param element The <code>TEntity</code> data to merge with the existing |
| 76 | + * element. |
| 77 | + * @return The <code>TEntity</code> as returned by the server, possibly with |
| 78 | + * additional fields set. <code>null</code> if the server does not respond |
| 79 | + * with a result entity. |
| 80 | + * @throws IOException Network communication failed. |
| 81 | + * @throws IllegalArgumentException {@link HttpStatus#SC_BAD_REQUEST} |
| 82 | + * @throws IllegalAccessException {@link HttpStatus#SC_UNAUTHORIZED} or |
| 83 | + * {@link HttpStatus#SC_FORBIDDEN} |
| 84 | + * @throws FileNotFoundException {@link HttpStatus#SC_NOT_FOUND} or |
| 85 | + * {@link HttpStatus#SC_GONE} |
| 86 | + * @throws IllegalStateException The entity has changed since it was last |
| 87 | + * retrieved with {@link #read()}. Your changes were rejected to prevent a |
| 88 | + * lost update. |
| 89 | + * @throws RuntimeException Other non-success status code. |
| 90 | + */ |
| 91 | + default TEntity merge(TEntity element) |
| 92 | + throws IOException, IllegalArgumentException, IllegalAccessException, FileNotFoundException, IllegalStateException { |
| 93 | + return get(element).merge(element); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Deletes an existing element from the collection. |
| 98 | + * |
| 99 | + * @param id The ID identifying the entity in the collection. |
| 100 | + * @throws IOException Network communication failed. |
| 101 | + * @throws IllegalArgumentException {@link HttpStatus#SC_BAD_REQUEST} |
| 102 | + * @throws IllegalAccessException {@link HttpStatus#SC_UNAUTHORIZED} or |
| 103 | + * {@link HttpStatus#SC_FORBIDDEN} |
| 104 | + * @throws FileNotFoundException {@link HttpStatus#SC_NOT_FOUND} or |
| 105 | + * {@link HttpStatus#SC_GONE} |
| 106 | + * @throws IllegalStateException The entity has changed since it was last |
| 107 | + * retrieved with {@link #read()}. Your delete call was rejected to prevent |
| 108 | + * a lost update. |
| 109 | + * @throws RuntimeException Other non-success status code. |
| 110 | + */ |
| 111 | + default void delete(String id) |
| 112 | + throws IOException, IllegalArgumentException, IllegalAccessException, FileNotFoundException, IllegalStateException { |
| 113 | + get(id).delete(); |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Deletes an existing element from the collection. |
| 118 | + * |
| 119 | + * @param element The element to be deleted. |
| 120 | + * @throws IOException Network communication failed. |
| 121 | + * @throws IllegalArgumentException {@link HttpStatus#SC_BAD_REQUEST} |
| 122 | + * @throws IllegalAccessException {@link HttpStatus#SC_UNAUTHORIZED} or |
| 123 | + * {@link HttpStatus#SC_FORBIDDEN} |
| 124 | + * @throws FileNotFoundException {@link HttpStatus#SC_NOT_FOUND} or |
| 125 | + * {@link HttpStatus#SC_GONE} |
| 126 | + * @throws IllegalStateException The entity has changed since it was last |
| 127 | + * retrieved with {@link #read()}. Your delete call was rejected to prevent |
| 128 | + * a lost update. |
| 129 | + * @throws RuntimeException Other non-success status code. |
| 130 | + */ |
| 131 | + default void delete(TEntity element) |
| 132 | + throws IOException, IllegalArgumentException, IllegalAccessException, FileNotFoundException, IllegalStateException { |
| 133 | + get(element).delete(); |
| 134 | + } |
11 | 135 | } |
0 commit comments