List of usage examples for java.lang Float Float
@Deprecated(since = "9") public Float(String s) throws NumberFormatException
From source file:com.judoscript.jamaica.MyUtils.java
public static Object parseFloatObject(String x, String typeHint) { char ch = x.charAt(x.length() - 1); boolean isDouble = ch == 'd' || ch == 'D'; if (ch == 'f' || ch == 'F' || ch == 'd' || ch == 'D') x = x.substring(0, x.length() - 1); isDouble |= "double".equals(typeHint); if (isDouble && typeHint == null) typeHint = "double"; double d;/* w w w.j a va2s. c o m*/ try { d = Double.parseDouble(x); } catch (Exception e) { d = 0; } if (typeHint != null) return number2object(d, typeHint); if (isDouble) return new Double(d); else return new Float((float) d); }
From source file:at.ac.dbisinformatik.snowprofile.web.svgcreator.SVGCreator.java
/** * returns a ByteArrayOutputStream which contains the converted SVG-Graph to JPG * // w w w . j av a 2 s.c o m * @param inputStream * @return * @throws TranscoderException * @throws IOException */ public static ByteArrayOutputStream createJPG(InputStream inputStream) throws TranscoderException, IOException { ByteArrayOutputStream ret = new ByteArrayOutputStream(); JPEGTranscoder t = new JPEGTranscoder(); t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(.8)); TranscoderInput input = new TranscoderInput(inputStream); TranscoderOutput output = new TranscoderOutput(ret); t.transcode(input, output); return ret; }
From source file:org.zilverline.service.TestSearchService.java
public void testDoSearch() { CollectionManager colMan = (CollectionManager) applicationContext.getBean("collectionMan"); assertTrue("collections must exist", colMan.getCollections().size() > 0); SearchServiceImpl service = (SearchServiceImpl) applicationContext.getBean("searchService"); assertNotNull(service);/* ww w . j a va 2 s.c o m*/ assertNotNull(service.getCollectionManager()); assertNotNull(service.getFactors()); BoostFactor bf = new BoostFactor(); Map factors = new HashMap(); factors.put("contents", "1"); factors.put("title", "3.0"); factors.put("summary", "2"); factors.put("name", "4"); bf.setFactors(factors); service.setFactors(bf); assertNotNull(service.getFactors().getFactors()); assertEquals("contents boostfactor not 1", (Float) service.getFactors().getFactors().get("contents"), new Float(1.0)); DocumentCollection thisCollection = (DocumentCollection) colMan.getCollections().toArray()[Utils .pickOne(colMan.getCollections().size())]; assertNotNull(thisCollection); log.debug("Searching through " + thisCollection.getName()); SearchResult result; // get one result: the first try { result = service.doSearch(new String[] { thisCollection.getName() }, "jsp 2.0 taglib", 0, 1); int hits = result.getNumberOfHits(); if (hits > 0) { Result[] results = result.getResults(); assertNotNull(results); assertNotNull(results[0]); assertTrue(results.length == 1); Result res = results[0]; assertEquals(thisCollection.getName(), res.getCollection()); } } catch (SearchException e) { fail(e.getMessage()); } // get one result: the second try { result = service.doSearch(new String[] { thisCollection.getName() }, "jsp 2.0 taglib", 1, 1); int hits = result.getNumberOfHits(); if (hits > 0) { Result[] results = result.getResults(); assertNotNull(results); assertNotNull(results[0]); assertTrue(results.length == 1); Result res = results[0]; assertEquals(thisCollection.getName(), res.getCollection()); } } catch (SearchException e) { fail(e.getMessage()); } // get one result: for all collections try { result = service.doSearch(new String[] {}, "jsp 2.0 taglib", 1, 1); int hits = result.getNumberOfHits(); if (hits > 0) { Result[] results = result.getResults(); assertNotNull(results); assertNotNull(results[0]); assertTrue(results.length == 1); Result res = results[0]; assertEquals(thisCollection.getName(), res.getCollection()); } } catch (SearchException e) { fail(e.getMessage()); } }
From source file:com.sp.keyword_generator.Keyword.java
public String getStringWeight() { return String.format("%.2f", new Float(weight)); }
From source file:test.gov.nih.nci.cacoresdk.domain.other.primarykey.FloatPrimitiveKeyResourceTest.java
/** * Uses Nested Search Criteria for search * Verifies that the results are returned * Verifies size of the result set// w ww .j ava 2 s. com * Verifies that none of the attributes are null * * @throws Exception */ public void testGet() throws Exception { try { FloatPrimitiveKey searchObject = new FloatPrimitiveKey(); Collection results = getApplicationService() .search("gov.nih.nci.cacoresdk.domain.other.primarykey.FloatPrimitiveKey", searchObject); String id = ""; if (results != null && results.size() > 0) { FloatPrimitiveKey obj = (FloatPrimitiveKey) ((List) results).get(0); Float idVal = obj.getId(); id = new Float(idVal).toString(); } else return; if (id.equals("")) return; String url = baseURL + "/rest/FloatPrimitiveKey/" + id; WebClient client = WebClient.create(url); client.type("application/xml").accept("application/xml"); Response response = client.get(); if (response.getStatus() == Status.NOT_ACCEPTABLE.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); assertEquals(jDoc.getRootElement().getName(), "response"); } else if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); assertEquals(jDoc.getRootElement().getName(), "response"); } else if (response.getStatus() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); } File myFile = new File("FloatPrimitiveKey" + "XML.xml"); System.out.println("writing data to file " + myFile.getAbsolutePath()); FileWriter myWriter = new FileWriter(myFile); BufferedReader br = new BufferedReader(new InputStreamReader(((InputStream) response.getEntity()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { myWriter.write(output); System.out.println(output); } myWriter.flush(); myWriter.close(); } catch (Exception e) { e.printStackTrace(); throw e; } }
From source file:Main.java
/** * Divides num1 by num2, and return the result in the correct number class. * //from w w w .j av a2 s . c om * @param num1 numerator * @param num2 denominator * @return num1/num2 in the most appropriate class */ static Number divide(Number num1, Number num2) { Number[] both = new Number[2]; both[0] = num1; both[1] = num2; Number division = (Number) getObject(both); if (division == null) { return null; } //Integer, Long, Float, Double if (division instanceof Integer) { //we've got 2 integers, but we're going to use double anyways return new Double(num1.doubleValue() / num2.doubleValue()); } else if (division instanceof Long) { return new Long(num1.longValue() / num2.longValue()); } else if (division instanceof Float) { return new Float(num1.floatValue() / num2.floatValue()); } else if (division instanceof Double) { return new Double(num1.doubleValue() / num2.doubleValue()); } else { return null; } }
From source file:com.redhat.rhn.frontend.graphing.test.GraphGeneratorTest.java
private TimeSeriesData[] getTestTimeSeriesData(String metric, int size) { TimeSeriesData[] tsd = new TimeSeriesData[size]; for (int i = 0; i < tsd.length; i++) { Calendar start = Calendar.getInstance(); start.roll(Calendar.HOUR, -3); start.add(Calendar.MINUTE, (i * 5)); Float rnd = new Float(Math.random() * 10); tsd[i] = new TimeSeriesData("1-2-test", rnd, start.getTime(), metric); }/*from w ww . j a v a2 s. co m*/ return tsd; }
From source file:com.couchbase.sqoop.mapreduce.db.CouchbaseRecordReadSerializeTest.java
@Before @Override//from www. j a v a2 s.c o m public void setUp() throws Exception { super.setUp(); tappedStuff = new HashMap<String, ResponseMessage>(); URI uri = new URI(CouchbaseUtils.CONNECT_STRING); String user = CouchbaseUtils.COUCHBASE_USER_NAME; String pass = CouchbaseUtils.COUCHBASE_USER_PASS; try { cb = new CouchbaseClient(Arrays.asList(uri), user, pass); } catch (IOException e) { LOG.error("Couldn't connect to server" + e.getMessage()); fail(e.toString()); } this.client = new TapClient(Arrays.asList(uri), user, pass); cb.flush(); Thread.sleep(500); // set up the items we're going to deserialize Integer anint = new Integer(Integer.MIN_VALUE); cb.set(anint.toString(), 0x300, anint).get(); Long along = new Long(Long.MAX_VALUE); cb.set(along.toString(), 0, along).get(); Float afloat = new Float(Float.MAX_VALUE); cb.set(afloat.toString(), 0, afloat).get(); Double doubleBase = new Double(Double.NEGATIVE_INFINITY); cb.set(doubleBase.toString(), 0, doubleBase).get(); Boolean booleanBase = true; cb.set(booleanBase.toString(), 0, booleanBase).get(); rightnow = new Date(); // instance, needed later dateText = rightnow.toString().replaceAll(" ", "_"); cb.set(dateText, 0, rightnow).get(); Byte byteMeSix = new Byte("6"); cb.set(byteMeSix.toString(), 0, byteMeSix).get(); String ourString = "hi,there"; cb.set(ourString.toString(), 0, ourString).get(); client.tapDump("tester"); while (client.hasMoreMessages()) { ResponseMessage m = client.getNextMessage(); if (m == null) { continue; } tappedStuff.put(m.getKey(), m); } }
From source file:net.jofm.format.NumberFormat.java
private Object convert(Number result, Class<?> destinationClazz) { if (destinationClazz.equals(BigDecimal.class)) { return new BigDecimal(result.doubleValue()); }//from www.j a v a2s . c o m if (destinationClazz.equals(Short.class) || destinationClazz.equals(short.class)) { return new Short(result.shortValue()); } if (destinationClazz.equals(Integer.class) || destinationClazz.equals(int.class)) { return new Integer(result.intValue()); } if (destinationClazz.equals(Long.class) || destinationClazz.equals(long.class)) { return new Long(result.longValue()); } if (destinationClazz.equals(Float.class) || destinationClazz.equals(float.class)) { return new Float(result.floatValue()); } if (destinationClazz.equals(Double.class) || destinationClazz.equals(double.class)) { return new Double(result.doubleValue()); } throw new FixedMappingException("Unable to parse the data to type " + destinationClazz.getName() + " using " + this.getClass().getName()); }
From source file:org.spring.data.gemfire.cache.TemplateBasedRegionCreationTest.java
protected void assertCommonRegionAttributes(final Region<String, Integer> region, final String expectedRegionName) { assertNotNull("The Region cannot be null!", region); assertNotNull("The RegionAttributes cannot be null!", region.getAttributes()); assertEquals(expectedRegionName, region.getName()); assertEquals("/" + expectedRegionName, region.getFullPath()); assertTrue(region.getAttributes().getCloningEnabled()); assertTrue(region.getAttributes().getConcurrencyChecksEnabled()); assertTrue(region.getAttributes().isDiskSynchronous()); //assertEquals(600, region.getAttributes().getEntryIdleTimeout().getTimeout()); //assertEquals(600, region.getAttributes().getEntryTimeToLive().getTimeout()); assertEquals(String.class, region.getAttributes().getKeyConstraint()); assertEquals(1024, region.getAttributes().getInitialCapacity()); assertEquals(new Float(0.85f), new Float(region.getAttributes().getLoadFactor())); //assertEquals(600, region.getAttributes().getRegionIdleTimeout().getTimeout()); //assertEquals(600, region.getAttributes().getRegionTimeToLive().getTimeout()); assertTrue(region.getAttributes().getStatisticsEnabled()); assertEquals(Integer.class, region.getAttributes().getValueConstraint()); }