package android.support.v4.widget;

import android.graphics.Rect;
import android.support.v4.widget.k.a;
import java.util.Comparator;

class k$c<T> implements Comparator<T> {
    private final Rect QP = new Rect();
    private final Rect QQ = new Rect();
    private final boolean QR;
    private final a<T> QS;

    k$c(boolean z, a<T> aVar) {
        this.QR = z;
        this.QS = aVar;
    }

    public final int compare(T t, T t2) {
        Rect rect = this.QP;
        Rect rect2 = this.QQ;
        this.QS.b(t, rect);
        this.QS.b(t2, rect2);
        if (rect.top < rect2.top) {
            return -1;
        }
        if (rect.top > rect2.top) {
            return 1;
        }
        if (rect.left < rect2.left) {
            if (this.QR) {
                return 1;
            }
            return -1;
        } else if (rect.left > rect2.left) {
            if (this.QR) {
                return -1;
            }
            return 1;
        } else if (rect.bottom < rect2.bottom) {
            return -1;
        } else {
            if (rect.bottom > rect2.bottom) {
                return 1;
            }
            if (rect.right < rect2.right) {
                if (this.QR) {
                    return 1;
                }
                return -1;
            } else if (rect.right <= rect2.right) {
                return 0;
            } else {
                if (this.QR) {
                    return -1;
                }
                return 1;
            }
        }
    }
}
