Search in sources :

Example 1 with AbstractParameterDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.AbstractParameterDeclaration in project mule by mulesoft.

the class ParameterLayoutOrderDeclarationEnricher method addMissingParameterOrders.

private int addMissingParameterOrders(List<AbstractParameterDeclaration> declarations) {
    AtomicInteger minOrder = new AtomicInteger(INITIAL_ORDER);
    Set<Integer> takenOrders = new HashSet<>();
    List<AbstractParameterDeclaration> nonOrderedParams = new ArrayList<>();
    declarations.forEach(param -> {
        LayoutModel layoutModel = param.getLayoutModel();
        if (layoutModel != null && layoutModel.getOrder().isPresent()) {
            takenOrders.add(layoutModel.getOrder().get());
            minOrder.set(min(layoutModel.getOrder().get(), minOrder.get()));
        } else {
            nonOrderedParams.add(param);
        }
    });
    AtomicInteger currentOrder = new AtomicInteger(INITIAL_ORDER);
    nonOrderedParams.forEach(param -> param.setLayoutModel(builderFrom(param.getLayoutModel()).order(getNextOrder(currentOrder, takenOrders)).build()));
    return minOrder.get();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.AbstractParameterDeclaration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LayoutModel(org.mule.runtime.api.meta.model.display.LayoutModel)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AbstractParameterDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.AbstractParameterDeclaration)1 LayoutModel (org.mule.runtime.api.meta.model.display.LayoutModel)1