Search in sources :

Example 1 with Timed

use of org.elixir_lang.structure_view.element.Timed in project intellij-elixir by KronicDeth.

the class Time method getComparator.

/*
     * Constructors
     */
/**
     * Returns the comparator used for comparing nodes in the tree.
     *
     * @return the comparator for comparing nodes.
     */
@Override
public Comparator getComparator() {
    return new Comparator() {

        @Override
        public int compare(Object o1, Object o2) {
            int comparison;
            if (o1 instanceof Timed && o2 instanceof Timed) {
                Timed timed1 = (Timed) o1;
                Timed timed2 = (Timed) o2;
                Timed.Time time1 = timed1.time();
                Timed.Time time2 = timed2.time();
                if (time1 == time2) {
                    comparison = 0;
                } else if (time1 == Timed.Time.COMPILE && time2 == Timed.Time.RUN) {
                    comparison = -1;
                } else if (time1 == Timed.Time.RUN && time2 == Timed.Time.COMPILE) {
                    comparison = 1;
                } else {
                    throw new NotImplementedException("Only COMPILE and RUN time are expected");
                }
            } else if (o1 instanceof Timed && !(o2 instanceof Timed)) {
                Timed timed1 = (Timed) o1;
                Timed.Time time1 = timed1.time();
                switch(time1) {
                    case COMPILE:
                        comparison = -1;
                        break;
                    case RUN:
                        comparison = 1;
                        break;
                    default:
                        throw new NotImplementedException("Only COMPILE and RUN time are expected");
                }
            } else if (!(o1 instanceof Timed) && o2 instanceof Timed) {
                Timed timed2 = (Timed) o2;
                Timed.Time time2 = timed2.time();
                switch(time2) {
                    case COMPILE:
                        comparison = 1;
                        break;
                    case RUN:
                        comparison = -1;
                        break;
                    default:
                        throw new NotImplementedException("Only COMPILE and RUN time are expected");
                }
            } else {
                assert !(o1 instanceof Timed) && !(o2 instanceof Timed);
                comparison = 0;
            }
            return comparison;
        }
    };
}
Also used : Timed(org.elixir_lang.structure_view.element.Timed) NotImplementedException(org.apache.commons.lang.NotImplementedException) Comparator(java.util.Comparator)

Aggregations

Comparator (java.util.Comparator)1 NotImplementedException (org.apache.commons.lang.NotImplementedException)1 Timed (org.elixir_lang.structure_view.element.Timed)1