Package org.jcsp.util.filter

# Interface WriteFiltered

All Known Subinterfaces:
  `FilteredChannelOutput`, `FilteredSharedChannelOutput`, `MigratableChannelOutput`

All Known Implementing Classes:
  `FilteredSharedChannelOutputWrapper`

public interface WriteFiltered

Interface for a channel end supporting write filtering operations. A channel end that implements this interface can have instances of the `Filter` interface installed to apply transformations on data as it is written to the channel.

Multiple filters can be installed and referenced by a zero-based index to specify a specific ordering.

If multiple filters are installed, they are applied in order of increasing index. For example:

       FilteredChannelOutput out = ...;

       Filter f1 = ...;
       Filter f2 = ...;

       out.addWriteFilter (f1, 0);
       out.addWriteFilter (f2, 1);

The `out.write()` method will deliver `f2.filter (f1.filter (obj))` to the reader of the channel where `obj` is the data value that would have been delivered in the absence of filters.

Author:
  Quickstone Technologies Limited
See Also:
  - `Filter`
  - `FilteredChannelOutput`

## Method Summary

Modifier and Type
Method
Description
`void`
`addWriteFilter(Filter filter)`
Installs a write filter defining a transformation to be applied by the `write` method of the channel end.
`void`
`addWriteFilter(Filter filter, int index)`
Installs a write filter defining a transformation to be applied by the `write` method of the channel end at a specific index.
`Filter`
`getWriteFilter(int index)`
Returns the write filter installed at the given index.
`int`
`getWriteFilterCount()`
Returns the number of write filters currently installed.
`void`
`removeWriteFilter(int index)`
Removes the write filter installed at the given index.
`void`
`removeWriteFilter(Filter filter)`
Removes the first write filter (lowest index) matching the filter given as a parameter.

## Method Details

### addWriteFilter

void addWriteFilter(Filter filter)
Installs a write filter defining a transformation to be applied by the `write` method of the channel end. The filter will be appended to the end of the current list, making it the last to be applied.

Parameters:
  `filter` - the filter to be installed; may not be null.

### addWriteFilter

void addWriteFilter(Filter filter, int index)
Installs a write filter defining a transformation to be applied by the `write` method of the channel end at a specific index. If there is already a filter at that index position the existing filters are shifted to make room. If the index is greater than the number of filters already installed the filter is placed at the end.

Parameters:
  `filter` - the filter to be installed; may not be null.
  `index` - the zero based index; may not be negative.

### removeWriteFilter

void removeWriteFilter(Filter filter)
Removes the first write filter (lowest index) matching the filter given as a parameter. The filter removed, `r`, will satisfy the condition `r.equals (filter)`. The remaining filters are shifted to close the gap in the index allocation.

Parameters:
  `filter` - the filter to be removed; may not be null.

### removeWriteFilter

void removeWriteFilter(int index)
Removes the write filter installed at the given index. The remaining filters are shifted to close the gap in the index allocation.

Parameters:
  `index` - zero-based index of the filter to be removed.

### getWriteFilter

Filter getWriteFilter(int index)
Returns the write filter installed at the given index.

Parameters:
  `index` - zero-based index of the filter to return.
Returns:
  the filter at that position.

### getWriteFilterCount

int getWriteFilterCount()
Returns the number of write filters currently installed.