List of usage examples for java.lang Float Float
@Deprecated(since = "9") public Float(String s) throws NumberFormatException
From source file:com.apm4all.tracy.TracyTest.java
@Test public void testGetEvents_floatAnnotation() throws InterruptedException { final String FLOAT_NAME = "floatName"; float floatValue = Float.MAX_VALUE; Tracy.setContext(TASK_ID_VALUE, PARENT_OPT_ID_VALUE, COMPONENT_VALUE); Tracy.before(L1_LABEL_NAME);//from ww w. ja v a 2s .co m Tracy.annotate(FLOAT_NAME, floatValue); Tracy.after(L1_LABEL_NAME); List<TracyEvent> events = Tracy.getEvents(); assertEquals(1, events.size()); TracyEvent event = events.get(0); assertEquals(TASK_ID_VALUE, event.getTaskId()); assertEquals(PARENT_OPT_ID_VALUE, event.getParentOptId()); assertEquals(L1_LABEL_NAME, event.getLabel()); assertEquals(event.getAnnotation(FLOAT_NAME), new Float(floatValue)); assertEquals(new Float(floatValue), Tracy.getEventsAsMaps().get(0).get(FLOAT_NAME)); String jsonEvent = Tracy.getEventsAsJson().get(0); assertTrue(jsonEvent.contains("\"" + FLOAT_NAME + "\":" + Float.toString(floatValue))); Tracy.clearContext(); }
From source file:net.sf.jrf.domain.PersistentObjectDynaProperty.java
/** Gets default value. * @return default value.// w w w . j a v a2 s . c o m */ public Object getDefaultValue() { if (defaultValue != null) return this.defaultValue; Class cls = getType(); if (primitiveWrapperClass != null) { if (cls.equals(Boolean.TYPE)) return new Boolean(false); else if (cls.equals(Byte.TYPE)) return new Byte((byte) 0); else if (cls.equals(Character.TYPE)) return new Character((char) 0); else if (cls.equals(Double.TYPE)) return new Double((double) 0); else if (cls.equals(Float.TYPE)) return new Float((float) 0); else if (cls.equals(Integer.TYPE)) return new Integer((int) 0); else if (cls.equals(Long.TYPE)) return new Long((long) 0); else if (cls.equals(Short.TYPE)) return new Short((short) 0); else return null; } else return null; }
From source file:com.examples.with.different.packagename.testcarver.NumberConverter.java
/** * Default String to Number conversion.// w w w .j a v a2s . c om * <p> * This method handles conversion from a String to the following types: * <ul> * <li><code>java.lang.Byte</code></li> * <li><code>java.lang.Short</code></li> * <li><code>java.lang.Integer</code></li> * <li><code>java.lang.Long</code></li> * <li><code>java.lang.Float</code></li> * <li><code>java.lang.Double</code></li> * <li><code>java.math.BigDecimal</code></li> * <li><code>java.math.BigInteger</code></li> * </ul> * @param sourceType The type being converted from * @param targetType The Number type to convert to * @param value The String value to convert. * * @return The converted Number value. */ private Number toNumber(Class sourceType, Class targetType, String value) { // Byte if (targetType.equals(Byte.class)) { return new Byte(value); } // Short if (targetType.equals(Short.class)) { return new Short(value); } // Integer if (targetType.equals(Integer.class)) { return new Integer(value); } // Long if (targetType.equals(Long.class)) { return new Long(value); } // Float if (targetType.equals(Float.class)) { return new Float(value); } // Double if (targetType.equals(Double.class)) { return new Double(value); } // BigDecimal if (targetType.equals(BigDecimal.class)) { return new BigDecimal(value); } // BigInteger if (targetType.equals(BigInteger.class)) { return new BigInteger(value); } String msg = toString(getClass()) + " cannot handle conversion from '" + toString(sourceType) + "' to '" + toString(targetType) + "'"; throw new ConversionException(msg); }
From source file:com.tc.object.ApplicatorDNAEncodingTest.java
public void testBasic() throws Exception { final TCByteBufferOutputStream output = new TCByteBufferOutputStream(); final List<Object> data = new ArrayList<Object>(); data.add(new ObjectID(1)); data.add("one"); data.add(new Boolean(true)); data.add("two"); data.add(new Byte((byte) 42)); data.add("three"); data.add(new Character('\t')); data.add("four"); data.add(new Double(Math.PI)); data.add("five"); data.add(new Float(Math.E)); data.add("six"); data.add(new Integer(Integer.MAX_VALUE)); data.add("seven"); data.add(new Long(System.currentTimeMillis() % 17)); data.add("eight"); data.add(new Short((short) -1)); final DNAEncoding encoding = getApplicatorEncoding(); for (Object d : data) { encoding.encode(d, output);/*w w w . jav a2 s . c o m*/ } final TCByteBufferInputStream input = new TCByteBufferInputStream(output.toArray()); for (Object orig : data) { final Object decoded = encoding.decode(input); assertEquals(orig, decoded); } assertEquals(0, input.available()); }
From source file:com.gisgraphy.importer.GeonamesZipCodeImporterTest.java
@Test public void findFeatureExtendedThenBasicWithOneResult() { String lat = "3.5"; String lng = "44"; String accuracy = "5"; String placeName = "place name"; String countryCode = "FR"; String adm1Name = "adm1name"; String adm1Code = "adm1code"; String adm2Name = "adm2name"; String adm2Code = "adm2code"; String adm3Name = "adm3name"; String adm3COde = "adm3code"; FulltextQuery fulltextQuery = new FulltextQuery(placeName + " " + adm1Name); fulltextQuery.limitToCountryCode(countryCode); fulltextQuery.withPlaceTypes(com.gisgraphy.fulltext.Constants.CITY_AND_CITYSUBDIVISION_PLACETYPE); final long featureId = 456L; GeonamesZipCodeSimpleImporter importer = new GeonamesZipCodeSimpleImporter() { int count = 0; @Override/*ww w .j a va 2 s . c om*/ protected FulltextResultsDto doAFulltextSearch(String query, String countryCode) { count = count + 1; if (count == 1) { return new FulltextResultsDto(); } else if (count == 2) { return dtoWithOneResult; } else return null; } @Override protected Long findNearest(Point zipPoint, int maxDistance, FulltextResultsDto results) { return featureId; } }; String[] fields = { countryCode, "post", placeName, adm1Name, adm1Code, adm2Name, adm2Code, adm3Name, adm3COde, lat, lng, accuracy }; Point point = GeolocHelper.createPoint(new Float(lng), new Float(lat)); int maxDistance = importer.getAccurateDistance(new Integer(accuracy)); Long actualFeatureId = importer.findFeature(fields, point, maxDistance); Assert.assertEquals(dtoWithOneResult.getResults().get(0).getFeature_id(), actualFeatureId); }
From source file:edu.hawaii.soest.hioos.isus.ISUSFrame.java
public double getNitrogenConcentration() { this.nitrogenConcentration.flip(); return (new Float(this.nitrogenConcentration.getFloat())).doubleValue(); }
From source file:com.germinus.easyconf.ComponentProperties.java
public float getFloat(String key, Filter filter, float defaultValue) { return getFloat(key, filter, new Float(defaultValue)).floatValue(); }
From source file:edu.hawaii.soest.hioos.isus.ISUSFrame.java
public double getAuxConcentration1() { this.auxConcentration1.flip(); return (new Float(this.auxConcentration1.getFloat())).doubleValue(); }
From source file:javadz.beanutils.converters.NumberConverter.java
/** * Default String to Number conversion./*ww w . j a v a2 s .com*/ * <p> * This method handles conversion from a String to the following types: * <ul> * <li><code>java.lang.Byte</code></li> * <li><code>java.lang.Short</code></li> * <li><code>java.lang.Integer</code></li> * <li><code>java.lang.Long</code></li> * <li><code>java.lang.Float</code></li> * <li><code>java.lang.Double</code></li> * <li><code>java.math.BigDecimal</code></li> * <li><code>java.math.BigInteger</code></li> * </ul> * @param sourceType The type being converted from * @param targetType The Number type to convert to * @param value The String value to convert. * * @return The converted Number value. */ private Number toNumber(Class sourceType, Class targetType, String value) { // Byte if (targetType.equals(Byte.class)) { return new Byte(value); } // Short if (targetType.equals(Short.class)) { return new Short(value); } // Integer if (targetType.equals(Integer.class)) { return new Integer(value); } // Long if (targetType.equals(Long.class)) { return new Long(value); } // Float if (targetType.equals(Float.class)) { return new Float(value); } // Double if (targetType.equals(Double.class)) { return new Double(value); } // BigDecimal if (targetType.equals(BigDecimal.class)) { return new BigDecimal(value); } // BigInteger if (targetType.equals(BigInteger.class)) { return new BigInteger(value); } String msg = toString(getClass()) + " cannot handle conversion from '" + toString(sourceType) + "' to '" + toString(targetType) + "'"; if (log().isWarnEnabled()) { log().warn(" " + msg); } throw new ConversionException(msg); }
From source file:com.wordnik.swagger.testframework.APITestRunner.java
/** * Execute all assertions in the test case. If there are nay failures test case will be amrked as failed * and logged into test status object./* ww w . j av a 2 s.com*/ * @param testCase */ private void executeAssertions(String testCasePath, TestCase testCase) { List<Assertion> assertions = testCase.getAssertions(); if (assertions != null) { for (Assertion assertion : assertions) { try { Object actualOutPut = getParamValue(assertion.getActualOutput()); Object expectedValue = getParamValue(assertion.getExpectedOutput()); boolean failed = false; if (assertion.getCondition().equals(CONDITION_EQUAL)) { if (expectedValue.toString().equalsIgnoreCase("NULL") && actualOutPut == null) { failed = false; } else { if (expectedValue.getClass().isAssignableFrom(String.class)) { actualOutPut = actualOutPut.toString(); } if (!actualOutPut.equals(expectedValue)) { failed = true; } } } else if (assertion.getCondition().equals(CONDITION_NOT_EQUAL)) { if (expectedValue.toString().equalsIgnoreCase("EXCEPTION")) { //this means user is not expecting any exception, output can be null, if we have reached // here means there are no exceptions hence we can call the assertion is passed. failed = false; } else if (actualOutPut == null || actualOutPut.equals(expectedValue)) { failed = true; } } else { float actual = new Float(actualOutPut.toString()); float expected = new Float(expectedValue.toString()); if (assertion.getCondition().equals(CONDITION_GREATER)) { if (!(actual > expected)) { failed = true; } } else if (assertion.getCondition().equals(CONDITION_LESSER)) { if (!(actual < expected)) { failed = true; } } else if (assertion.getCondition().equals(CONDITION_LESSER_EQUAL)) { if (!(actual <= expected)) { failed = true; } } else if (assertion.getCondition().equals(CONDITION_GREATER_EQUAL)) { if (!(actual >= expected)) { failed = true; } } } if (failed) { if (actualOutPut == null) { testStatus.logAssertionStatus(testCasePath, false, expectedValue.toString(), null, assertion.getCondition()); } else { testStatus.logAssertionStatus(testCasePath, false, expectedValue.toString(), actualOutPut.toString(), assertion.getCondition()); } } else { if (actualOutPut == null) { testStatus.logAssertionStatus(testCasePath, true, expectedValue.toString(), "null", assertion.getCondition()); } else { testStatus.logAssertionStatus(testCasePath, true, expectedValue.toString(), actualOutPut.toString(), assertion.getCondition()); } } } catch (Exception e) { e.printStackTrace(); testStatus.logAssertionStatus(testCasePath, false, assertion.getExpectedOutput(), assertion.getActualOutput(), assertion.getCondition(), e); } } } }