/** * Copyright (C) 2018 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * * Hebdobot is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Hebdobot is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Hebdobot. If not, see */ package org.april.hebdobot.model.stats; import java.util.Comparator; /** * The Class Stat. */ public class IntegerStatComparator implements Comparator { public enum Sorting { VALUE, COUNT } private Sorting sorting; /** * Instantiates a new review data comparator. * * @param sorting * the sorting */ public IntegerStatComparator(final Sorting sorting) { this.sorting = sorting; } /* (non-Javadoc) * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ @Override public int compare(final IntegerStat alpha, final IntegerStat bravo) { int result; result = compare(alpha, bravo, this.sorting); // return result; } /** * Compare. * * @param alpha * the alpha * @param bravo * the bravo * @return the int */ public static int compare(final Integer alpha, final Integer bravo) { int result; // if ((alpha == null) && (bravo == null)) { result = 0; } else if (alpha == null) { result = -1; } else if (bravo == null) { result = +1; } else { result = alpha.compareTo(bravo); } // return result; } /** * Compare. * * @param alpha * the alpha * @param bravo * the bravo * @param sorting * the sorting * @return the int */ public static int compare(final IntegerStat alpha, final IntegerStat bravo, final Sorting sorting) { int result; if (sorting == null) { result = 0; } else { switch (sorting) { case VALUE: result = compare(getValue(alpha), getValue(bravo)); break; case COUNT: result = compare(getCount(alpha), getCount(bravo)); break; default: result = 0; } } // return result; } /** * Compare. * * @param alpha * the alpha * @param bravo * the bravo * @return the int */ public static int compare(final Long alpha, final Long bravo) { int result; // if ((alpha == null) && (bravo == null)) { result = 0; } else if (alpha == null) { result = -1; } else if (bravo == null) { result = +1; } else { result = alpha.compareTo(bravo); } // return result; } /** * Gets the user count. * * @param source * the source * @return the user count */ public static Integer getCount(final IntegerStat source) { Integer result; if (source == null) { result = null; } else { result = source.getCount(); } // return result; } /** * Gets the duration. * * @param source * the source * @return the duration */ public static Integer getValue(final IntegerStat source) { Integer result; if (source == null) { result = null; } else { result = source.getValue(); } // return result; } }