Example usage for java.lang Float compare

List of usage examples for java.lang Float compare

Introduction

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

Prototype

public static int compare(float f1, float f2) 

Source Link

Document

Compares the two specified float values.

Usage

From source file:org.ejbca.core.model.ra.ExtendedInformation.java

/** Implementation of UpgradableDataHashMap function upgrade. */
public void upgrade() {
    if (Float.compare(LATEST_VERSION, getVersion()) != 0) {
        // New version of the class, upgrade
        String msg = intres.getLocalizedMessage("endentity.extendedinfoupgrade", new Float(getVersion()));
        log.info(msg);//from  w w w  . ja v  a  2s. co m

        if (data.get(SUBJECTDIRATTRIBUTES) == null) {
            data.put(SUBJECTDIRATTRIBUTES, "");
        }
        if (data.get(MAXFAILEDLOGINATTEMPTS) == null) {
            setMaxLoginAttempts(DEFAULT_MAXLOGINATTEMPTS);
        }
        if (data.get(REMAININGLOGINATTEMPTS) == null) {
            setRemainingLoginAttempts(DEFAULT_REMAININGLOGINATTEMPTS);
        }
        // In EJBCA 4.0.0 we changed the date format
        if (getVersion() < 3) {
            final DateFormat oldDateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT,
                    Locale.US);
            final FastDateFormat newDateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm");
            try {
                final String oldCustomStartTime = getCustomData(ExtendedInformation.CUSTOM_STARTTIME);
                if (!isEmptyOrRelative(oldCustomStartTime)) {
                    // We use an absolute time format, so we need to upgrade
                    final String newCustomStartTime = newDateFormat
                            .format(oldDateFormat.parse(oldCustomStartTime));
                    setCustomData(ExtendedInformation.CUSTOM_STARTTIME, newCustomStartTime);
                    if (log.isDebugEnabled()) {
                        log.debug("Upgraded " + ExtendedInformation.CUSTOM_STARTTIME + " from \""
                                + oldCustomStartTime + "\" to \"" + newCustomStartTime
                                + "\" in ExtendedInformation.");
                    }
                }
            } catch (ParseException e) {
                log.error("Unable to upgrade " + ExtendedInformation.CUSTOM_STARTTIME
                        + " in extended user information.", e);
            }
            try {
                final String oldCustomEndTime = getCustomData(ExtendedInformation.CUSTOM_ENDTIME);
                if (!isEmptyOrRelative(oldCustomEndTime)) {
                    // We use an absolute time format, so we need to upgrade
                    final String newCustomEndTime = newDateFormat.format(oldDateFormat.parse(oldCustomEndTime));
                    setCustomData(ExtendedInformation.CUSTOM_ENDTIME, newCustomEndTime);
                    if (log.isDebugEnabled()) {
                        log.debug(
                                "Upgraded " + ExtendedInformation.CUSTOM_ENDTIME + " from \"" + oldCustomEndTime
                                        + "\" to \"" + newCustomEndTime + "\" in ExtendedInformation.");
                    }
                }
            } catch (ParseException e) {
                log.error("Unable to upgrade " + ExtendedInformation.CUSTOM_ENDTIME
                        + " in extended user information.", e);
            }
        }
        // In 4.0.2 we further specify the storage format by saying that UTC TimeZone is implied instead of local server time
        if (getVersion() < 4) {
            final String[] timePatterns = { "yyyy-MM-dd HH:mm" };
            final String oldStartTime = getCustomData(ExtendedInformation.CUSTOM_STARTTIME);
            if (!isEmptyOrRelative(oldStartTime)) {
                try {
                    final String newStartTime = ValidityDate
                            .formatAsUTC(DateUtils.parseDateStrictly(oldStartTime, timePatterns));
                    setCustomData(ExtendedInformation.CUSTOM_STARTTIME, newStartTime);
                    if (log.isDebugEnabled()) {
                        log.debug("Upgraded " + ExtendedInformation.CUSTOM_STARTTIME + " from \"" + oldStartTime
                                + "\" to \"" + newStartTime + "\" in EndEntityProfile.");
                    }
                } catch (ParseException e) {
                    log.error("Unable to upgrade " + ExtendedInformation.CUSTOM_STARTTIME
                            + " to UTC in EndEntityProfile! Manual interaction is required (edit and verify).",
                            e);
                }
            }
            final String oldEndTime = getCustomData(ExtendedInformation.CUSTOM_ENDTIME);
            if (!isEmptyOrRelative(oldEndTime)) {
                // We use an absolute time format, so we need to upgrade
                try {
                    final String newEndTime = ValidityDate
                            .formatAsUTC(DateUtils.parseDateStrictly(oldEndTime, timePatterns));
                    setCustomData(ExtendedInformation.CUSTOM_ENDTIME, newEndTime);
                    if (log.isDebugEnabled()) {
                        log.debug("Upgraded " + ExtendedInformation.CUSTOM_ENDTIME + " from \"" + oldEndTime
                                + "\" to \"" + newEndTime + "\" in EndEntityProfile.");
                    }
                } catch (ParseException e) {
                    log.error("Unable to upgrade " + ExtendedInformation.CUSTOM_ENDTIME
                            + " to UTC in EndEntityProfile! Manual interaction is required (edit and verify).",
                            e);
                }
            }
        }
        data.put(VERSION, new Float(LATEST_VERSION));
    }
}

