List of usage examples for java.lang Float toString
public static String toString(float f)
From source file:org.aludratest.cloud.web.config.ConfigPreferences.java
@Override public void setValue(String key, float value) { setValue(key, Float.toString(value)); }
From source file:com.yoncabt.abys.core.util.EBRConf.java
public float getValue(String key, float defaultValue) { return Float.valueOf(getValueFromAll(key, Float.toString(defaultValue))); }
From source file:femr.business.services.system.ResearchService.java
public static ResearchGraphDataItem createResearchGraphItem(ResearchResult primaryResult, ResearchResult secondaryResult, ResearchFilterItem filters) { ResearchGraphDataItem graphModel = new ResearchGraphDataItem(); List<ResearchItem> graphData = new ArrayList<>(); Map<String, ResearchItem> groupedData = new HashMap<>(); String yAxisTitle = "Number of Patients"; String xAxisTitle = WordUtils.capitalize(StringUtils.splitCamelCase(primaryResult.getDataType())); String unitOfMeasurement = primaryResult.getUnitOfMeasurement(); List<Float> sortedPrimary = new ArrayList<>(); Map<Integer, Float> primaryDataset = primaryResult.getDataset(); Map<Integer, Float> secondaryDataset = secondaryResult.getDataset(); int sampleSize = primaryDataset.size(); float total = 0; float rangeHigh = 0; float rangeLow = 10000; float median = 0; // Medications will not group correctly, just bundle and return if (filters.getPrimaryDataset().equals("prescribedMeds") || filters.getPrimaryDataset().equals("dispensedMeds")) { for (Integer key : primaryDataset.keySet()) { // Make sure all secondary keys are set for all items Float value = primaryDataset.get(key); ResearchItem currItem = new ResearchItem(); currItem.setPrimaryName(Float.toString((float) key)); currItem.setPrimaryValue(value); graphData.add(currItem);//from w ww. jav a 2s . c om } graphModel.setAverage(0.0f); graphModel.setMedian(median); graphModel.setRangeLow(rangeLow); graphModel.setRangeHigh(rangeHigh); graphModel.setGraphData(graphData); graphModel.setPrimaryValuemap(primaryResult.getValueMap()); graphModel.setSecondaryValuemap(secondaryResult.getValueMap()); graphModel.setyAxisTitle(yAxisTitle); graphModel.setxAxisTitle(xAxisTitle); graphModel.setUnitOfMeasurement(unitOfMeasurement); return graphModel; } // total the individual patients based on their value Map<Float, ResearchItem> primaryGraphTotals = new HashMap<>(); // used to ensure all secondary keys are present in all items, just in case they have no data Map<String, Integer> secondaryKeyset = new HashMap<>(); for (Integer key : primaryDataset.keySet()) { Float value = primaryDataset.get(key); sortedPrimary.add(value); // Find current primary Value and add to builder map ResearchItem currItem; if (primaryGraphTotals.containsKey(value)) { currItem = primaryGraphTotals.get(value); float currItemTotal = currItem.getPrimaryValue() + 1; currItem.setPrimaryValue(currItemTotal); } else { currItem = new ResearchItem(); currItem.setPrimaryValue(1); } currItem.setPrimaryName(value.toString()); // check for and add secondary item to total if (secondaryDataset.containsKey(key)) { // Get secondary item form current ResearchItem Map<String, Float> secondaryItems = currItem.getSecondaryData(); Float secondaryValue = secondaryDataset.get(key); Float secondaryTotal = 1.0f; String secondaryKey = secondaryValue.toString(); // Keep track of unique keys for secondary items // want to make sure all possible keys are present in graphData secondaryKeyset.put(secondaryKey, 0); if (secondaryItems.containsKey(secondaryKey)) { secondaryTotal = secondaryItems.get(secondaryKey); secondaryTotal++; secondaryItems.put(secondaryKey, secondaryTotal); } else { secondaryItems.put(secondaryKey, 1.0f); } // add secondary totals to currItem currItem.setSecondaryData(secondaryItems); } primaryGraphTotals.put(value, currItem); // Calculate Stats while building data // check range if (value > rangeHigh) { rangeHigh = value; } if (value < rangeLow) { rangeLow = value; } // sum total for average total += value; } // If no grouping and over 30 items, force groups of 10 if (primaryGraphTotals.keySet().size() > 30 && !filters.isGroupPrimary() && (filters.getGraphType().equals("pie") || filters.getGraphType().equals("stacked-bar") || filters.getGraphType().equals("grouped-bar"))) { filters.setGroupPrimary(true); filters.setGroupFactor(10); } // Build group key values -- don't bother if there will only be 1 group // make happen automatically too? -- primaryGraphTotals.keySet().size() > 20 if (filters.isGroupPrimary() && primaryGraphTotals.keySet().size() > filters.getGroupFactor()) { int groupFactor = filters.getGroupFactor(); int firstLowKey = (int) (rangeLow / groupFactor) * groupFactor; int lastLowKey = (int) (rangeHigh / groupFactor) * groupFactor; //int totalGroups = (int)((lastLowKey-firstLowKey) / groupFactor); List<String> groupIndexes = new ArrayList<String>(); for (int low = firstLowKey; low <= lastLowKey; low += groupFactor) { int lowTemp = low; if (low < filters.getRangeStart()) { lowTemp = filters.getRangeStart().intValue(); } int high = low + (groupFactor - 1); if (high > filters.getRangeEnd()) { high = filters.getRangeEnd().intValue(); } String groupIndex = String.format("%d - %d", lowTemp, high); groupIndexes.add(groupIndex); ResearchItem blankItem = new ResearchItem(groupIndex); groupedData.put(groupIndex, blankItem); } for (Float key : primaryGraphTotals.keySet()) { ResearchItem currItem = primaryGraphTotals.get(key); Float newVal = Float.parseFloat(currItem.getPrimaryName()); Float newCount = currItem.getPrimaryValue(); int targetGroup = (int) (newVal / groupFactor) - (firstLowKey / groupFactor); String groupIndex = groupIndexes.get(targetGroup); ResearchItem finalItem; if (groupedData.containsKey(groupIndex)) { // add current single item to existing group Item finalItem = groupedData.get(groupIndex); Float currCount = finalItem.getPrimaryValue(); currCount += newCount; finalItem.setPrimaryValue(currCount); Map<String, Float> currSecondaryData = currItem.getSecondaryData(); for (String sKey : currSecondaryData.keySet()) { Float sCount = currSecondaryData.get(sKey); Map<String, Float> finalSecondaryData = finalItem.getSecondaryData(); if (finalSecondaryData.containsKey(sKey)) { Float finalCount = finalSecondaryData.get(sKey); finalCount += sCount; finalSecondaryData.put(sKey, finalCount); } else { finalSecondaryData.put(sKey, sCount); } finalItem.setSecondaryData(finalSecondaryData); } } else { // haven't encountered item in range before, just set to current single item finalItem = new ResearchItem(); finalItem.setPrimaryName(groupIndex); finalItem.setPrimaryValue(newCount); finalItem.setSecondaryData(currItem.getSecondaryData()); } // add item to grouped data groupedData.put(groupIndex, finalItem); } SortedSet<String> keys = new TreeSet<>(new GroupedCompare()); keys.addAll(groupedData.keySet()); for (String key : keys) { // Make sure all secondary keys are set for all items ResearchItem currItem = groupedData.get(key); Map<String, Float> secondaryData = currItem.getSecondaryData(); for (String secondaryKey : secondaryKeyset.keySet()) { if (!secondaryData.containsKey(secondaryKey)) { secondaryData.put(secondaryKey, 0.0f); } } graphData.add(currItem); } } else { SortedSet<Float> keys = new TreeSet<>(primaryGraphTotals.keySet()); for (Float key : keys) { // Make sure all secondary keys are set for all items ResearchItem currItem = primaryGraphTotals.get(key); Map<String, Float> secondaryData = currItem.getSecondaryData(); for (String secondaryKey : secondaryKeyset.keySet()) { if (!secondaryData.containsKey(secondaryKey)) { secondaryData.put(secondaryKey, 0.0f); } } graphData.add(currItem); } } // Sort primary Data Collections.sort(sortedPrimary); // Get Median Value from sorted list float average = total / sampleSize; if (sampleSize > 1) { if (sampleSize % 2 == 0) { int i = (sampleSize / 2) - 1; int j = i + 1; // get vals i and j float val1 = sortedPrimary.get(i); float val2 = sortedPrimary.get(j); //Integer key1 = primaryKeyList.get(i); //Integer key2 = primaryKeyList.get(j); //float val1 = primaryDataset.get(key1); //float val2 = primaryDataset.get(key2); median = (val1 + val2) / 2; } else { int i = (int) Math.floor(sampleSize / 2); //Integer key = primaryKeyList.get(i); //median = primaryDataset.get(key); median = sortedPrimary.get(i); } } else { median = sortedPrimary.get(0); } // build graph model item graphModel.setAverage(average); graphModel.setMedian(median); graphModel.setRangeLow(rangeLow); graphModel.setRangeHigh(rangeHigh); graphModel.setGraphData(graphData); graphModel.setPrimaryValuemap(primaryResult.getValueMap()); graphModel.setSecondaryValuemap(secondaryResult.getValueMap()); graphModel.setyAxisTitle(yAxisTitle); graphModel.setxAxisTitle(xAxisTitle); graphModel.setUnitOfMeasurement(unitOfMeasurement); return graphModel; }
From source file:com.basetechnology.s0.agentserver.util.JsonUtils.java
public static String getString(JSONObject objectJson, String key, String defaultString) { if (objectJson.has(key)) { Object object = objectJson.opt(key); if (object instanceof Boolean) return Boolean.toString((Boolean) object); else if (object instanceof Integer) return Integer.toString((Integer) object); else if (object instanceof Long) return Long.toString((Long) object); else if (object instanceof Float) return Float.toString((Float) object); else if (object instanceof Double) return Double.toString((Double) object); else// ww w . j av a 2s . c om return (String) object; } else return defaultString; }
From source file:com.health.openscale.gui.TableFragment.java
@Override public void updateOnView(ArrayList<ScaleData> scaleDataList) { TableRow headerRow = (TableRow) tableView.findViewById(R.id.tableHeader); tableDataView.removeAllViews();// w w w . j a va 2 s.c om tableDataView.addView(headerRow); for (ScaleData scaleData : scaleDataList) { TableRow dataRow = new TableRow(tableView.getContext()); dataRow.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); TextView idView = new TextView(tableView.getContext()); idView.setText(Long.toString(scaleData.id)); idView.setVisibility(View.GONE); dataRow.addView(idView); TextView dateTextView = new TextView(tableView.getContext()); if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) { dateTextView.setText(new SimpleDateFormat("dd. MMM yyyy (EE)").format(scaleData.date_time)); } else { dateTextView.setText(new SimpleDateFormat("dd/MM/yy").format(scaleData.date_time)); } dateTextView.setPadding(0, 5, 5, 5); dataRow.addView(dateTextView); TextView timeTextView = new TextView(tableView.getContext()); timeTextView.setText(new SimpleDateFormat("HH:mm").format(scaleData.date_time)); timeTextView.setPadding(0, 5, 5, 5); dataRow.addView(timeTextView); TextView weightView = new TextView(tableView.getContext()); weightView.setText(Float.toString(scaleData.weight)); weightView.setPadding(0, 5, 5, 5); dataRow.addView(weightView); TextView fatView = new TextView(tableView.getContext()); fatView.setText(Float.toString(scaleData.fat)); fatView.setPadding(0, 5, 5, 5); dataRow.addView(fatView); TextView waterView = new TextView(tableView.getContext()); waterView.setText(Float.toString(scaleData.water)); waterView.setPadding(0, 5, 5, 5); dataRow.addView(waterView); TextView muscleView = new TextView(tableView.getContext()); muscleView.setText(Float.toString(scaleData.muscle)); muscleView.setPadding(0, 5, 5, 5); dataRow.addView(muscleView); Button deleteButton = new Button(tableView.getContext()); deleteButton.setText("X"); deleteButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10); deleteButton.setTextColor(Color.WHITE); deleteButton.setBackgroundResource(R.drawable.flat_selector); deleteButton.setGravity(Gravity.CENTER); deleteButton.setPadding(0, 0, 0, 0); deleteButton.setMinimumHeight(35); deleteButton.setHeight(35); deleteButton.setOnClickListener(new onClickListenerDelete()); dataRow.addView(deleteButton); if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_XLARGE && (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_LARGE) { dateTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11); timeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11); weightView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11); fatView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11); waterView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11); muscleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11); } tableDataView.addView(dataRow, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); } }
From source file:com.mk4droid.IMC_Utils.GEO.java
/** * Convert the distance to a string of distance plus its units e.g. m or km * /*from ww w.j av a 2 s. com*/ * @param distanceData distance (range of data) * @return */ public static String DistanceToText(int distanceData) { String res = ""; if (distanceData >= 10000 && distanceData < Constants_API.initRange) res = Float.toString(distanceData / 1000) + "km"; else if (distanceData < 10000) res = Integer.toString(distanceData) + "m"; else if (distanceData == Constants_API.initRange) res = "Inf"; return res; }
From source file:de.micromata.genome.util.strings.converter.StandardStringConverter.java
@Override public Pair<Character, String> objectToString(Object value) { if (value == null) { return Pair.make(ConvertedStringTypes.NULL.getShortType(), null); }//from ww w . j a v a 2 s . c o m if (value instanceof String) { return Pair.make(ConvertedStringTypes.STRING.getShortType(), (String) value); } if (value instanceof Boolean) { return Pair.make(ConvertedStringTypes.BOOLEAN.getShortType(), Boolean.toString((Boolean) value)); } if (value instanceof Byte) { return Pair.make(ConvertedStringTypes.BYTE.getShortType(), Byte.toString((Byte) value)); } if (value instanceof Short) { return Pair.make(ConvertedStringTypes.SHORT.getShortType(), Short.toString((Short) value)); } if (value instanceof Integer) { return Pair.make(ConvertedStringTypes.INTEGER.getShortType(), Integer.toString((Integer) value)); } if (value instanceof Long) { return Pair.make(ConvertedStringTypes.LONG.getShortType(), Long.toString((Long) value)); } if (value instanceof Float) { return Pair.make(ConvertedStringTypes.FLOAT.getShortType(), Float.toString((Float) value)); } if (value instanceof Double) { return Pair.make(ConvertedStringTypes.DOUBLE.getShortType(), Double.toString((Double) value)); } if (value instanceof Date) { return Pair.make(ConvertedStringTypes.DATE.getShortType(), formatDate((Date) value)); } if (value instanceof BigDecimal) { return Pair.make(ConvertedStringTypes.BIGDECIMAL.getShortType(), formatBigDecimal((BigDecimal) value)); } if (value instanceof Character) { return Pair.make(ConvertedStringTypes.CHAR.getShortType(), Character.toString((Character) value)); } if (value instanceof byte[]) { return Pair.make(ConvertedStringTypes.BYTEARRAY.getShortType(), formatByteArray((byte[]) value)); } if (value instanceof String[]) { return Pair.make(ConvertedStringTypes.STRINGARRAY.getShortType(), formatStringArray((String[]) value)); } if (value instanceof Long[]) { return Pair.make(ConvertedStringTypes.LONGARRAY.getShortType(), formatLongArray((Long[]) value)); } throw new IllegalArgumentException( "StringConverter; Cannot encode object to string: " + value.getClass().getName()); }
From source file:com.moviejukebox.plugin.MovieListingPluginCsv.java
/** * @param sItemType// w ww . ja v a 2 s . c o m * @param movie * @return output string properly formatted for CSV output */ @SuppressWarnings("deprecation") protected String toCSV(String sItemType, Movie movie) { Collection<ExtraFile> extras = movie.getExtraFiles(); Collection<MovieFile> movieFiles = movie.getMovieFiles(); Collection<String> genres = movie.getGenres(); Collection<String> cast = movie.getCast(); StringBuilder headerLine = new StringBuilder(); headerLine.append(prepOutput(sItemType)); headerLine.append(prepOutput(movie.getTitle())); headerLine.append(prepOutput(movie.getTitleSort())); headerLine.append(prepOutput(movie.getOriginalTitle())); headerLine.append(prepOutput(movie.getId(ImdbPlugin.IMDB_PLUGIN_ID))); headerLine.append(prepOutput(movie.getDirector())); headerLine.append(prepOutput(movie.getCompany())); headerLine.append(prepOutput(movie.getCountriesAsString())); headerLine.append(prepOutput(movie.getLanguage())); headerLine.append(prepOutput(movie.getRuntime())); headerLine.append(prepOutput(movie.getReleaseDate())); headerLine.append(prepOutput(movie.getYear())); headerLine.append(prepOutput(movie.getCertification())); headerLine.append(prepOutput(blankNegatives(movie.getSeason()))); headerLine.append(prepOutput(movie.getId(TheTvDBPlugin.THETVDB_PLUGIN_ID))); headerLine.append(prepOutput(movie.getVideoSource())); headerLine.append(prepOutput(movie.getContainer())); headerLine.append(prepOutput(movie.getContainerFile().getAbsolutePath())); headerLine.append(prepOutput(movie.getAudioCodec())); headerLine.append(prepOutput(movie.getAudioChannels())); headerLine.append(prepOutput(movie.getResolution())); headerLine.append(prepOutput(movie.getVideoCodec())); headerLine.append(prepOutput(movie.getVideoOutput())); headerLine.append(prepOutput(Float.toString(movie.getFps()))); headerLine.append(prepOutput(String.valueOf(null == movieFiles ? "0" : movieFiles.size()))); headerLine.append(prepOutput(String.valueOf(null == extras ? "0" : extras.size()))); headerLine.append(prepOutput(String.valueOf(null == genres ? "0" : genres.size()))); headerLine.append(prepOutput(String.valueOf(null == cast ? "0" : cast.size()))); headerLine.append(prepOutput(movie.getSubtitles())); headerLine.append(prepOutput((null != movie.getPosterURL() ? TRUE : FALSE))); headerLine.append(prepOutput(String.valueOf(null != movie.getDetailPosterFilename() ? TRUE : FALSE))); headerLine.append(prepOutput(String.valueOf(movie.getRating()))); headerLine.append(prepOutput(String.valueOf(movie.getTop250()))); headerLine.append(prepOutput(movie.getLibraryDescription())); headerLine.append(prepOutput(movie.getLibraryPath())); headerLine.append(prepOutput(movie.getId(AllocinePlugin.ALLOCINE_PLUGIN_ID))); headerLine.append(prepOutput(movie.getId(FilmUpITPlugin.FILMUPIT_PLUGIN_ID))); headerLine.append(prepOutput(movie.getId(FilmwebPlugin.FILMWEB_PLUGIN_ID))); headerLine.append(prepOutput(movie.getId(KinopoiskPlugin.KINOPOISK_PLUGIN_ID))); headerLine.append(prepOutput(movie.getId(AnimatorPlugin.ANIMATOR_PLUGIN_ID))); headerLine.append(prepOutput(movie.getId(SratimPlugin.SRATIM_PLUGIN_ID))); headerLine.append(prepOutput(new Timestamp(movie.getLastModifiedTimestamp()).toString())); headerLine.append(prepOutput(movie.getFileSizeString())); headerLine.append(prepOutput(String.valueOf(movie.isWatched()), false)); return headerLine.toString(); }
From source file:com.example.hbranciforte.trafficclient.DataTraffic.java
private JSONObject getPaymentInfo() { JSONObject payment = new JSONObject(); EditText paymentField1 = (EditText) findViewById(R.id.payment_field1); EditText licenseSec = (EditText) findViewById(R.id.payment_security); TextView valor = (TextView) findViewById(R.id.valor); try {// w w w . ja v a2s . co m payment.put("type", "test_method"); payment.put("data", "{\"data\",\"".concat(paymentField1.getText().toString()).concat("\",\"security\":\"") .concat(licenseSec.getText().toString().concat("\",\"price\":") .concat(Float.toString(price)).concat("}"))); payment.put("price", price); return payment; } catch (JSONException e) { Log.e("json error", e.getMessage()); } return payment; }
From source file:com.laex.cg2d.model.joints.BEPrismaticJoint.java
@Override public Object getPropertyValue(Object id) { if (isWorldAnchorProp(id)) { return new Vec2PropertySource(this.worldAnchor); } else if (isWorldAxisProp(id)) { return new Vec2PropertySource(this.worldAxis); } else if (isReferenceAngleProp(id)) { return Float.toString((float) Math.toDegrees(this.prismaticJointDef.referenceAngle)); } else if (isEnableLimitProp(id)) { return BooleanUtil.getIntegerFromBoolean(prismaticJointDef.enableLimit); } else if (isLowerTranslationProp(id)) { return Float.toString(prismaticJointDef.lowerTranslation); } else if (isUpperTranslationProp(id)) { return Float.toString(prismaticJointDef.upperTranslation); } else if (isEnableMotorProp(id)) { return BooleanUtil.getIntegerFromBoolean(prismaticJointDef.enableMotor); } else if (isMaxMotorForceProp(id)) { return Float.toString(prismaticJointDef.maxMotorForce); } else if (isMotorSpeedProp(id)) { return Float.toString(prismaticJointDef.motorSpeed); }/*w ww. ja v a 2s . c o m*/ return super.getPropertyValue(id); }