List of usage examples for java.lang Float Float
@Deprecated(since = "9") public Float(String s) throws NumberFormatException
From source file:org.openmrs.module.vcttrac.web.view.chart.VCTCreatePieChartView.java
private JFreeChart createVCTvsPITPieChartView() { DefaultPieDataset pieDataset = new DefaultPieDataset(); VCTModuleService service = Context.getService(VCTModuleService.class); try {//ww w . ja va 2s. c o m Date reportingDate = new Date(); int numberOfClientInVCT = service.getNumberOfClientByVCTOrPIT(1, reportingDate); int numberOfClientInPIT = service.getNumberOfClientByVCTOrPIT(2, reportingDate); int all = numberOfClientInVCT + numberOfClientInPIT; Float percentageVCT = new Float(100 * numberOfClientInVCT / all); pieDataset.setValue(VCTTracUtil.getMessage("vcttrac.home.vctclient", null) + " (" + numberOfClientInVCT + " , " + percentageVCT + "%)", percentageVCT); Float percentagePIT = new Float(100 * numberOfClientInPIT / all); pieDataset.setValue(VCTTracUtil.getMessage("vcttrac.home.pitclient", null) + " (" + numberOfClientInPIT + " , " + percentagePIT + "%)", percentagePIT); JFreeChart chart = ChartFactory.createPieChart( VCTTracUtil.getMessage("vcttrac.home.vctclient", null) + " " + VCTTracUtil.getMessage("vcttrac.graph.statistic.comparedto", null) + " " + VCTTracUtil.getMessage("vcttrac.home.pitclient", null), pieDataset, true, true, false); return chart; } catch (Exception e) { log.error(">>VCT>>vs>>PIT>>PIE>>CHART>> " + e.getMessage()); e.printStackTrace(); return ChartFactory.createPieChart(VCTTracUtil.getMessage("vcttrac.home.vctclient", null) + " " + VCTTracUtil.getMessage("vcttrac.graph.statistic.comparedto", null) + " " + VCTTracUtil.getMessage("vcttrac.home.pitclient", null), null, true, true, false); } }
From source file:Main.java
/** * Casts an object to the specified type * * @param var// ww w .j a v a2s .c o m * @param type * */ static Object convert(Object var, Class type) { if (var instanceof Number) { //use number conversion Number newNum = (Number) var; if (type == Integer.class) { return new Integer(newNum.intValue()); } else if (type == Long.class) { return new Long(newNum.longValue()); } else if (type == Float.class) { return new Float(newNum.floatValue()); } else if (type == Double.class) { return new Double(newNum.doubleValue()); } else if (type == String.class) { return new String(newNum.toString()); } } else { //direct cast if (type == Integer.class) { return new Integer(((Integer) var).intValue()); } else if (type == Long.class) { return new Long(((Long) var).longValue()); } else if (type == Float.class) { return new Float(((Float) var).floatValue()); } else if (type == Double.class) { return new Double(((Double) var).doubleValue()); } else if (type == String.class) { return new String(var.toString()); } } return null; }
From source file:agilejson.JSON.java
/** * This method takes in a primitive that has been converted to an object * and creates a copy of it so that .equals results in different objects. * @param v/* w w w.ja v a2 s . c o m*/ * @throws java.lang.Exception */ private static Object getObjectForPrimitive(Object v) throws Exception { Class c = v.getClass(); if (c == Byte.class) { return new String(new byte[] { ((Byte) v).byteValue() }); } else if (c == Boolean.class) { return new Boolean((Boolean) v); } else if (c == Character.class) { return new Character((Character) v); } else if (c == Short.class) { return new Short((Short) v); } else if (c == Integer.class) { return new Integer((Integer) v); } else if (c == Long.class) { return new Long((Long) v); } else if (c == Float.class) { return new Float((Float) v); } else if (c == Double.class) { return new Double((Double) v); } else { throw new Exception("Unknown Primitive"); } }
From source file:MutableFloat.java
/** * Gets the value as a Float instance.// w w w .j a v a 2s . c o m * * @return the value as a Float */ public Object getValue() { return new Float(this.value); }
From source file:nl.wur.plantbreeding.logic.jfreechart.PieChart.java
/** * Create the Pie Chart using the given dataset. * It assigns to the chart the given title, prints the legend if asked, * adds a tooltips of the given url./* ww w . j a va2s . co m*/ * @param dataset a PieDataset * @param title the title of the graph * @param boollegend wether to add the legend or not * @param tooltips wether to add the tooltips or not * @param urls wether to link the different part of the plot or not * @return a JFreeChart object of the pie chart */ public final JFreeChart createChart(final PieDataset dataset, final String title, final boolean boollegend, final boolean tooltips, final boolean urls) { JFreeChart chart = ChartFactory.createPieChart(title, // chart title dataset, // data boollegend, // include legend tooltips, // include tooltips urls // include urls ); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundAlpha(new Float(0.0)); plot.setSectionOutlinesVisible(false); plot.setNoDataMessage("No data available"); plot.setOutlineVisible(false); // remove borders around the plot return chart; }
From source file:nz.co.senanque.validationengine.ConvertUtils.java
public static Comparable<?> convertTo(Class<?> clazz, Object obj) { if (obj == null) { return null; }/*from www . j a v a 2 s . co m*/ if (clazz.isAssignableFrom(obj.getClass())) { return (Comparable<?>) obj; } if (clazz.isPrimitive()) { if (clazz.equals(Long.TYPE)) { clazz = Long.class; } else if (clazz.equals(Integer.TYPE)) { clazz = Integer.class; } else if (clazz.equals(Float.TYPE)) { clazz = Float.class; } else if (clazz.equals(Double.TYPE)) { clazz = Double.class; } else if (clazz.equals(Boolean.TYPE)) { clazz = Boolean.class; } } if (Number.class.isAssignableFrom(clazz)) { if (obj.getClass().equals(String.class)) { obj = new Double((String) obj); } if (!Number.class.isAssignableFrom(obj.getClass())) { throw new RuntimeException( "Cannot convert from " + obj.getClass().getName() + " to " + clazz.getName()); } Number number = (Number) obj; if (clazz.equals(Long.class)) { return new Long(number.longValue()); } if (clazz.equals(Integer.class)) { return new Integer(number.intValue()); } if (clazz.equals(Float.class)) { return new Float(number.floatValue()); } if (clazz.equals(Double.class)) { return new Double(number.doubleValue()); } if (clazz.equals(BigDecimal.class)) { return new BigDecimal(number.doubleValue()); } } final String oStr = String.valueOf(obj); if (clazz.equals(String.class)) { return oStr; } if (clazz.equals(java.util.Date.class)) { return java.sql.Date.valueOf(oStr); } if (clazz.equals(java.sql.Date.class)) { return java.sql.Date.valueOf(oStr); } if (clazz.equals(Boolean.class)) { return new Boolean(oStr); } throw new RuntimeException("Cannot convert from " + obj.getClass().getName() + " to " + clazz.getName()); }
From source file:com.yahoo.egads.models.adm.AnomalyDetectionAbstractModel.java
public AnomalyDetectionAbstractModel(Properties config) { logger = org.apache.logging.log4j.LogManager.getLogger(this.getClass().getName()); // Set the assumed amount of anomaly in your data. if (config.getProperty("AUTO_SENSITIVITY_ANOMALY_PCNT") != null) { this.amntAutoSensitivity = new Float(config.getProperty("AUTO_SENSITIVITY_ANOMALY_PCNT")); }//w w w .j a v a 2 s . co m // Set the standard deviation for auto sensitivity. if (config.getProperty("AUTO_SENSITIVITY_SD") != null) { this.sDAutoSensitivity = new Float(config.getProperty("AUTO_SENSITIVITY_SD")); } this.outputDest = config.getProperty("OUTPUT"); }
From source file:it.uniroma2.sag.kelp.kernel.standard.LinearKernelCombination.java
/** * Scales the weights in order to make their sum being equal to 1 */// w w w . j a v a2s. co m public void normalizeWeights() { float sum = 0; for (float weight : weights) { sum += weight; } for (int i = 0; i < this.weights.size(); i++) { float val = this.weights.get(i).floatValue(); this.weights.set(i, new Float(val / sum)); } }
From source file:com.liferay.util.servlet.fileupload.LiferayInputStream.java
public int read(byte[] b, int off, int len) throws IOException { int bytesRead = super.read(b, off, len); if (bytesRead > 0) { _totalRead += bytesRead;//from w w w . j a v a 2 s. co m } else { _totalRead = _totalSize; } float percent = _totalRead / _totalSize; _log.debug(bytesRead + "/" + _totalRead + "=" + percent); _ses.setAttribute(LiferayFileUpload.PERCENT, new Float(percent)); _cachedBytes.write(b); return bytesRead; }
From source file:test.gov.nih.nci.cacoresdk.domain.other.primarykey.FloatKeyResourceTest.java
/** * Uses Nested Search Criteria for search * Verifies that the results are returned * Verifies size of the result set/*w w w. ja va 2 s. c om*/ * Verifies that none of the attributes are null * * @throws Exception */ public void testGet() throws Exception { try { FloatKey searchObject = new FloatKey(); Collection results = getApplicationService() .search("gov.nih.nci.cacoresdk.domain.other.primarykey.FloatKey", searchObject); String id = ""; if (results != null && results.size() > 0) { FloatKey obj = (FloatKey) ((List) results).get(0); Float idVal = obj.getId(); id = new Float(idVal).toString(); } else return; if (id.equals("")) return; String url = baseURL + "/rest/FloatKey/" + 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("FloatKey" + "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; } }