List of usage examples for java.lang Float valueOf
@HotSpotIntrinsicCandidate public static Float valueOf(float f)
From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreter.java
private AbstractInsnNode handleMul(final int opcode, final Number one, final Number two) { final Number number; switch (opcode) { case IMUL:/*w ww.ja v a2 s . c om*/ number = Integer.valueOf(one.intValue() * two.intValue()); break; case DMUL: number = Double.valueOf(one.doubleValue() * two.doubleValue()); break; case FMUL: number = Float.valueOf(one.floatValue() * two.floatValue()); break; case LMUL: number = Long.valueOf(one.longValue() * two.longValue()); break; default: return null; } return NodeHelper.getInsnNodeFor(number); }
From source file:com.aselalee.trainschedule.GetResultsFromSiteV2.java
private boolean JSONToPriceList(String strJSON) { JSONObject jObject = GetResultsObject(strJSON); JSONArray ratesArray = null;/*from ww w .j a va 2s . c o m*/ if (jObject == null) return false; try { ratesArray = jObject.getJSONArray("priceList"); } catch (JSONException e) { errorCode = Constants.ERR_JSON_ERROR; errorString = "JSONObjectERROR : Error Parsing JSON string : " + e; Log.e(Constants.LOG_TAG, errorString); return false; } prices = new float[ratesArray.length()]; String strTmp = null; for (int i = 0; i < ratesArray.length(); i++) { try { strTmp = ratesArray.getJSONObject(i).getString("priceLKR").trim(); prices[i] = Float.valueOf(strTmp); } catch (JSONException e) { errorCode = Constants.ERR_JSON_ERROR; errorString = "getJSONObject.getStringError : Error Parsing JSON array object : " + e; Log.e(Constants.LOG_TAG, errorString); return false; } } return true; }
From source file:com.jada.order.document.InvoiceEngine.java
public void calculateHeader() throws Exception { float invoiceTotal = 0; Iterator<?> iterator = invoiceHeader.getInvoiceDetails().iterator(); while (iterator.hasNext()) { InvoiceDetail invoiceDetail = (InvoiceDetail) iterator.next(); invoiceTotal += invoiceDetail.getItemInvoiceAmount().floatValue(); Iterator<?> taxIterator = invoiceDetail.getInvoiceDetailTaxes().iterator(); while (taxIterator.hasNext()) { InvoiceDetailTax invoiceDetailTax = (InvoiceDetailTax) taxIterator.next(); invoiceTotal += invoiceDetailTax.getTaxAmount(); }/* w ww. j ava 2 s. c om*/ } invoiceTotal += invoiceHeader.getShippingTotal(); iterator = invoiceHeader.getInvoiceTaxes().iterator(); while (iterator.hasNext()) { InvoiceDetailTax invoiceDetailTax = (InvoiceDetailTax) iterator.next(); if (invoiceDetailTax.getInvoiceDetail() != null) { continue; } invoiceTotal += invoiceDetailTax.getTaxAmount(); } invoiceHeader.setInvoiceTotal(Float.valueOf(invoiceTotal)); invoiceHeader.setRecUpdateBy(userId); invoiceHeader.setRecUpdateDatetime(new Date()); }
From source file:se.gothiaforum.controller.actorssearch.ActorsSearchController.java
private List<ActorArticle> extractActorArticles(ThemeDisplay themeDisplay, QueryResponse queryResponse) throws PortalException, SystemException { Map<String, ActorArticle> articleIdActorArticleMap = new HashMap<String, ActorArticle>(); Iterator<SolrDocument> resultIter; if (queryResponse != null) { if (queryResponse.getResults() != null) { resultIter = queryResponse.getResults().iterator(); while (resultIter.hasNext()) { SolrDocument solrArticleEntry = resultIter.next(); ActorArticle actorArticle = new ActorArticle(); String actorsArticlePk = extractFieldValue(solrArticleEntry, ActorsConstants.ACTORS_ARTICLE_PK); actorArticle.setArticleId(actorsArticlePk); if (solrArticleEntry.getFieldValue(ActorsConstants.GROUP_ID) != null) { actorArticle.setGroupId( Long.valueOf(extractFieldValue(solrArticleEntry, ActorsConstants.GROUP_ID))); }/*from w w w .j a v a 2 s .c o m*/ if (solrArticleEntry.getFieldValue("version") != null) { actorArticle.setVersion(extractFieldValue(solrArticleEntry, "version")); } // In case of faulty solr index take care of not adding incorrect articles. try { setArticleContentAndTitle(themeDisplay, queryResponse, solrArticleEntry, actorArticle); long articleGroupId = actorArticle.getGroupId(); try { Group actorGroup = groupService.getGroup(articleGroupId); String namePrefix = actorGroup.getFriendlyURL(); actorArticle .setProfileURL(ActorsConstants.PROFILE_REDIRECT_URL + namePrefix.substring(1)); // If the map doesn't contain the article id, just add it... if (!articleIdActorArticleMap.containsKey(actorArticle.getArticleId())) { articleIdActorArticleMap.put(actorArticle.getArticleId(), actorArticle); } else { // otherwise only add if this is a later version Float thisVersion = Float.valueOf(actorArticle.getVersion()); ActorArticle that = articleIdActorArticleMap.get(actorArticle.getArticleId()); Float thatVersion = Float.valueOf(that.getVersion()); if (thisVersion > thatVersion) { articleIdActorArticleMap.put(actorArticle.getArticleId(), actorArticle); } } } catch (NoSuchGroupException nsge) { // Do nothing for now } } catch (NoSuchArticleException e) { log.warn("Warning: " + e.getMessage() + "may reindex."); } } } } ArrayList<ActorArticle> actorArticles = new ArrayList<ActorArticle>(articleIdActorArticleMap.values()); Collections.sort(actorArticles, new Comparator<ActorArticle>() { @Override public int compare(ActorArticle o1, ActorArticle o2) { return o1.getTitle().compareTo(o2.getTitle()); } }); return actorArticles; }
From source file:com.alibaba.wasp.client.TestDataCorrectness.java
/** * Get the byte data of a seq id as given data type * //from w ww.j a va 2 s . c o m * @param dataType * @param seqId * @return the byte data of given seqId and data type */ private static byte[] getDataValueAsType(DataType dataType, int seqId) { if (dataType == DataType.INT32) { return Bytes.toBytes(Integer.valueOf(seqId)); } else if (dataType == DataType.INT64) { return Bytes.toBytes(Long.valueOf(seqId)); } else if (dataType == DataType.FLOAT) { return Bytes.toBytes(Float.valueOf(seqId)); } else if (dataType == DataType.DOUBLE) { return Bytes.toBytes(Double.valueOf(seqId)); } else if (dataType == DataType.STRING) { return Bytes.toBytes(String.format("%07d", seqId)); } else { fail("Unsupport data type:" + dataType); return null; } }
From source file:jenkins.plugins.tanaguru.TanaguruRunnerBuilder.java
private void setBuildStatus(AbstractBuild build, TanaguruRunner tanaguruRunner) { if ((StringUtils.isBlank(minMarkThresholdForStable) || Integer.valueOf(minMarkThresholdForStable) < 0) && (StringUtils.isBlank(maxFailedOccurencesForStable) || Integer.valueOf(maxFailedOccurencesForStable) < 0)) { build.setResult(Result.SUCCESS); return;/*from www . j a v a 2 s.c o m*/ } if (Integer.valueOf(minMarkThresholdForStable) > 0 && Float.valueOf(tanaguruRunner.mark) < Integer.valueOf(minMarkThresholdForStable)) { build.setResult(Result.UNSTABLE); return; } if (Integer.valueOf(maxFailedOccurencesForStable) > 0 && Integer .valueOf(tanaguruRunner.nbFailedOccurences) > Integer.valueOf(maxFailedOccurencesForStable)) { build.setResult(Result.UNSTABLE); return; } build.setResult(Result.SUCCESS); }
From source file:com.mozilla.testpilot.hive.serde.TestPilotJsonSerde.java
/** * Deserialize a JSON Object into a row for the table *//*from ww w . ja v a 2s.com*/ @SuppressWarnings("unchecked") @Override public Object deserialize(Writable blob) throws SerDeException { String rowText = ((Text) blob).toString(); if (LOG.isDebugEnabled()) { LOG.debug("Deserialize row: " + rowText); } // Try parsing row into JSON object Map<String, Object> values = new HashMap<String, Object>(); try { Map<String, Object> tempValues = jsonMapper.readValue(rowText, new TypeReference<Map<String, Object>>() { }); // Metadata if (tempValues.containsKey("metadata")) { Map<String, Object> metadata = (Map<String, Object>) tempValues.get("metadata"); Map<String, String> preferencesMap = new HashMap<String, String>(); for (Map.Entry<String, Object> metaEntry : metadata.entrySet()) { String key = metaEntry.getKey(); Object vo = metaEntry.getValue(); // Extensions if ("extensions".equals(key)) { List<Object> extensions = (List<Object>) vo; Map<String, Boolean> extensionMap = new HashMap<String, Boolean>(); for (Object o : extensions) { Map<String, Object> ex = (Map<String, Object>) o; String id = (String) ex.get("id"); Boolean isEnabled = (Boolean) ex.get("isEnabled"); extensionMap.put(id, isEnabled); } values.put("extensions", extensionMap); // Accessibilities } else if ("accessibilities".equals(key)) { List<Object> accessibilities = (List<Object>) vo; Map<String, String> accessibilityMap = new HashMap<String, String>(); for (Object o : accessibilities) { Map<String, Object> a = (Map<String, Object>) o; String name = (String) a.get("name"); // Get a string value of everything since we have mixed types String v = String.valueOf(a.get("value")); accessibilityMap.put(name, v); } values.put("accessibilities", accessibilityMap); // Hack preferences } else if (key.startsWith("Preference")) { String name = key.replace("Preference ", ""); preferencesMap.put(name.toLowerCase(), String.valueOf(metaEntry.getValue())); } else if ("Sync configured".equals(key)) { preferencesMap.put("sync.configured", String.valueOf(metaEntry.getValue())); // Leave survey answers as a JSON value for now } else if ("surveyAnswers".equals(key)) { values.put("surveyanswers", jsonMapper.writeValueAsString(vo)); // location is a hive keyword } else if ("location".equals(key)) { values.put("loc", vo); } else { values.put(key.toLowerCase(), vo); } } if (preferencesMap.size() > 0) { values.put("preferences", preferencesMap); } } // Events if (tempValues.containsKey("events")) { List<List<Long>> events = (List<List<Long>>) tempValues.get("events"); values.put("events", events); } } catch (JsonParseException e) { LOG.error("JSON Parse Error", e); } catch (JsonMappingException e) { LOG.error("JSON Mapping Error", e); } catch (IOException e) { LOG.error("IOException during JSON parsing", e); } if (values.size() == 0) { return null; } // Loop over columns in table and set values for (int c = 0; c < numColumns; c++) { String colName = columnNames.get(c); TypeInfo ti = columnTypes.get(c); Object value = null; try { // Get type-safe JSON values if (ti.getTypeName().equalsIgnoreCase(Constants.DOUBLE_TYPE_NAME)) { value = Double.valueOf((String) values.get(colName)); } else if (ti.getTypeName().equalsIgnoreCase(Constants.BIGINT_TYPE_NAME)) { value = Long.valueOf((String) values.get(colName)); } else if (ti.getTypeName().equalsIgnoreCase(Constants.INT_TYPE_NAME)) { value = Integer.valueOf((String) values.get(colName)); } else if (ti.getTypeName().equalsIgnoreCase(Constants.TINYINT_TYPE_NAME)) { value = Byte.valueOf((String) values.get(colName)); } else if (ti.getTypeName().equalsIgnoreCase(Constants.FLOAT_TYPE_NAME)) { value = Float.valueOf((String) values.get(colName)); } else if (ti.getTypeName().equalsIgnoreCase(Constants.BOOLEAN_TYPE_NAME)) { value = Boolean.valueOf((String) values.get(colName)); } else { // Fall back, just get an object value = values.get(colName); } } catch (RuntimeException e) { LOG.error("Class cast error for column name: " + colName); Object o = values.get(colName); if (o != null) { LOG.error("Value was: " + o.toString()); } throw new SerDeException(e); } if (value == null) { // If the column cannot be found, just make it a NULL value and // skip over it LOG.warn("Column '" + colName + "' not found in row: " + rowText.toString()); } row.set(c, value); } return row; }
From source file:es.agrega.soporte.http.BrowserDetector.java
/** * Process the HttpServletRequest for client information. * Prosecute to the fullest extent possible ;-) * * @param request An HttpRequest used to gather client information. *///w w w .j a va 2 s. c o m public void setRequest(HttpServletRequest request) { // because different containers/web-servers use diffent naming conventions, // we need to be extra careful fetching this headers String tempUAS = HttpUtils.findHeader(request, "USER_AGENT"); if (tempUAS != null) { this.setUserAgentString(tempUAS); } // get values from request headers clientIP = request.getRemoteAddr(); clientHost = request.getRemoteHost(); String acceptEncoding = HttpUtils.findHeader(request, "ACCEPT_ENCODING"); if (acceptEncoding != null && acceptEncoding.indexOf("gzip") != -1) { gzipOK = true; } // acceptMIME: parse ACCEPT and place into ARRAYLIST String[] acceptArray = StringUtils.split(HttpUtils.findHeader(request, "ACCEPT"), ","); acceptMIME = java.util.Arrays.asList(acceptArray); String protocol = request.getProtocol(); if (protocol != null && protocol.indexOf("/") != -1) { int slashLoc = protocol.indexOf("/"); protocolType = protocol.substring(0, slashLoc); try { protocolVersion = Float.valueOf(protocol.substring(slashLoc + 1)).floatValue(); } catch (Exception e) { // if there was an error getting protocolVersion, set to -1 protocolVersion = (float) -1.0; } if ("HTTP".equals(protocolType) && protocolVersion > 1.0) keepAliveOK = true; } }
From source file:com.ebay.nest.io.sede.RegexSerDe.java
@Override public Object deserialize(Writable blob) throws SerDeException { Text rowText = (Text) blob; Matcher m = inputPattern.matcher(rowText.toString()); if (m.groupCount() != numColumns) { throw new SerDeException("Number of matching groups doesn't match the number of columns"); }/* ww w .ja v a 2 s. c o m*/ // If do not match, ignore the line, return a row with all nulls. if (!m.matches()) { unmatchedRowsCount++; if (!alreadyLoggedNoMatch) { // Report the row if its the first time LOG.warn("" + unmatchedRowsCount + " unmatched rows are found: " + rowText); alreadyLoggedNoMatch = true; } return null; } // Otherwise, return the row. for (int c = 0; c < numColumns; c++) { try { String t = m.group(c + 1); TypeInfo typeInfo = columnTypes.get(c); String typeName = typeInfo.getTypeName(); // Convert the column to the correct type when needed and set in row obj if (typeName.equals(serdeConstants.STRING_TYPE_NAME)) { row.set(c, t); } else if (typeName.equals(serdeConstants.TINYINT_TYPE_NAME)) { Byte b; b = Byte.valueOf(t); row.set(c, b); } else if (typeName.equals(serdeConstants.SMALLINT_TYPE_NAME)) { Short s; s = Short.valueOf(t); row.set(c, s); } else if (typeName.equals(serdeConstants.INT_TYPE_NAME)) { Integer i; i = Integer.valueOf(t); row.set(c, i); } else if (typeName.equals(serdeConstants.BIGINT_TYPE_NAME)) { Long l; l = Long.valueOf(t); row.set(c, l); } else if (typeName.equals(serdeConstants.FLOAT_TYPE_NAME)) { Float f; f = Float.valueOf(t); row.set(c, f); } else if (typeName.equals(serdeConstants.DOUBLE_TYPE_NAME)) { Double d; d = Double.valueOf(t); row.set(c, d); } else if (typeName.equals(serdeConstants.BOOLEAN_TYPE_NAME)) { Boolean b; b = Boolean.valueOf(t); row.set(c, b); } else if (typeName.equals(serdeConstants.TIMESTAMP_TYPE_NAME)) { Timestamp ts; ts = Timestamp.valueOf(t); row.set(c, ts); } else if (typeName.equals(serdeConstants.DATE_TYPE_NAME)) { Date d; d = Date.valueOf(t); row.set(c, d); } else if (typeName.equals(serdeConstants.DECIMAL_TYPE_NAME)) { HiveDecimal bd; bd = new HiveDecimal(t); row.set(c, bd); } else if (typeInfo instanceof PrimitiveTypeInfo && ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory() == PrimitiveCategory.VARCHAR) { VarcharTypeParams varcharParams = (VarcharTypeParams) ParameterizedPrimitiveTypeUtils .getTypeParamsFromTypeInfo(typeInfo); HiveVarchar hv = new HiveVarchar(t, varcharParams != null ? varcharParams.length : -1); row.set(c, hv); } } catch (RuntimeException e) { partialMatchedRowsCount++; if (!alreadyLoggedPartialMatch) { // Report the row if its the first row LOG.warn("" + partialMatchedRowsCount + " partially unmatched rows are found, " + " cannot find group " + c + ": " + rowText); alreadyLoggedPartialMatch = true; } row.set(c, null); } } return row; }
From source file:app.order.OrderController.java
public void setCheckWithFields(Check check) { check.setName(checkName.getText());// w w w . j ava2s . c o m check.setAmount(Float.valueOf(checkAmount.getText())); check.setBank(checkBank.getValue()); check.setDueDate(Date.valueOf(checkDueDate.getValue())); if (check.getPaymentState() == null) check.setPaymentState(PaymentState.NONPAYE); }