From source file:org.ejbca.core.model.ca.caadmin.extendedcaservices.KeyRecoveryCAService.java

@Override
public void upgrade() {
    if (Float.compare(LATEST_VERSION, getVersion()) != 0) {
        String msg = intres.getLocalizedMessage("caservice.upgrade", new Float(getVersion()));
        log.info(msg);/* ww  w.  j  a  v a 2 s .  c  om*/
        data.put(VERSION, new Float(LATEST_VERSION));
    }
}

From source file:Main.java

public static boolean isUndefined(float value) {
    return Float.compare(value, Float.NaN) == 0;
}

From source file:tds.assessment.Assessment.java

@Override
public boolean equals(final Object o) {
    if (this == o)
        return true;
    if (o == null || getClass() != o.getClass())
        return false;

    final Assessment that = (Assessment) o;

    if (Float.compare(that.startAbility, startAbility) != 0)
        return false;
    if (prefetch != that.prefetch)
        return false;
    if (Float.compare(that.abilitySlope, abilitySlope) != 0)
        return false;
    if (Float.compare(that.abilityIntercept, abilityIntercept) != 0)
        return false;
    if (maxOpportunities != that.maxOpportunities)
        return false;
    if (initialAbilityBySubject != that.initialAbilityBySubject)
        return false;
    if (validateCompleteness != that.validateCompleteness)
        return false;
    if (deleteUnansweredItems != that.deleteUnansweredItems)
        return false;
    if (multiStageBraille != that.multiStageBraille)
        return false;
    if (!key.equals(that.key))
        return false;
    if (assessmentId != null ? !assessmentId.equals(that.assessmentId) : that.assessmentId != null)
        return false;
    if (label != null ? !label.equals(that.label) : that.label != null)
        return false;
    if (selectionAlgorithm != that.selectionAlgorithm)
        return false;
    if (subject != null ? !subject.equals(that.subject) : that.subject != null)
        return false;
    if (accommodationFamily != null ? !accommodationFamily.equals(that.accommodationFamily)
            : that.accommodationFamily != null)
        return false;
    if (fieldTestStartDate != null ? !fieldTestStartDate.equals(that.fieldTestStartDate)
            : that.fieldTestStartDate != null)
        return false;
    if (fieldTestEndDate != null ? !fieldTestEndDate.equals(that.fieldTestEndDate)
            : that.fieldTestEndDate != null)
        return false;
    if (accommodationDependencies != null ? !accommodationDependencies.equals(that.accommodationDependencies)
            : that.accommodationDependencies != null)
        return false;
    if (itemConstraints != null ? !itemConstraints.equals(that.getItemConstraints())
            : that.itemConstraints != null)
        return false;
    if (segments != null ? !segments.equals(that.getSegments()) : that.segments != null)
        return false;
    if (strands != null ? !strands.equals(that.strands) : that.strands != null)
        return false;
    if (languageCodes != null ? !languageCodes.equals(that.languageCodes) : that.languageCodes != null)
        return false;
    if (grades != null ? !grades.equals(that.grades) : that.grades != null)
        return false;
    if (handScoreProjectId != null ? !handScoreProjectId.equals(that.handScoreProjectId)
            : that.handScoreProjectId != null)
        return false;
    if (contract != null ? !contract.equals(that.contract) : that.contract != null)
        return false;
    if (type != null ? !type.equals(that.type) : that.type != null)
        return false;
    if (academicYear != null ? !academicYear.equals(that.academicYear) : that.academicYear != null)
        return false;
    if (loadVersion != null ? !loadVersion.equals(that.loadVersion) : that.loadVersion != null)
        return false;
    return updateVersion != null ? updateVersion.equals(that.updateVersion) : that.updateVersion == null;
}

