Example usage for java.lang Float isNaN

List of usage examples for java.lang Float isNaN

Introduction

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

Prototype

public static boolean isNaN(float v) 

Source Link

Document

Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.

Usage

From source file:org.apache.hadoop.hbase.regionserver.LruHashMap.java

/**
 * Constructs a new, empty map with the specified initial capacity,
 * load factor, and maximum memory usage.
 *
 * @param initialCapacity the initial capacity
 * @param loadFactor the load factor/*from w  w  w .j a  va2 s  .  c o m*/
 * @param maxMemUsage the maximum total memory usage
 * @throws IllegalArgumentException if the initial capacity is less than one
 * @throws IllegalArgumentException if the initial capacity is greater than
 * the maximum capacity
 * @throws IllegalArgumentException if the load factor is <= 0
 * @throws IllegalArgumentException if the max memory usage is too small
 * to support the base overhead
 */
public LruHashMap(int initialCapacity, float loadFactor, long maxMemUsage) {
    if (initialCapacity < 1) {
        throw new IllegalArgumentException("Initial capacity must be > 0");
    }
    if (initialCapacity > MAXIMUM_CAPACITY) {
        throw new IllegalArgumentException("Initial capacity is too large");
    }
    if (loadFactor <= 0 || Float.isNaN(loadFactor)) {
        throw new IllegalArgumentException("Load factor must be > 0");
    }
    if (maxMemUsage <= (OVERHEAD + initialCapacity * ClassSize.REFERENCE)) {
        throw new IllegalArgumentException("Max memory usage too small to " + "support base overhead");
    }

    /** Find a power of 2 >= initialCapacity */
    int capacity = calculateCapacity(initialCapacity);
    this.loadFactor = loadFactor;
    this.threshold = calculateThreshold(capacity, loadFactor);
    this.entries = new Entry[capacity];
    this.memFree = maxMemUsage;
    this.memTotal = maxMemUsage;
    init();
}

From source file:com.tmall.wireless.tangram3.structure.card.GridCard.java

@Nullable
@Override//from  w  ww .  j a  v a2  s .c om
public LayoutHelper convertLayoutHelper(@Nullable LayoutHelper helper) {
    //create new layoutHelper to simplify recycling background view in vlayout
    RangeGridLayoutHelper gridHelper = new RangeGridLayoutHelper(1, mCells.size());

    gridHelper.setItemCount(mCells.size());
    gridHelper.setSpanCount(mColumn);

    // update style
    if (style instanceof GridStyle) {
        GridStyle gridStyle = (GridStyle) style;

        int totalColumn = mColumn;
        if (gridStyle.column > 0) {
            totalColumn = gridStyle.column;
            gridHelper.setSpanCount(gridStyle.column);
        }

        gridHelper.setSpanSizeLookup(new CellSpanSizeLookup(mCells, totalColumn));

        gridHelper.setVGap(gridStyle.vGap);
        gridHelper.setHGap(gridStyle.hGap);
        gridHelper.setAutoExpand(gridStyle.autoExpand);

        if (gridStyle.cols != null && gridStyle.cols.length > 0) {
            gridHelper.setWeights(gridStyle.cols);
        }

        if (!Float.isNaN(gridStyle.aspectRatio)) {
            gridHelper.setAspectRatio(gridStyle.aspectRatio);
        }
    }

    gridHelper.getRootRangeStyle().onClearChildMap();
    convertChildLayoutHelper(gridHelper, this);

    return gridHelper;
}

From source file:org.janusgraph.core.attribute.Geoshape.java

@Override
public boolean equals(Object other) {
    if (this == other)
        return true;
    else if (other == null)
        return false;
    else if (!getClass().isInstance(other))
        return false;
    Geoshape oth = (Geoshape) other;/*from  w  w w  .j a v a  2  s.co m*/
    Preconditions.checkArgument(coordinates.length == 2 && oth.coordinates.length == 2);
    for (int i = 0; i < coordinates.length; i++) {
        if (coordinates[i].length != oth.coordinates[i].length)
            return false;
        for (int j = 0; j < coordinates[i].length; j++) {
            if (Float.isNaN(coordinates[i][j]) && Float.isNaN(oth.coordinates[i][j]))
                continue;
            if (coordinates[i][j] != oth.coordinates[i][j])
                return false;
        }
    }
    return true;
}

From source file:org.netbeans.util.source.minify.Minify.java

