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:edu.purdue.cc.bionet.ui.GraphVisualizer.java

/**
 * Scales to the given zoom level, 1.0 being 100%, centered on the 
 * given point./*from   ww w .  ja  va2  s . c  o  m*/
 * 
 * @param level The level to zoom to.
 * @param center The center point for the scaling operation.
 * @return The new zoom level.
 */
public float scaleTo(float level, Point2D center) {
    if (this.scrollPane == null)
        return 1.0f;
    float oldZoom = this.currentZoom;
    this.currentZoom = Math.max(minimumZoom, level);
    //      this.absoluteViewScaler.scale( this, level, center );
    Dimension viewSize;
    if (level < 1.0f) {
        viewSize = this.scrollPane.getSize();
    } else {
        viewSize = this.scrollPane.getViewport().getExtentSize();
    }
    Dimension newSize = new Dimension((int) (viewSize.width * currentZoom),
            (int) (viewSize.height * currentZoom));
    this.setPreferredSize(newSize);
    this.setSize(newSize);
    //      new LayoutScaler( this.getGraphLayout( )).setSize( newSize );
    if (Float.compare(level, 1.0f) <= 0)
        this.center();

    // translate the new view position so the mouse is in the same place
    // on the scaled view.
    JViewport vp = this.scrollPane.getViewport();
    double centerX = center.getX();
    double centerY = center.getY();
    double viewPortMouseX = centerX - vp.getViewPosition().getX();
    double viewPortMouseY = centerY - vp.getViewPosition().getY();
    centerX *= currentZoom / oldZoom;
    centerY *= currentZoom / oldZoom;
    viewPortMouseX = centerX - viewPortMouseX;
    viewPortMouseY = centerY - viewPortMouseY;
    vp.setViewPosition(new Point((int) viewPortMouseX, (int) viewPortMouseY));

    return this.currentZoom;
}

From source file:org.wso2.carbon.apimgt.hostobjects.AssetStoreHostObject.java

public static NativeArray jsFunction_getTopRatedAPIs(Context cx, final Scriptable thisObj, Object[] args,
        Function funObj) throws ScriptException, APIManagementException {

    NativeArray myn = new NativeArray(0);
    if (isStringArray(args)) {
        String limitArg = args[0].toString();
        int limit = Integer.parseInt(limitArg);
        try {/*from   w  ww . j av a2s  . c o  m*/
            GovernanceArtifact[] artifacts = getArtifacts(limit, thisObj);
            Arrays.sort(artifacts, new Comparator<GovernanceArtifact>() {
                public int compare(GovernanceArtifact o1, GovernanceArtifact o2) {
                    try {
                        Registry registry = getRegistry(thisObj);
                        return Float.compare(registry.getAverageRating(o1.getPath()),
                                registry.getAverageRating(o2.getPath()));
                    } catch (RegistryException ignored) {
                        return -1;
                    }
                }
            });
            buildDataRows(thisObj, myn, artifacts);
        } catch (NullPointerException e) {
            log.error("Error from Registry API while getting Top Rated APIs Information, "
                    + "No APIs in Registry", e);
            return myn;
        } catch (Exception e) {
            log.error("Error while getting Top Rated APIs Information", e);
            return myn;
        }

    } // end of the if
    return myn;
}

From source file:org.wso2.carbon.appmgt.hostobjects.AssetStoreHostObject.java

public static NativeArray jsFunction_getTopRatedAPIs(Context cx, final Scriptable thisObj, Object[] args,
        Function funObj) throws ScriptException, AppManagementException {

    NativeArray myn = new NativeArray(0);
    if (isStringArray(args)) {
        String limitArg = args[0].toString();
        int limit = Integer.parseInt(limitArg);
        try {//from   ww  w  . j a  v  a  2 s.  co m
            GovernanceArtifact[] artifacts = getArtifacts(limit, thisObj);
            Arrays.sort(artifacts, new Comparator<GovernanceArtifact>() {
                public int compare(GovernanceArtifact o1, GovernanceArtifact o2) {
                    try {
                        Registry registry = getRegistry(thisObj);
                        return Float.compare(registry.getAverageRating(o1.getPath()),
                                registry.getAverageRating(o2.getPath()));
                    } catch (RegistryException ignored) {
                        return -1;
                    }
                }
            });
            buildDataRows(thisObj, myn, artifacts);
        } catch (NullPointerException e) {
            log.error("Error from Registry WebApp while getting Top Rated APIs Information, "
                    + "No APIs in Registry", e);
            return myn;
        } catch (Exception e) {
            log.error("Error while getting Top Rated APIs Information", e);
            return myn;
        }

    } // end of the if
    return myn;
}

From source file:tds.assessment.Segment.java

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

    final Segment segment = (Segment) o;

    if (Float.compare(segment.startAbility, startAbility) != 0)
        return false;
    if (position != segment.position)
        return false;
    if (minItems != segment.minItems)
        return false;
    if (maxItems != segment.maxItems)
        return false;
    if (fieldTestMinItems != segment.fieldTestMinItems)
        return false;
    if (fieldTestMaxItems != segment.fieldTestMaxItems)
        return false;
    if (fieldTestStartPosition != segment.fieldTestStartPosition)
        return false;
    if (fieldTestEndPosition != segment.fieldTestEndPosition)
        return false;
    if (refreshMinutes != segment.refreshMinutes)
        return false;
    if (Float.compare(segment.blueprintWeight, blueprintWeight) != 0)
        return false;
    if (Float.compare(segment.itemWeight, itemWeight) != 0)
        return false;
    if (Float.compare(segment.abilityOffset, abilityOffset) != 0)
        return false;
    if (candidateSet1Size != segment.candidateSet1Size)
        return false;
    if (randomizer != segment.randomizer)
        return false;
    if (initialRandom != segment.initialRandom)
        return false;
    if (Float.compare(segment.abilityWeight, abilityWeight) != 0)
        return false;
    if (Float.compare(segment.reportingCandidateAbilityWeight, reportingCandidateAbilityWeight) != 0)
        return false;
    if (Float.compare(segment.precisionTarget, precisionTarget) != 0)
        return false;
    if (Float.compare(segment.precisionTargetMetWeight, precisionTargetMetWeight) != 0)
        return false;
    if (Float.compare(segment.precisionTargetNotMetWeight, precisionTargetNotMetWeight) != 0)
        return false;
    if (Float.compare(segment.adaptiveCut, adaptiveCut) != 0)
        return false;
    if (Float.compare(segment.tooCloseStandardErrors, tooCloseStandardErrors) != 0)
        return false;
    if (terminationOverallInformation != segment.terminationOverallInformation)
        return false;
    if (terminationReportingCategoryInfo != segment.terminationReportingCategoryInfo)
        return false;
    if (terminationMinCount != segment.terminationMinCount)
        return false;
    if (terminationTooClose != segment.terminationTooClose)
        return false;
    if (terminationFlagsAnd != segment.terminationFlagsAnd)
        return false;
    if (Float.compare(segment.slope, slope) != 0)
        return false;
    if (Float.compare(segment.intercept, intercept) != 0)
        return false;
    if (key != null ? !key.equals(segment.key) : segment.key != null)
        return false;
    if (label != null ? !label.equals(segment.label) : segment.label != null)
        return false;
    if (selectionAlgorithm != segment.selectionAlgorithm)
        return false;
    if (segmentId != null ? !segmentId.equals(segment.segmentId) : segment.segmentId != null)
        return false;
    if (subject != null ? !subject.equals(segment.subject) : segment.subject != null)
        return false;
    if (assessmentKey != null ? !assessmentKey.equals(segment.assessmentKey) : segment.assessmentKey != null)
        return false;
    if (fieldTestStartDate != null ? !fieldTestStartDate.equals(segment.fieldTestStartDate)
            : segment.fieldTestStartDate != null)
        return false;
    if (fieldTestEndDate != null ? !fieldTestEndDate.equals(segment.fieldTestEndDate)
            : segment.fieldTestEndDate != null)
        return false;
    if (candidateSet1Order != null ? !candidateSet1Order.equals(segment.candidateSet1Order)
            : segment.candidateSet1Order != null)
        return false;
    if (adaptiveVersion != null ? !adaptiveVersion.equals(segment.adaptiveVersion)
            : segment.adaptiveVersion != null)
        return false;
    if (forms != null ? !forms.equals(segment.forms) : segment.forms != null)
        return false;
    if (strands != null ? !strands.equals(segment.strands) : segment.strands != null)
        return false;
    return items != null ? items.equals(segment.items) : segment.items == null;
}

