Example usage for java.lang Float compareTo

List of usage examples for java.lang Float compareTo

Introduction

In this page you can find the example usage for java.lang Float compareTo.

Prototype

public int compareTo(Float anotherFloat) 

Source Link

Document

Compares two Float objects numerically.

Usage

From source file:org.searsia.Hit.java

@Override
public int compareTo(Hit hit2) {
    Float score1 = getScore();
    Float score2 = hit2.getScore();
    if (score1.compareTo(score2) == 0) {
        Integer rank1 = getRank();
        Integer rank2 = hit2.getRank();
        if (rank1 != null && rank2 != null) {
            return rank2.compareTo(rank1); // yes reversed!
        } else {//from w  w w. j  a v a 2 s .  c  o  m
            return 0;
        }
    } else {
        return score1.compareTo(score2);
    }
}

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJFloatEditor.java

public boolean isEditValid() {
    final String S_ProcName = "isEditValid";
    if (!hasValue()) {
        setValue(null);//from  ww  w.  j  a  va2 s . c o  m
        return (true);
    }

    boolean retval = super.isEditValid();
    if (retval) {
        try {
            commitEdit();
        } catch (ParseException e) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Field is not valid - " + e.getMessage(), e);

        }
        Object obj = getValue();
        if (obj == null) {
            retval = false;
        } else if (obj instanceof Float) {
            Float v = (Float) obj;
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Double) {
            Double v = (Double) obj;
            Double min = getMinValue().doubleValue();
            Double max = getMaxValue().doubleValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Short) {
            Short s = (Short) obj;
            Float v = new Float(s.floatValue());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Integer) {
            Integer i = (Integer) obj;
            Float v = new Float(i.floatValue());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Long) {
            Long l = (Long) obj;
            Float v = new Float(l.floatValue());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } else if (obj instanceof BigDecimal) {
            BigDecimal b = (BigDecimal) obj;
            Float v = new Float(b.toString());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Number) {
            Number n = (Number) obj;
            Float v = new Float(n.toString());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } else {
            throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                    "EditedValue", obj, "Short, Integer, Long, BigDecimal, Float, Double or Number");
        }
    }
    return (retval);
}

From source file:net.lightbody.bmp.proxy.jetty.http.HttpFields.java

/** List values in quality order.
 * @param enm Enumeration of values with quality parameters
 * @return values in quality order./*from   w w  w . j a v a2s .co m*/
 */
public static List qualityList(Enumeration enm) {
    if (enm == null || !enm.hasMoreElements())
        return Collections.EMPTY_LIST;

    Object list = null;
    Object qual = null;

    // Assume list will be well ordered and just add nonzero
    while (enm.hasMoreElements()) {
        String v = enm.nextElement().toString();
        Float q = getQuality(v);

        if (q.floatValue() >= 0.001) {
            list = LazyList.add(list, v);
            qual = LazyList.add(qual, q);
        }
    }

    List vl = LazyList.getList(list, false);
    if (vl.size() < 2)
        return vl;

    List ql = LazyList.getList(qual, false);

    // sort list with swaps
    Float last = __zero;
    for (int i = vl.size(); i-- > 0;) {
        Float q = (Float) ql.get(i);
        if (last.compareTo(q) > 0) {
            Object tmp = vl.get(i);
            vl.set(i, vl.get(i + 1));
            vl.set(i + 1, tmp);
            ql.set(i, ql.get(i + 1));
            ql.set(i + 1, q);
            last = __zero;
            i = vl.size();
            continue;
        }
        last = q;
    }
    ql.clear();
    return vl;
}

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJFloatEditor.java