public void minify() {
    MinifyProperty minifyProperty = MinifyProperty.getInstance();
    InputOutput io = IOProvider.getDefault().getIO(Bundle.CTL_Minify(), false);
    MinifyUtil util = new MinifyUtil();
    try {//  w w  w . j  av a 2 s.  c  o m
        long startTime = new Date().getTime();
        FileObject source = context.getPrimaryFile();
        FileObject target = null;
        if (minifyProperty.isSeparatBuild()) {
            File sourceFile = FileUtil.toFile(source);
            File targetFile = getTargetFolder(new File(
                    sourceFile.getParentFile().getPath() + File.separator + sourceFile.getName() + "_BUILD"));
            FileUtils.copyDirectory(sourceFile, targetFile);
            target = FileUtil.toFileObject(targetFile);
        } else {
            target = source;
        }

        MinifyResult minifyResult = util.minify(target, minifyProperty);
        long endTime = new Date().getTime();
        long totalTime = endTime - startTime;

        minifyResult.setDirectories(minifyResult.getDirectories() + 1);
        float jsSpaceSaved = (1
                - ((float) minifyResult.getOutputJsFilesSize() / (float) minifyResult.getInputJsFilesSize()))
                * 100;
        float cssSpaceSaved = (1
                - ((float) minifyResult.getOutputCssFilesSize() / (float) minifyResult.getInputCssFilesSize()))
                * 100;
        float htmlSpaceSaved = (1 - ((float) minifyResult.getOutputHtmlFilesSize()
                / (float) minifyResult.getInputHtmlFilesSize())) * 100;
        float xmlSpaceSaved = (1
                - ((float) minifyResult.getOutputXmlFilesSize() / (float) minifyResult.getInputXmlFilesSize()))
                * 100;
        float jsonSpaceSaved = (1 - ((float) minifyResult.getOutputJsonFilesSize()
                / (float) minifyResult.getInputJsonFilesSize())) * 100;

        String cssEval = "", jsEval = "", htmlEval = "", xmlEval = "", jsonEval = "";

        if (!Float.isNaN(jsSpaceSaved)) {
            jsEval = "Input JS Files Size :  " + minifyResult.getInputJsFilesSize() + " Bytes \n"
                    + "After Minifying JS Files Size :  " + minifyResult.getOutputJsFilesSize() + " Bytes \n"
                    + "JS Space Saved " + jsSpaceSaved + "% \n";
        }
        if (!Float.isNaN(cssSpaceSaved)) {
            cssEval = "Input CSS Files Size :  " + minifyResult.getInputCssFilesSize() + " Bytes \n"
                    + "After Minifying CSS Files Size :  " + minifyResult.getOutputCssFilesSize() + " Bytes \n"
                    + "CSS Space Saved " + cssSpaceSaved + "% \n";
        }
        if (!Float.isNaN(htmlSpaceSaved)) {
            htmlEval = "Input HTML Files Size :  " + minifyResult.getInputHtmlFilesSize() + " Bytes \n"
                    + "After Minifying HTML Files Size :  " + minifyResult.getOutputHtmlFilesSize()
                    + " Bytes \n" + "HTML Space Saved " + htmlSpaceSaved + "% \n";
        }
        if (!Float.isNaN(xmlSpaceSaved)) {
            xmlEval = "Input XML Files Size :  " + minifyResult.getInputXmlFilesSize() + " Bytes \n"
                    + "After Minifying XML Files Size :  " + minifyResult.getOutputXmlFilesSize() + " Bytes \n"
                    + "XML Space Saved " + xmlSpaceSaved + "% \n";
        }
        if (!Float.isNaN(jsonSpaceSaved)) {
            jsonEval = "Input JSON Files Size :  " + minifyResult.getInputJsonFilesSize() + " Bytes \n"
                    + "After Minifying JSON Files Size :  " + minifyResult.getOutputJsonFilesSize()
                    + " Bytes \n" + "JSON Space Saved " + jsonSpaceSaved + "% \n";
        }
        if (minifyProperty.isEnableOutputLogAlert()) {
            JOptionPane.showMessageDialog(null, "Js Css Minified Completed Successfully \n Logs - \n"
                    + minifyResult.getDirectories() + " Directories Found \n" + minifyResult.getJsFiles()
                    + " JS Files Minified \n" + minifyResult.getCssFiles() + " CSS Files Minified \n"
                    + minifyResult.getHtmlFiles() + " HTML Files Minified \n" + minifyResult.getXmlFiles()
                    + " XML Files Minified \n" + minifyResult.getJsonFiles() + " JSON Files Minified \n"
                    + jsEval + cssEval + htmlEval + xmlEval + jsonEval + "Total Time - " + totalTime + "ms");
        }
    } catch (Exception ex) {
        io.getOut().println("Exception: " + ex.toString());
    }
}

From source file:MutableFloat.java

/**
 * Checks whether the float value is the special NaN value.
 * 
 * @return true if NaN
 */
public boolean isNaN() {
    return Float.isNaN(value);
}

From source file:WeakIdentityMap.java

public WeakIdentityMap(int initialCapacity, float loadFactor) {
    if (initialCapacity <= 0) {
        throw new IllegalArgumentException("Initial capacity must be greater than 0");
    }/*from   w  w w  . ja  v a 2s. c o  m*/
    if (loadFactor <= 0 || Float.isNaN(loadFactor)) {
        throw new IllegalArgumentException("Load factor must be greater than 0");
    }
    this.loadFactor = loadFactor;
    this.table = new Entry[initialCapacity];
    this.threshold = (int) (initialCapacity * loadFactor);
    this.queue = new ReferenceQueue();
}

From source file:org.caleydo.core.util.impute.KNNImpute.java

@Override
protected Table<Integer, Integer, Float> compute() {
    //      data/* w  ww .  ja  v a 2 s.  c om*/
    //      An expression matrix with genes in the rows, samples in the columns
    //      k
    //      Number of neighbors to be used in the imputation (default=10)
    //      rowmax
    //      The maximum percent missing data allowed in any row (default 50%). For any
    //      rows with more than rowmax% missing are imputed using the overall mean per
    //      sample.
    //      colmax
    //      The maximum percent missing data allowed in any column (default 80%). If
    //      any column has more than colmax% missing data, the program halts and reports
    //      an error.
    //      maxp
    //      The largest block of genes imputed using the knn algorithm inside impute.knn
    //      (default 1500); larger blocks are divided by two-means clustering (recursively)
    //      prior to imputation. If maxp=p, only knn imputation is done.
    //      rng.seed
    //      The seed used for the random number generator (default 362436069) for repro-
    //      ducibility.
    //      impute.knn uses k-nearest neighbors in the space of genes to impute missing expression values.
    //      For each gene with missing values, we find the k nearest neighbors using a Euclidean metric, con-
    //      fined to the columns for which that gene is NOT missing. Each candidate neighbor might be missing
    //      some of the coordinates used to calculate the distance. In this case we average the distance from
    //      the non-missing coordinates. Having found the k nearest neighbors for a gene, we impute the miss-
    //      ing elements by averaging those (non-missing) elements of its neighbors. This can fail if ALL the
    //      neighbors are missing in a particular element. In this case we use the overall column mean for that
    //      block of genes.
    //      Since nearest neighbor imputation costs O(plog(p)) operations per gene, where p is the number
    //      of rows, the computational time can be excessive for large p and a large number of missing rows.
    //      Our strategy is to break blocks with more than maxp genes into two smaller blocks using two-mean
    //      clustering. This is done recursively till all blocks have less than maxp genes. For each block, k-
    //      nearest neighbor imputation is done separately. We have set the default value of maxp to 1500.
    //      Depending on the speed of the machine, and number of samples, this number might be increased.
    //      Making it too small is counter-productive, because the number of two-mean clustering algorithms
    //      will increase.

    if (toomanyNaNsInAColumn())
        throw new IllegalStateException();

    final float rowMax = desc.getRowmax();
    final boolean validRowMax = !Float.isInfinite(rowMax) && !Float.isNaN(rowMax);
    final int max = validRowMax ? Math.round(desc.getRowmax() * samples) : 0;

    //list of possible
    List<Gene> neighborhood;
    int withMissing = 0;
    Collection<ForkJoinTask<Void>> tasks = new ArrayList<>();
    if (!validRowMax) {
        neighborhood = genes;// all genes
    } else {
        neighborhood = new ArrayList<>(genes.size());
        for (Gene gene : genes) {
            if (gene.getNaNs() == 0) {// nothing to impute
                neighborhood.add(gene);
            } else if (validRowMax && gene.getNaNs() > max) { // too many nans use the sample mean
                tasks.add(new ImputeSampleMean(gene));
                //not a good neighbor
            } else {
                // neighbor but something needs to be done
                neighborhood.add(gene);
                withMissing++;
            }
        }
    }

    if (withMissing > 0)
        tasks.add(new ImputeKNNMean(neighborhood));
    invokeAll(tasks);

    ImmutableTable.Builder<Integer, Integer, Float> b = ImmutableTable.builder();
    for (Gene gene : genes) {
        if (gene.isAnySet()) {
            gene.fillImpute(b);
        }
    }
    return b.build();
}

From source file:com.cloudera.oryx.als.serving.ServerRecommender.java

