Java tutorial
//package com.java2s; import android.support.annotation.Nullable; public class Main { public static int compareInts(@Nullable Integer one, @Nullable Integer another, boolean ascending) { return one != null ? (another != null ? !ascending ? (int) Math.signum(another - one) : (int) Math.signum(one - another) : 1) : -1; } }