/** * alternate to actual value comparison i.e., either (lsh & rhs) one the value could be null * * @param cm * - a enum used to idetify the position for sorting */ private int compareAlternate(CompareMode cm) { int compareState = LESSER; switch (cm) { case LESS_THAN: compareState = LESSER * determinePosition(); break; case GREATER_THAN: compareState = GREATER * determinePosition(); break; case EQUAL: compareState = EQUAL * determinePosition(); break; } return compareState; }
/** * fetching a value from given object * * @param obj * - a {@link java.lang.Object} * @return object - a {@link java.lang.Object} - return of given method * @throws InvocationTargetException * @throws IllegalAccessException * @throws NoSuchMethodException */ private Object getValue(Object obj) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { return invoke(getMethod(obj), obj); }
/** * {@inheritDoc} */ @Override public int compare(Object o1, Object o2) { int response = LESSER; try { Object v1 = (null == this.targetMethod) ? o1 : getValue(o1); Object v2 = (null == this.targetMethod) ? o2 : getValue(o2); CompareMode cm = findCompareMode(v1, v2); if (!cm.equals(CompareMode.DEFAULT)) { return compareAlternate(cm); } final String returnType = (null == this.targetMethod) ? o1.getClass().getName() : getMethod(o1).getReturnType().getName(); response = compareActual(v1, v2, returnType); } catch (NoSuchMethodException nsme) { LOGGER.error("NoSuchMethodException occurred while comparing", nsme); } catch (IllegalAccessException iae) { LOGGER.error("IllegalAccessException occurred while comparing", iae); } catch (InvocationTargetException ite) { LOGGER.error("InvocationTargetException occurred while comparing", ite); } return response; }
case "int": case "java.lang.Integer": acutal = (((Integer) v1).compareTo((Integer) v2) * determinePosition()); break; case "boolean": case "java.lang.Boolean": acutal = (((Boolean) v1).compareTo((Boolean) v2) * determinePosition()); break; case "java.lang.String": acutal = (((String) v1).compareTo((String) v2) * determinePosition()); break; case "java.util.Date": acutal = (((Date) v1).compareTo((Date) v2) * determinePosition()); break; case "java.lang.Long": acutal = (((Long) v1).compareTo((Long) v2) * determinePosition()); break; case "java.lang.Float": acutal = (((Float) v1).compareTo((Float) v2) * determinePosition()); break; case "java.lang.Double": acutal = (((Double) v1).compareTo((Double) v2) * determinePosition()); break; default: