# SequenceValidator

Import: `import com.install4j.api.beaninfo.SequenceValidator;`

```java
interface SequenceValidator
```

Interface for controlling insertion and reordering of beans at design-time. The
[`Install4JBeanInfo.ATTRIBUTE_SEQUENCE_VALIDATOR`](Install4JBeanInfo.md#attribute-sequence-validator) value of a bean descriptor expects an instance of
this class.

## Methods

| Signature | Returns | Description |
|---|---|---|
| [`getInsertIndex(Bean, List<Bean>)`](#getinsertindex-bean-list-bean) | `int` | When a bean is inserted the first time at design-time, this method will be called to determine the insertion index. |
| [`isBarrier(Bean, Bean)`](#isbarrier-bean-bean) | `boolean` | When a bean is moved in the list of beans, this method is called to check whether the move is valid. |

### getInsertIndex(Bean, List<Bean>)

```java
int getInsertIndex(Bean bean, List<Bean> beans)
```

When a bean is inserted the first time at design-time, this method will be called to
determine the insertion index. If this method returns -1, the bean will be inserted in its default position.
This method is not called for existing bean instances that are loaded from a project.


**Parameters:**

- `bean` — the bean that is being inserted
- `beans` — the list of existing beans into which the bean is to be inserted

**Returns:** the insertion index into the list

### isBarrier(Bean, Bean)

```java
boolean isBarrier(Bean movedBean, Bean possibleBarrierBean)
```

When a bean is moved in the list of beans, this method is called to check whether the move is valid.
This method is called symmetrically for both beans whose location is to be swapped.
This means that the user might actually be moving the `possibleBarrierBean` instead of the `movedBean`.


**Parameters:**

- `movedBean` — the bean that is being moved. This is always an instance of the bean with the BeanInfo class that contains this sequence validator.
- `possibleBarrierBean` — the other bean whose location is about to be swapped with the `movedBean`.

**Returns:** whether the move is valid. If you return `false` an error message will be displayed by the install4j GUI.

