# Manipulator Java SequenceIterator Methods

> The manipulator Java SequenceIterator methods take a variety of sequence arguments and produce result sequences as described in the table below:

> `SequenceIterator parse(String val, Sequence.Type type)` | Construct a sequence from the string literal `val` or the `type` specified; i.e. "{1.0, -1.1, 0}"
> `SequenceIterator map(SequenceIterator positions)` | Extract from the underlying sequence the elements with positions specified in the provided sequence. The `positions` should be provided in ascending order (they are intended to be obtained using methods `filterPos()`or `topPos()`)
> `SequenceIterator[] tee()` | Fork the sequence iterator; i.e. create two instances of iterators for the same sequence. These iterators should be traversed together (used in the same expression). Return an array with the pair of forked iterators
> `SequenceIterator constant(double val, Sequence.Type type)` | Construct a sequence of the `type` specified with the double constant value `val`
> `SequenceIterator constant(long val, Sequence.Type type)` | Construct a sequence of the `type` specified with the long constant value `val`
> `SequenceIterator constant(byte[] val, Sequence.Type type)` | Construct a sequence of the `type` specified with the byte array constant value `val`
> `SequenceIterator concat(SequenceIterator tail)` | Concatenate the two sequences: eg. for sequence `{1,2,3}`, `concat({4,5})` would produce result sequence `{1,2,3,4,5}`. Return result sequence iterator
> `SequenceIterator cat(SequenceIterator other)` | Concatenate the two sequences: eg. for sequence `{('a','b','c'}`, `cat({'x','y','z'})` would produce result sequence `{'ax', 'by', 'cz'}`. Return result sequence iterator
> SequenceIterator unique() | Copy to the result sequence only the unique elements in ordered sequence input by "collapsing duplicates"
> SequenceIterator normalize() | Return the normalized input sequence; i.e. divide each sequence element by the square root of the sum of squares of all elements
> SequenceIterator thin(long origin, long step) | Copy the input sequence to result selecting elements with the specified origin and step
> SequenceIterator limit(long from, long till) | Copy to the result sequence the sub-sequence from the input using sequence positions from and till.
> SequenceIterator reverse() | Return in result the sequence in reverse order
> SequenceIterator diff() | Return in result the differences between pairs of sequence elements in input.
> SequenceIterator trend() | Return in result the value 1, -1 or 0 determined by comparing pairs of element values to determine if the values are trending up or down (See page SQL Sequence Trend Function for a detailed description)
> SequenceIterator repeat(int count) | Return in result each element of the input sequence repeated n_times times.
> SequenceIterator stretch(SequenceIterator ts1, SequenceIterator ts2, long filler) also SequenceIterator stretch(SequenceIterator ts1, SequenceIterator ts2, double filler) | Return in result the elements of the values sequence stretched to the length of the ts1 sequence by repeating the elements of values while the corresponding timestamp in sequence ts2 is larger than timestamp from ts1. Use the filler values for elements where the corresponding timestamp in sequence ts2 is less than timestamp from ts1. For example, assume ts1 = `{1,2,3,4,5}`, ts2 = `{2,4}`, values = `{1.1,2.2}` and filler =`1.0`. With these input sequences the result will be `{1.1,2.2,2.2,1.0,1.0}`. (This method can be used to calculate split adjusted price where it is necessary to revert time series of splits, calculate the cumulative product and multiply on price.)
> SequenceIterator stretch0(SequenceIterator ts1, SequenceIterator ts2, long filler) also SequenceIterator stretch0(SequenceIterator ts1, SequenceIterator ts2, double filler) | Return in result the elements of the values and filler sequences by injecting the elements of values where the corresponding timestamps in sequence ts2 match the timestamp from ts1. Use the filler values for elements where the timestamp in sequence ts2 has no matching timestamp in ts1. For example, assume ts1 = `{1,2,3,5}`, ts2 = `{2,3,4}`, values = `{1.1,1.2,1.3}` and filler = `0.0`. With these input sequences the result will be `{0.0,1.1,1.2,1.3,0.0}`.
> SequenceIterator asofJoin(SequenceIterator ts1, SequenceIterator ts2) | Return in result the elements of the values sequence corresponding to the timestamp of ts2 closest to the timestamp of ts1. For example, assume ts1 = `{4,9}`, ts2 = `{1,3,6,10}`, and values = `{0.1,0.3,0.6,1.0}`. With these input sequences the result will be `{0.3,1.0}`.
> SequenceIterator cast(Sequence.Type type) | Return in result the sequence converted to the specified `type`
> SequenceIterator cross(int firstCrossDirection) | Return in result the positions in the input sequence where it crosses zero. If the integer argument first_cross_direction is positive then the result sequence starts with the first cross above zero; if negative it starts with cross below zero; if first_cross_direction is zero then it doesn't matter, i.e. the first cross can be above or below zero.
> SequenceIterator extrema(int firstExtremum) | Return in result the positions of extrema (local minimum and maximums) in the input sequence. If the integer argument first_extremum is positive then the result sequence starts with first local maximum; if negative it starts with with local minimum; if first_extremum is zero then it doesn't matter.
> SequenceIterator hash() also SequenceIterator hash(SequenceIterator other) |

> ## Example

> Following is an example code snippet demonstrating sequence manipulator methods:

>         public static void windowAggregate(Connection con)
>         {
>             con.startTransaction(Database.TransactionType.ReadOnly);
>             Cursor<Quote> cursor = new Cursor<Quote>(con, Quote.class, "symbol");
>             for (Quote quote : cursor)
>             {
>                 SequenceIterator cross = quote.day.map(quote.close.iterator().
>                                 windowAggAvg(20).sub(quote.close.iterator().
>                                 windowAggAvg(5)).cross(1));
>                 ...
>             }
>             con.commitTransaction();
>         }