Example usage for java.lang Float valueOf

List of usage examples for java.lang Float valueOf

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static Float valueOf(float f) 

Source Link

Document

Returns a Float instance representing the specified float value.

Usage

From source file:br.com.atmatech.sac.webService.WebServiceFinanceiro.java

public List<FinanceiroBeans> getFinanceiro(String url, String user, String password) throws IOException {
    String chave = "";
    HttpPost post = new HttpPost(url);
    boolean result = false;
    /* Configura os parmetros do POST */
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("login", user));
    nameValuePairs.add(new BasicNameValuePair("senha", password));
    nameValuePairs.add(new BasicNameValuePair("x", "26"));
    nameValuePairs.add(new BasicNameValuePair("y", "26"));
    post.setEntity(new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8));
    // post.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0");
    HttpResponse response = client.execute(post);
    // System.out.println("Login form get: " + response.getStatusLine());
    EntityUtils.consume(response.getEntity());
    HttpPost get = new HttpPost("http://atma.serveftp.com/atma/view/index.php?page=BAIXAR&mostrar=1");
    get.setEntity(new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8));
    response = client.execute(get);/*from   w  w  w  . j a  va2  s .c om*/
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String line;
    //        // Grava pagina no arquivo
    FileWriter out = new FileWriter("./logfin.txt");
    PrintWriter gravarArq = new PrintWriter(out);
    int indexant = 11;
    boolean doc = true;
    boolean cliente = true;
    boolean valor = true;
    boolean vencimento = true;
    boolean contato = true;
    boolean tel = true;
    String tdoc = "";
    String tcliente = "";
    float tvalor = 0;
    Date tvencimento = null;
    String tcontato = "";
    String ttel = "";
    List<FinanceiroBeans> lfb = new ArrayList<>();
    while ((line = rd.readLine()) != null) {
        if (line.contains("<tr><td>")) {
            //gravarArq.print(line+"\n");
            line = line.replace("<tr><td>", "\n").replace("</td></tr>", "\n");
            line = line.replace("</td><td>", ";")
                    .replace("</td><td align='center'><a class='btn default' target='_blank'", ";")
                    .replace("</i></a>", ":");
            gravarArq.print(line + "\n");
            for (int i = 0; i < line.length(); i++) {
                if (doc && (indexant != i)) {
                    if (line.charAt(i) == ';') {
                        tdoc = line.substring(indexant + 1, i);
                        indexant = i;
                        doc = false;
                    }
                } else {
                    if ((!doc) && (cliente) && (indexant != i)) {
                        if (line.charAt(i) == ';') {
                            tcliente = line.substring(indexant + 1, i);
                            indexant = i;
                            cliente = false;
                        }
                    } else {
                        if ((!doc) && (!cliente) && (valor) && (indexant != i)) {
                            if (line.charAt(i) == ';') {
                                tvalor = Float.valueOf(line.substring(indexant + 1, i));
                                indexant = i;
                                valor = false;
                            }
                        } else {
                            if ((!doc) && (!cliente) && (!valor) && (vencimento) && (indexant != i)) {
                                if (line.charAt(i) == ';') {
                                    String data = line.substring(indexant + 1, i).replace("/", ".");
                                    int ind1 = data.indexOf(".");
                                    int ind2 = data.indexOf(".", ind1 + 1);
                                    String dd = data.substring(0, ind1);
                                    String mm = data.substring(ind1 + 1, ind2);
                                    String yyyy = data.substring(ind2 + 1);
                                    tvencimento = new Date(Integer.parseInt(yyyy) - 1900,
                                            Integer.parseInt(mm) - 1, Integer.parseInt(dd));
                                    indexant = i;
                                    vencimento = false;
                                }
                            } else {
                                if ((!doc) && (!cliente) && (!valor) && (!vencimento) && (contato)
                                        && (indexant != i)) {
                                    if (line.charAt(i) == ';') {
                                        tcontato = line.substring(indexant + 1, i);
                                        indexant = i;
                                        contato = false;
                                    }
                                } else {
                                    if ((!doc) && (!cliente) && (!valor) && (!vencimento) && (!contato) && (tel)
                                            && (indexant != i)) {
                                        if (line.charAt(i) == ';') {
                                            ttel = line.substring(indexant + 1, i);
                                            indexant = i;
                                            tel = false;
                                        }
                                    } else {
                                        if ((!doc) && (!cliente) && (!valor) && (!vencimento) && (!contato)
                                                && (!tel) && (line.charAt(i) == ':')) {
                                            indexant = i + 2;
                                            FinanceiroBeans fb = new FinanceiroBeans();
                                            fb.setCliente(tcliente);
                                            fb.setContato(tcontato);
                                            fb.setDoc(tdoc);
                                            fb.setTelcel(ttel);
                                            fb.setValor(tvalor);
                                            fb.setVencimento(tvencimento);
                                            lfb.add(fb);
                                            doc = true;
                                            cliente = true;
                                            valor = true;
                                            vencimento = true;
                                            contato = true;
                                            tel = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

    }
    out.close();
    return lfb;
}

From source file:com.ikanow.aleph2.search_service.elasticsearch.utils.TestJsonNodeWritableUtils.java

@Test
public void test_transform() {
    final ObjectMapper mapper = BeanTemplateUtils.configureMapper(Optional.empty());
    new JsonNodeWritableUtils(); //coverage!

    assertEquals(NullNode.instance, JsonNodeWritableUtils.transform("banana", JsonNodeFactory.instance));
    assertEquals(null, JsonNodeWritableUtils.transform(null, JsonNodeFactory.instance));
    assertEquals(NullNode.instance,// w  w  w. j av  a 2s  .  c  o  m
            JsonNodeWritableUtils.transform(NullWritable.get(), JsonNodeFactory.instance));
    assertEquals(mapper.convertValue(true, JsonNode.class),
            JsonNodeWritableUtils.transform(new BooleanWritable(true), JsonNodeFactory.instance));
    assertEquals(mapper.convertValue("test", JsonNode.class),
            JsonNodeWritableUtils.transform(new Text("test"), JsonNodeFactory.instance));
    assertEquals(mapper.convertValue(new byte[] { (byte) 0xFF }, JsonNode.class),
            JsonNodeWritableUtils.transform(new ByteWritable((byte) 0xFF), JsonNodeFactory.instance));
    assertEquals(mapper.convertValue(4, JsonNode.class),
            JsonNodeWritableUtils.transform(new IntWritable(4), JsonNodeFactory.instance));
    assertEquals(mapper.convertValue(4, JsonNode.class),
            JsonNodeWritableUtils.transform(new VIntWritable(4), JsonNodeFactory.instance));
    assertEquals(mapper.convertValue(4L, JsonNode.class),
            JsonNodeWritableUtils.transform(new LongWritable(4), JsonNodeFactory.instance));
    assertEquals(mapper.convertValue(4L, JsonNode.class),
            JsonNodeWritableUtils.transform(new VLongWritable(4), JsonNodeFactory.instance));
    assertEquals(mapper.convertValue(new byte[] { (byte) 0xFF, (byte) 0xFE }, JsonNode.class),
            JsonNodeWritableUtils.transform(new BytesWritable(new byte[] { (byte) 0xFF, (byte) 0xFE }),
                    JsonNodeFactory.instance));
    assertEquals(mapper.convertValue(4.0, JsonNode.class),
            JsonNodeWritableUtils.transform(new DoubleWritable(4), JsonNodeFactory.instance));
    //(had real trouble creating a float node!)
    assertEquals(JsonNodeFactory.instance.numberNode(Float.valueOf((float) 4.0)),
            JsonNodeWritableUtils.transform(new FloatWritable(4), JsonNodeFactory.instance));

    // will test object writable and array writable below      
}

From source file:net.sourceforge.fenixedu.domain.candidacy.workflow.form.OriginInformationForm.java

private static String roundUpGrade(String grade) {
    return String.valueOf(Math.round(Float.valueOf(grade)));
}

From source file:com.mousebird.maply.MaplyStarModel.java

public MaplyStarModel(String fileName, String imageName, Activity activity) throws IOException {
    AssetManager assetMgr = activity.getAssets();
    InputStream inputStream = null;
    String[] paths = assetMgr.list("maplystarmodel");
    for (String path : paths) {
        if (path.equals(imageName)) {
            //image
            BufferedInputStream bufferedInputStream = null;
            try {
                inputStream = assetMgr.open("maplystarmodel/" + path);
                bufferedInputStream = new BufferedInputStream(inputStream);
                image = BitmapFactory.decodeStream(bufferedInputStream);
            } finally {
                if (bufferedInputStream != null) {
                    try {
                        bufferedInputStream.close();
                    } catch (IOException e) {
                    }//w  w  w .ja  va  2 s . co m
                }
            }
        }
        if (path.equals(fileName)) {
            //data
            Matcher m;
            try {
                inputStream = assetMgr.open("maplystarmodel/" + path);
                String stars = IOUtils.toString(inputStream, Charset.defaultCharset());
                Pattern p = Pattern.compile("[-]?[0-9]*\\.?[0-9]+");
                m = p.matcher(stars);
            } finally {
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (IOException e) {
                    }
                }
            }

            this.stars = new ArrayList<SingleStar>();
            if (m.groupCount() % 3 == 0) {
                int i = 0;
                SingleStar s = null;
                while (m.find()) {
                    switch (i) {
                    case 0:
                        s = new SingleStar();
                        s.ra = Float.valueOf(m.group());
                        i++;
                        break;
                    case 1:
                        s.dec = Float.valueOf(m.group());
                        i++;
                        break;
                    case 2:
                        s.mag = Float.valueOf(m.group());
                        this.stars.add(s);
                        i = 0;
                        break;
                    default:
                        break;
                    }
                }
            }
        }
    }
}

From source file:gov.nih.nci.caintegrator.web.action.query.form.SegmentCriterionWrapper.java

private TextFieldParameter createLowerLimitParameter() {
    final String label = "Segment Mean Value >=";
    TextFieldParameter textParameter = new TextFieldParameter(getParameters().size(), getRow().getRowIndex(),
            getCopyNumberAlterationCriterion().getDisplayLowerLimit());
    textParameter.setLabel(label);/*from   ww  w  .  java 2 s.  co m*/
    ValueHandler valueChangeHandler = new ValueHandlerAdapter() {

        @Override
        public boolean isValid(String value) {
            return StringUtils.isBlank(value) || NumberUtils.isNumber(value);
        }

        @Override
        public void validate(String formFieldName, String value, ValidationAware action) {
            if (!isValid(value)) {
                action.addActionError("Numeric value required or blank for " + label);
            }
        }

        @Override
        public void valueChanged(String value) {
            if (StringUtils.isBlank(value)) {
                getCopyNumberAlterationCriterion().setLowerLimit(null);
            } else {
                getCopyNumberAlterationCriterion().setLowerLimit(Float.valueOf(value));
            }
        }
    };
    textParameter.setValueHandler(valueChangeHandler);
    return textParameter;
}

From source file:org.apache.usergrid.java.client.utils.JsonUtils.java

@Nullable
@SuppressWarnings("unchecked")
public static <T> T getProperty(@NotNull final Map<String, JsonNode> properties, @NotNull final String name) {
    JsonNode value = properties.get(name);
    if (value == null) {
        return null;
    } else if (value instanceof TextNode) {
        return (T) value.asText();
    } else if (value instanceof LongNode) {
        Long valueLong = value.asLong();
        return (T) valueLong;
    } else if (value instanceof BooleanNode) {
        Boolean valueBoolean = value.asBoolean();
        return (T) valueBoolean;
    } else if (value instanceof IntNode) {
        Integer valueInteger = value.asInt();
        return (T) valueInteger;
    } else if (value instanceof FloatNode) {
        return (T) Float.valueOf(value.toString());
    } else {//from   w w w.  jav a  2s  . c  om
        return (T) value;
    }
}

From source file:io.openmessaging.rocketmq.utils.BeanUtils.java

public static void setProperties(Class<?> clazz, Object obj, String methodName, Object value)
        throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    Class<?> parameterClass = getMethodClass(clazz, methodName);
    Method setterMethod = clazz.getMethod(methodName, parameterClass);
    if (parameterClass == Boolean.TYPE) {
        setterMethod.invoke(obj, Boolean.valueOf(value.toString()));
    } else if (parameterClass == Integer.TYPE) {
        setterMethod.invoke(obj, Integer.valueOf(value.toString()));
    } else if (parameterClass == Double.TYPE) {
        setterMethod.invoke(obj, Double.valueOf(value.toString()));
    } else if (parameterClass == Float.TYPE) {
        setterMethod.invoke(obj, Float.valueOf(value.toString()));
    } else if (parameterClass == Long.TYPE) {
        setterMethod.invoke(obj, Long.valueOf(value.toString()));
    } else// ww w. ja va 2s  . co  m
        setterMethod.invoke(obj, value);
}

From source file:info.magnolia.ui.form.field.upload.basic.BasicUploadProgressIndicator.java

@Override
public void refreshLayout(long readBytes, long contentLength, String fileName) {
    progressIndicator.setValue(Float.valueOf(readBytes / (float) contentLength));

    uploadFileLocation.setValue(i18n.translate(this.inProgressCaption, fileName));

    uploadFileProgress.setValue(createPercentage(readBytes, contentLength));

    String bytesRead = FileUtils.byteCountToDisplaySize(readBytes);
    String totalBytes = FileUtils.byteCountToDisplaySize(contentLength);
    uploadFileRatio.setValue(i18n.translate(this.inProgressRatioCaption, bytesRead, totalBytes));
}

From source file:com.ibuildapp.romanblack.TableReservationPlugin.JSONParser.java

/**
 * Downloads and parses JSON messages data.
 * @param url URL resource that contains JSON data
 * @return messages array// w  w  w.  java  2  s.  co  m
 */
public static ArrayList<FanWallMessage> parseMessagesUrl(String url) {
    try {
        String resp = loadURLData(url);

        if (resp == null) {
            return null;
        }

        if (resp.length() == 0) {
            return null;
        }

        JSONObject mainObject = new JSONObject(resp);

        JSONArray messagesJSON = mainObject.getJSONArray("posts");

        ArrayList<FanWallMessage> parsedMessages = new ArrayList<FanWallMessage>();

        for (int i = 0; i < messagesJSON.length(); i++) {
            JSONObject messageJSON = messagesJSON.getJSONObject(i);

            FanWallMessage tmpMessage = new FanWallMessage();
            tmpMessage.setId(Long.valueOf(messageJSON.getString("post_id")).longValue());
            tmpMessage.setAuthor(messageJSON.getString("user_name"));
            tmpMessage.setDate(new Date(Long.valueOf(messageJSON.getString("create")).longValue()));
            tmpMessage.setUserAvatarUrl(messageJSON.getString("user_avatar"));
            tmpMessage.setText(messageJSON.getString("text"));
            try {
                tmpMessage.setPoint(Float.valueOf(messageJSON.getString("latitude")).floatValue(),
                        Float.valueOf(messageJSON.getString("longitude")).floatValue());
            } catch (NumberFormatException nFEx) {
            }

            try {
                tmpMessage.setParentId(Integer.valueOf(messageJSON.getString("parent_id")).intValue());
            } catch (NumberFormatException nFEx) {
                Log.e("", "");
            }

            try {
                tmpMessage.setReplyId(Integer.valueOf(messageJSON.getString("reply_id")).intValue());
            } catch (NumberFormatException nFEx) {
                Log.e("", "");
            }

            tmpMessage.setTotalComments(Integer.valueOf(messageJSON.getString("total_comments")).intValue());

            JSONArray imagesJSON = messageJSON.getJSONArray("images");
            if (imagesJSON.length() > 0) {
                tmpMessage.setImageUrl(imagesJSON.getString(0));
            }

            tmpMessage.setAccountId(messageJSON.getString("account_id"));
            tmpMessage.setAccountType(messageJSON.getString("account_type"));

            parsedMessages.add(tmpMessage);
        }

        return parsedMessages;
    } catch (JSONException jSSONEx) {
        return null;
    }
}