From source file:com.android.printspooler.widget.PrintContentView.java

private void onDragProgress(float progress) {
    if (Float.compare(mDragProgress, progress) == 0) {
        return;//from  w  w  w . j a v  a 2s.  c o m
    }

    if ((mDragProgress == 0 && progress > 0) || (mDragProgress == 1.0f && progress < 1.0f)) {
        mSummaryContent.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        mDraggableContent.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        mMoreOptionsButton.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        ensureImeClosedAndInputFocusCleared();
    }
    if ((mDragProgress > 0 && progress == 0) || (mDragProgress < 1.0f && progress == 1.0f)) {
        mSummaryContent.setLayerType(View.LAYER_TYPE_NONE, null);
        mDraggableContent.setLayerType(View.LAYER_TYPE_NONE, null);
        mMoreOptionsButton.setLayerType(View.LAYER_TYPE_NONE, null);
        mMoreOptionsButton.setLayerType(View.LAYER_TYPE_NONE, null);
    }

    mDragProgress = progress;

    mSummaryContent.setAlpha(progress);

    final float inverseAlpha = 1.0f - progress;
    mOptionsContainer.setAlpha(inverseAlpha);
    mMoreOptionsButton.setAlpha(inverseAlpha);

    mEmbeddedContentScrim.setBackgroundColor(computeScrimColor());
    if (progress == 0) {
        if (mOptionsStateChangeListener != null) {
            mOptionsStateChangeListener.onOptionsOpened();
        }
        mExpandCollapseHandle.setContentDescription(mContext.getString(R.string.collapse_handle));
        announceForAccessibility(mContext.getString(R.string.print_options_expanded));
        mSummaryContent.setVisibility(View.GONE);
        mEmbeddedContentScrim.setOnClickListener(this);
        mExpandCollapseIcon.setBackgroundResource(R.drawable.ic_expand_less);
    } else {
        mSummaryContent.setVisibility(View.VISIBLE);
    }

    if (progress == 1.0f) {
        if (mOptionsStateChangeListener != null) {
            mOptionsStateChangeListener.onOptionsClosed();
        }
        mExpandCollapseHandle.setContentDescription(mContext.getString(R.string.expand_handle));
        announceForAccessibility(mContext.getString(R.string.print_options_collapsed));
        if (mMoreOptionsButton.getVisibility() != View.GONE) {
            mMoreOptionsButton.setVisibility(View.INVISIBLE);
        }
        mDraggableContent.setVisibility(View.INVISIBLE);
        // If we change the scrim visibility the dimming is lagging
        // and is janky. Now it is there but transparent, doing nothing.
        mEmbeddedContentScrim.setOnClickListener(null);
        mEmbeddedContentScrim.setClickable(false);
        mExpandCollapseIcon.setBackgroundResource(R.drawable.ic_expand_more);
    } else {
        if (mMoreOptionsButton.getVisibility() != View.GONE) {
            mMoreOptionsButton.setVisibility(View.VISIBLE);
        }
        mDraggableContent.setVisibility(View.VISIBLE);
    }
}

From source file:me.lizheng.deckview.views.DeckView.java

/**
 * Synchronizes the views with the model
 *//*from   w w w  .  j  a va  2s.  co m*/
