List of usage examples for java.lang Float isNaN
public static boolean isNaN(float v)
From source file:net.myrrix.common.collection.FastByIDFloatMap.java
public void increment(long key, float delta) { Preconditions.checkArgument(key != KEY_NULL && key != REMOVED); int index = find(key); float currentValue = values[index]; if (Float.isNaN(currentValue)) { put(key, delta);/*from w w w. j a v a 2s . com*/ } else { values[index] = currentValue + delta; } }
From source file:com.tmall.wireless.tangram.view.BannerViewPager.java
protected void onMeasurePage(int widthMeasureSpec, int heightMeasureSpec) { View child = pagerAdapter.getViewAtPosition(getCurrentItem()); if (child == null) { child = getChildAt(0);//w w w . j ava 2 s.c om } if (child == null) { return; } int childCount = getChildCount(); for (int i = 0; i < childCount; 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 = 0; if (!Double.isNaN(itemRatio)) { int itemHeight = (int) (childWidth / itemRatio); for (int i = 0; i < childCount; i++) { View view = getChildAt(i); view.measure(MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(itemHeight, MeasureSpec.EXACTLY)); } } else { for (int i = 0; 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); } } } 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; i < childCount; i++) { View view = getChildAt(i); view.measure(MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY), heightMeasureSpec); } } else { if (autoMeasureHeight) { constrainLength = MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.EXACTLY); setMeasuredDimension(getMeasuredWidth(), childHeight); } } if (!pagerAdapter.isEnableMultiScr()) { return; } int pageLength = getMeasuredWidth(); final int childLength = child.getMeasuredWidth(); // Check that the measurement was successful if (childLength > 0) { 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:org.fhcrc.cpl.viewer.quant.gui.PanelWithLogRatioHistAndFields.java
/** * Set the log ratios, build the histogram and display, removing the old one if there was one. Nothing gets * cleaned up related to the old chart; it'll just hang around intil GC * todo: do I need to dispose of the old chart in a better way? * @param logRatios//from w w w .jav a 2s . co m */ public void setLogRatios(List<Float> logRatios) { _log.debug("setLogRatios 1"); if (logRatioHistogram != null) { remove(logRatioHistogram); } this.logRatios = logRatios; float minLogRatioBound = (float) Math.log(minRatioBound); float maxLogRatioBound = (float) Math.log(maxRatioBound); _log.debug("setLogRatios 2"); List<Float> boundedLogRatios = new ArrayList<Float>(logRatios.size()); for (float logRatio : logRatios) boundedLogRatios.add(Math.min(maxLogRatioBound, Math.max(minLogRatioBound, logRatio))); logRatioHistogram = new PanelWithHistogram(boundedLogRatios, "Log Ratios", 200); Dimension histDimension = new Dimension(300, 80); if (!Float.isNaN(domainCrosshairValue)) { logRatioHistogram.getChart().getXYPlot().setDomainCrosshairValue(domainCrosshairValue, true); logRatioHistogram.getChart().getXYPlot().setDomainCrosshairVisible(true); } _log.debug("setLogRatios 1"); logRatioHistogram.setPreferredSize(histDimension); logRatioHistogram.getChart().removeLegend(); logRatioHistogram.getChart().getXYPlot().getDomainAxis().setLowerBound(minLogRatioBound); logRatioHistogram.getChart().getXYPlot().getDomainAxis().setUpperBound(maxLogRatioBound); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.anchor = GridBagConstraints.LINE_START; gbc.insets = new Insets(0, 0, 0, 0); gbc.weighty = 10; gbc.weightx = 1; gbc.gridwidth = GridBagConstraints.REMAINDER; add(logRatioHistogram, gbc); histMouseListener = new LogRatioHistMouseListener(logRatioHistogram); ChartPanel histChartPanel = logRatioHistogram.getChartPanel(); histChartPanel.setMouseZoomable(false); logRatioHistogram.getChartPanel().addMouseListener(histMouseListener); logRatioHistogram.getChartPanel().addMouseMotionListener(histMouseListener); histMouseListener.addRangeUpdateListener(new LogRatioHistogramListener(this)); logRatioHistogram.updateUI(); //if there are specified minHigh and maxHigh values, and they're valid, draw the initially selected region if (minHighRatio > maxLowRatio && minHighRatio > 0 && maxLowRatio > 0) updateSelectedRegion(); //remove axes from chart ((XYPlot) logRatioHistogram.getPlot()).getRangeAxis().setVisible(false); ((XYPlot) logRatioHistogram.getPlot()).getDomainAxis().setVisible(false); logRatioHistogram.updateUI(); }
From source file:com.tmall.wireless.tangram3.view.BannerViewPager.java
protected void onMeasurePage(int widthMeasureSpec, int heightMeasureSpec) { if (pagerAdapter == null) { return;// www . j av a 2 s.co m } View child = pagerAdapter.getViewAtPosition(getCurrentItem()); if (child == null) { child = getChildAt(0); } if (child == null) { return; } int childCount = getChildCount(); for (int i = 0; i < childCount; 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 = 0; if (!Double.isNaN(itemRatio) || itemRatio != 0) { int itemHeight = (int) (childWidth / itemRatio); for (int i = 0; i < childCount; i++) { View view = getChildAt(i); view.measure(MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(itemHeight, MeasureSpec.EXACTLY)); } } else { for (int i = 0; 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); } } } 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; i < childCount; i++) { View view = getChildAt(i); view.measure(MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY), heightMeasureSpec); } } else { if (autoMeasureHeight) { constrainLength = MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.EXACTLY); setMeasuredDimension(getMeasuredWidth(), childHeight); } } if (!pagerAdapter.isEnableMultiScr()) { return; } int pageLength = getMeasuredWidth(); final int childLength = child.getMeasuredWidth(); // Check that the measurement was successful if (childLength > 0) { 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:savant.diff.DiffDataSource.java
/** * The number of records we return will be based on the first input. In some cases, * the second input may not happen to have a point at the expected location, so * we may have to interpolate./*from ww w .j a v a 2s . c om*/ * * The data-sources are expected to return records in order, so we can count on that * to simplify our task. */ @Override public List<ContinuousRecord> getRecords(String ref, RangeAdapter range, Resolution res, RecordFilterAdapter filter) throws InterruptedException, IOException { List<ContinuousRecord> result = null; if (inputsAttached()) { List<? extends ContinuousRecord> aRecords = inputA.getRecords(ref, range, res, filter); List<? extends ContinuousRecord> bRecords = inputB.getRecords(ref, range, res, filter); result = new ArrayList<ContinuousRecord>(aRecords.size()); int j = 0; ContinuousRecord recB = bRecords.get(j); for (int i = 0; i < aRecords.size(); i++) { ContinuousRecord recA = aRecords.get(i); int pos = recA.getPosition(); // Figure out which record in B corresponds to A. while (recB.getPosition() < pos && j + 1 < bRecords.size()) { j++; recB = bRecords.get(j); } // For the purposes of this demonstration, we'll treat NaNs as zero. float value = recA.getValue(); if (Float.isNaN(value)) { value = 0.0f; } value -= interpolate(bRecords, j, pos); result.add(GenericContinuousRecord.valueOf(ref, pos, value)); } } return result; }
From source file:IdentityHashMap.java
/** * Constructs a new, empty map with the specified initial * capacity and the specified load factor. * * @param initialCapacity the initial capacity of the HashMap. * @param loadFactor the load factor of the HashMap * @throws IllegalArgumentException if the initial capacity is less * than zero, or if the load factor is nonpositive. *///from w w w . j ava2 s .c o m public IdentityHashMap(int initialCapacity, float loadFactor) { if (initialCapacity < 0) throw new IllegalArgumentException("Illegal Initial Capacity: " + initialCapacity); if (loadFactor <= 0 || Float.isNaN(loadFactor)) throw new IllegalArgumentException("Illegal Load factor: " + loadFactor); if (initialCapacity == 0) initialCapacity = 1; this.loadFactor = loadFactor; table = new Entry[initialCapacity]; threshold = (int) (initialCapacity * loadFactor); }
From source file:eu.itesla_project.modelica_export.records.LoadRecord.java
@Override public void createRecord(ModExportContext modContext, DDBManager ddbManager, SimulatorInst simulator) { if (!Float.isNaN(this.busVoltage) && this.busConnected) { if (super.isCorrect()) { if (super.getModelicaType() != null) this.addValue(super.getModelicaType() + StaticData.WHITE_SPACE); else//from w w w. j a v a2 s .c om this.addValue(DEFAULT_LOAD_TYPE + StaticData.WHITE_SPACE); this.addValue(super.getModelicaName()); this.addValue(" ("); this.addValue(StaticData.NEW_LINE); if (!iidmloadParameters.isEmpty()) { for (int i = 0; i < iidmloadParameters.size() - 1; i++) { if (iidmloadParameters.get(i).getValue() != null) { this.addValue("\t " + iidmloadParameters.get(i).getName() + " = " + iidmloadParameters.get(i).getValue() + ","); } else { this.addValue("\t " + iidmloadParameters.get(i).getName() + ","); } this.addValue(StaticData.NEW_LINE); } this.addValue("\t " + iidmloadParameters.get(iidmloadParameters.size() - 1).getName() + " = " + iidmloadParameters.get(iidmloadParameters.size() - 1).getValue()); this.addValue(StaticData.NEW_LINE); } else if (!loadParameters.isEmpty()) { for (int i = 0; i < loadParameters.size() - 1; i++) { this.addValue("\t " + loadParameters.get(i).getName() + " = " + loadParameters.get(i).getValue() + ","); this.addValue(StaticData.NEW_LINE); } this.addValue("\t " + loadParameters.get(loadParameters.size() - 1).getName() + " = " + loadParameters.get(loadParameters.size() - 1).getValue()); this.addValue(StaticData.NEW_LINE); } this.addValue("\t " + EurostagFixedData.ANNOT); //Clear data iidmloadParameters = null; loadParameters = null; } else _log.error(this.getModelicaName() + " not added to grid model."); } else { _log.warn("Load " + this.getModelicaName() + " disconnected."); this.addValue(StaticData.COMMENT + " Load " + this.getModelicaName() + " disconnected."); } }
From source file:com.cloudera.oryx.als.computation.merge.MergeNewOldValuesFn.java
private void output(long userID, LongFloatMap oldPrefs, LongFloatMap newPrefs, LongSet removedItemIDs, Emitter<Pair<Long, NumericIDValue>> emitter) { // Old prefs may be null when there is no previous generation, for example, or the user is new. // First, write out existing prefs, possibly updated by new values if (oldPrefs != null && !oldPrefs.isEmpty()) { for (LongFloatMap.MapEntry entry : oldPrefs.entrySet()) { long itemID = entry.getKey(); float oldPrefValue = entry.getValue(); Preconditions.checkState(!Float.isNaN(oldPrefValue), "No prior pref value?"); // May be NaN if no new data at all, or new data has no update: float sum = oldPrefValue; if (newPrefs != null) { float newPrefValue = newPrefs.get(itemID); if (!Float.isNaN(newPrefValue)) { sum += newPrefValue; }//from w ww . jav a 2 s . c om } boolean remove = false; if (removedItemIDs != null && removedItemIDs.contains(itemID)) { remove = true; } else if (FastMath.abs(sum) <= zeroThreshold) { remove = true; } if (!remove) { emitter.emit(Pair.of(userID, new NumericIDValue(itemID, sum))); } } } // Now output new data, that didn't exist in old prefs if (newPrefs != null && !newPrefs.isEmpty()) { for (LongFloatMap.MapEntry entry : newPrefs.entrySet()) { long itemID = entry.getKey(); if (oldPrefs == null || !oldPrefs.containsKey(itemID)) { // It wasn't already written. If it exists in newPrefs, it's also not removed float newPrefValue = entry.getValue(); if (FastMath.abs(newPrefValue) > zeroThreshold) { emitter.emit(Pair.of(userID, new NumericIDValue(itemID, newPrefValue))); } } } } }
From source file:com.frank.search.solr.core.mapping.SimpleSolrPersistentProperty.java
@Override public boolean isBoosted() { Float boost = getBoost(); return boost != null && !Float.isNaN(boost); }
From source file:com.qs.qswlw.view.Mypager.UltraViewPager.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (!Float.isNaN(ratio)) { int widthSize = MeasureSpec.getSize(widthMeasureSpec); heightMeasureSpec = MeasureSpec.makeMeasureSpec((int) (widthSize / ratio), MeasureSpec.EXACTLY); }/* ww w . j av a2 s. co m*/ size.set(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec)); if (maxWidth >= 0 || maxHeight >= 0) { maxSize.set(maxWidth, maxHeight); constrainTo(size, maxSize); widthMeasureSpec = MeasureSpec.makeMeasureSpec(size.x, MeasureSpec.EXACTLY); heightMeasureSpec = MeasureSpec.makeMeasureSpec(size.y, MeasureSpec.EXACTLY); } if (viewPager.getConstrainLength() > 0) { if (viewPager.getConstrainLength() == heightMeasureSpec) { viewPager.measure(widthMeasureSpec, heightMeasureSpec); setMeasuredDimension(size.x, size.y); } else { if (viewPager.getScrollMode() == ScrollMode.HORIZONTAL) { super.onMeasure(widthMeasureSpec, viewPager.getConstrainLength()); } else { super.onMeasure(viewPager.getConstrainLength(), heightMeasureSpec); } } } else { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } }