| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Sequence |
|
| 0.0;0 |
| 1 | /* | |
| 2 | Copyright 2004-2008 Paul R. Holser, Jr. All rights reserved. | |
| 3 | Licensed under the Academic Free License version 3.0 | |
| 4 | */ | |
| 5 | ||
| 6 | package jaggregate; | |
| 7 | ||
| 8 | /** | |
| 9 | * Provides protocol for writing to an ordered collection of objects whose | |
| 10 | * <dfn>elements</dfn> can be accessed using external integer <dfn>keys</dfn>. | |
| 11 | * | |
| 12 | * @param <E> a restriction on the types of elements that may be included in the | |
| 13 | * sequence | |
| 14 | * | |
| 15 | * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a> | |
| 16 | * @version $Id: Sequence.java,v 1.4 2008/05/07 06:00:48 pholser Exp $ | |
| 17 | */ | |
| 18 | public interface Sequence<E> extends ReadOnlySequence<E> { | |
| 19 | /** | |
| 20 | * {@inheritDoc} | |
| 21 | * | |
| 22 | * @return a sequence of transformations | |
| 23 | */ | |
| 24 | <R> Sequence<R> collect( UnaryFunctor<? super E, ? extends R> transformer ); | |
| 25 | ||
| 26 | /** | |
| 27 | * {@inheritDoc} | |
| 28 | * | |
| 29 | * @return a sequence of rejects | |
| 30 | */ | |
| 31 | Sequence<E> reject( UnaryCondition<? super E> discriminator ); | |
| 32 | ||
| 33 | /** | |
| 34 | * {@inheritDoc} | |
| 35 | * | |
| 36 | * @return a sequence of selections | |
| 37 | */ | |
| 38 | Sequence<E> select( UnaryCondition<? super E> discriminator ); | |
| 39 | ||
| 40 | /** | |
| 41 | * {@inheritDoc} | |
| 42 | */ | |
| 43 | Sequence<E> concat( ReadOnlySequence<? extends E> otherSequence ); | |
| 44 | ||
| 45 | /** | |
| 46 | * {@inheritDoc} | |
| 47 | */ | |
| 48 | Sequence<E> copyRange( int start, int stop ); | |
| 49 | ||
| 50 | /** | |
| 51 | * {@inheritDoc} | |
| 52 | */ | |
| 53 | Sequence<E> copyWith( E newElement ); | |
| 54 | ||
| 55 | /** | |
| 56 | * {@inheritDoc} | |
| 57 | */ | |
| 58 | Sequence<E> copyWithout( E oldElement ); | |
| 59 | ||
| 60 | /** | |
| 61 | * {@inheritDoc} | |
| 62 | */ | |
| 63 | Sequence<E> reverse(); | |
| 64 | ||
| 65 | /** | |
| 66 | * Replaces the element in this sequence at a given index with a new element. | |
| 67 | * | |
| 68 | * @param index the index at which to replace the element | |
| 69 | * @param newElement the element to place at {@code index} | |
| 70 | * @return the previous element at {@code index}, or {@code null} if there is | |
| 71 | * no such element | |
| 72 | * @throws IndexOutOfBoundsException if {@code index < 0} or {@code index >=} this | |
| 73 | * sequence's {@linkplain #size() size} | |
| 74 | */ | |
| 75 | E putAt( int index, E newElement ); | |
| 76 | ||
| 77 | /** | |
| 78 | * Replaces the elements in this sequence specified by the given indices with a new | |
| 79 | * element. | |
| 80 | * <p/> | |
| 81 | * This message is equivalent to storing {@code newElement} in this sequence at | |
| 82 | * each index specified by {@code indices} using {@link #putAt(int,Object) putAt}. | |
| 83 | * | |
| 84 | * @param indices the indices at which to replace elements | |
| 85 | * @param newElement the element to place at each of the {@code indices} | |
| 86 | * @throws NullPointerException if {@code indices} or any of its elements is | |
| 87 | * {@code null} | |
| 88 | * @throws IndexOutOfBoundsException if any element of {@code indices} is | |
| 89 | * {@code < 0} or {@code >=} this sequence's {@linkplain #size() size} | |
| 90 | */ | |
| 91 | void putAtAll( Collection<? extends Integer> indices, E newElement ); | |
| 92 | ||
| 93 | /** | |
| 94 | * @see #putAtAll(Collection,Object) | |
| 95 | * @param indices the indices at which to replace elements | |
| 96 | * @param newElement the element to place at each of the {@code indices} | |
| 97 | * @throws NullPointerException if {@code indices} or any of its elements is | |
| 98 | * {@code null} | |
| 99 | * @throws IndexOutOfBoundsException if any element of {@code indices} is | |
| 100 | * {@code < 0} or {@code >=} this sequence's {@linkplain #size() size} | |
| 101 | */ | |
| 102 | void putAtAll( int[] indices, E newElement ); | |
| 103 | ||
| 104 | /** | |
| 105 | * @param indices the indices at which to replace elements | |
| 106 | * @param newElement the element to place at each of the {@code indices} | |
| 107 | * @throws NullPointerException if {@code indices} or any of its elements is | |
| 108 | * {@code null} | |
| 109 | * @throws IndexOutOfBoundsException if any element of {@code indices} is | |
| 110 | * {@code < 0} or {@code >=} this sequence's {@linkplain #size() size} | |
| 111 | * @see #putAtAll(Collection,Object) | |
| 112 | */ | |
| 113 | void putAtAll( Integer[] indices, E newElement ); | |
| 114 | ||
| 115 | /** | |
| 116 | * @see #putAtAll(Collection,Object) | |
| 117 | * @param indices the indices at which to replace elements | |
| 118 | * @param newElement the element to place at each of the {@code indices} | |
| 119 | * @throws NullPointerException if {@code indices} or any of its elements is | |
| 120 | * {@code null} | |
| 121 | * @throws IndexOutOfBoundsException if any element of {@code indices} is | |
| 122 | * {@code < 0} or {@code >=} this sequence's {@linkplain #size() size} | |
| 123 | */ | |
| 124 | void putAtAll( Iterable<? extends Integer> indices, E newElement ); | |
| 125 | ||
| 126 | /** | |
| 127 | * Replaces all the elements in this sequence with a new element. | |
| 128 | * <p/> | |
| 129 | * This message is equivalent to storing {@code newElement} in this sequence at each | |
| 130 | * index from {@code 0} to this sequence's {@linkplain #size() size} minus 1 using | |
| 131 | * {@link #putAt(int,Object) putAt}. | |
| 132 | * | |
| 133 | * @param newElement the element to place at each index | |
| 134 | */ | |
| 135 | void putAtAll( E newElement ); | |
| 136 | ||
| 137 | /** | |
| 138 | * Replaces the elements of this sequence between two positions, inclusive, with a | |
| 139 | * given element. | |
| 140 | * | |
| 141 | * @param start beginning index | |
| 142 | * @param stop ending index | |
| 143 | * @param replacement element with which to replace the elements between | |
| 144 | * {@code start} and {@code stop}, inclusive | |
| 145 | * @throws IndexOutOfBoundsException if either {@code start} or {@code stop} is | |
| 146 | * {@code < 0} or {@code >=} this sequence's {@linkplain #size() size} | |
| 147 | */ | |
| 148 | void replace( int start, int stop, E replacement ); | |
| 149 | ||
| 150 | /** | |
| 151 | * Replaces the elements of this sequence between two positions, inclusive, with a | |
| 152 | * given replacement sequence in their original order. | |
| 153 | * <p/> | |
| 154 | * The first element of {@code replacements} is stored in this sequence at position | |
| 155 | * {@code start}, the second at position {@code start + 1}, etc. Any previously | |
| 156 | * stored elements at these positions are replaced. | |
| 157 | * <p/> | |
| 158 | * @param start beginning index | |
| 159 | * @param stop ending index | |
| 160 | * @param replacements elements to replace in between {@code start} and | |
| 161 | * {@code stop}, inclusive | |
| 162 | * @throws NullPointerException if {@code replacements} is {@code null} | |
| 163 | * @throws IndexOutOfBoundsException if either {@code start} or {@code stop} is | |
| 164 | * {@code < 0} or {@code >=} this sequence's {@linkplain #size() size} | |
| 165 | * @throws IllegalArgumentException if the {@linkplain #size() size} of | |
| 166 | * {@code replacements} is not equal to {@code stop - start + 1} | |
| 167 | */ | |
| 168 | void replaceRange( int start, int stop, ReadOnlySequence<? extends E> replacements ); | |
| 169 | ||
| 170 | /** | |
| 171 | * Replaces the elements of this sequence between two positions, inclusive, with a | |
| 172 | * given replacement sequence, in their original order, starting at a given | |
| 173 | * position in the replacement sequence. | |
| 174 | * <p/> | |
| 175 | * The element at position {@code replacementStart} in {@code replacements} | |
| 176 | * is stored in this sequence at position {@code start}; the element at | |
| 177 | * {@code replacementStart + 1} is stored at position {@code start + 1}; etc. | |
| 178 | * Any previously stored elements at these positions are replaced. | |
| 179 | * | |
| 180 | * @param start beginning index | |
| 181 | * @param stop ending index | |
| 182 | * @param replacements elements to replace in between {@code start} and | |
| 183 | * {@code stop}, inclusive | |
| 184 | * @param replacementStart index to start at in {@code replacements} | |
| 185 | * @throws NullPointerException if {@code replacements} is {@code null} | |
| 186 | * @throws IndexOutOfBoundsException if either {@code start} or {@code stop} is | |
| 187 | * {@code < 0} or {@code >=} this sequence's {@linkplain #size() size}, or if | |
| 188 | * {@code replacementStart} is {@code < 0} or {@code >=} {@code replacements}'s | |
| 189 | * {@linkplain #size() size} | |
| 190 | * @throws IllegalArgumentException if the {@linkplain #size() size} of | |
| 191 | * {@code replacements} is not equal to {@code replacementStart + stop - start} | |
| 192 | */ | |
| 193 | void replaceRange( int start, int stop, ReadOnlySequence<? extends E> replacements, | |
| 194 | int replacementStart ); | |
| 195 | } |