boolean synchronizeStackViewsWithModel() {
    if (mStackViewsDirty) {
        // Get all the task transforms
        ArrayList<T> data = mCallback.getData();
        float stackScroll = mStackScroller.getStackScroll();
        int[] visibleRange = mTmpVisibleRange;
        boolean isValidVisibleRange = updateStackTransforms(mCurrentTaskTransforms, data, stackScroll,
                visibleRange, false);

        // Return all the invisible children to the pool
        mTmpTaskViewMap.clear();
        int childCount = getChildCount();
        for (int i = childCount - 1; i >= 0; i--) {
            @SuppressWarnings("unchecked")
            DeckChildView<T> tv = (DeckChildView) getChildAt(i);
            T key = tv.getAttachedKey();
            int taskIndex = data.indexOf(key);

            if (visibleRange[1] <= taskIndex && taskIndex <= visibleRange[0]) {
                mTmpTaskViewMap.put(key, tv);
            } else {
                mViewPool.returnViewToPool(tv);
            }
        }

        for (int i = visibleRange[0]; isValidVisibleRange && i >= visibleRange[1]; i--) {
            T key = data.get(i);
            DeckChildViewTransform transform = mCurrentTaskTransforms.get(i);
            DeckChildView tv = mTmpTaskViewMap.get(key);

            if (tv == null) {
                // TODO Check
                tv = mViewPool.pickUpViewFromPool(key, key);

                if (mStackViewsAnimationDuration > 0) {
                    // For items in the list, put them in start animating them from the
                    // approriate ends of the list where they are expected to appear
                    if (Float.compare(transform.p, 0f) <= 0) {
                        mLayoutAlgorithm.getStackTransform(0f, 0f, mTmpTransform, null);
                    } else {
                        mLayoutAlgorithm.getStackTransform(1f, 0f, mTmpTransform, null);
                    }
                    tv.updateViewPropertiesToTaskTransform(mTmpTransform, 0);
                }
            }

            // Animate the task into place
            tv.updateViewPropertiesToTaskTransform(mCurrentTaskTransforms.get(i), mStackViewsAnimationDuration,
                    mRequestUpdateClippingListener);
        }

        // Reset the request-synchronize params
        mStackViewsAnimationDuration = 0;
        mStackViewsDirty = false;
        mStackViewsClipDirty = true;
        return true;
    }
    return false;
}

From source file:name.nanek.gdwprototype.shared.model.support.CompareToBuilder.java

/**
 * <p>Appends to the <code>builder</code> the comparison of
 * two <code>float</code>s.</p>
 *
 * <p>This handles NaNs, Infinities, and <code>-0.0</code>.</p>
 *
 * <p>It is compatible with the hash code generated by
 * <code>HashCodeBuilder</code>.</p>
 *
 * @param lhs  left-hand value//from w w w .j  a  v a  2  s  .c  o m
 * @param rhs  right-hand value
 * @return this - used to chain append calls
 */
public CompareToBuilder append(float lhs, float rhs) {
    if (comparison != 0) {
        return this;
    }
    comparison = Float.compare(lhs, rhs);
    return this;
}

From source file:org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity.ReservedContainerCandidatesSelector.java

private List<NodeForPreemption> getNodesForPreemption(Resource cluster,
        Map<String, Map<String, Resource>> queueToPreemptableResourceByPartition,
        Map<ApplicationAttemptId, Set<RMContainer>> selectedCandidates, Resource totalPreemptionAllowed) {
    List<NodeForPreemption> nfps = new ArrayList<>();

    // get nodes have reserved container
    for (FiCaSchedulerNode node : preemptionContext.getScheduler().getAllNodes().values()) {
        if (node.getReservedContainer() != null) {
            NodeForPreemption nfp = getPreemptionCandidatesOnNode(node, cluster,
                    queueToPreemptableResourceByPartition, selectedCandidates, totalPreemptionAllowed, true);
            if (null != nfp) {
                // Null means we cannot preempt containers on the node to satisfy
                // reserved container
                nfps.add(nfp);//from  ww  w.  j  a v  a 2  s .c  o m
            }
        }
    }

    // Return sorted node-for-preemptions (by cost)
    Collections.sort(nfps, new Comparator<NodeForPreemption>() {
        @Override
        public int compare(NodeForPreemption o1, NodeForPreemption o2) {
            return Float.compare(o1.preemptionCost, o2.preemptionCost);
        }
    });

    return nfps;
}

From source file:indexer.DocVector.java

@Override
public int compareTo(DocVector that) {
    return Float.compare(this.distFromQry, that.distFromQry);
}

From source file:org.apache.hadoop.yarn.client.api.impl.TimelineClientImpl.java

protected TimelineWriter createTimelineWriter(Configuration conf, UserGroupInformation ugi, Client webClient,
        URI uri) throws IOException {
    if (Float.compare(this.timelineServiceVersion, 1.5f) == 0) {
        return new FileSystemTimelineWriter(conf, ugi, webClient, uri);
    } else {// w  w w  .  jav a 2s.  c o  m
        return new DirectTimelineWriter(ugi, webClient, uri);
    }
}