public Float getFloatValue() {
    final String S_ProcName = "getFloatValue";
    Float retval;/* w w  w .  jav  a 2s .  c om*/
    String text = getText();
    if ((text == null) || (text.length() <= 0)) {
        retval = null;
    } else {
        if (!isEditValid()) {
            throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName,
                    "Field is not valid");
        }
        try {
            commitEdit();
        } catch (ParseException e) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Field is not valid - " + e.getMessage(), e);

        }
        Object obj = getValue();
        if (obj == null) {
            retval = null;
        } else if (obj instanceof Float) {
            Float v = (Float) obj;
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, min, max);
            }
            retval = v;
        } else if (obj instanceof Double) {
            Double v = (Double) obj;
            Double min = getMinValue().doubleValue();
            Double max = getMaxValue().doubleValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, min, max);
            }
            retval = new Float(v.floatValue());
        } else if (obj instanceof Short) {
            Short s = (Short) obj;
            Float v = new Float(s.floatValue());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, min, max);
            }
            retval = v;
        } else if (obj instanceof Integer) {
            Integer i = (Integer) obj;
            Float v = new Float(i.floatValue());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, min, max);
            }
            retval = v;
        } else if (obj instanceof Long) {
            Long l = (Long) obj;
            Float v = new Float(l.floatValue());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, min, max);
            }
            retval = v;
        } else if (obj instanceof BigDecimal) {
            BigDecimal b = (BigDecimal) obj;
            Float v = new Float(b.toString());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, min, max);
            }
            retval = v;
        } else if (obj instanceof Number) {
            Number n = (Number) obj;
            Float v = new Float(n.toString());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, min, max);
            }
            retval = v;
        } else {
            throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                    "EditedValue", obj, "Short, Integer, Long, BigDecimal or Number");
        }
    }
    return (retval);
}

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJFloatEditor.java

public void setMinValue(Float value) {
    final String S_ProcName = "setMinValue";
    if (value == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1, "value");
    }/*from w w  w  .j a  va  2 s .c om*/
    if (value.compareTo(Float.MIN_VALUE) < 0) {
        throw CFLib.getDefaultExceptionFactory().newArgumentUnderflowException(getClass(), S_ProcName, 1,
                "value", value, Float.MIN_VALUE);
    }
    minValue = value;
}

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJFloatEditor.java

public void setMaxValue(Float value) {
    final String S_ProcName = "setMaxValue";
    if (value == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1, "value");
    }/*from  w w  w  .ja  va2 s.  co m*/
    if (value.compareTo(Float.MAX_VALUE) > 0) {
        throw CFLib.getDefaultExceptionFactory().newArgumentOverflowException(getClass(), S_ProcName, 1,
                "value", value, Float.MAX_VALUE);
    }
    maxValue = value;
}

From source file:com.sun.labs.aura.fb.DataManager.java

public Artist guessArtist(String artistName) {
    Artist bestMatch = null;//from www .  j a va 2s .  c  o m
    bestMatch = nameToArtist.get(artistName);
    if (bestMatch == null) {
        try {
            List<Scored<Artist>> matches = mdb.artistSearch(artistName, 20);
            if (!matches.isEmpty()) {
                //
                // Find the best matched name
                Artist firstMatch = matches.get(0).getItem();
                if (matches.size() == 1) {
                    bestMatch = firstMatch;
                } else {
                    if (artistName.equalsIgnoreCase(firstMatch.getName())) {
                        //
                        // First match is an exact hit, so take it
                        bestMatch = firstMatch;
                    } else {
                        //
                        // Sort the top 20 by popularity and use the most
                        // popular option
                        Collections.sort(matches, new Comparator<Scored<Artist>>() {
                            @Override
                            public int compare(Scored<Artist> o1, Scored<Artist> o2) {
                                Float p1 = o1.getItem().getPopularity();
                                Float p2 = o2.getItem().getPopularity();
                                //
                                // Reverse order, most popular first
                                return p2.compareTo(p1);
                            }

                        });
                        bestMatch = matches.get(0).getItem();
                    }
                }
            }
            if (bestMatch != null) {
                nameToArtist.put(artistName, bestMatch);
            }
        } catch (AuraException e) {
            logger.info("Search failed for " + artistName + e.getMessage());
        }
    }
    return bestMatch;
}

From source file:org.trustedanalytics.scoringengine.ATKScoringEngine.java