@Override
public void ingest(Reader reader) {
    for (CharSequence line : new FileLineIterable(reader)) {
        String[] columns = DelimitedDataUtils.decode(line);
        if (columns.length < 2) {
            throw new IllegalArgumentException("Bad line: [" + line + "]");
        }/*from   w w  w  .j  a  v a 2s .com*/
        String userID = columns[0];
        String itemID = columns[1];
        if (columns.length > 2) {
            String valueToken = columns[2];
            float value = valueToken.isEmpty() ? Float.NaN : LangUtils.parseFloat(valueToken);
            if (Float.isNaN(value)) {
                removePreference(userID, itemID);
            } else {
                setPreference(userID, itemID, value);
            }
        } else {
            setPreference(userID, itemID);
        }
    }
}

From source file:com.qs.qswlw.view.Mypager.UltraViewPagerView.java

protected void onMeasurePage(int widthMeasureSpec, int heightMeasureSpec) {
    Log.d("TEST", "onMeasurePage" + getCurrentItem());
    View child = pagerAdapter.getViewAtPosition(getCurrentItem());
    if (child == null) {
        child = getChildAt(0);/*  ww  w . j a v a2 s . c  om*/
    }
    if (child == null) {
        return;
    }
    for (int i = 0; i < getChildCount(); i++) {
        View view = getChildAt(i);
        if ((view.getPaddingLeft() != itemMarginLeft || view.getPaddingTop() != itemMarginTop
                || view.getPaddingRight() != itemMarginRight || view.getPaddingBottom() != itemMarginBottom)) {
            view.setPadding(itemMarginLeft, itemMarginTop, itemMarginRight, itemMarginBottom);
        }
    }

    ViewGroup.LayoutParams lp = child.getLayoutParams();
    final int childWidthSpec = getChildMeasureSpec(widthMeasureSpec, 0, lp.width);
    final int childHeightSpec = getChildMeasureSpec(heightMeasureSpec, 0, lp.height);

    int childWidth = (int) ((MeasureSpec.getSize(childWidthSpec) - getPaddingLeft() - getPaddingRight())
            * pagerAdapter.getPageWidth(getCurrentItem()));
    int childHeight = MeasureSpec.getSize(childHeightSpec) - getPaddingTop() - getPaddingBottom();

    if (!needsMeasurePage || childWidth == 0 && childHeight == 0) {
        return;
    }

    if (!Double.isNaN(itemRatio)) {
        int itemHeight = (int) (childWidth / itemRatio);
        for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
            View view = getChildAt(i);
            view.measure(MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY),
                    MeasureSpec.makeMeasureSpec(itemHeight, MeasureSpec.EXACTLY));
        }
    } else {
        for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
            View view = getChildAt(i);
            if (pagerAdapter.getPageWidth(getCurrentItem()) != 1) {
                view.measure(MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY),
                        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            } else {
                view.measure(childWidthSpec, childHeightSpec);
            }
        }
    }

    final boolean isHorizontalScroll = scrollMode == UltraViewPager.ScrollMode.HORIZONTAL;

    childWidth = itemMarginLeft + child.getMeasuredWidth() + itemMarginRight;
    childHeight = itemMarginTop + child.getMeasuredHeight() + itemMarginBottom;

    if (!Float.isNaN(ratio)) {
        heightMeasureSpec = MeasureSpec.makeMeasureSpec((int) (getMeasuredWidth() / ratio),
                MeasureSpec.EXACTLY);
        setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
        for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
            View view = getChildAt(i);
            view.measure(MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY), heightMeasureSpec);
        }
    } else {
        if (autoMeasureHeight) {
            if (isHorizontalScroll) {
                constrainLength = MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.EXACTLY);
                setMeasuredDimension(getMeasuredWidth(), childHeight);
            } else {
                constrainLength = MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY);
                setMeasuredDimension(childWidth, getMeasuredHeight());
            }

            needsMeasurePage = childHeight == itemMarginTop + itemMarginBottom;
        }
    }

    if (!pagerAdapter.isEnableMultiScr()) {
        return;
    }

    int pageLength = isHorizontalScroll ? getMeasuredWidth() : getMeasuredHeight();

    final int childLength = isHorizontalScroll ? child.getMeasuredWidth() : child.getMeasuredHeight();

    // Check that the measurement was successful
    if (childLength > 0) {
        needsMeasurePage = false;
        int difference = pageLength - childLength;
        if (getPageMargin() == 0) {
            setPageMargin(-difference);
        }
        int offscreen = (int) Math.ceil((float) pageLength / (float) childLength) + 1;
        setOffscreenPageLimit(offscreen);
        requestLayout();
    }
}

From source file:com.frank.search.solr.core.mapping.SimpleSolrPersistentProperty.java

@Override
public Float getBoost() {

    Float boost = Float.NaN;
    Indexed indexedAnnotation = getIndexAnnotation();
    if (indexedAnnotation != null) {
        boost = indexedAnnotation.boost();
    }/*ww  w . ja va2  s . co m*/
    return Float.isNaN(boost) ? null : boost;
}