List of usage examples for java.lang Float toString
public static String toString(float f)
From source file:com.runwaysdk.query.function.AggregateFunctionMasterSetup.java
@Transaction public void setUp() { mdBusiness = MdBusinessDAO.newInstance(); mdBusiness.setValue(MdBusinessInfo.NAME, classQueryInfo.getTypeName()); mdBusiness.setValue(MdBusinessInfo.PACKAGE, classQueryInfo.getPackageName()); mdBusiness.setValue(MdBusinessInfo.REMOVE, MdAttributeBooleanInfo.TRUE); mdBusiness.setStructValue(MdBusinessInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, "Function Object Type"); mdBusiness.setStructValue(MdBusinessInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, "Class used to test query functions"); mdBusiness.setValue(MdBusinessInfo.EXTENDABLE, MdAttributeBooleanInfo.FALSE); mdBusiness.setValue(MdBusinessInfo.ABSTRACT, MdAttributeBooleanInfo.FALSE); mdBusiness.setGenerateMdController(false); mdBusiness.apply();/*w w w .jav a 2 s . c o m*/ QueryMasterSetup.loadAttributePrimitives(mdBusiness, FUNC_PREFIX); comMdBusiness = MdBusinessDAO.newInstance(); comMdBusiness.setValue(MdBusinessInfo.NAME, comQueryInfo.getTypeName()); comMdBusiness.setValue(MdBusinessInfo.PACKAGE, comQueryInfo.getPackageName()); comMdBusiness.setValue(MdBusinessInfo.REMOVE, MdAttributeBooleanInfo.TRUE); comMdBusiness.setStructValue(MdBusinessInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, "Function Object Type"); comMdBusiness.setStructValue(MdBusinessInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, "Class used to test query functions"); comMdBusiness.setValue(MdBusinessInfo.EXTENDABLE, MdAttributeBooleanInfo.FALSE); comMdBusiness.setValue(MdBusinessInfo.ABSTRACT, MdAttributeBooleanInfo.FALSE); comMdBusiness.setGenerateMdController(false); comMdBusiness.apply(); QueryMasterSetup.loadAttributePrimitives(comMdBusiness, COM_FUNC_PREFIX); countMdBusiness = MdBusinessDAO.newInstance(); countMdBusiness.setValue(MdBusinessInfo.NAME, countQueryInfo.getTypeName()); countMdBusiness.setValue(MdBusinessInfo.PACKAGE, countQueryInfo.getPackageName()); countMdBusiness.setValue(MdBusinessInfo.REMOVE, MdAttributeBooleanInfo.TRUE); countMdBusiness.setStructValue(MdBusinessInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, "Function Object Type"); countMdBusiness.setStructValue(MdBusinessInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, "Class used to test query functions"); countMdBusiness.setValue(MdBusinessInfo.EXTENDABLE, MdAttributeBooleanInfo.FALSE); countMdBusiness.setValue(MdBusinessInfo.ABSTRACT, MdAttributeBooleanInfo.FALSE); countMdBusiness.setGenerateMdController(false); countMdBusiness.apply(); QueryMasterSetup.loadAttributePrimitives(countMdBusiness, COUNT_FUNC_PREFIX); sumMdBusiness = MdBusinessDAO.newInstance(); sumMdBusiness.setValue(MdBusinessInfo.NAME, sumQueryInfo.getTypeName()); sumMdBusiness.setValue(MdBusinessInfo.PACKAGE, sumQueryInfo.getPackageName()); sumMdBusiness.setValue(MdBusinessInfo.REMOVE, MdAttributeBooleanInfo.TRUE); sumMdBusiness.setStructValue(MdBusinessInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, "Function Object Type"); sumMdBusiness.setStructValue(MdBusinessInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, "Class used to test query functions"); sumMdBusiness.setValue(MdBusinessInfo.EXTENDABLE, MdAttributeBooleanInfo.FALSE); sumMdBusiness.setValue(MdBusinessInfo.ABSTRACT, MdAttributeBooleanInfo.FALSE); sumMdBusiness.setGenerateMdController(false); sumMdBusiness.apply(); QueryMasterSetup.loadAttributePrimitives(sumMdBusiness, SUM_FUNC_PREFIX); floatOracle(); doubleOracle(); decimalOracle(); integerOracle(); longOracle(); dateOracle(); dateTimeOracle(); timeOracle(); booleanOracle(); for (int i = 0; i < numOfObjects; i++) { long dateLong = dateArray[i]; Date date = new Date(dateLong); String dateString = new java.text.SimpleDateFormat(Constants.DATE_FORMAT).format(date); long dateTimeLong = dateTimeArray[i]; Date dateTime = new Date(dateTimeLong); String dateTimeString = new java.text.SimpleDateFormat(Constants.DATETIME_FORMAT).format(dateTime); long timeLong = timeArray[i]; Date time = new Date(timeLong); String timeString = new java.text.SimpleDateFormat(Constants.TIME_FORMAT).format(time); BusinessDAO classQueryObject = BusinessDAO.newInstance(classQueryInfo.getType()); classQueryObject.setValue("funcBoolean", Boolean.toString(booleanArray[i])); classQueryObject.setValue("funcCharacter", "some character value"); classQueryObject.setValue("funcText", "some text value"); classQueryObject.setValue("funcDateTime", dateTimeString); classQueryObject.setValue("funcDate", dateString); classQueryObject.setValue("funcTime", timeString); classQueryObject.setValue("funcInteger", Integer.toString(integerArray[i])); classQueryObject.setValue("funcLong", Long.toString(longArray[i])); classQueryObject.setValue("funcFloat", Float.toString(floatArray[i])); classQueryObject.setValue("funcDecimal", Double.toString(decimalArray[i])); classQueryObject.setValue("funcDouble", Double.toString(doubleArray[i])); classQueryObject.apply(); classObjectList.add(classQueryObject); BusinessDAO compareQueryObject = BusinessDAO.newInstance(comQueryInfo.getType()); compareQueryObject.setValue("comFuncBoolean", Boolean.toString(booleanArray[i])); compareQueryObject.setValue("comFuncCharacter", "some character value"); compareQueryObject.setValue("comFuncText", "some text value"); compareQueryObject.setValue("comFuncDateTime", dateTimeString); compareQueryObject.setValue("comFuncDate", dateString); compareQueryObject.setValue("comFuncTime", timeString); compareQueryObject.setValue("comFuncInteger", Integer.toString(integerArray[i])); compareQueryObject.setValue("comFuncLong", Long.toString(longArray[i])); compareQueryObject.setValue("comFuncFloat", Float.toString(floatArray[i])); compareQueryObject.setValue("comFuncDecimal", Double.toString(decimalArray[i])); compareQueryObject.setValue("comFuncDouble", Double.toString(doubleArray[i])); compareQueryObject.apply(); compareObjectList.add(compareQueryObject); } for (int i = 0; i < countFloatArray.length; i++) { long dateLong = dateArray[i]; Date date = new Date(dateLong); String dateString = new java.text.SimpleDateFormat(Constants.DATE_FORMAT).format(date); long dateTimeLong = dateTimeArray[i]; Date dateTime = new Date(dateTimeLong); String dateTimeString = new java.text.SimpleDateFormat(Constants.DATETIME_FORMAT).format(dateTime); long timeLong = timeArray[i]; Date time = new Date(timeLong); String timeString = new java.text.SimpleDateFormat(Constants.TIME_FORMAT).format(time); BusinessDAO sumQueryObject = BusinessDAO.newInstance(countQueryInfo.getType()); sumQueryObject.setValue("countFuncBoolean", Boolean.toString(booleanArray[i])); sumQueryObject.setValue("countFuncCharacter", "some character value"); sumQueryObject.setValue("countFuncText", "some text value"); sumQueryObject.setValue("countFuncDateTime", dateTimeString); sumQueryObject.setValue("countFuncDate", dateString); sumQueryObject.setValue("countFuncTime", timeString); sumQueryObject.setValue("countFuncInteger", Integer.toString(countIntegerArray[i])); sumQueryObject.setValue("countFuncLong", Long.toString(countLongArray[i])); sumQueryObject.setValue("countFuncFloat", Float.toString(countFloatArray[i])); sumQueryObject.setValue("countFuncDecimal", Double.toString(countDecimalArray[i])); sumQueryObject.setValue("countFuncDouble", Double.toString(countDoubleArray[i])); sumQueryObject.apply(); } for (int i = 0; i < sumIntegerArray.length; i++) { long dateLong = dateArray[i]; Date date = new Date(dateLong); String dateString = new java.text.SimpleDateFormat(Constants.DATE_FORMAT).format(date); long dateTimeLong = dateTimeArray[i]; Date dateTime = new Date(dateTimeLong); String dateTimeString = new java.text.SimpleDateFormat(Constants.DATETIME_FORMAT).format(dateTime); long timeLong = timeArray[i]; Date time = new Date(timeLong); String timeString = new java.text.SimpleDateFormat(Constants.TIME_FORMAT).format(time); BusinessDAO sumQueryObject = BusinessDAO.newInstance(sumQueryInfo.getType()); sumQueryObject.setValue("sumFuncBoolean", Boolean.toString(booleanArray[i])); sumQueryObject.setValue("sumFuncCharacter", "some character value"); sumQueryObject.setValue("sumFuncText", "some text value"); sumQueryObject.setValue("sumFuncDateTime", dateTimeString); sumQueryObject.setValue("sumFuncDate", dateString); sumQueryObject.setValue("sumFuncTime", timeString); sumQueryObject.setValue("sumFuncInteger", Integer.toString(sumIntegerArray[i])); sumQueryObject.setValue("sumFuncLong", Long.toString(sumLongArray[i])); sumQueryObject.setValue("sumFuncFloat", Float.toString(floatArray[i])); sumQueryObject.setValue("sumFuncDecimal", Double.toString(decimalArray[i])); sumQueryObject.setValue("sumFuncDouble", Double.toString(doubleArray[i])); sumQueryObject.apply(); } QueryFactory factory = new QueryFactory(); BusinessDAOQuery query = factory.businessDAOQuery(AggregateFunctionMasterSetup.comQueryInfo.getType()); query.ORDER_BY(query.aTime("comFuncTime"), OrderBy.SortOrder.ASC); }
From source file:com.limewoodmedia.nsdroid.activities.Nation.java
private void doEconomySetup() { economyTitle.setText(getString(R.string.nation_economy_title, Utils.capitalize(data.demonym))); // GDP, GDPPC, Poorest and Richest economyGDP.setText(//from ww w.j ava 2 s . c o m getString(R.string.nation_economy_gdp, Utils.formatCurrencyAmount(this, data.gdp), data.currency)); economyGDPPC.setText(getString(R.string.nation_economy_gdppc, Utils.formatCurrencyAmount(this, Math.round(data.gdp / (data.population * 1000000f))), data.currency)); economyPoorest.setText(getString(R.string.nation_economy_poorest, Utils.formatCurrencyAmount(this, data.poorest), data.currency)); economyRichest.setText(getString(R.string.nation_economy_richest, Utils.formatCurrencyAmount(this, data.richest), data.currency)); economySeries.clear(); economyRenderer.removeAllRenderers(); Set<Map.Entry<IndustrySector, Float>> secs = data.sectors.entrySet(); TreeSet<Map.Entry<IDescriptable, Float>> sectors = new TreeSet<>(); for (Map.Entry<IndustrySector, Float> d : secs) { sectors.add(new DescriptionMapEntry(d, false)); } NumberFormat format = NumberFormat.getPercentInstance(); format.setMaximumFractionDigits(1); Map<IDescriptable, String> legends = new HashMap<>(); StringBuilder legend; String desc; int colour; for (Map.Entry<IDescriptable, Float> s : sectors) { if (s.getValue() == 0) continue; desc = s.getKey().getDescription(); economySeries.add(desc, s.getValue() / 100f); SimpleSeriesRenderer renderer = new SimpleSeriesRenderer(); colour = CHART_COLOURS[(economySeries.getItemCount() - 1) % CHART_COLOURS.length]; renderer.setColor(colour); renderer.setChartValuesFormat(format); economyRenderer.addSeriesRenderer(renderer); legend = new StringBuilder(); legend.append("<b><font color='").append(Integer.toString(colour)).append("'>").append(desc); legends.put(s.getKey(), legend.toString()); } economyChart.repaint(); // Legend legend = new StringBuilder(); for (IndustrySector sector : IndustrySector.values()) { if (legend.length() > 0) { legend.append("<br/>"); } if (legends.containsKey(sector)) { legend.append(legends.get(sector)).append(": ").append(Float.toString(data.sectors.get(sector))) .append("%</font></b>"); } else { legend.append("<font color='grey'>").append(sector.getDescription()).append(": ") .append("0%</font>"); } } economyLegend.setText(Html.fromHtml(legend.toString()), TextView.BufferType.SPANNABLE); }
From source file:edu.msViz.mzTree.MzTree.java
/** * Exports the given data range into a csv at filepath * @param filepath out location/* w w w .j a v a 2 s . c o m*/ * @param minMZ lower mz bound * @param maxMZ upper mz bound * @param minRT lower rt bound * @param maxRT upper rt bound * @throws java.io.IOException */ public int export(String filepath, double minMZ, double maxMZ, float minRT, float maxRT) throws IOException { //append csv extension if not already there if (!filepath.endsWith(".csv")) filepath = filepath + ".csv"; try (CSVWriter writer = new CSVWriter(new FileWriter(filepath))) { writer.writeNext(new String[] { "m/z", "RT", "intensity", "meta1" }); // get the points of the data range // THIS IS WHERE THE OPTIMIZATION PROBLEM STARTS // currently loads all pertinent points into memory (could be the whole file) List<MsDataPoint> points = this.query(minMZ, maxMZ, minRT, maxRT, 0); // write away! for (MsDataPoint p : points) writer.writeNext(new String[] { Double.toString(p.mz), Float.toString(p.rt), Double.toString(p.intensity), Integer.toString(p.meta1) }); return points.size(); } }
From source file:com.jogden.spunkycharts.traditionalchart.TraditionalChartFragmentAdapter.java
private void _createPriceAxisY() { Thread thisThread = new Thread() { public void run() { /////////////////////////////////// /* START PREEMPTION LOGIC */ ///////////////////////////////// boolean noWait; final int MAX_PREEMPT_COUNT = ApplicationPreferences.getMaxPreemptCount(); if (!(noWait = _priceAxisLck.tryLock())) { synchronized (_priceAxisThrdMntr) { if (_priceAxisPrmptCnt++ > MAX_PREEMPT_COUNT) return; if (_priceAxisThrd != null) _priceAxisThrd.interrupt(); }/*from w w w. j a v a2 s. c o m*/ _priceAxisPrmptStck.offer(this); _priceAxisLck.lock(); } try { /* everything that follows should assume we own monitor */ if (!noWait) { if (this != _priceAxisPrmptStck.peekLast()) return; else { /* don't assume stack hasn't grown since the peek */ Iterator<Thread> dIter = _priceAxisPrmptStck.iterator(); do { _priceAxisPrmptStck.poll(); } while (dIter.next() != this); } } synchronized (_priceAxisThrdMntr) { _priceAxisThrd = this; } ///////////////////////////////// /* END PREEMPTION LOGIC */ /////////////////////////////// _updateLtch.await(); /* wait for historic data to be inserted */ float rangeDiff = _highPriceDsply - _lowPriceDsply; /* deal with problematic high/low parameters */ if (rangeDiff <= 0 || _highPriceDsply < 0 || _lowPriceDsply < 0) if (rangeDiff == 0 && _highPriceDsply > 0) { _highPriceDsply *= 1.001; _lowPriceDsply *= .999; rangeDiff = _highPriceDsply - _lowPriceDsply; _priceSgmnt.setYRange(_highPriceDsply, _lowPriceDsply, _highPrice, _lowPrice); } else throw new IllegalStateException("Invalid high and/or low price in the ChartAdapter"); /* if we haven't calculated the height of a price-label view */ if (_priceElemHght == 0) {/* can cached value doesn't go stale? */ final YAxisPriceLabel tv1 = (YAxisPriceLabel) _inflater.inflate(R.layout.y_axis_price_label, null); tv1.setText("X"); tv1.setTextSize(_axisFontSz); tv1.setVisibility(View.INVISIBLE); final ConditionVariable cond = new ConditionVariable(); _guiThrdHndlr.post(new Runnable() { public void run() { _priceAxis.removeAllViews(); _priceAxis.addView(tv1); cond.open(); } }); cond.block(); cond.close(); YAxisPriceLabel tv1b = (YAxisPriceLabel) _priceAxis.getChildAt(0); /* make sure a valid priceElemHeightt, or quit entirely */ /* just spin, a new thread preempts us anyway */ while ((_priceElemHght = tv1b.getHeight()) == 0) Thread.sleep(_axisTimeoutIncr); } _guiThrdHndlr.post(new Runnable() { public void run() { _priceAxis.removeAllViews(); } }); int totalHeight; /* make sure a valid totalHeight, or quit entirely */ /* just spin, a new thread preempts us anyway */ while ((totalHeight = _priceAxis.getHeight()) == 0 || totalHeight > _myContainer.getHeight()) Thread.sleep(_axisTimeoutIncr); float[] incrVals = new float[2]; try { int maxNodes = (int) (totalHeight / _priceElemHght); if (rangeDiff < 0 || maxNodes < 0) throw new TraditionalChartLogicError("rangeDiff and maxNodes can't be negative."); /* call down to our native sub to find increment values */ incrVals = MainApplication.IncrementRegressNative(rangeDiff, maxNodes); if (incrVals[0] < 0 || incrVals[1] <= 0) throw new TraditionalChartLogicError("IncrementRegressNative() sub-routine aborted. " + "retVals[0]: " + incrVals[0] + "retVals[1]: " + incrVals[1] + "adjRangeDiff: " + rangeDiff + "maxNodes" + maxNodes); } catch (TraditionalChartLogicError e) { Log.e("TraditionalChartLogicError", e.getMessage()); return; /* just leave the axis empty*/ } /* adjust height to new increment values */ final int adjPriceElemHeight = (int) (totalHeight / (int) incrVals[1]); /* we'll need to account for any unused space in the axis */ final int vacantHeight = totalHeight - (int) (adjPriceElemHeight * (int) incrVals[1]); double distFromIncr = Math.IEEEremainder((double) _highPriceDsply, (double) incrVals[0]); /* distance from rounded incr */ double adjTopNodeVal = (double) _highPriceDsply - distFromIncr; if (distFromIncr > 0) /* be sure to round to the upper incr */ adjTopNodeVal += incrVals[0]; DecimalFormat df = new DecimalFormat("0.00"); double lastNodeVal = adjTopNodeVal; int count = 0; do { /* loop through the increments */ final YAxisPriceLabel tv = (YAxisPriceLabel) _inflater.inflate(R.layout.y_axis_price_label, null); tv.setTextSize(_axisFontSz); tv.setText(df.format(lastNodeVal)); tv.setTextColor(_axisFontColor); tv.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 0, 1)); _guiThrdHndlr.post(new Runnable() { public void run() { _priceAxis.addView(tv); } }); /* for the loop-contingent side-effect */ } while (++count < (int) incrVals[1] && (lastNodeVal -= incrVals[0]) > 0); /* values for padding the axis and adjusting the segments */ final double adjTopNodeOffset = ((adjTopNodeVal - _highPriceDsply) / rangeDiff) * totalHeight; final double adjBottomNodeOffset = ((_lowPriceDsply - lastNodeVal) / rangeDiff) * totalHeight; final float halfVacantHeight = vacantHeight / 2; final float halfPriceElemHeight = adjPriceElemHeight / 2; final int topBuf = (int) (adjTopNodeOffset + halfVacantHeight + halfPriceElemHeight); final int bottomBuf = (int) (adjBottomNodeOffset + halfVacantHeight + halfPriceElemHeight); /* adjust price segments so they align w/ axis vals */ _priceSgmnt.setVerticalBuffers(topBuf, bottomBuf); _guiThrdHndlr.post(new Runnable() { public void run() { _priceAxis.setPadding( /* center price-views */ 0, (int) halfVacantHeight, 0, (int) halfVacantHeight); _priceAxis.setClipChildren(false); _priceAxis.setClipToPadding(false); _priceAxis.invalidate(); _priceSgmnt.forceDraw(); } }); synchronized (_priceAxisThrdMntr) { _priceAxisPrmptCnt = 0; } } catch (InterruptedException e) { } catch (IllegalStateException e) { Log.d("IllegalState(High, Low): ", "IllegalStateException caught in _createPriceAxisY: " + Float.toString(_highPriceDsply) + " - " + Float.toString(_lowPriceDsply)); } catch (RuntimeException e) { e.printStackTrace(); throw e; } finally { synchronized (_priceAxisThrdMntr) { _priceAxisThrd = null; } _activeThreads.remove(this); _priceAxisLck.unlock(); } } }; _activeThreads.add(thisThread); thisThread.start(); }
From source file:com.example.psumaps.MapView.java
public void pref(LatLng point, String str) { locationCount++;/*from w w w .ja v a 2s. c om*/ // Opening the sharedPreferences object sharedPreferences = getSharedPreferences("location", 0); /** Opening the editor object to write data to sharedPreferences */ SharedPreferences.Editor editor = sharedPreferences.edit(); // Storing the latitude for the i-th location editor.putString("lat" + Integer.toString((locationCount - 1)), Double.toString(point.latitude)); // Storing the longitude for the i-th location editor.putString("lng" + Integer.toString((locationCount - 1)), Double.toString(point.longitude)); // Storing the title for the i-th location editor.putString("title" + Integer.toString((locationCount - 1)), str); // Storing the count of locations or marker count editor.putInt("locationCount", locationCount); /** Storing the zoom level to the shared preferences */ editor.putString("zoom", Float.toString(map.getCameraPosition().zoom)); /** Saving the values stored in the shared preferences */ editor.commit(); // Toast.makeText(getBaseContext(), "Marker is added to the Map", Toast.LENGTH_SHORT).show(); }
From source file:com.ushahidi.swiftriver.core.api.service.BucketService.java
/** * Adds a {@link Place} to the {@link BucketDrop} with the specified * <code>dropId</code> The drop must be in the {@link Bucket} whose ID is * specified in <code>bucketId</code> * // w w w .j a va 2s .c o m * The created {@link Place} entity is transformed to a DTO for purposes of * consumption by {@link BucketsController} * * @param bucketId * @param dropId * @param createDTO * @param authUser * @return */ @Transactional public GetPlaceDTO addDropPlace(Long bucketId, Long dropId, CreatePlaceDTO createDTO, String authUser) { Bucket bucket = getBucket(bucketId); if (!isOwner(bucket, authUser)) throw new ForbiddenException("Permission denied"); BucketDrop bucketDrop = getBucketDrop(bucketId, dropId); String hashInput = createDTO.getName(); hashInput += Float.toString(createDTO.getLongitude()); hashInput += Float.toString(createDTO.getLatitude()); String hash = MD5Util.md5Hex(hashInput); // Generate a hash for the place name Place place = placeDao.findByHash(hash); if (place == null) { place = new Place(); place.setPlaceName(createDTO.getName()); place.setPlaceNameCanonical(createDTO.getName().toLowerCase()); place.setHash(hash); place.setLatitude(createDTO.getLatitude()); place.setLongitude(createDTO.getLongitude()); placeDao.create(place); } else { if (bucketDropDao.findPlace(bucketDrop, place) != null) { throw new BadRequestException( String.format("Drop %d already has the place %s with coordinates [%f, %f]", dropId, place.getPlaceName(), place.getLatitude(), place.getLongitude())); } } bucketDropDao.addPlace(bucketDrop, place); return mapper.map(place, GetPlaceDTO.class); }
From source file:com.ushahidi.swiftriver.core.api.service.RiverService.java
/** * Adds a {@link Place} to the {@link RiverDrop} with the specified * <code>dropId</code> The drop must be in the {@link River} whose ID is * specified in <code>id</code> * /*w ww. j a va2 s . co m*/ * The created {@link Place} entity is transformed to a DTO for purposes of * consumption by {@link RiversController} * * @param riverId * @param dropId * @param createDTO * @param authUser * @return */ @Transactional public GetPlaceDTO addDropPlace(Long riverId, Long dropId, CreatePlaceDTO createDTO, String authUser) { River river = getRiver(riverId); if (!isOwner(river, authUser)) throw new ForbiddenException("Permission denied"); RiverDrop riverDrop = getRiverDrop(riverId, dropId); String hashInput = createDTO.getName(); hashInput += Float.toString(createDTO.getLongitude()); hashInput += Float.toString(createDTO.getLatitude()); String hash = MD5Util.md5Hex(hashInput); // Generate a hash for the place name Place place = placeDao.findByHash(hash); if (place == null) { place = new Place(); place.setPlaceName(createDTO.getName()); place.setLatitude(createDTO.getLatitude()); place.setLongitude(createDTO.getLongitude()); placeDao.create(place); } else { if (riverDropDao.findPlace(riverDrop, place) != null) { throw new BadRequestException( String.format("Drop %d already has the place %s with coordinates [%f, %f]", dropId, place.getPlaceName(), place.getLatitude(), place.getLongitude())); } } riverDropDao.addPlace(riverDrop, place); return mapper.map(place, GetPlaceDTO.class); }
From source file:com.bazaarvoice.jackson.rison.RisonGenerator.java
private String formatFloat(float f) { return Float.toString(f).toLowerCase(); }
From source file:Logica.Usuario.java
/** * * @param sol//from www .j av a 2 s. c o m * @param itemsSolicitud * @return * @throws RemoteException * * Crea la solicitud */ @Override public Integer crearSolicitud(solicitudPr sol, ArrayList<ItemInventario> itemsSolicitud) throws RemoteException { EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU"); boolean solCreada = false; boolean itemsEnviados = false; SolicitudPr s = new SolicitudPr(); SolicitudPrJpaController con = new SolicitudPrJpaController(emf); s.setIdSolicitante(sol.getIdSolicitante()); s.setFecha(new java.util.Date(sol.getFecha().getTimeInMillis())); s.setObservaciones(sol.getObservaciones()); s.setRevisado("NO"); con.create(s); solCreada = true; Double numSol = 0.0; if (solCreada == true) { EntityManager em = emf.createEntityManager(); Query q = em.createNamedQuery("SolicitudPr.getUltima"); q.setParameter("id", sol.getIdSolicitante()); numSol = new Double(q.getResultList().get(0).toString()); ItxsolJpaController conItems = new ItxsolJpaController(emf); for (ItemInventario i : itemsSolicitud) { if (i.getCantidadSolicitada() <= 0) { itemsEnviados = false; } else { conItems.create(new Itxsol(new Double(Float.toString(i.getCantidadSolicitada())), numSol, new Item(i.getNumero()), "NO", 0.0)); } } itemsEnviados = true; TablamostrarJpaController conTabla = new TablamostrarJpaController(emf); Tablamostrar tablamostrar = new Tablamostrar(); tablamostrar.setIdArchivo(numSol); tablamostrar.setIdUsuario(sol.getIdSolicitante()); tablamostrar.setTipoArchivo("Solicitud"); tablamostrar.setMostrar("SI"); conTabla.create(tablamostrar); tablamostrar.setTipoArchivo("SolicitudRev"); tablamostrar.setMostrar("SI"); conTabla.create(tablamostrar); tablamostrar.setTipoArchivo("SolicitudNoRev"); tablamostrar.setMostrar("SI"); conTabla.create(tablamostrar); } if (itemsEnviados == false) { try { con.destroy(numSol); } catch (NonexistentEntityException ex) { Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex); } } emf.close(); return (solCreada && itemsEnviados) ? numSol.intValue() : 0; }
From source file:ImageInfo.java
private static void printLine(int indentLevels, String text, float value, float minValidValue) { if (value < minValidValue) { return;/*from ww w. ja va 2s .co m*/ } printLine(indentLevels, text, Float.toString(value)); }