List of usage examples for java.lang Float POSITIVE_INFINITY
float POSITIVE_INFINITY
To view the source code for java.lang Float POSITIVE_INFINITY.
Click Source Link
From source file:com.cinnober.msgcodec.json.JsonValueHandlerTest.java
@Test public void testFloat32EncodePosInfinity() throws IOException { StringWriter out = new StringWriter(); JsonGenerator g = f.createGenerator(out); JsonValueHandler.FLOAT32.writeValue(Float.POSITIVE_INFINITY, g); g.flush();//from ww w .j ava 2 s . co m assertEquals("\"Infinity\"", out.toString()); }
From source file:com.restfb.JsonMapperToJsonTest.java
@Test public void mapWithInfiniteFloatValueKey() { Map<String, Float> map = new HashMap<String, Float>(); map.put("test", Float.POSITIVE_INFINITY); try {/*from ww w.java 2s . c o m*/ String json = createJsonMapper().toJson(map); fail("Map with infinity value should not be possible"); } catch (FacebookJsonMappingException fe) { assertTrue(fe.getMessage().startsWith("Unable to process value")); } }
From source file:com.cinnober.msgcodec.json.JsonValueHandlerTest.java
@Test public void testFloat32DecodePosInfinity() throws IOException { JsonParser p = f.createParser("\"Infinity\""); p.nextToken();/* ww w. j a va 2s . co m*/ assertTrue(Float.POSITIVE_INFINITY == JsonValueHandler.FLOAT32.readValue(p)); }
From source file:org.apache.olingo.fit.base.JSONFormatConformanceTestITCase.java
/** * MUST be prepared to receive all data types (section 7.1) * <ol>// w w w .ja v a 2s . c o m * <li>defined in this specification (client)</li> * <li>exposed by the service (service)</li> * </ol> * . */ @Test public void item3() throws Exception { final String fromSection71 = "{" + "\"NullValue\": null," + "\"TrueValue\": true," + "\"FalseValue\": false," + "\"BinaryValue@odata.type\": \"Binary\"," + "\"BinaryValue\": \"T0RhdGE\"," + "\"IntegerValue\": -128," + "\"DoubleValue\": 3.1415926535897931," + "\"SingleValue@odata.type\": \"Single\"," + "\"SingleValue\": \"INF\"," + "\"DecimalValue@odata.type\": \"Decimal\"," + "\"DecimalValue\": 34.95," + "\"StringValue\": \"Say \\\"Hello\\\",\\nthen go\"," + "\"DateValue@odata.type\": \"Date\"," + "\"DateValue\": \"2012-12-03\"," + "\"DateTimeOffsetValue@odata.type\": \"DateTimeOffset\"," + "\"DateTimeOffsetValue\": \"2012-12-03T07:16:23Z\"," + "\"DurationValue@odata.type\": \"Duration\"," + "\"DurationValue\": \"P12DT23H59M59.999999999999S\"," + "\"TimeOfDayValue@odata.type\": \"TimeOfDay\"," + "\"TimeOfDayValue\": \"07:59:59.999\"," + "\"GuidValue@odata.type\": \"Guid\"," + "\"GuidValue\": \"01234567-89ab-cdef-0123-456789abcdef\"," + "\"Int64Value@odata.type\": \"Int64\"," + "\"Int64Value\": 0," + "\"ColorEnumValue@odata.type\": \"Test.Color\"," + "\"ColorEnumValue\": \"Yellow\"," + "\"GeographyPoint\": {\"type\": \"Point\",\"coordinates\":[142.1,64.1]}" + "}"; final ClientEntity entity = client.getReader().readEntity(IOUtils.toInputStream(fromSection71), ContentType.JSON); assertTrue(entity.getProperty("NullValue").hasNullValue()); assertEquals(EdmPrimitiveTypeKind.Boolean, entity.getProperty("TrueValue").getPrimitiveValue().getTypeKind()); assertEquals(Boolean.TRUE, entity.getProperty("TrueValue").getPrimitiveValue().toCastValue(Boolean.class)); assertEquals(EdmPrimitiveTypeKind.Boolean, entity.getProperty("FalseValue").getPrimitiveValue().getTypeKind()); assertEquals(Boolean.FALSE, entity.getProperty("FalseValue").getPrimitiveValue().toCastValue(Boolean.class)); assertEquals(EdmPrimitiveTypeKind.Binary, entity.getProperty("BinaryValue").getPrimitiveValue().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.Int32, entity.getProperty("IntegerValue").getPrimitiveValue().getTypeKind()); assertEquals(-128, entity.getProperty("IntegerValue").getPrimitiveValue().toCastValue(Integer.class), 0); assertEquals(EdmPrimitiveTypeKind.Double, entity.getProperty("DoubleValue").getPrimitiveValue().getTypeKind()); assertEquals(3.1415926535897931, entity.getProperty("DoubleValue").getPrimitiveValue().toCastValue(Double.class), 0); assertEquals(EdmPrimitiveTypeKind.Single, entity.getProperty("SingleValue").getPrimitiveValue().getTypeKind()); assertEquals(Float.POSITIVE_INFINITY, entity.getProperty("SingleValue").getPrimitiveValue().toCastValue(Float.class), 0); assertEquals(EdmPrimitiveTypeKind.Decimal, entity.getProperty("DecimalValue").getPrimitiveValue().getTypeKind()); assertEquals(BigDecimal.valueOf(34.95), entity.getProperty("DecimalValue").getPrimitiveValue().toCastValue(BigDecimal.class)); assertEquals(EdmPrimitiveTypeKind.String, entity.getProperty("StringValue").getPrimitiveValue().getTypeKind()); assertEquals("Say \"Hello\",\nthen go", entity.getProperty("StringValue").getPrimitiveValue().toCastValue(String.class)); assertEquals(EdmPrimitiveTypeKind.Date, entity.getProperty("DateValue").getPrimitiveValue().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.DateTimeOffset, entity.getProperty("DateTimeOffsetValue").getPrimitiveValue().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.Duration, entity.getProperty("DurationValue").getPrimitiveValue().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.TimeOfDay, entity.getProperty("TimeOfDayValue").getPrimitiveValue().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.Guid, entity.getProperty("GuidValue").getPrimitiveValue().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.Int64, entity.getProperty("Int64Value").getPrimitiveValue().getTypeKind()); assertTrue(entity.getProperty("ColorEnumValue").hasEnumValue()); assertEquals(EdmPrimitiveTypeKind.GeographyPoint, entity.getProperty("GeographyPoint").getPrimitiveValue().getTypeKind()); }
From source file:org.apache.olingo.fit.v4.JSONFormatConformanceTestITCase.java
/** * MUST be prepared to receive all data types (section 7.1) * <ol>//from w ww .j a v a 2 s . co m * <li>defined in this specification (client)</li> * <li>exposed by the service (service)</li> * </ol> * . */ @Test public void item3() throws Exception { final String fromSection71 = "{" + "\"NullValue\": null," + "\"TrueValue\": true," + "\"FalseValue\": false," + "\"BinaryValue@odata.type\": \"Binary\"," + "\"BinaryValue\": \"T0RhdGE\"," + "\"IntegerValue\": -128," + "\"DoubleValue\": 3.1415926535897931," + "\"SingleValue@odata.type\": \"Single\"," + "\"SingleValue\": \"INF\"," + "\"DecimalValue@odata.type\": \"Decimal\"," + "\"DecimalValue\": 34.95," + "\"StringValue\": \"Say \\\"Hello\\\",\\nthen go\"," + "\"DateValue@odata.type\": \"Date\"," + "\"DateValue\": \"2012-12-03\"," + "\"DateTimeOffsetValue@odata.type\": \"DateTimeOffset\"," + "\"DateTimeOffsetValue\": \"2012-12-03T07:16:23Z\"," + "\"DurationValue@odata.type\": \"Duration\"," + "\"DurationValue\": \"P12DT23H59M59.999999999999S\"," + "\"TimeOfDayValue@odata.type\": \"TimeOfDay\"," + "\"TimeOfDayValue\": \"07:59:59.999\"," + "\"GuidValue@odata.type\": \"Guid\"," + "\"GuidValue\": \"01234567-89ab-cdef-0123-456789abcdef\"," + "\"Int64Value@odata.type\": \"Int64\"," + "\"Int64Value\": 0," + "\"ColorEnumValue@odata.type\": \"Test.Color\"," + "\"ColorEnumValue\": \"Yellow\"," + "\"GeographyPoint\": {\"type\": \"Point\",\"coordinates\":[142.1,64.1]}" + "}"; final ODataEntity entity = client.getReader().readEntity(IOUtils.toInputStream(fromSection71), ODataFormat.JSON); assertTrue(entity.getProperty("NullValue").hasNullValue()); assertEquals(EdmPrimitiveTypeKind.Boolean, entity.getProperty("TrueValue").getPrimitiveValue().getTypeKind()); assertEquals(Boolean.TRUE, entity.getProperty("TrueValue").getPrimitiveValue().toCastValue(Boolean.class)); assertEquals(EdmPrimitiveTypeKind.Boolean, entity.getProperty("FalseValue").getPrimitiveValue().getTypeKind()); assertEquals(Boolean.FALSE, entity.getProperty("FalseValue").getPrimitiveValue().toCastValue(Boolean.class)); assertEquals(EdmPrimitiveTypeKind.Binary, entity.getProperty("BinaryValue").getPrimitiveValue().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.Int32, entity.getProperty("IntegerValue").getPrimitiveValue().getTypeKind()); assertEquals(-128, entity.getProperty("IntegerValue").getPrimitiveValue().toCastValue(Integer.class), 0); assertEquals(EdmPrimitiveTypeKind.Double, entity.getProperty("DoubleValue").getPrimitiveValue().getTypeKind()); assertEquals(3.1415926535897931, entity.getProperty("DoubleValue").getPrimitiveValue().toCastValue(Double.class), 0); assertEquals(EdmPrimitiveTypeKind.Single, entity.getProperty("SingleValue").getPrimitiveValue().getTypeKind()); assertEquals(Float.POSITIVE_INFINITY, entity.getProperty("SingleValue").getPrimitiveValue().toCastValue(Float.class), 0); assertEquals(EdmPrimitiveTypeKind.Decimal, entity.getProperty("DecimalValue").getPrimitiveValue().getTypeKind()); assertEquals(BigDecimal.valueOf(34.95), entity.getProperty("DecimalValue").getPrimitiveValue().toCastValue(BigDecimal.class)); assertEquals(EdmPrimitiveTypeKind.String, entity.getProperty("StringValue").getPrimitiveValue().getTypeKind()); assertEquals("Say \"Hello\",\nthen go", entity.getProperty("StringValue").getPrimitiveValue().toCastValue(String.class)); assertEquals(EdmPrimitiveTypeKind.Date, entity.getProperty("DateValue").getPrimitiveValue().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.DateTimeOffset, entity.getProperty("DateTimeOffsetValue").getPrimitiveValue().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.Duration, entity.getProperty("DurationValue").getPrimitiveValue().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.TimeOfDay, entity.getProperty("TimeOfDayValue").getPrimitiveValue().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.Guid, entity.getProperty("GuidValue").getPrimitiveValue().getTypeKind()); assertEquals(EdmPrimitiveTypeKind.Int64, entity.getProperty("Int64Value").getPrimitiveValue().getTypeKind()); assertTrue(entity.getProperty("ColorEnumValue").hasEnumValue()); assertEquals(EdmPrimitiveTypeKind.GeographyPoint, entity.getProperty("GeographyPoint").getPrimitiveValue().getTypeKind()); }
From source file:ffx.xray.parsers.MTZWriter.java
/** * <p>/*from ww w.j a va 2 s.c o m*/ * write</p> */ public void write() { ByteOrder byteOrder = ByteOrder.nativeOrder(); FileOutputStream fileOutputStream; DataOutputStream dataOutputStream; try { if (logger.isLoggable(Level.INFO)) { StringBuilder sb = new StringBuilder(); sb.append(format("\n Writing MTZ HKL file: \"%s\"\n", fileName)); logger.info(sb.toString()); } fileOutputStream = new FileOutputStream(fileName); dataOutputStream = new DataOutputStream(fileOutputStream); byte bytes[] = new byte[80]; int offset = 0; int writeLen = 0; int iMapData; float fMapData; // Header. StringBuilder sb = new StringBuilder(); sb.append("MTZ "); dataOutputStream.writeBytes(sb.toString()); // Header offset. int headerOffset = n * nCol + 21; ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); byteBuffer.order(byteOrder).putInt(headerOffset); // Machine code: double, float, int, uchar // 0x4441 for LE, 0x1111 for BE if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) { iMapData = 0x4441; } else { iMapData = 0x1111; } byteBuffer.order(byteOrder).putInt(iMapData); dataOutputStream.write(bytes, offset, 8); sb = new StringBuilder(); sb.append(" "); sb.setLength(68); dataOutputStream.writeBytes(sb.toString()); // Data. Vector<String> colname = new Vector<>(nCol); char colType[] = new char[nCol]; double res[] = new double[2]; res[0] = Double.POSITIVE_INFINITY; res[1] = Double.NEGATIVE_INFINITY; float colMinMax[][] = new float[nCol][2]; for (int i = 0; i < nCol; i++) { colMinMax[i][0] = Float.POSITIVE_INFINITY; colMinMax[i][1] = Float.NEGATIVE_INFINITY; } ReflectionSpline sigmaASpline = new ReflectionSpline(reflectionList, refinementData.sigmaa.length); int col = 0; colname.add("H"); colType[col++] = 'H'; colname.add("K"); colType[col++] = 'H'; colname.add("L"); colType[col++] = 'H'; writeLen += 12; if (mtzType != MTZType.FCONLY) { colname.add("FO"); colType[col++] = 'F'; colname.add("SIGFO"); colType[col++] = 'Q'; colname.add("FreeR"); colType[col++] = 'I'; writeLen += 12; } if (mtzType != MTZType.DATAONLY) { colname.add("Fs"); colType[col++] = 'F'; colname.add("PHIFs"); colType[col++] = 'P'; colname.add("Fc"); colType[col++] = 'F'; colname.add("PHIFc"); colType[col++] = 'P'; writeLen += 16; } if (mtzType == MTZType.ALL) { colname.add("FOM"); colType[col++] = 'W'; colname.add("PHIW"); colType[col++] = 'P'; colname.add("SigmaAs"); colType[col++] = 'F'; colname.add("SigmaAw"); colType[col++] = 'Q'; colname.add("FWT"); colType[col++] = 'F'; colname.add("PHWT"); colType[col++] = 'P'; colname.add("DELFWT"); colType[col++] = 'F'; colname.add("PHDELWT"); colType[col++] = 'P'; writeLen += 32; } for (HKL ih : reflectionList.hkllist) { col = 0; int i = ih.index(); // Skip the 0 0 0 reflection. if (ih.h() == 0 && ih.k() == 0 && ih.l() == 0) { continue; } double ss = Crystal.invressq(crystal, ih); res[0] = min(ss, res[0]); res[1] = max(ss, res[1]); // HKL first (3) fMapData = ih.h(); colMinMax[col][0] = min(fMapData, colMinMax[0][0]); colMinMax[col][1] = max(fMapData, colMinMax[0][1]); byteBuffer.rewind(); byteBuffer.order(byteOrder).putFloat(fMapData); col++; fMapData = ih.k(); colMinMax[col][0] = min(fMapData, colMinMax[1][0]); colMinMax[col][1] = max(fMapData, colMinMax[1][1]); byteBuffer.order(byteOrder).putFloat(fMapData); col++; fMapData = ih.l(); colMinMax[col][0] = min(fMapData, colMinMax[2][0]); colMinMax[col][1] = max(fMapData, colMinMax[2][1]); byteBuffer.order(byteOrder).putFloat(fMapData); col++; if (mtzType != MTZType.FCONLY) { // F/sigF (2) fMapData = (float) refinementData.getF(i); if (!isNaN(fMapData)) { colMinMax[col][0] = min(fMapData, colMinMax[col][0]); colMinMax[col][1] = max(fMapData, colMinMax[col][1]); } byteBuffer.order(byteOrder).putFloat(fMapData); col++; fMapData = (float) refinementData.getSigF(i); if (!isNaN(fMapData)) { colMinMax[col][0] = min(fMapData, colMinMax[col][0]); colMinMax[col][1] = max(fMapData, colMinMax[col][1]); } byteBuffer.order(byteOrder).putFloat(fMapData); col++; // Free R (1) fMapData = (float) refinementData.getFreeR(i); if (!isNaN(fMapData)) { colMinMax[col][0] = min(fMapData, colMinMax[col][0]); colMinMax[col][1] = max(fMapData, colMinMax[col][1]); } byteBuffer.order(byteOrder).putFloat(fMapData); col++; } if (mtzType == MTZType.FCONLY) { // Fs (2) fMapData = (float) refinementData.fsF(i); colMinMax[col][0] = min(fMapData, colMinMax[col][0]); colMinMax[col][1] = max(fMapData, colMinMax[col][1]); byteBuffer.order(byteOrder).putFloat(fMapData); col++; fMapData = (float) toDegrees(refinementData.fsPhi(i)); colMinMax[col][0] = min(fMapData, colMinMax[col][0]); colMinMax[col][1] = max(fMapData, colMinMax[col][1]); byteBuffer.order(byteOrder).putFloat(fMapData); col++; // Fc (unscaled!) (2) fMapData = (float) refinementData.fcF(i); if (!isNaN(fMapData)) { colMinMax[col][0] = min(fMapData, colMinMax[col][0]); colMinMax[col][1] = max(fMapData, colMinMax[col][1]); } byteBuffer.order(byteOrder).putFloat(fMapData); col++; fMapData = (float) Math.toDegrees(refinementData.fcPhi(i)); if (!isNaN(fMapData)) { colMinMax[col][0] = min(fMapData, colMinMax[col][0]); colMinMax[col][1] = max(fMapData, colMinMax[col][1]); } byteBuffer.order(byteOrder).putFloat(fMapData); col++; } if (mtzType == MTZType.ALL) { // Fs (2) fMapData = (float) refinementData.fsF(i); colMinMax[col][0] = min(fMapData, colMinMax[col][0]); colMinMax[col][1] = max(fMapData, colMinMax[col][1]); byteBuffer.order(byteOrder).putFloat(fMapData); col++; fMapData = (float) toDegrees(refinementData.fsPhi(i)); colMinMax[col][0] = min(fMapData, colMinMax[col][0]); colMinMax[col][1] = max(fMapData, colMinMax[col][1]); byteBuffer.order(byteOrder).putFloat(fMapData); col++; // Fctot (2) fMapData = (float) refinementData.fcTotF(i); if (!isNaN(fMapData)) { colMinMax[col][0] = min(fMapData, colMinMax[col][0]); colMinMax[col][1] = max(fMapData, colMinMax[col][1]); } byteBuffer.order(byteOrder).putFloat(fMapData); col++; fMapData = (float) toDegrees(refinementData.fcTotPhi(i)); if (!isNaN(fMapData)) { colMinMax[col][0] = Math.min(fMapData, colMinMax[col][0]); colMinMax[col][1] = Math.max(fMapData, colMinMax[col][1]); } byteBuffer.order(byteOrder).putFloat(fMapData); col++; // FOM/phase (2) fMapData = (float) refinementData.fomphi[i][0]; if (!isNaN(fMapData)) { colMinMax[col][0] = Math.min(fMapData, colMinMax[col][0]); colMinMax[col][1] = Math.max(fMapData, colMinMax[col][1]); } byteBuffer.order(byteOrder).putFloat(fMapData); col++; fMapData = (float) toDegrees(refinementData.fomphi[i][1]); colMinMax[col][0] = min(fMapData, colMinMax[col][0]); colMinMax[col][1] = max(fMapData, colMinMax[col][1]); byteBuffer.order(byteOrder).putFloat(fMapData); col++; // Spline setup. double fh = spline.f(ss, refinementData.spline); double sa = sigmaASpline.f(ss, refinementData.sigmaa); double wa = sigmaASpline.f(ss, refinementData.sigmaw); // sigmaA/w (2) fMapData = (float) sa; if (!isNaN(fMapData)) { colMinMax[col][0] = min(fMapData, colMinMax[col][0]); colMinMax[col][1] = max(fMapData, colMinMax[col][1]); } byteBuffer.order(byteOrder).putFloat(fMapData); col++; fMapData = (float) wa; if (!isNaN(fMapData)) { colMinMax[col][0] = min(fMapData, colMinMax[col][0]); colMinMax[col][1] = max(fMapData, colMinMax[col][1]); } byteBuffer.order(byteOrder).putFloat(fMapData); col++; // Map coeffs (4). fMapData = (float) refinementData.FoFc2F(i); colMinMax[col][0] = min(fMapData, colMinMax[col][0]); colMinMax[col][1] = max(fMapData, colMinMax[col][1]); byteBuffer.order(byteOrder).putFloat(fMapData); col++; fMapData = (float) toDegrees(refinementData.FoFc2Phi(i)); colMinMax[col][0] = min(fMapData, colMinMax[col][0]); colMinMax[col][1] = max(fMapData, colMinMax[col][1]); byteBuffer.order(byteOrder).putFloat(fMapData); col++; fMapData = (float) refinementData.foFc1F(i); colMinMax[col][0] = min(fMapData, colMinMax[col][0]); colMinMax[col][1] = max(fMapData, colMinMax[col][1]); byteBuffer.order(byteOrder).putFloat(fMapData); col++; fMapData = (float) toDegrees(refinementData.foFc1Phi(i)); colMinMax[col][0] = min(fMapData, colMinMax[col][0]); colMinMax[col][1] = max(fMapData, colMinMax[col][1]); byteBuffer.order(byteOrder).putFloat(fMapData); col++; } dataOutputStream.write(bytes, offset, writeLen); } // Header. sb = new StringBuilder(); sb.append("VERS MTZ:V1.1 "); while (sb.length() < 80) { sb.append(" "); } dataOutputStream.writeBytes(sb.toString()); Date now = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss "); sb = new StringBuilder(); sb.append("TITLE FFX output: " + sdf.format(now)); while (sb.length() < 80) { sb.append(" "); } dataOutputStream.writeBytes(sb.toString()); sb = new StringBuilder(); sb.append(String.format("NCOL %8d %12d %8d", nCol, n, 0)); while (sb.length() < 80) { sb.append(" "); } dataOutputStream.writeBytes(sb.toString()); sb = new StringBuilder(); sb.append("SORT 0 0 0 0 0 "); while (sb.length() < 80) { sb.append(" "); } dataOutputStream.writeBytes(sb.toString()); sb = new StringBuilder(); char cdata = spaceGroup.shortName.charAt(0); if (cdata == 'H') { cdata = 'R'; } sb.append(String.format("SYMINF %3d %2d %c %5d %22s %5s", spaceGroup.getNumberOfSymOps(), spaceGroup.numPrimitiveSymEquiv, cdata, spaceGroup.number, "'" + spaceGroup.shortName + "'", spaceGroup.pointGroupName)); while (sb.length() < 80) { sb.append(" "); } dataOutputStream.writeBytes(sb.toString()); for (int i = 0; i < spaceGroup.symOps.size(); i++) { sb = new StringBuilder(); sb.append("SYMM "); SymOp symop = spaceGroup.symOps.get(i); sb.append(symop.toXYZString()); while (sb.length() < 80) { sb.append(" "); } dataOutputStream.writeBytes(sb.toString()); } sb = new StringBuilder(); sb.append(String.format("RESO %8.6f%13s%8.6f", res[0], " ", res[1])); while (sb.length() < 80) { sb.append(" "); } dataOutputStream.writeBytes(sb.toString()); sb = new StringBuilder(); sb.append("VALM NAN "); while (sb.length() < 80) { sb.append(" "); } dataOutputStream.writeBytes(sb.toString()); sb = new StringBuilder(); sb.append("NDIF 1 "); while (sb.length() < 80) { sb.append(" "); } dataOutputStream.writeBytes(sb.toString()); sb = new StringBuilder(); sb.append("PROJECT 1 project "); while (sb.length() < 80) { sb.append(" "); } dataOutputStream.writeBytes(sb.toString()); sb = new StringBuilder(); sb.append("CRYSTAL 1 crystal "); while (sb.length() < 80) { sb.append(" "); } dataOutputStream.writeBytes(sb.toString()); sb = new StringBuilder(); sb.append("DATASET 1 dataset "); while (sb.length() < 80) { sb.append(" "); } dataOutputStream.writeBytes(sb.toString()); for (int j = 0; j < nCol; j++) { sb = new StringBuilder(); sb.append(String.format("COLUMN %-30s %c %17.4f %17.4f 1", colname.get(j), colType[j], colMinMax[j][0], colMinMax[j][1])); dataOutputStream.writeBytes(sb.toString()); } sb = new StringBuilder(); sb.append(String.format("CELL %10.4f %9.4f %9.4f %9.4f %9.4f %9.4f ", crystal.a, crystal.b, crystal.c, crystal.alpha, crystal.beta, crystal.gamma)); while (sb.length() < 80) { sb.append(" "); } dataOutputStream.writeBytes(sb.toString()); sb = new StringBuilder(); sb.append(String.format("DCELL %9d %10.4f %9.4f %9.4f %9.4f %9.4f %9.4f ", 1, crystal.a, crystal.b, crystal.c, crystal.alpha, crystal.beta, crystal.gamma)); while (sb.length() < 80) { sb.append(" "); } dataOutputStream.writeBytes(sb.toString()); sb = new StringBuilder(); sb.append("DWAVEL 1 1.00000 "); while (sb.length() < 80) { sb.append(" "); } dataOutputStream.writeBytes(sb.toString()); sb = new StringBuilder(); sb.append("END "); while (sb.length() < 80) { sb.append(" "); } dataOutputStream.writeBytes(sb.toString()); sb = new StringBuilder(); sb.append("MTZENDOFHEADERS "); while (sb.length() < 80) { sb.append(" "); } dataOutputStream.writeBytes(sb.toString()); dataOutputStream.close(); } catch (Exception e) { String message = "Fatal exception evaluating structure factors.\n"; logger.log(Level.SEVERE, message, e); } }
From source file:net.pms.util.Rational.java
/** * Returns an instance that represents the value of {@code value}. * * @param value the value./* w ww. j a v a 2 s . co m*/ * @return An instance that represents the value of {@code value}. */ @Nonnull public static Rational valueOf(float value) { if (value == Float.POSITIVE_INFINITY) { return POSITIVE_INFINITY; } if (value == Float.NEGATIVE_INFINITY) { return NEGATIVE_INFINITY; } if (Float.isNaN(value)) { return NaN; } return valueOf(BigDecimal.valueOf(value)); }
From source file:org.apache.hadoop.yarn.server.resourcemanager.TestApplicationMasterService.java
@Test(timeout = 1200000) public void testProgressFilter() throws Exception { MockRM rm = new MockRM(conf); rm.start();//from w w w.j ava 2s.c o m // Register node1 MockNM nm1 = rm.registerNode("127.0.0.1:1234", 6 * GB); // Submit an application RMApp app1 = rm.submitApp(2048); nm1.nodeHeartbeat(true); RMAppAttempt attempt1 = app1.getCurrentAppAttempt(); MockAM am1 = rm.sendAMLaunched(attempt1.getAppAttemptId()); am1.registerAppAttempt(); AllocateRequestPBImpl allocateRequest = new AllocateRequestPBImpl(); List<ContainerId> release = new ArrayList<ContainerId>(); List<ResourceRequest> ask = new ArrayList<ResourceRequest>(); allocateRequest.setReleaseList(release); allocateRequest.setAskList(ask); allocateRequest.setProgress(Float.POSITIVE_INFINITY); am1.allocate(allocateRequest); while (attempt1.getProgress() != 1) { LOG.info("Waiting for allocate event to be handled ..."); sleep(100); } allocateRequest.setProgress(Float.NaN); am1.allocate(allocateRequest); while (attempt1.getProgress() != 0) { LOG.info("Waiting for allocate event to be handled ..."); sleep(100); } allocateRequest.setProgress((float) 9); am1.allocate(allocateRequest); while (attempt1.getProgress() != 1) { LOG.info("Waiting for allocate event to be handled ..."); sleep(100); } allocateRequest.setProgress(Float.NEGATIVE_INFINITY); am1.allocate(allocateRequest); while (attempt1.getProgress() != 0) { LOG.info("Waiting for allocate event to be handled ..."); sleep(100); } allocateRequest.setProgress((float) 0.5); am1.allocate(allocateRequest); while (attempt1.getProgress() != 0.5) { LOG.info("Waiting for allocate event to be handled ..."); sleep(100); } allocateRequest.setProgress((float) -1); am1.allocate(allocateRequest); while (attempt1.getProgress() != 0) { LOG.info("Waiting for allocate event to be handled ..."); sleep(100); } }
From source file:org.shaman.terrain.polygonal.GraphToHeightmap.java
private void addVoronoiNoise() { float cellSize = (float) size / (float) VORONOI_CELL_COUNT; List<Vector3f> pointList = new ArrayList<>(); for (int x = 0; x < VORONOI_CELL_COUNT; ++x) { for (int y = 0; y < VORONOI_CELL_COUNT; ++y) { float nx = x * cellSize; float ny = y * cellSize; for (int i = 0; i < VORONOI_POINTS_PER_CELL; ++i) { pointList.add(new Vector3f(nx + rand.nextFloat() * cellSize, ny + rand.nextFloat() * cellSize, rand.nextFloat())); }//from w w w . j av a 2 s. c o m } } Vector3f[] points = pointList.toArray(new Vector3f[pointList.size()]); LOG.info("voronoi point created"); //now cycle through cells and find influencing hills Heightmap tmp = new Heightmap(size); Vector3f first = new Vector3f(); Vector3f second = new Vector3f(); float min = Float.POSITIVE_INFINITY; float max = Float.NEGATIVE_INFINITY; for (int x = 0; x < size; ++x) { for (int y = 0; y < size; ++y) { //sort points by distance to (x,y) final float px = x; final float py = y; findClosestTwoPoints(points, px, py, first, second); assert (dist(first, px, py) <= dist(second, px, py)); //calc height float v = -1 * dist(first, px, py) + 1 * dist(second, px, py); tmp.setHeightAt(x, y, v); min = Math.min(v, min); max = Math.max(v, max); } } //normalize float factor = 1f / (max - min); for (int x = 0; x < size; ++x) { for (int y = 0; y < size; ++y) { float h = tmp.getHeightAt(x, y); tmp.setHeightAt(x, y, (h - min) * factor); } } LOG.info("voronoi cells calculated"); //distort Noise distortionNoise = new Noise(rand.nextLong()); Heightmap tmp2 = new Heightmap(size); for (int x = 0; x < size; ++x) { for (int y = 0; y < size; ++y) { float s = x / (float) size; float t = y / (float) size; float ss = (float) (s + VORONOI_DISTORTION_AMPLITUDE * 2 * distortionNoise .noise(s * VORONOI_DISTORTION_FREQUENCY, t * VORONOI_DISTORTION_FREQUENCY, 0)); float tt = (float) (t + VORONOI_DISTORTION_AMPLITUDE * 2 * distortionNoise .noise(s * VORONOI_DISTORTION_FREQUENCY, t * VORONOI_DISTORTION_FREQUENCY, 3.4)); float v = tmp.getHeightInterpolating(ss * size, tt * size); tmp2.setHeightAt(x, y, v); } } LOG.info("voronoi cells distorted"); //apply for (int x = 0; x < size; ++x) { for (int y = 0; y < size; ++y) { float amplitude = noise[x][y][2]; heightmap.adjustHeightAt(x, y, amplitude * tmp.getHeightAt(x, y) * VORONOI_SCALE); } } LOG.info("voronoi noise added"); }
From source file:com.frostwire.android.gui.transfers.AzureusBittorrentDownload.java
public String getSeedToPeerRatio() { float ratio = -1; DownloadManager dm = downloadManager; if (dm != null) { TRTrackerScraperResponse response = dm.getTrackerScrapeResponse(); int seeds; int peers; if (response != null && response.isValid()) { seeds = Math.max(dm.getNbSeeds(), response.getSeeds()); int trackerPeerCount = response.getPeers(); peers = dm.getNbPeers();// www .j a v a 2 s. c o m if (peers == 0 || trackerPeerCount > peers) { if (trackerPeerCount <= 0) { peers = dm.getActivationCount(); } else { peers = trackerPeerCount; } } } else { seeds = dm.getNbSeeds(); peers = dm.getNbPeers(); } if (peers < 0 || seeds < 0) { ratio = 0; } else { if (peers == 0) { if (seeds == 0) ratio = 0; else ratio = Float.POSITIVE_INFINITY; } else { ratio = (float) seeds / peers; } } } if (ratio == -1) { return ""; } else if (ratio == 0) { return "??"; } else { return DisplayFormatters.formatDecimal(ratio, 3); } }