Example usage for java.lang Float Float

List of usage examples for java.lang Float Float

Introduction

In this page you can find the example usage for java.lang Float Float.

Prototype

@Deprecated(since = "9")
public Float(String s) throws NumberFormatException 

Source Link

Document

Constructs a newly allocated Float object that represents the floating-point value of type float represented by the string.

Usage

From source file:com.yahoo.egads.models.adm.AdaptiveKernelDensityChangePointDetector.java

public AdaptiveKernelDensityChangePointDetector(Properties config) {
    super(config);

    this.maxHrsAgo = new Integer(config.getProperty("MAX_ANOMALY_TIME_AGO"));
    if (config.getProperty("PRE_WINDOW_SIZE") == null) {
        throw new IllegalArgumentException("PRE_WINDOW_SIZE is NULL");
    }//from  w  w w  .  jav a 2s.  c o  m

    if (config.getProperty("POST_WINDOW_SIZE") == null) {
        throw new IllegalArgumentException("POST_WINDOW_SIZE is NULL");
    }

    this.preWindowSize = new Integer(config.getProperty("PRE_WINDOW_SIZE"));
    this.postWindowSize = new Integer(config.getProperty("POST_WINDOW_SIZE"));

    if (config.getProperty("CONFIDENCE") == null) {
        this.confidence = 0.8F;
    } else {
        this.confidence = new Float(config.getProperty("CONFIDENCE"));
    }
}

From source file:arena.utils.XMLUtils.java

/**
 * Searches the node for content of type Float. If non-long content is found,
 * it logs a warning and returns null./*from   w  w w .j a v a 2 s.  c om*/
 */
public static Float extractFloatFromElement(Node element) {
    // Get the content and try to parse for a long
    String nodeContent = extractStringFromElement(element);

    if (nodeContent == null) {
        return null;
    } else {
        try {
            return new Float(nodeContent);
        } catch (NumberFormatException err) {
            LogFactory.getLog(XMLUtils.class).warn("Invalid data in float field: " + nodeContent);
            return null;
        }
    }
}

From source file:de.mat.utils.pdftools.PdfResize.java

@Override
public void doJob() throws Throwable {
    String inFile = this.cmdLine.getOptionValue("i", null);
    String outFile = this.cmdLine.getOptionValue("o", null);
    Float scaleX = new Float(this.cmdLine.getOptionValue("x", null));
    Float scaleY = new Float(this.cmdLine.getOptionValue("y", null));
    Float pixelLeft = new Float(this.cmdLine.getOptionValue("l", null));
    Float pixelTop = new Float(this.cmdLine.getOptionValue("t", null));

    resizePdf(inFile, outFile, scaleX, scaleY, pixelLeft, pixelTop);
}

From source file:it.unibs.sandroide.lib.item.generalIO.SandroideDevice.java

synchronized protected void runAction(byte[] towrite) {
    List input = new ArrayList<Float>();
    for (int i = 0; i < towrite.length; i++) {
        input.add(new Float(towrite[i]));
        //input.addAll(new ArrayList<byte>(towrite));
    }//from w  w w. jav a2s. co  m
    //input) float
    //towrite
    runAction("send_string_value", input);
    /*
            DeviceControl deviceControl = this.mDeviceControl;
            //BluetoothLeDevice mBluetoothLeDevice = deviceControl.mBluetoothLeDevice;
            //mServices =
            
            try {
    boolean lockGot;
    do{
        lockGot=deviceControl.getLock().tryLock(100, TimeUnit.MILLISECONDS);
    }
    while (!lockGot);
    try{
        int delay=0;
        //BluetoothGatt mBluetoothGatt = mBluetoothLeDevice.getBluetoothGatt();
        deviceControl.writeChar("713d0000-503e-4c75-ba94-3148f18d941e","713d0003-503e-4c75-ba94-3148f18d941e",towrite);
        //BluetoothGattCharacteristic gattCharacteristic = mServices.get(service).get(characteristic);
        //gattCharacteristic.setValue(command);
        //boolean a=mBluetoothGatt.writeCharacteristic(gattCharacteristic);
        //Log.d(TAG, "writing was " + a);
        //Log.d(TAG, "byteArray was " + Arrays.toString(command));
        //Delay(20);
    } finally {
        deviceControl.getLock().unlock();
    }
            } catch (InterruptedException e) {
    e.printStackTrace();
            }*/

}

From source file:com.xpn.xwiki.plugin.charts.params.DefaultChartParams2.java

