List of usage examples for java.lang Float NaN
float NaN
To view the source code for java.lang Float NaN.
Click Source Link
From source file:xyz.zpayh.hdimage.HDImageView.java
private float viewToSourceX(float vx) { if (mViewTranslate == null) return Float.NaN; return (vx - mViewTranslate.x) / mScale; }
From source file:android.support.v7.preference.Preference.java
/** * Attempts to persist a float to the {@link android.content.SharedPreferences}. * * @param value The value to persist.// w w w. j av a 2 s. c o m * @return True if this Preference is persistent. (This is not whether the * value was persisted, since we may not necessarily commit if there * will be a batch commit later.) * @see #persistString(String) * @see #getPersistedFloat(float) */ protected boolean persistFloat(float value) { if (shouldPersist()) { if (value == getPersistedFloat(Float.NaN)) { // It's already there, so the same as persisting return true; } SharedPreferences.Editor editor = mPreferenceManager.getEditor(); editor.putFloat(mKey, value); tryCommit(editor); return true; } return false; }
From source file:xyz.zpayh.hdimage.HDImageView.java
private float viewToSourceY(float vy) { if (mViewTranslate == null) return Float.NaN; return (vy - mViewTranslate.y) / mScale; }
From source file:com.yahoo.egads.models.tsmm.TestOlympicModel2.java
@Test public void predict() throws Exception { OlympicModel2 model = new OlympicModel2(config); TimeSeries ts = new TimeSeries(); ts.append(1475452800, 10);// ww w .java 2 s .c o m ts.append(1475453100, 25); ts.append(1476057600, 20); ts.append(1476057900, 45); ts.append(1476662400, 30); ts.append(1476662700, 55); ts.append(1477267200, 40); ts.append(1477267500, 65); model.train(ts.data); ts.append(1477872000, Float.NaN); ts.append(1477872300, Float.NaN); model.predict(ts.data); assertEquals(1477872000, ts.data.get(8).time); assertEquals(25, ts.data.get(8).value, 0.0001); assertEquals(1477872300, ts.data.get(9).time); assertEquals(47.5, ts.data.get(9).value, 0.0001); assertEquals(10, ts.data.size()); // new series ts = new TimeSeries(); ts.append(1477872000, Float.NaN); ts.append(1477872300, Float.NaN); model.predict(ts.data); assertEquals(1477872000, ts.data.get(0).time); assertEquals(25, ts.data.get(0).value, 0.0001); assertEquals(1477872300, ts.data.get(1).time); assertEquals(47.5, ts.data.get(1).value, 0.0001); assertEquals(2, ts.data.size()); // missing later point ts = new TimeSeries(); ts.append(1477872000, Float.NaN); model.predict(ts.data); assertEquals(1477872000, ts.data.get(0).time); assertEquals(25, ts.data.get(0).value, 0.0001); assertEquals(1, ts.data.size()); // missing first point ts = new TimeSeries(); ts.append(1477872300, Float.NaN); model.predict(ts.data); assertEquals(1477872300, ts.data.get(0).time); assertEquals(47.5, ts.data.get(0).value, 0.0001); assertEquals(1, ts.data.size()); // higher resolution sequence than model ts = new TimeSeries(); ts.append(1477872000, Float.NaN); ts.append(1477872060, Float.NaN); ts.append(1477872120, Float.NaN); ts.append(1477872180, Float.NaN); ts.append(1477872240, Float.NaN); ts.append(1477872300, Float.NaN); ts.append(1477872360, Float.NaN); model.predict(ts.data); assertEquals(1477872000, ts.data.get(0).time); assertEquals(25.0, ts.data.get(0).value, 0.0001); assertEquals(1477872060, ts.data.get(1).time); assertTrue(Float.isNaN(ts.data.get(1).value)); assertEquals(1477872120, ts.data.get(2).time); assertTrue(Float.isNaN(ts.data.get(2).value)); assertEquals(1477872180, ts.data.get(3).time); assertTrue(Float.isNaN(ts.data.get(3).value)); assertEquals(1477872240, ts.data.get(4).time); assertTrue(Float.isNaN(ts.data.get(4).value)); assertEquals(1477872300, ts.data.get(5).time); assertEquals(47.5, ts.data.get(5).value, 0.0001); assertEquals(1477872360, ts.data.get(6).time); assertTrue(Float.isNaN(ts.data.get(6).value)); assertEquals(7, ts.data.size()); }
From source file:au.org.ala.layers.intersect.Grid.java
/** * @param points input array for longitude and latitude * double[number_of_points][2] * @return array of .gri file values corresponding to the * points provided/*from ww w . jav a2s. co m*/ */ public float[] getValues(double[][] points) { //confirm inputs since they come from somewhere else if (points == null || points.length == 0) { return null; } //use preloaded grid data if available Grid g = Grid.getLoadedGrid(filename); if (g != null) { return g.getValues2(points); } if (subgrids != null) { return getValues3(points, Math.min(1024 * 1024, 64 * points.length)); } float[] ret = new float[points.length]; int length = points.length; long size; int i, pos; byte[] b; RandomAccessFile afile = null; File f2 = new File(filename + ".GRI"); try { //read of random access file can throw an exception if (!f2.exists()) { afile = new RandomAccessFile(filename + ".gri", "r"); } else { afile = new RandomAccessFile(filename + ".GRI", "r"); } if (datatype.equalsIgnoreCase("BYTE")) { size = 1; b = new byte[(int) size]; for (i = 0; i < length; i++) { pos = (int) getcellnumber(points[i][0], points[i][1]); if (pos >= 0) { afile.seek(pos * size); ret[i] = afile.readByte(); } else { ret[i] = Float.NaN; } } } else if (datatype.equalsIgnoreCase("UBYTE")) { size = 1; b = new byte[(int) size]; for (i = 0; i < length; i++) { pos = (int) getcellnumber(points[i][0], points[i][1]); if (pos >= 0) { afile.seek(pos * size); ret[i] = afile.readByte(); if (ret[i] < 0) { ret[i] += 256; } } else { ret[i] = Float.NaN; } } } else if (datatype.equalsIgnoreCase("SHORT")) { size = 2; b = new byte[(int) size]; for (i = 0; i < length; i++) { pos = (int) getcellnumber(points[i][0], points[i][1]); if (pos >= 0) { afile.seek(pos * size); afile.read(b); if (byteorderLSB) { ret[i] = (short) (((0xFF & b[1]) << 8) | (b[0] & 0xFF)); } else { ret[i] = (short) (((0xFF & b[0]) << 8) | (b[1] & 0xFF)); } //ret[i] = afile.readShort(); } else { ret[i] = Float.NaN; } } } else if (datatype.equalsIgnoreCase("INT")) { size = 4; b = new byte[(int) size]; for (i = 0; i < length; i++) { pos = (int) getcellnumber(points[i][0], points[i][1]); if (pos >= 0) { afile.seek(pos * size); afile.read(b); if (byteorderLSB) { ret[i] = ((0xFF & b[3]) << 24) | ((0xFF & b[2]) << 16) + ((0xFF & b[1]) << 8) + (b[0] & 0xFF); } else { ret[i] = ((0xFF & b[0]) << 24) | ((0xFF & b[1]) << 16) + ((0xFF & b[2]) << 8) + ((0xFF & b[3]) & 0xFF); } //ret[i] = afile.readInt(); } else { ret[i] = Float.NaN; } } } else if (datatype.equalsIgnoreCase("LONG")) { size = 8; b = new byte[(int) size]; for (i = 0; i < length; i++) { pos = (int) getcellnumber(points[i][0], points[i][1]); if (pos >= 0) { afile.seek(pos * size); afile.read(b); if (byteorderLSB) { ret[i] = ((long) (0xFF & b[7]) << 56) + ((long) (0xFF & b[6]) << 48) + ((long) (0xFF & b[5]) << 40) + ((long) (0xFF & b[4]) << 32) + ((long) (0xFF & b[3]) << 24) + ((long) (0xFF & b[2]) << 16) + ((long) (0xFF & b[1]) << 8) + (0xFF & b[0]); } else { ret[i] = ((long) (0xFF & b[0]) << 56) + ((long) (0xFF & b[1]) << 48) + ((long) (0xFF & b[2]) << 40) + ((long) (0xFF & b[3]) << 32) + ((long) (0xFF & b[4]) << 24) + ((long) (0xFF & b[5]) << 16) + ((long) (0xFF & b[6]) << 8) + (0xFF & b[7]); } //ret[i] = afile.readLong(); } else { ret[i] = Float.NaN; } } } else if (datatype.equalsIgnoreCase("FLOAT")) { size = 4; b = new byte[(int) size]; for (i = 0; i < length; i++) { pos = (int) getcellnumber(points[i][0], points[i][1]); if (pos >= 0) { afile.seek(pos * size); afile.read(b); ByteBuffer bb = ByteBuffer.wrap(b); if (byteorderLSB) { bb.order(ByteOrder.LITTLE_ENDIAN); } ret[i] = bb.getFloat(); } else { ret[i] = Float.NaN; } } } else if (datatype.equalsIgnoreCase("DOUBLE")) { size = 8; b = new byte[8]; for (i = 0; i < length; i++) { pos = (int) getcellnumber(points[i][0], points[i][1]); if (pos >= 0) { afile.seek(pos * size); afile.read(b); ByteBuffer bb = ByteBuffer.wrap(b); if (byteorderLSB) { bb.order(ByteOrder.LITTLE_ENDIAN); } ret[i] = (float) bb.getDouble(); //ret[i] = afile.readFloat(); } else { ret[i] = Float.NaN; } } } else { logger.error("datatype not supported in Grid.getValues: " + datatype); // / should not happen; catch anyway... for (i = 0; i < length; i++) { ret[i] = Float.NaN; } } //replace not a number for (i = 0; i < length; i++) { if ((float) ret[i] == (float) nodatavalue) { ret[i] = Float.NaN; } else { ret[i] *= rescale; } } } catch (Exception e) { logger.error("error getting grid file values", e); } finally { if (afile != null) { try { afile.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } } } return ret; }
From source file:xyz.zpayh.hdimage.HDImageView.java
private float sourceToViewX(float sx) { if (mViewTranslate == null) { return Float.NaN; }//from w w w.ja v a 2 s .c om return (sx * mScale) + mViewTranslate.x; }
From source file:xyz.zpayh.hdimage.HDImageView.java
private float sourceToViewY(float sy) { if (mViewTranslate == null) { return Float.NaN; }/* w ww . j a va 2 s. co m*/ return (sy * mScale) + mViewTranslate.y; }
From source file:net.pms.util.Rational.java
/** * Converts this {@link Rational} to a {@code float}. This conversion is * similar to the <i>narrowing primitive conversion</i> from {@code double} * to {@code float} as defined in section 5.1.3 of <cite>The Java™ * Language Specification</cite>: if this {@link Rational} has too great a * magnitude to represent as a {@code float}, it will be converted to * {@link Float#NEGATIVE_INFINITY} or {@link Float#POSITIVE_INFINITY} as * appropriate./* w w w . j a v a 2 s . c o m*/ * <p> * Note that even when the return value is finite, this conversion can lose * information about the precision of the {@link Rational} value. * * @return This {@link Rational} converted to a {@code float}. */ @Override public float floatValue() { if (isNaN()) { return Float.NaN; } if (isInfinitePositive()) { return Float.POSITIVE_INFINITY; } if (isInfiniteNegative()) { return Float.NEGATIVE_INFINITY; } return new BigDecimal(reducedNumerator).divide(new BigDecimal(reducedDenominator), MathContext.DECIMAL32) .floatValue(); }
From source file:org.geotools.gce.imagemosaic.RasterLayerResponse.java
/** * This method is responsible for creating a coverage from the supplied {@link RenderedImage}. * //from w w w . j a v a 2 s . c om * @param image * @return * @throws IOException */ private GridCoverage2D prepareCoverage(RenderedImage image) throws IOException { // creating bands final SampleModel sm = image.getSampleModel(); final ColorModel cm = image.getColorModel(); final int numBands = sm.getNumBands(); final GridSampleDimension[] bands = new GridSampleDimension[numBands]; Set<String> bandNames = new HashSet<String>(); // setting bands names. for (int i = 0; i < numBands; i++) { ColorInterpretation colorInterpretation = null; String bandName = null; if (cm != null) { // === color interpretation colorInterpretation = TypeMap.getColorInterpretation(cm, i); if (colorInterpretation == null) { throw new IOException("Unrecognized sample dimension type"); } bandName = colorInterpretation.name(); if (bandNames.contains(bandName)) {// make sure we create no duplicate band names bandName = "Band" + (i + 1); } } else { // no color model bandName = "Band" + (i + 1); colorInterpretation = ColorInterpretation.UNDEFINED; } // sample dimension type final SampleDimensionType st = TypeMap.getSampleDimensionType(sm, i); // set some no data values, as well as Min and Max values final double noData; double min = -Double.MAX_VALUE, max = Double.MAX_VALUE; if (backgroundValues != null) { // sometimes background values are not specified as 1 per each band, therefore we need to be careful noData = backgroundValues[backgroundValues.length > i ? i : 0]; } else { if (st.compareTo(SampleDimensionType.REAL_32BITS) == 0) noData = Float.NaN; else if (st.compareTo(SampleDimensionType.REAL_64BITS) == 0) noData = Double.NaN; else if (st.compareTo(SampleDimensionType.SIGNED_16BITS) == 0) { noData = Short.MIN_VALUE; min = Short.MIN_VALUE; max = Short.MAX_VALUE; } else if (st.compareTo(SampleDimensionType.SIGNED_32BITS) == 0) { noData = Integer.MIN_VALUE; min = Integer.MIN_VALUE; max = Integer.MAX_VALUE; } else if (st.compareTo(SampleDimensionType.SIGNED_8BITS) == 0) { noData = -128; min = -128; max = 127; } else { //unsigned noData = 0; min = 0; // compute max if (st.compareTo(SampleDimensionType.UNSIGNED_1BIT) == 0) max = 1; else if (st.compareTo(SampleDimensionType.UNSIGNED_2BITS) == 0) max = 3; else if (st.compareTo(SampleDimensionType.UNSIGNED_4BITS) == 0) max = 7; else if (st.compareTo(SampleDimensionType.UNSIGNED_8BITS) == 0) max = 255; else if (st.compareTo(SampleDimensionType.UNSIGNED_16BITS) == 0) max = 65535; else if (st.compareTo(SampleDimensionType.UNSIGNED_32BITS) == 0) max = Math.pow(2, 32) - 1; } } bands[i] = new SimplifiedGridSampleDimension(bandName, st, colorInterpretation, noData, min, max, 1, //no scale 0, //no offset null).geophysics(true); } // creating the final coverage by keeping into account the fact that we Map<String, String> properties = null; if (granulesPaths != null) { properties = new HashMap<String, String>(); properties.put(AbstractGridCoverage2DReader.FILE_SOURCE_PROPERTY, granulesPaths); } return coverageFactory.create(rasterManager.getCoverageIdentifier(), image, new GridGeometry2D(new GridEnvelope2D(PlanarImage.wrapRenderedImage(image).getBounds()), PixelInCell.CELL_CORNER, finalGridToWorldCorner, this.mosaicBBox.getCoordinateReferenceSystem(), hints), bands, null, properties); }
From source file:com.eurelis.opencms.admin.systeminformation.CmsDBPoolsOverviewDialog.java
protected void initPools() { String myconfigPath = org.opencms.main.OpenCms.getSystemInfo() .getAbsoluteRfsPathRelativeToWebInf(org.opencms.main.CmsSystemInfo.FOLDER_CONFIG_DEFAULT); LOG.debug("initPools... myconfig path = " + myconfigPath); org.opencms.configuration.CmsConfigurationManager myconfig = null; myconfig = new org.opencms.configuration.CmsConfigurationManager(myconfigPath); org.opencms.configuration.CmsParameterConfiguration propertyConfiguration = null; String path = null;/* w w w .ja v a2s. c om*/ try { path = org.opencms.main.OpenCms.getSystemInfo().getConfigurationFileRfsPath(); LOG.debug("initPools... configurationFileRfsPath = " + path); propertyConfiguration = new org.opencms.configuration.CmsParameterConfiguration(path); myconfig.setConfiguration(propertyConfiguration); } catch (Exception e) { LOG.error(e.getMessage() + " (" + path + ")", e); } Map configParameter = myconfig.getConfiguration(); this.m_configParameter = configParameter; List poolsName = new ArrayList(); int poolNumber = 1; if (configParameter != null) { String poolsNameProperty = (String) configParameter.get("db.pools"); String[] poolNames = poolsNameProperty.split(","); for (int i = 0; i < poolNames.length; i++) { if (poolNames[i] != null) { poolsName.add(poolNames[i]); LOG.debug("initPools... Pool name = " + poolNames[i]); if (poolNumber <= 5) { String poolName = poolNames[i]; String poolUrl = getPoolUrl(poolName); LOG.debug("initPools... Pool url = " + poolUrl); int activeConnections = getActiveConnections(poolUrl); LOG.debug("initPools... Pool activeConnections = " + activeConnections); int idleConnections = getIdleConnections(poolUrl); LOG.debug("initPools... Pool idleConnections = " + idleConnections); String poolStrategyProperty = getStrategy(poolName); LOG.debug("initPools... Pool poolStrategyProperty = " + poolStrategyProperty); String maxActivesConfiguratedString = getMaxActive(poolName); LOG.debug( "initPools... Pool maxActivesConfiguratedString = " + maxActivesConfiguratedString); float pourcentage = Float.NaN; if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(maxActivesConfiguratedString)) { pourcentage = (activeConnections * 100f) / (1f * (Integer.valueOf(maxActivesConfiguratedString))); } if (poolNumber == 1) { setPoolUrl1("" + poolUrl); setPoolStrategy1("" + poolStrategyProperty); setPoolMaxPoolSize1("" + maxActivesConfiguratedString); setActiveConnections1("" + activeConnections); setIdleConnections1("" + idleConnections); setCurrentUsage1("" + pourcentage + "%"); } else if (poolNumber == 2) { setPoolUrl2("" + poolUrl); setPoolStrategy2("" + poolStrategyProperty); setPoolMaxPoolSize2("" + maxActivesConfiguratedString); setActiveConnections2("" + activeConnections); setIdleConnections2("" + idleConnections); setCurrentUsage2("" + pourcentage + "%"); } else if (poolNumber == 3) { setPoolUrl3("" + poolUrl); setPoolStrategy3("" + poolStrategyProperty); setPoolMaxPoolSize3("" + maxActivesConfiguratedString); setActiveConnections3("" + activeConnections); setIdleConnections3("" + idleConnections); setCurrentUsage3("" + pourcentage + "%"); } else if (poolNumber == 4) { setPoolUrl4("" + poolUrl); setPoolStrategy4("" + poolStrategyProperty); setPoolMaxPoolSize4("" + maxActivesConfiguratedString); setActiveConnections4("" + activeConnections); setIdleConnections4("" + idleConnections); setCurrentUsage4("" + pourcentage + "%"); } else if (poolNumber == 5) { setPoolUrl5("" + poolUrl); setPoolStrategy5("" + poolStrategyProperty); setPoolMaxPoolSize5("" + maxActivesConfiguratedString); setActiveConnections5("" + activeConnections); setIdleConnections5("" + idleConnections); setCurrentUsage5("" + pourcentage + "%"); } } poolNumber++; } } } this.m_poolsName = poolsName; }