List of usage examples for java.lang Comparable compareTo
public int compareTo(T o);
From source file:org.pentaho.reporting.engine.classic.core.function.TotalItemMaxFunction.java
/** * Receives notification that a row of data is being processed. * * @param event the event.//from w w w. j av a 2 s.c om */ public void itemsAdvanced(final ReportEvent event) { if (field == null) { return; } if (FunctionUtilities.isDefinedPrepareRunLevel(this, event) == false) { return; } final Object fieldValue = event.getDataRow().get(getField()); if (fieldValue instanceof Comparable == false) { return; } try { final Comparable compare = (Comparable) fieldValue; final Comparable oldValue = result.get(lastGroupSequenceNumber); if (oldValue == null || oldValue.compareTo(compare) < ZERO_I) { result.set(lastGroupSequenceNumber, compare); } } catch (Exception e) { logger.error("TotalItemMaxFunction.advanceItems(): problem comparing values."); } }
From source file:org.pentaho.reporting.engine.classic.core.function.TotalItemMinFunction.java
/** * Receives notification that a row of data is being processed. * * @param event the event./* w ww . j av a 2 s . c o m*/ */ public void itemsAdvanced(final ReportEvent event) { if (field == null) { return; } if (FunctionUtilities.isDefinedPrepareRunLevel(this, event) == false) { return; } final Object fieldValue = event.getDataRow().get(getField()); if (fieldValue instanceof Comparable == false) { return; } try { final Comparable compare = (Comparable) fieldValue; final Comparable oldValue = result.get(lastGroupSequenceNumber); if (oldValue == null || oldValue.compareTo(compare) > ZERO_I) { result.set(lastGroupSequenceNumber, compare); } } catch (Exception e) { logger.error("TotalItemMinFunction.advanceItems(): problem comparing values."); } }
From source file:com.datatorrent.lib.util.TopNUniqueSort.java
/** * Adds object//from w w w . j av a 2 s . c o m * @param e object to be added * @return true if offer() succeeds */ @SuppressWarnings("unchecked") public boolean offer(E e) { MutableInt ival = hmap.get(e); if (ival != null) { // already exists, so no insertion ival.increment(); return true; } if (q.size() < qbound) { if (ival == null) { hmap.put(e, new MutableInt(1)); } return q.offer(e); } boolean ret = false; boolean insert; Comparable<? super E> head = (Comparable<? super E>) q.peek(); if (ascending) { // means head is the lowest value due to inversion insert = head.compareTo(e) < 0; // e > head } else { // means head is the highest value due to inversion insert = head.compareTo(e) > 0; // head is < e } // object e makes it, someone else gets dropped if (insert && q.offer(e)) { hmap.put(e, new MutableInt(1)); ret = true; // the dropped object will never make it to back in anymore E drop = q.poll(); hmap.remove(drop); } return ret; }
From source file:com.px100systems.data.core.CalculatingCriteria.java
@Override public CalculatingCriteria.Predicate convert(Criteria.lt c) { return new Predicate() { @SuppressWarnings("unchecked") @Override/*w w w .ja v a 2s .c o m*/ public boolean eval() { Comparable val = (Comparable) def.getField(bean, c.getMember()); return val == null || val.compareTo(c.getValue()) < 0; } }; }
From source file:com.px100systems.data.core.CalculatingCriteria.java
@Override public CalculatingCriteria.Predicate convert(Criteria.le c) { return new Predicate() { @SuppressWarnings("unchecked") @Override/*from www . jav a 2s .co m*/ public boolean eval() { Comparable val = (Comparable) def.getField(bean, c.getMember()); return val == null || val.compareTo(c.getValue()) <= 0; } }; }
From source file:com.px100systems.data.core.CalculatingCriteria.java
@Override public CalculatingCriteria.Predicate convert(Criteria.gt c) { return new Predicate() { @SuppressWarnings("unchecked") @Override/*w w w .j a va 2 s. com*/ public boolean eval() { Comparable val = (Comparable) def.getField(bean, c.getMember()); return val != null && val.compareTo(c.getValue()) > 0; } }; }
From source file:com.px100systems.data.core.CalculatingCriteria.java
@Override public CalculatingCriteria.Predicate convert(Criteria.ge c) { return new Predicate() { @SuppressWarnings("unchecked") @Override/*from w ww . ja v a2s . c om*/ public boolean eval() { Comparable val = (Comparable) def.getField(bean, c.getMember()); return val != null && val.compareTo(c.getValue()) >= 0; } }; }
From source file:com.px100systems.data.core.CalculatingCriteria.java
@Override public CalculatingCriteria.Predicate convert(Criteria.between c) { return new Predicate() { @SuppressWarnings("unchecked") @Override// www .java 2s.co m public boolean eval() { Comparable val = (Comparable) def.getField(bean, c.getMember()); return val != null && val.compareTo(c.getMin()) >= 0 && val.compareTo(c.getMax()) <= 0; } }; }
From source file:com.aurel.track.fieldType.runtime.custom.picker.CustomPickerRT.java
/** * Get the sort order related to the value * By default the value is directly used as sortOrder * the select fields has extra sortOrder columns * @param fieldID//from w w w . j av a2 s. c o m * @param parameterCode * @param value the value the sortorder is looked for * @param workItemID * @param localLookupContainer * @return */ @Override public Comparable getSortOrderValue(Integer fieldID, Integer parameterCode, Object value, Integer workItemID, LocalLookupContainer localLookupContainer) { Integer[] optionIDs = CustomSelectUtil.getSelectedOptions(value); if (optionIDs == null || optionIDs.length == 0) { LOGGER.debug("No option seleced by getting the sort order value"); return null; } else { Comparable minSortOrderValue = null; //select the option with the smallest sortOrder for (int i = 0; i < optionIDs.length; i++) { ISortedBean sortedBean = (ISortedBean) LookupContainer .getNotLocalizedLabelBean(getDropDownMapFieldKey(fieldID), optionIDs[i]); //beansMap.get(optionIDs[i]); if (sortedBean != null && sortedBean.getSortOrderValue() != null) { Comparable currentSortOrder = sortedBean.getSortOrderValue(); if (minSortOrderValue == null || currentSortOrder.compareTo(minSortOrderValue) < 0) { minSortOrderValue = currentSortOrder; } } } return minSortOrderValue; } }
From source file:org.apache.camel.util.ObjectHelper.java
/** * A helper method for performing an ordered comparison on the objects * handling nulls and objects which do not handle sorting gracefully * * @param a the first object/*from w ww . ja v a2 s . c om*/ * @param b the second object * @param ignoreCase ignore case for string comparison */ @SuppressWarnings("unchecked") public static int compare(Object a, Object b, boolean ignoreCase) { if (a == b) { return 0; } if (a == null) { return -1; } if (b == null) { return 1; } if (a instanceof Ordered && b instanceof Ordered) { return ((Ordered) a).getOrder() - ((Ordered) b).getOrder(); } if (ignoreCase && a instanceof String && b instanceof String) { return ((String) a).compareToIgnoreCase((String) b); } if (a instanceof Comparable) { Comparable comparable = (Comparable) a; return comparable.compareTo(b); } int answer = a.getClass().getName().compareTo(b.getClass().getName()); if (answer == 0) { answer = a.hashCode() - b.hashCode(); } return answer; }