protected DefaultChartParams2() throws ParamException {
    set(SERIES, "columns");

    set(HEIGHT, new Integer(600));
    set(WIDTH, new Integer(500));
    set(LINK_ATTRIBUTES, new HashMap());
    set(IMAGE_ATTRIBUTES, new HashMap());

    set(RENDERER, (Class) null); // default renderer is chart type dependent
    set(RENDERER_COLOR, AbstractRenderer.DEFAULT_PAINT);
    set(RENDERER_STROKE, AbstractRenderer.DEFAULT_STROKE);
    set(RENDERER_SHAPE, AbstractRenderer.DEFAULT_SHAPE);
    set(RENDERER_FILL_COLOR, Color.white);
    set(RENDERER_OUTLINE_COLOR, AbstractRenderer.DEFAULT_OUTLINE_PAINT);
    set(RENDERER_OUTLINE_STROKE, AbstractRenderer.DEFAULT_OUTLINE_STROKE);
    set(RENDERER_ITEM_LABEL_VISIBLE, Boolean.FALSE);
    set(RENDERER_ITEM_LABEL_COLOR, AbstractRenderer.DEFAULT_VALUE_LABEL_PAINT);
    set(RENDERER_ITEM_LABEL_FONT, AbstractRenderer.DEFAULT_VALUE_LABEL_FONT);
    set(RENDERER_SERIES_VISIBLE, Boolean.TRUE);
    set(RENDERER_SERIES_VISIBLE_IN_LEGEND, Boolean.TRUE);

    set(BORDER_VISIBLE, Boolean.FALSE);
    set(BORDER_COLOR, Color.black);
    set(BORDER_STROKE, new BasicStroke(1.0f));

    setTitle(TITLE_PREFIX);/*from  ww w.  j  a  va  2s  .  c  om*/
    set(TITLE_PREFIX + TITLE_FONT_SUFFIX, JFreeChart.DEFAULT_TITLE_FONT);
    setTitle(SUBTITLE_PREFIX);

    set(ANTI_ALIAS, Boolean.TRUE);
    set(BACKGROUND_COLOR, JFreeChart.DEFAULT_BACKGROUND_PAINT);

    set(PLOT_BACKGROUND_COLOR, Plot.DEFAULT_BACKGROUND_PAINT);
    set(PLOT_BACKGROUND_ALPHA, new Float(Plot.DEFAULT_BACKGROUND_ALPHA));
    set(PLOT_FOREGROUND_ALPHA, new Float(Plot.DEFAULT_FOREGROUND_ALPHA));
    set(PLOT_INSERTS, Plot.DEFAULT_INSETS);
    set(PLOT_OUTLINE_COLOR, Plot.DEFAULT_OUTLINE_PAINT);
    set(PLOT_OUTLINE_STROKE, Plot.DEFAULT_OUTLINE_STROKE);

    set(XYPLOT_ORIENTATION, PlotOrientation.VERTICAL);
    set(XYPLOT_QUADRANT_ORIGIN, new Point2D.Double(0.0, 0.0));
    List colors = new LinkedList();
    colors.add(null);
    colors.add(null);
    colors.add(null);
    colors.add(null);
    set(XYPLOT_QUADRANT_COLORS, colors);

    set(LEGEND_BACKGROUND_COLOR, (Color) null);
    set(LEGEND_ITEM_FONT, LegendTitle.DEFAULT_ITEM_FONT);
    set(LEGEND_ITEM_LABEL_PADDING, new RectangleInsets(2.0, 2.0, 2.0, 2.0));
    set(LEGEND_ITEM_GRAPHIC_ANCHOR, RectangleAnchor.CENTER);
    set(LEGEND_ITEM_GRAPHIC_EDGE, RectangleEdge.LEFT);
    set(LEGEND_ITEM_GRAPHIC_LOCATION, RectangleAnchor.CENTER);
    set(LEGEND_ITEM_GRAPHIC_PADDING, new RectangleInsets(2.0, 2.0, 2.0, 2.0));

    setAxis(AXIS_DOMAIN_PREFIX);
    setAxis(AXIS_RANGE_PREFIX);

    set(TIME_PERIOD_CLASS, Day.class);
    set(DATE_FORMAT, new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
}

From source file:MathUtils.java

/**
 * <p>//from  ww w .  j a  va  2  s.c  o m
 * Returns a visual approximation of a number, keeping only a specified decimals. <br/>
 * For exemple : <br/>
 *    &nbsp; approximate(12.2578887 , 2) will return 12.25 <br/>
 *    &nbsp; approximate(12.25 , 0) will return 12 <br/>
 *    &nbsp; approximate(12.00 , 3) will return 12 <br/>
 *    &nbsp; approximate(19.5 , 0) will return 20 <br/>
 *</p>
 * <p>The last exemple emphasis the fact that it's made for showing convenient numbers for no mathematical public. If the number was</p>
 * <p>Note that Math.round(19.5) returns 20, not 19. This function will act the same way.</p>
 * @param n
 * @param precision
 * @return
 */
public static String approximate(Number n, int precision) {

    if (n instanceof Integer) {
        return n.toString();
    }

    String s = n.toString();

    if (!s.contains(".")) {
        return s;
    }

    String serious = s.substring(0, s.indexOf('.'));

    s = s.substring(s.indexOf('.') + 1);
    s = StringUtils.removeTrailingCharacters(s, '0');

    if (s.length() == 0) {
        return serious;
    }

    // We'll comments results based on approximate(12.63645, 3) and approximate(12.63545, 0)
    String decimals = "";

    if (s.length() > precision) {

        decimals = StringUtils.truncate(s, precision + 1);
        //decimal is now "636" or "6"

        Float after = new Float(decimals);
        //after is 636 or 6, as Float objects
        after = after / 10;
        //after is 63.6 or .6, as Float objects
        Integer round = Math.round(after);
        //round is 64 or 1
        decimals = round.toString();
        decimals = StringUtils.removeTrailingCharacters(decimals, '0');

    } else {

        decimals = StringUtils.truncate(s, precision);
        decimals = StringUtils.removeTrailingCharacters(decimals, '0');

    }

    if (decimals.length() > 0 && precision > 0) {
        return serious + "." + decimals;
    } else {
        //if we must round the serious string
        if (decimals.length() > 0 && precision == 0) {
            assert decimals.length() == 1 : "problem here !";
            if (decimals.length() != 1) {
                throw new IllegalStateException(
                        "Error in the algorithm for MathUtilisties.approximate(" + n + ", " + precision + ")");
            }
            Integer finalValue = new Integer(decimals);
            if (finalValue > 0) {
                Integer si = new Integer(serious);
                si += 1;
                return si.toString();
            } else {
                return serious;
            }
        } else {
            return serious;
        }
    }
}

From source file:ar.com.zauber.commons.dao.Paging.java

/**
 * Retorna el nmero de la ltima pgina.//from w w  w  .j a  v a  2 s  . c om
 * 
 * @return the last page number
 */
public final int getLastPageNumber() {
    if (resultSize == null) {
        throw new IllegalStateException("No se sete el tamao del " + "resultado");
    }

    return Math.round(new Float(Math.ceil((double) resultSize / resultsPerPage)));
}

From source file:ctblocktest.CTblocktest.java

static void runTest(String modeName, boolean packMode, boolean zipMode, boolean numMode) {
    try {/*from   w w w  .  j a v a  2  s .c o m*/
        CTwriter ctw = new CTwriter(sourceFolder + File.separator + modeName); // new CTwriter at root/source folder

        ctw.setTimeRelative(relativeTime); // relative (vs absolute) timestamps
        ctw.setBlockMode(packMode, zipMode); // pack multiple points per block? (linear timestamps per block)
        ctw.autoFlush(blockPts * dt); // autoflush blocks and segments
        ctw.autoSegment(segBlocks);
        CTinfo.setDebug(false);

        double iTime = 1460000000.; // sec 

        // loop and write some output
        for (int i = 0; i < nsamp; i++, iTime += dt) { // output to nfile
            ctw.setTime(iTime); // msec (packed-data ignore intermediate timestamps)

            for (int j = 0; j < nchan; j++) { // nchan per time-step
                if (numMode)
                    ctw.putData("c" + j, new Float(i + j)); // numeric format (default)
                else
                    ctw.putData("c" + j + ".f32", new Float(i + j)); // binary format
                //               System.err.println("put chan: c"+j+".f32: "+new Float(i+j));
            }
        }
        ctw.flush(); // clean up

    } catch (Exception e) {
        System.err.println("Exception: " + e);
    }
    System.err.println("writeTest done: " + modeName);
}

From source file:com.orange.clara.cloud.servicedbdumper.config.CatalogConfig.java

private float getCostFromQuota(String quota, String formula) throws ParseException, ScriptException {
    long size = ByteFormat.parse(quota);
    String formulaInjected = formula.replaceAll("quota", String.valueOf(size * this.getDefaultCost()));
    ScriptEngineManager factory = new ScriptEngineManager();
    ScriptEngine engine = factory.getEngineByName("JavaScript");
    Object eval = engine.eval(formulaInjected);
    if (eval instanceof Integer) {
        return new Float((Integer) eval);
    }/*from w  w  w  . j  ava 2 s  . c o  m*/
    if (eval instanceof Float) {
        return (Float) eval;
    }
    return Math.round((Double) eval);
}

From source file:es.udc.fic.test.model.ClasificacionServiceTest.java

@Test
public void getClasificacionTest() {

    //Creamos una sola regata con la instancia de todos los objetos en memoria
    Regata regata = new Regata();
    regata.setNombre("Mock Regata");
    regata.setDescripcion("Mock Desc");
    regataDao.save(regata);//from  w  w w  .  ja  v a2s.c o  m

    Tipo tipoCatamaran = new Tipo("Catamarn", "Desc Catamarn", false);
    tipoDao.save(tipoCatamaran);

    Tipo tipoCrucero = new Tipo("Crucero", "Desc Crucero", false);
    tipoDao.save(tipoCrucero);

    Tipo tipoLigero = new Tipo("Vela ligera", "Desc Vela ligera", true);
    tipoDao.save(tipoLigero);

    Barco b1 = new Barco(204566, "Juan Sebastian El Cano", tipoCatamaran, new Float(1.5), "Lagoon 421");
    inscripcionService.inscribir(regata, b1, "Iago Surez");
    Barco b2 = new Barco(199012, "El Holandes Errante", tipoCrucero, new Float(2.5), "SWAN 66 FD");
    inscripcionService.inscribir(regata, b2, "Samu Paredes");
    Barco b3 = new Barco(201402, "La Perla Negra", tipoCrucero, new Float(1.5), "X6");
    inscripcionService.inscribir(regata, b3, "Adrian Pallas");
    Barco b4 = new Barco(202102, "La Pinta", tipoCrucero, new Float(1.5), "X6");
    inscripcionService.inscribir(regata, b4, "Pedro Cabalar");
    Barco b5 = new Barco(182345, "Venus", tipoLigero, null, "Laser Standar");
    inscripcionService.inscribir(regata, b5, "Jesus Lopez");
    Barco b6 = new Barco(206745, "Apolo", tipoLigero, null, "Laser Radial");
    inscripcionService.inscribir(regata, b6, "Diego Bascoy");

    Calendar dia1 = Calendar.getInstance();
    dia1.add(Calendar.DAY_OF_YEAR, -18);

    Calendar dia2 = Calendar.getInstance();
    dia2.add(Calendar.DAY_OF_YEAR, -18);
    dia2.add(Calendar.HOUR, 2);

    Calendar dia3 = Calendar.getInstance();
    dia3.add(Calendar.DAY_OF_YEAR, -17);

    Manga manga1 = new Manga(dia1, regata, null, 100);
    Manga manga2 = new Manga(dia2, regata, null, 100);
    Manga manga3 = new Manga(dia3, regata, null, 100);

    List<Posicion> posManga1 = new ArrayList<Posicion>();

    posManga1.add(new Posicion(new Long(3600), Posicion.Penalizacion.ZFP, manga1, b1, (long) 0));
    posManga1.add(new Posicion(new Long(3700), Posicion.Penalizacion.NAN, manga1, b2, (long) 0));
    posManga1.add(new Posicion(new Long(3750), Posicion.Penalizacion.ZFP, manga1, b3, (long) 0));
    posManga1.add(new Posicion(new Long(3900), Posicion.Penalizacion.NAN, manga1, b4, (long) 0));
    posManga1.add(new Posicion(new Long(3400), Posicion.Penalizacion.NAN, manga1, b5, (long) 0));
    posManga1.add(new Posicion(new Long(2400), Posicion.Penalizacion.SCP, manga1, b6, (long) 0));
    manga1.setPosiciones(posManga1);

    mangaService.cerrarYGuardarManga(manga1);
    regata.addManga(manga1);

    List<Posicion> posManga2 = new ArrayList<Posicion>();

    posManga2.add(new Posicion(new Long(3400), Posicion.Penalizacion.ZFP, manga2, b1, (long) 0));
    posManga2.add(new Posicion(new Long(3600), Posicion.Penalizacion.NAN, manga2, b2, (long) 0));
    posManga2.add(new Posicion(new Long(3950), Posicion.Penalizacion.ZFP, manga2, b3, (long) 0));
    posManga2.add(new Posicion(new Long(3200), Posicion.Penalizacion.NAN, manga2, b4, (long) 0));
    posManga2.add(new Posicion(new Long(3100), Posicion.Penalizacion.ZFP, manga2, b5, (long) 0));
    posManga2.add(new Posicion(new Long(2800), Posicion.Penalizacion.SCP, manga2, b6, (long) 0));
    manga2.setPosiciones(posManga2);
    mangaService.cerrarYGuardarManga(manga2);
    regata.addManga(manga2);

    List<Posicion> posManga3 = new ArrayList<Posicion>();

    posManga3.add(new Posicion(new Long(13500), Posicion.Penalizacion.SCP, manga3, b1, (long) 0));
    posManga3.add(new Posicion(new Long(13200), Posicion.Penalizacion.NAN, manga3, b2, (long) 0));
    posManga3.add(new Posicion(new Long(13350), Posicion.Penalizacion.NAN, manga3, b3, (long) 0));
    posManga3.add(new Posicion(new Long(13900), Posicion.Penalizacion.ZFP, manga3, b4, (long) 0));
    posManga3.add(new Posicion(new Long(14400), Posicion.Penalizacion.NAN, manga3, b5, (long) 0));
    posManga3.add(new Posicion(new Long(15400), Posicion.Penalizacion.SCP, manga3, b6, (long) 0));
    manga3.setPosiciones(posManga3);
    mangaService.cerrarYGuardarManga(manga3);
    regata.addManga(manga3);

    //        //Mostrar los datos:
    //        for(List<Posicion> lp : posicionesGeneralFinal){
    //            int total = 0;
    //            System.out.print(lp.get(0).getBarco().getVela() + ": ");
    //            for(Posicion p : lp){
    //                System.out.print(p.getPuntos() + " | ");
    //                total += p.getPuntos();
    //            }
    //            System.out.println("Tot: " + total);
    //        }

    //Testeamos la clasificacion Final por Tipo
    Tipo tipo = tipoCrucero;
    List<List<Posicion>> posicionesFinalTipo = regataService.getClasificacion(regata, null, tipo);

    //Comprobamos que estn todos los barcos y que no estn repetido
    assertEquals(inscripcionService.getInscripcionesByTipo(regata, tipo).size(), posicionesFinalTipo.size());

    //Comprobamos que hay tantas posiciones como mangas
    for (List<Posicion> posBarco : posicionesFinalTipo) {
        assertEquals(posBarco.size(), regata.getMangas().size());
    }

    //Comprobamos que todas las posiciones de la misma sublista pertenecen 
    // al mismo Barco.
    for (List<Posicion> posBarco : posicionesFinalTipo) {
        Barco barcoAct = posBarco.get(0).getBarco();
        for (Posicion p : posBarco) {
            assertEquals(barcoAct, p.getBarco());
        }
    }

    Calendar fechaAnterior = null;
    //Comprobamos que las listas internas estn ordenadas por la fecha de 
    // la manga
    for (List<Posicion> posBarco : posicionesFinalTipo) {
        for (int i = 0; i < posBarco.size(); i++) {
            Calendar fechaActual = posBarco.get(i).getManga().getFecha();
            if (i > 0) {
                //Comparamos los calendars:
                assertTrue(fechaAnterior.before(fechaActual));
            }
            fechaAnterior = fechaActual;
        }
    }

    int puntActual;
    int puntAnterior = 0;
    //Comprobamos que el resultado viene bien ordenado por la puntuacion
    for (List<Posicion> posBarco : posicionesFinalTipo) {
        puntActual = 0;
        for (Posicion p : posBarco) {
            puntActual += p.getPuntos();
        }
        assertTrue(puntActual >= puntAnterior);
        puntAnterior = puntActual;
    }

    for (List<Posicion> posBarco : posicionesFinalTipo) {
        for (Posicion posicion : posBarco) {
            assertEquals(tipo, posicion.getBarco().getTipo());
        }
    }

    //Testeamos la clasificacion General por Dia
    Calendar dia = dia2;
    List<List<Posicion>> posicionesDiaGeneral = regataService.getClasificacion(regata, dia, null);

    for (List<Posicion> posBarco : posicionesDiaGeneral) {
        for (Posicion posicion : posBarco) {
            assertTrue(TimeUtil.compareByDay(dia, posicion.getManga().getFecha()));
        }
    }

    //Testeamos la clisificacion de un Tipo en un Dia
    Tipo tipoEspecifico = tipoCrucero;
    Calendar diaEspecifico = dia2;
    List<List<Posicion>> posicionesDiaTipo = regataService.getClasificacion(regata, diaEspecifico,
            tipoEspecifico);

    for (List<Posicion> posBarco : posicionesDiaTipo) {
        for (Posicion posicion : posBarco) {
            assertEquals(tipoEspecifico, posicion.getBarco().getTipo());
            assertTrue(TimeUtil.compareByDay(diaEspecifico, posicion.getManga().getFecha()));
        }
    }
}