From source file:ml.shifu.shifu.core.dtrain.wdl.WDLWorker.java

private boolean isPositive(float value) {
    return Float.compare(1f, value) == 0;
}

From source file:org.shaman.terrain.polygonal.PolygonalMapGenerator.java

/**
 * Step 4: assign elevation/*from ww  w.ja  v  a  2  s.  c o m*/
 */
private void assignElevation() {
    if (graph == null) {
        return;
    }
    Random rand = new Random(seed * 2);
    //initialize border corners with zero elevation
    Deque<Graph.Corner> q = new ArrayDeque<>();
    for (Graph.Corner c : graph.corners) {
        if (c.border) {
            c.elevation = 0;
            q.add(c);
        } else {
            c.elevation = Float.POSITIVE_INFINITY;
        }
    }
    // Traverse the graph and assign elevations to each point. As we
    // move away from the map border, increase the elevations. This
    // guarantees that rivers always have a way down to the coast by
    // going downhill (no local minima).
    while (!q.isEmpty()) {
        Graph.Corner c = q.poll();
        for (Graph.Corner a : c.adjacent) {
            if (c.ocean && a.ocean && a.elevation > 0) {
                a.elevation = 0;
                q.addFirst(a);
                continue;
            }
            float elevation = c.elevation + (a.ocean ? 0 : 0.01f);
            if (!c.water && !a.water) {
                elevation += 1;
            }
            //add some more randomness
            //elevation += rand.nextDouble()/4;
            if (elevation < a.elevation) {
                a.elevation = elevation;
                q.add(a);
            }
        }
    }

    //redistribute elevation
    float SCALE_FACTOR = 1.1f;
    ArrayList<Graph.Corner> corners = new ArrayList<>();
    for (Graph.Corner c : graph.corners) {
        if (!c.ocean) {
            corners.add(c);
        }
    }
    Collections.sort(corners, new Comparator<Graph.Corner>() {
        @Override
        public int compare(Graph.Corner o1, Graph.Corner o2) {
            return Float.compare(o1.elevation, o2.elevation);
        }
    });
    for (int i = 0; i < corners.size(); i++) {
        // Let y(x) be the total area that we want at elevation <= x.
        // We want the higher elevations to occur less than lower
        // ones, and set the area to be y(x) = 1 - (1-x)^2.
        float y = (float) i / (float) (corners.size() - 1);
        float x = (float) (Math.sqrt(SCALE_FACTOR) - Math.sqrt(SCALE_FACTOR * (1 - y)));
        if (x > 1.0)
            x = 1; // TODO: does this break downslopes?
        corners.get(i).elevation = x;
    }

    assignCenterElevations();

    //update mesh
    updateElevationGeometry();
}

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

@Override
public void upgrade() {
    if (Float.compare(LATEST_VERSION, getVersion()) != 0) {
        // New version of the class, upgrade
        data.put(ExtendedCAServiceInfo.IMPLEMENTATIONCLASS, this.getClass().getName()); // For integration with CESeCore
        data.put(VERSION, new Float(LATEST_VERSION));
    }/*w  w  w  .  j  av  a  2 s . co  m*/
}

