// Path: sorter/src/main/java/sortpom/wrapper/content/Phase.java
// static int compareTo(Phase o1, Phase o2) {
//     if (o1 == null) {
//         if (o2 == null) {
//             return 0;
//         }
//         return -1;
//     }
//     if (o2 == null) {
//         return 1;
//     }
//     if (o1 instanceof NonStandardPhase) {
//         if (o2 instanceof NonStandardPhase) {
//             return o1.getText().compareTo(o2.getText());
//         } else {
//             return 1;
//         }
//     }
//     StandardPhase so1 = (StandardPhase) o1;
//     if (o2 instanceof NonStandardPhase) {
//         return -1;
//     }
//     return so1.compareTo((StandardPhase) o2);
// }


import org.jdom.Content;
import org.jdom.Element;
import java.util.List;
import static sortpom.wrapper.content.Phase.compareTo;
package sortpom.wrapper.content;




/**
 * A wrapper that contains a execution element. The element is sorted according to:
 * 1 no phase and no id
 * 2 no phase and id (sorted by id value)
 * 3 standard phase and no id (sorted by Maven phase order)
 * 4 standard phase and id (sorted by Maven phase order and then id value)
 * 5 other phase and no id (sorted by phase value)
 * 6 other phase and id (sorted by phase value and then id value)
 */
public class ExecutionSortedWrapper extends SortedWrapper {
    private final Phase phase;
    private final String id;

    /**
     * Instantiates a new child element sorted wrapper with a plugin element.
     *
     * @param element   the element
     * @param sortOrder the sort order
     */
    public ExecutionSortedWrapper(final Element element, final int sortOrder) {
        super(element, sortOrder);
        @SuppressWarnings("unchecked")
        List<Element> children = getContent().getChildren();

        phase = children.stream()
                .filter(e -> e.getName().equals("phase") && e.getText() != null)
                .map(e -> Phase.getPhase(e.getTextTrim()))
                .findFirst()
                .orElse(null);

        id = children.stream()
                .filter(e -> e.getName().equals("id"))
                .map(Element::getTextTrim)
                .findFirst()
                .orElse("");

    }

    @Override
    public boolean isBefore(final Wrapper<? extends Content> wrapper) {
        if (wrapper instanceof ExecutionSortedWrapper) {
            return isBeforeWrapper((ExecutionSortedWrapper) wrapper);
        }
        return super.isBefore(wrapper);
    }

    private boolean isBeforeWrapper(final ExecutionSortedWrapper wrapper) {
// Path: sorter/src/main/java/sortpom/wrapper/content/Phase.java
// static int compareTo(Phase o1, Phase o2) {
//     if (o1 == null) {
//         if (o2 == null) {
//             return 0;
//         }
//         return -1;
//     }
//     if (o2 == null) {
//         return 1;
//     }
//     if (o1 instanceof NonStandardPhase) {
//         if (o2 instanceof NonStandardPhase) {
//             return o1.getText().compareTo(o2.getText());
//         } else {
//             return 1;
//         }
//     }
//     StandardPhase so1 = (StandardPhase) o1;
//     if (o2 instanceof NonStandardPhase) {
//         return -1;
//     }
//     return so1.compareTo((StandardPhase) o2);
// }


// Path: sorter/src/main/java/sortpom/wrapper/content/ExecutionSortedWrapper.java
import org.jdom.Content;
import org.jdom.Element;
import java.util.List;
import static sortpom.wrapper.content.Phase.compareTo;

package sortpom.wrapper.content;




/**
 * A wrapper that contains a execution element. The element is sorted according to:
 * 1 no phase and no id
 * 2 no phase and id (sorted by id value)
 * 3 standard phase and no id (sorted by Maven phase order)
 * 4 standard phase and id (sorted by Maven phase order and then id value)
 * 5 other phase and no id (sorted by phase value)
 * 6 other phase and id (sorted by phase value and then id value)
 */
public class ExecutionSortedWrapper extends SortedWrapper {
    private final Phase phase;
    private final String id;

    /**
     * Instantiates a new child element sorted wrapper with a plugin element.
     *
     * @param element   the element
     * @param sortOrder the sort order
     */
    public ExecutionSortedWrapper(final Element element, final int sortOrder) {
        super(element, sortOrder);
        @SuppressWarnings("unchecked")
        List<Element> children = getContent().getChildren();

        phase = children.stream()
                .filter(e -> e.getName().equals("phase") && e.getText() != null)
                .map(e -> Phase.getPhase(e.getTextTrim()))
                .findFirst()
                .orElse(null);

        id = children.stream()
                .filter(e -> e.getName().equals("id"))
                .map(Element::getTextTrim)
                .findFirst()
                .orElse("");

    }

    @Override
    public boolean isBefore(final Wrapper<? extends Content> wrapper) {
        if (wrapper instanceof ExecutionSortedWrapper) {
            return isBeforeWrapper((ExecutionSortedWrapper) wrapper);
        }
        return super.isBefore(wrapper);
    }

    private boolean isBeforeWrapper(final ExecutionSortedWrapper wrapper) {
        int compare = compareTo(phase, wrapper.phase);