public Boolean score(float[] data) {
    String commaSeparatedNumbers = convertToCommaSeparated(data);
    String url = getUrl() + commaSeparatedNumbers;
    Float result;
    try {/* w ww .  j  a v a  2 s.com*/
        RestTemplate template = new RestTemplate();
        ResponseEntity<String> response = template.postForEntity(url, null, String.class);
        String body = response.getBody();
        result = Float.parseFloat(body);
        LOG.debug("Score from scoring engine: {}", result);
    } catch (Exception ex) {
        LOG.warn("problem with getting scoring result! " + ex.getMessage(), ex);
        result = -100f;
    }

    return result.compareTo(1.0f) == 0;
}

From source file:org.eclipse.jubula.client.ui.rcp.dialogs.ProjectDialog.java

/**
 * @param parent/*from   w ww.ja va  2 s.c  o m*/
 *            The parent composite.
 */
private void createComboBoxes(Composite parent) {
    createEmptyLabel(parent);
    new Label(parent, SWT.NONE).setText(Messages.OpenProjectActionLabel);
    m_nameComboBox = new DirectCombo<String>(parent, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY, m_guidList,
            m_nameList, false, true);
    GridData gridData = newGridData();
    LayoutUtil.addToolTipAndMaxWidth(gridData, m_nameComboBox);
    m_nameComboBox.setLayoutData(gridData);
    m_nameComboBox.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            m_versionList = m_guidToVersionMap.get(m_nameComboBox.getSelectedObject());
            m_versionComboBox.setItems(m_versionList, m_versionList);
            m_versionComboBox.select(m_versionComboBox.getItemCount() - 1);
            enableOKButton();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing                
        }
    });
    if (m_nameComboBox.getItemCount() > 0) {
        m_nameComboBox.select(0);
    }
    m_versionList = m_guidToVersionMap.get(m_nameComboBox.getSelectedObject());
    createEmptyLabel(parent);
    new Label(parent, SWT.NONE).setText(Messages.OpenProjectActionLabel2);
    m_versionComboBox = new DirectCombo<String>(parent, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY, m_versionList,
            m_versionList, false, new Comparator<String>() {

                public int compare(String s1, String s2) {
                    Float f1 = Float.parseFloat(s1);
                    Float f2 = Float.parseFloat(s2);

                    return f1.compareTo(f2);
                }

            });
    gridData = new GridData();
    gridData.grabExcessHorizontalSpace = false;
    gridData.horizontalAlignment = GridData.BEGINNING;
    gridData.horizontalSpan = HORIZONTAL_SPAN;
    m_versionComboBox.setLayoutData(gridData);
    m_versionComboBox.select(m_versionComboBox.getItemCount() - 1);
    m_versionComboBox.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            enableOKButton();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing                
        }
    });
}

From source file:org.etudes.mneme.impl.PoolStorageSample.java

/**
 * {@inheritDoc}/*from   w  w  w . jav  a  2  s . c  o  m*/
 */
public List<PoolImpl> findPools(String context, final PoolService.FindPoolsSort sort) {
    fakeIt();

    List<PoolImpl> rv = new ArrayList<PoolImpl>();

    for (PoolImpl pool : this.pools.values()) {
        if ((!pool.historical) && (!pool.getMint()) && pool.getContext().equals(context)) {
            rv.add(clone(pool));
        }
    }

    // sort
    Collections.sort(rv, new Comparator() {
        public int compare(Object arg0, Object arg1) {
            int rv = 0;
            switch (sort) {
            case title_a:
            case title_d: {
                String s0 = StringUtil.trimToZero(((Pool) arg0).getTitle());
                String s1 = StringUtil.trimToZero(((Pool) arg1).getTitle());
                rv = s0.compareToIgnoreCase(s1);
                break;
            }
            case points_a:
            case points_d: {
                Float f0 = ((Pool) arg0).getPoints();
                if (f0 == null)
                    f0 = Float.valueOf(0f);
                Float f1 = ((Pool) arg1).getPoints();
                if (f1 == null)
                    f1 = Float.valueOf(0f);
                rv = f0.compareTo(f1);
                break;
            }
            }

            return rv;
        }
    });

    if ((sort == PoolService.FindPoolsSort.title_d) || (sort == PoolService.FindPoolsSort.points_d)) {
        Collections.reverse(rv);
    }

    return rv;
}