From source file:com.milaboratory.core.alignment.KAlignerParameters.java

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

    KAlignerParameters that = (KAlignerParameters) o;

    if (floatingLeftBound != that.floatingLeftBound)
        return false;
    if (floatingRightBound != that.floatingRightBound)
        return false;
    if (Float.compare(that.mapperRelativeMinScore, mapperRelativeMinScore) != 0)
        return false;
    if (mapperKValue != that.mapperKValue)
        return false;
    if (Float.compare(that.mapperMatchScore, mapperMatchScore) != 0)
        return false;
    if (maxAdjacentIndels != that.maxAdjacentIndels)
        return false;
    if (mapperMaxSeedsDistance != that.mapperMaxSeedsDistance)
        return false;
    if (minAlignmentLength != that.minAlignmentLength)
        return false;
    if (Float.compare(that.mapperAbsoluteMinScore, mapperAbsoluteMinScore) != 0)
        return false;
    if (mapperMinSeedsDistance != that.mapperMinSeedsDistance)
        return false;
    if (Float.compare(that.mapperMismatchPenalty, mapperMismatchPenalty) != 0)
        return false;
    if (Float.compare(that.mapperOffsetShiftPenalty, mapperOffsetShiftPenalty) != 0)
        return false;
    if (alignmentStopPenalty != that.alignmentStopPenalty)
        return false;
    if (!scoring.equals(that.scoring))
        return false;

    return true;//from  w  w  w  . j  a  va2 s . com
}

From source file:org.wso2.carbon.apimgt.hostobjects.AssetStoreHostObject.java

public static NativeArray jsFunction_getRecentlyAddedAPIs(Context cx, final Scriptable thisObj, Object[] args,
        Function funObj) throws ScriptException, APIManagementException {
    NativeArray apiArray = new NativeArray(0);
    if (isStringArray(args)) {
        String limitArg = args[0].toString();
        int limit = Integer.parseInt(limitArg);
        try {/*w ww .  ja va 2s. co  m*/
            GovernanceArtifact[] artifacts = getArtifacts(limit, thisObj);
            Arrays.sort(artifacts, new Comparator<GovernanceArtifact>() {
                public int compare(GovernanceArtifact o1, GovernanceArtifact o2) {
                    try {
                        Registry registry = getRegistry(thisObj);
                        return Float.compare(registry.get(o1.getPath()).getCreatedTime().getTime(),
                                registry.get(o2.getPath()).getCreatedTime().getTime());
                    } catch (RegistryException ignored) {
                        return -1;
                    }
                }
            });
            buildDataRows(thisObj, apiArray, artifacts);
        } catch (NullPointerException e) {
            log.error("Error from Registry API while getting Recently Added APIs Information,"
                    + " No APIs in Registry", e);
            return apiArray;
        } catch (Exception e) {
            log.error("Error while getting Recently Added APIs Information", e);
            return apiArray;
        }

    } // end of the if
    return apiArray;
}

From source file:org.wso2.carbon.appmgt.hostobjects.AssetStoreHostObject.java

public static NativeArray jsFunction_getRecentlyAddedAPIs(Context cx, final Scriptable thisObj, Object[] args,
        Function funObj) throws ScriptException, AppManagementException {
    NativeArray apiArray = new NativeArray(0);
    if (isStringArray(args)) {
        String limitArg = args[0].toString();
        int limit = Integer.parseInt(limitArg);
        try {/*from   ww w  . ja v a 2 s . co m*/
            GovernanceArtifact[] artifacts = getArtifacts(limit, thisObj);
            Arrays.sort(artifacts, new Comparator<GovernanceArtifact>() {
                public int compare(GovernanceArtifact o1, GovernanceArtifact o2) {
                    try {
                        Registry registry = getRegistry(thisObj);
                        return Float.compare(registry.get(o1.getPath()).getCreatedTime().getTime(),
                                registry.get(o2.getPath()).getCreatedTime().getTime());
                    } catch (RegistryException ignored) {
                        return -1;
                    }
                }
            });
            buildDataRows(thisObj, apiArray, artifacts);
        } catch (NullPointerException e) {
            log.error("Error from Registry WebApp while getting Recently Added APIs Information,"
                    + " No APIs in Registry", e);
            return apiArray;
        } catch (Exception e) {
            log.error("Error while getting Recently Added APIs Information", e);
            return apiArray;
        }

    } // end of the if
    return apiArray;
}