List of usage examples for java.lang Float valueOf
@HotSpotIntrinsicCandidate public static Float valueOf(float f)
From source file:com.netflix.hollow.diffview.effigy.HollowEffigyFactory.java
private HollowEffigy objectEffigy(HollowObjectTypeDataAccess typeDataAccess, int ordinal, HollowDiffNodeIdentifier identifier) { HollowObjectSchema schema = typeDataAccess.getSchema(); HollowEffigy effigy = new HollowEffigy(schema.getName()); for (int i = 0; i < schema.numFields(); i++) { String fieldName = schema.getFieldName(i); String fieldType = schema.getFieldType(i) == FieldType.REFERENCE ? schema.getReferencedType(i) : schema.getFieldType(i).toString(); HollowDiffNodeIdentifier fieldIdentifier = memoize( new HollowDiffNodeIdentifier(identifier, fieldName, fieldType)); Object fieldValue = null; switch (schema.getFieldType(i)) { case BOOLEAN: fieldValue = typeDataAccess.readBoolean(ordinal, i); break; case BYTES: fieldValue = base64.encodeToString(typeDataAccess.readBytes(ordinal, i)); break; case DOUBLE: fieldValue = Double.valueOf(typeDataAccess.readDouble(ordinal, i)); break; case FLOAT: fieldValue = Float.valueOf(typeDataAccess.readFloat(ordinal, i)); break; case INT: fieldValue = Integer.valueOf(typeDataAccess.readInt(ordinal, i)); break; case LONG: long longVal = typeDataAccess.readLong(ordinal, i); if (longVal != Long.MIN_VALUE && "Date".equals(typeDataAccess.getSchema().getName())) fieldValue = new Date(longVal).toString(); else//from w ww .j a va 2s . c o m fieldValue = Long.valueOf(typeDataAccess.readLong(ordinal, i)); break; case STRING: fieldValue = typeDataAccess.readString(ordinal, i); break; case REFERENCE: fieldValue = effigy(typeDataAccess.getDataAccess(), schema.getReferencedType(i), typeDataAccess.readOrdinal(ordinal, i), fieldIdentifier); } if (schema.getFieldType(i) == FieldType.REFERENCE) effigy.add(new Field(fieldIdentifier, fieldValue)); else effigy.add(memoize(new Field(fieldIdentifier, fieldValue))); } return effigy; }
From source file:com.evolveum.midpoint.prism.xml.XmlTypeConverter.java
@SuppressWarnings("unchecked") public static <T> T toJavaValue(String stringContent, Class<T> type, boolean exceptionOnUnknown) { if (type.equals(String.class)) { return (T) stringContent; } else if (type.equals(char.class)) { return (T) (new Character(stringContent.charAt(0))); } else if (type.equals(File.class)) { return (T) new File(stringContent); } else if (type.equals(Integer.class)) { return (T) Integer.valueOf(stringContent); } else if (type.equals(int.class)) { return (T) Integer.valueOf(stringContent); } else if (type.equals(Short.class) || type.equals(short.class)) { return (T) Short.valueOf(stringContent); } else if (type.equals(Long.class)) { return (T) Long.valueOf(stringContent); } else if (type.equals(long.class)) { return (T) Long.valueOf(stringContent); } else if (type.equals(Byte.class)) { return (T) Byte.valueOf(stringContent); } else if (type.equals(byte.class)) { return (T) Byte.valueOf(stringContent); } else if (type.equals(float.class)) { return (T) Float.valueOf(stringContent); } else if (type.equals(Float.class)) { return (T) Float.valueOf(stringContent); } else if (type.equals(double.class)) { return (T) Double.valueOf(stringContent); } else if (type.equals(Double.class)) { return (T) Double.valueOf(stringContent); } else if (type.equals(BigInteger.class)) { return (T) new BigInteger(stringContent); } else if (type.equals(BigDecimal.class)) { return (T) new BigDecimal(stringContent); } else if (type.equals(byte[].class)) { byte[] decodedData = Base64.decodeBase64(stringContent); return (T) decodedData; } else if (type.equals(boolean.class) || Boolean.class.isAssignableFrom(type)) { // TODO: maybe we will need more inteligent conversion, e.g. to trim spaces, case insensitive, etc. return (T) Boolean.valueOf(stringContent); } else if (type.equals(GregorianCalendar.class)) { return (T) getDatatypeFactory().newXMLGregorianCalendar(stringContent).toGregorianCalendar(); } else if (XMLGregorianCalendar.class.isAssignableFrom(type)) { return (T) getDatatypeFactory().newXMLGregorianCalendar(stringContent); } else if (Duration.class.isAssignableFrom(type)) { return (T) getDatatypeFactory().newDuration(stringContent); } else if (type.equals(PolyString.class)) { return (T) new PolyString(stringContent); } else if (type.equals(ItemPath.class)) { throw new UnsupportedOperationException("Path conversion not supported yet"); } else {// w w w . j av a 2s.co m if (exceptionOnUnknown) { throw new IllegalArgumentException("Unknown conversion type " + type); } else { return null; } } }
From source file:com.hybris.mobile.Hybris.java
/** * TODO - Geofencing spoofed location/* w ww . j ava2s. c om*/ */ public static void saveSpoofedGeolocationValuesFromPreferences() { Handler handler = new Handler(); if (Boolean .valueOf(Hybris.getSharedPreferenceString(InternalConstants.KEY_PREF_GEOFENCING_SPOOF_OVERRIDE))) { double lat = 0; double longi = 0; float rad = 0; try { lat = Double.valueOf( getSharedPreferences().getString(InternalConstants.KEY_PREF_GEOFENCING_LATITUDE, "")); longi = Double.valueOf( getSharedPreferences().getString(InternalConstants.KEY_PREF_GEOFENCING_LONGITUDE, "")); rad = Float.valueOf( getSharedPreferences().getString(InternalConstants.KEY_PREF_GEOFENCING_RADIUS, "")); } catch (Exception e) { } if (lat != 0 && longi != 0 && rad != 0) { GeofenceObject geofence = new GeofenceObject(); geofence.setId("spoofedGeofence"); geofence.setExpirationDuration(Geofence.NEVER_EXPIRE); geofence.setLatitude(lat); geofence.setLongitude(longi); geofence.setRadius(rad); geofence.setTransitionType(Geofence.GEOFENCE_TRANSITION_ENTER); String tmpJson = "{\"geoPoint\":{\"longitude\":11.585745,\"latitude\":48.155121},\"storeImages\":[{\"url\":\"\\/medias\\/electronics-store-365x246-01.jpg?context=bWFzdGVyOjo6aW1hZ2VzOjo6MTA3NTE5Ojo6aW1hZ2UvanBlZzo6OmltYWdlcy9oMDIvaDYyLzg3OTY2ODc0MDA5OTAuanBnOjo6OTkzNWM1NTk5YjhmYjU3Y2QzNDc1NWFmMDBlM2NkMzk2YjFkZTlmYjI5Y2VkZjNkZGNhOGZkN2UxMWE4ZTBhMw\",\"format\":\"store\"},{\"url\":\"\\/medias\\/electronics-store-65x65-01.jpg?context=bWFzdGVyOjo6aW1hZ2VzOjo6MjA2OTM6OjppbWFnZS9qcGVnOjo6aW1hZ2VzL2g5Zi9oMDQvODc5NjY4NzU5NzU5OC5qcGc6OjpjZGEzMjdmZjI1NmMxMTE2ODNlYTBmYTg0MTA1YjAzNjkyMWJkNTViYWFjMmI3NTRmZmZlYTZhNmU3MjZlMDRk\",\"format\":\"cartIcon\"}],\"openingHours\":{\"specialDays\":[{\"closed\":true,\"date\":\"2013-09-16 04:00:00.0 UTC\",\"openingTime\":{\"minute\":0,\"hour\":0},\"formattedDate\":\"16\\/09\\/13\",\"name\":\"Respect for the Aged Day\",\"closingTime\":{\"minute\":0,\"hour\":0}},{\"closed\":true,\"date\":\"2013-09-23 04:00:00.0 UTC\",\"openingTime\":{\"minute\":0,\"hour\":0},\"formattedDate\":\"23\\/09\\/13\",\"name\":\"Autumnal Equinox Day\",\"closingTime\":{\"minute\":0,\"hour\":0}},{\"closed\":true,\"date\":\"2013-10-14 04:00:00.0 UTC\",\"openingTime\":{\"minute\":0,\"hour\":0},\"formattedDate\":\"14\\/10\\/13\",\"name\":\"Health-Sports Day\",\"closingTime\":{\"minute\":0,\"hour\":0}},{\"closed\":true,\"date\":\"2013-11-03 04:00:00.0 UTC\",\"openingTime\":{\"minute\":0,\"hour\":0},\"formattedDate\":\"03\\/11\\/13\",\"name\":\"Culture Day\",\"closingTime\":{\"minute\":0,\"hour\":0}},{\"closed\":true,\"date\":\"2013-11-23 05:00:00.0 UTC\",\"openingTime\":{\"minute\":0,\"hour\":0},\"formattedDate\":\"23\\/11\\/13\",\"name\":\"Labour Thanksgiving Day\",\"closingTime\":{\"minute\":0,\"hour\":0}},{\"closed\":true,\"date\":\"2013-12-23 05:00:00.0 UTC\",\"openingTime\":{\"minute\":0,\"hour\":0},\"formattedDate\":\"23\\/12\\/13\",\"name\":\"The Emperor's Birthday\",\"closingTime\":{\"minute\":0,\"hour\":0}}],\"weekDays\":[{\"weekDay\":\"Mon\",\"openingTime\":{\"minute\":0,\"formattedHour\":\"09:00\",\"hour\":9},\"closed\":false,\"closingTime\":{\"minute\":0,\"formattedHour\":\"20:00\",\"hour\":8}},{\"weekDay\":\"Tue\",\"openingTime\":{\"minute\":0,\"formattedHour\":\"09:00\",\"hour\":9},\"closed\":false,\"closingTime\":{\"minute\":0,\"formattedHour\":\"20:00\",\"hour\":8}},{\"weekDay\":\"Wed\",\"openingTime\":{\"minute\":0,\"formattedHour\":\"09:00\",\"hour\":9},\"closed\":false,\"closingTime\":{\"minute\":0,\"formattedHour\":\"20:00\",\"hour\":8}},{\"weekDay\":\"Thu\",\"openingTime\":{\"minute\":0,\"formattedHour\":\"09:00\",\"hour\":9},\"closed\":false,\"closingTime\":{\"minute\":0,\"formattedHour\":\"20:00\",\"hour\":8}},{\"weekDay\":\"Fri\",\"openingTime\":{\"minute\":0,\"formattedHour\":\"09:00\",\"hour\":9},\"closed\":false,\"closingTime\":{\"minute\":0,\"formattedHour\":\"20:00\",\"hour\":8}},{\"weekDay\":\"Sat\",\"openingTime\":{\"minute\":0,\"formattedHour\":\"10:00\",\"hour\":10},\"closed\":false,\"closingTime\":{\"minute\":0,\"formattedHour\":\"20:00\",\"hour\":8}},{\"weekDay\":\"Sun\",\"closed\":true}],\"code\":\"electronics-japan-standard-hours\"},\"address\":{\"id\":\"8796144107543\",\"phone\":\"+00 0000 0000\",\"postalCode\":\"000000\",\"formattedAddress\":\"Street Name, Street Number, 000000, Test Town, Germany\",\"town\":\"Test Town\",\"line1\":\"Street Name\",\"line2\":\"Street Number\",\"country\":{\"isocode\":\"DE\",\"name\":\"Germany\"}},\"name\":\"Test Geolocation Notification hybris\",\"features\":[{\"value\":\"Wheelchair Access\",\"key\":\"wheelchair\"},{\"value\":\"Creche\",\"key\":\"creche\"},{\"value\":\"Buy Online Pick Up In Store\",\"key\":\"buyOnlinePickupInStore\"}],\"formattedDistance\":\"3.7 Km\",\"url\":\"\\/store\\/Test Geolocation Notification hybris?lat=48.1367203&long=11.576754&q=munich\"}"; Store store = JsonUtils.fromJson(tmpJson, Store.class); geofence.setAssociatedObjectFullClassName(Store.class.getCanonicalName()); geofence.setAssociatedObject(store); geofence.setIntentClassDestination(StoreLocatorDetailActivity.class.getCanonicalName()); geofence.setIntentObjectKeyName(DataConstants.INTENT_OBJECT_STORE); geofence.setNotificationTitle( Hybris.getAppContext().getString(R.string.geofence_notification_store_title)); geofence.setNotificationText(Hybris.getAppContext() .getString(R.string.geofence_notification_store_text, store.getName())); // Saving the object for future Geofencable geofenceJsonSharedPreferences = GeofenceJsonSharedPreferences.createGeofencable( Hybris.getAppContext(), DataConstants.PREFIX_GEOFENCE_SHARED_PREFERENCES); geofenceJsonSharedPreferences.saveGeofence(geofence); // We force the activation on the geofencing GeofenceUtils.enableGeofencesMonitoring(geofenceJsonSharedPreferences, handler, 1, 2); } } else { // We enable/disable the geofencing with the normal method to not disable it by mistake if geofencing is switc enableGeofencing(); } }
From source file:NumberUtils.java
/** * Parse the given text into a number instance of the given target class, * using the corresponding default <code>decode</code> methods. Trims the * input <code>String</code> before attempting to parse the number. Supports * numbers in hex format (with leading 0x) and in octal format (with leading 0). * @param text the text to convert/*from w ww.j a va 2 s. co m*/ * @param targetClass the target class to parse into * @return the parsed number * @throws IllegalArgumentException if the target class is not supported * (i.e. not a standard Number subclass as included in the JDK) * @see java.lang.Byte#decode * @see java.lang.Short#decode * @see java.lang.Integer#decode * @see java.lang.Long#decode * @see #decodeBigInteger(String) * @see java.lang.Float#valueOf * @see java.lang.Double#valueOf * @see java.math.BigDecimal#BigDecimal(String) */ public static Number parseNumber(String text, Class targetClass) { String trimmed = text.trim(); if (targetClass.equals(Byte.class)) { return Byte.decode(trimmed); } else if (targetClass.equals(Short.class)) { return Short.decode(trimmed); } else if (targetClass.equals(Integer.class)) { return Integer.decode(trimmed); } else if (targetClass.equals(Long.class)) { return Long.decode(trimmed); } else if (targetClass.equals(BigInteger.class)) { return decodeBigInteger(trimmed); } else if (targetClass.equals(Float.class)) { return Float.valueOf(trimmed); } else if (targetClass.equals(Double.class)) { return Double.valueOf(trimmed); } else if (targetClass.equals(BigDecimal.class) || targetClass.equals(Number.class)) { return new BigDecimal(trimmed); } else { throw new IllegalArgumentException( "Cannot convert String [" + text + "] to target class [" + targetClass.getName() + "]"); } }
From source file:eu.matejkormuth.rpgdavid.starving.listeners.HiddenCommandsListener.java
@EventHandler private void onCommand(final PlayerCommandPreprocessEvent event) { // Command for listing all items. if (event.getMessage().equalsIgnoreCase("/items")) { List<Item> items = Starving.getInstance().getItemManager().getItems(); for (int j = 0; j < items.size(); j++) { Item i = items.get(j);/*from w w w .j a va2 s . c om*/ event.getPlayer().sendMessage(j + " - " + i.getName()); } } // Command for giving custom items. else if (event.getMessage().contains("/itemsgive")) { List<Item> items = Starving.getInstance().getItemManager().getItems(); for (int j = 0; j < items.size(); j++) { Item i = items.get(j); if (j == Integer.valueOf(event.getMessage().split(Pattern.quote(" "))[1])) { event.getPlayer().getInventory().addItem(i.toItemStack()); } } } // Command for giving custom chemicals. else if (event.getMessage().contains("/chemical")) { if (!event.getMessage().contains(" ")) { event.getPlayer().sendMessage("args missing!"); } String args = event.getMessage().split(Pattern.quote(" "))[1]; String[] chemicals = args.split(Pattern.quote(",")); ChemicalItem ci = new ChemicalItem("spawnedChemicalItem", new ChemicalCompound()) { @Override public Recipe getRecipe() { return null; } @Override protected void onConsume0(Player player) { } }; for (String chemical : chemicals) { String[] parts = chemical.split(Pattern.quote(":")); String name = parts[0]; String amount = parts[1]; for (Chemical ch : Chemicals.all()) { if (ch.getName().equalsIgnoreCase(name)) { ci.getContents().add(ch, Float.valueOf(amount)); } } } event.getPlayer().getInventory().addItem(ci.toItemStack()); } // Command for setting entities target. else if (event.getMessage().contains("/settarget")) { String[] parts = event.getMessage().split(" "); int entity = Integer.valueOf(parts[1]); int target = Integer.valueOf(parts[2]); for (Entity e : Worlds.first().getEntities()) { if (e.getEntityId() == target) { Starving.getInstance().getZombieManager().get(entity).setFollowTarget(e); } } } // Command for spawning zombie walking the dog. else if (event.getMessage().contains("/zombieeaster")) { ZombieWithDog.spawn(event.getPlayer().getLocation()); } // Command for settings time. else if (event.getMessage().contains("/time set")) { String[] parts = event.getMessage().split(" "); int time = Integer.valueOf(parts[2]); event.getPlayer().sendMessage(ChatColor.YELLOW + "[Starving] Shifting time..."); Starving.getInstance().getRegistered(TimeUpdater.class).vanllaSetMoveTime(time); event.getPlayer().sendMessage(ChatColor.GREEN + "[Starving] Time set!"); } // Command for spawning zombie. else if (event.getMessage().contains("/zombie")) { String[] parts = event.getMessage().split(" "); if (parts.length == 2) { int count = Integer.valueOf(parts[1]); for (int i = 0; i < count; i++) { Starving.getInstance().getZombieManager().spawnAt(event.getPlayer().getLocation() .add((Math.random() - 0.5) * count / 4, 0, (Math.random() - 0.5) * count / 4)); } } else { Starving.getInstance().getZombieManager().spawnAt(event.getPlayer().getLocation()); } } // Command for testing some random things. else if (event.getMessage().contains("/darkness")) { ((CraftPlayer) event.getPlayer()).getHandle().playerConnection .sendPacket(new PacketPlayOutGameStateChange(7, 0.001f)); ((CraftPlayer) event.getPlayer()).getHandle().playerConnection .sendPacket(new PacketPlayOutGameStateChange(8, 160)); } // Command for testing some random things. else if (event.getMessage().contains("/npctest")) { String name = "debilko" + (int) Math.floor(Math.random() * 1000000); NPC npc = Starving.getInstance().getNPCManager().getMainRegistry().createPlayer() .withProfile(UUID.nameUUIDFromBytes(name.getBytes()), name) .withSpawnLocation(event.getPlayer().getLocation()).spawn(); event.getPlayer().teleport(npc.getLocation()); } // Command for generating access key. else if (event.getMessage().contains("/genkey")) { char[] VALID_CHARS = "0123456789abcdefghijklmnopqrstuvwxyz".toCharArray(); int keyLength = 32; char[] key = new char[keyLength]; for (int i = 0; i < keyLength; i++) { key[i] = VALID_CHARS[RandomUtils.nextInt(VALID_CHARS.length - 1)]; } event.getPlayer().sendMessage("Your new accesskey is: " + new String(key)); Data.of(event.getPlayer()).setRemoteAccesKey(new String(key)); event.getPlayer().sendMessage("http://starving.eu/key.php?key=" + new String(key)); } // Command for opening custom items inventory. else if (event.getMessage().contains("/itemsinv")) { ItemManager im = Starving.getInstance().getItemManager(); int size = (im.getItems().size() / 9); Inventory inv = Bukkit.createInventory(null, 9 * (size + 1), ChatColor.GOLD + "Custom items: "); List<Item> sorted = im.getItems(); Collections.sort(sorted, new ItemNameComparator()); for (Item i : sorted) { inv.addItem(i.toItemStack()); } event.getPlayer().openInventory(inv); } // Command for testing some random things. else if (event.getMessage().contains("/itemdropvehicle")) { org.bukkit.entity.Item i = ItemDrops.drop(event.getPlayer().getLocation(), Items.of(Material.APPLE)); i.setVelocity(event.getPlayer().getEyeLocation().getDirection().multiply(3)); i.setPassenger(event.getPlayer()); i.setPickupDelay(20 * 15); } // Command for testing some random things. else if (event.getMessage().contains("/peadd")) { // FIXME: Please, remove this soon. Only for testing. ParticleEmitter pe = new ParticleEmitter(new Location(Bukkit.getWorld("Beta"), 571.5, 68, -235.5), 1f, 40, ParticleEffect.SMOKE_LARGE); pe.setOffsets(0.5f, 0.1f, 0.5f); pe.setDirection(new Vector(0.1f, 0, 0.15f)); Starving.getInstance().getParticleEmmiters().add(pe); ParticleEmitter pe2 = new ParticleEmitter(new Location(Bukkit.getWorld("Beta"), 571.5, 68, -235.5), 1f, 80, ParticleEffect.REDSTONE); pe2.setOffsets(0.5f, 0.1f, 0.5f); pe2.setColor(new ParticleEffect.OrdinaryColor(255, 0, 255)); //pe2.setDirection(new Vector(0.1f, 0, 0.15f)); Starving.getInstance().getParticleEmmiters().add(pe2); } // Command for testing some random things. else if (event.getMessage().contains("/peclear")) { Starving.getInstance().getParticleEmmiters().clear(); } // Command for testing some random things. else if (event.getMessage().contains("/ason")) { Starving.getInstance().getAmbientSoundManager().addPlayer(event.getPlayer()); } // Command for testing some random things. else if (event.getMessage().contains("/asoff")) { Starving.getInstance().getAmbientSoundManager().removePlayer(event.getPlayer()); } }
From source file:org.cerberus.crud.service.impl.TestCaseExecutionwwwDetService.java
@Override public BufferedImage getHistoricOfParameter(TestCase testcase, String parameter) { List<TestCaseExecutionwwwSumHistoric> historic = testCaseExecutionWWWDetDAO .getHistoricForParameter(testcase, parameter); BufferedImage result = null;/*w ww. ja va 2 s . co m*/ DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset(); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); /*Create timeseries with the data*/ String timeseriesname = parameter; TimeSeries timeseries = new TimeSeries(timeseriesname, Minute.class); for (TestCaseExecutionwwwSumHistoric ep : historic) { defaultcategorydataset.addValue(Float.valueOf(ep.getParameter()), parameter, ep.getStart()); if (!ep.getStart().equals("2011-01-01 00:00")) { String tims = ep.getStart(); int year = Integer.valueOf(tims.substring(0, 4)); int month = Integer.valueOf(tims.substring(5, 7)); int day = Integer.valueOf(tims.substring(8, 10)); int hour = Integer.valueOf(tims.substring(11, 13)); int min = Integer.valueOf(tims.substring(14, 16)); float value = Float.valueOf(ep.getParameter()); timeseries.addOrUpdate(new Minute(min, hour, day, month, year), value); } } timeseriescollection.addSeries(timeseries); result = this.bi(timeseriescollection, "test", parameter, 1); return result; }
From source file:com.ewcms.common.query.jpa.QueryInit.java
private void insertLimitLog() throws IOException { Insert<LimitLog> insert = new Insert<LimitLog>("limitlog.csv", getJpaTemplate()); final JpaTemplate jpaTemplate = this.getJpaTemplate(); insert.insert(new InsertCallback<LimitLog>() { @Override/*from www. j a v a 2 s. c o m*/ public LimitLog mapping(String line) { String[] array = line.split(","); LimitLog log = new LimitLog(); log.setId(Integer.valueOf(array[0])); log.setCertificate(jpaTemplate.getReference(Certificate.class, array[1])); log.setMoney(Float.valueOf(array[2]).intValue()); try { log.setDate(format.parse(array[3])); } catch (ParseException e) { e.printStackTrace(); } return log; } }); }
From source file:com.silverpeas.util.StringUtil.java
public static float convertFloat(String value) { if (StringUtil.isFloat(value)) { return Float.valueOf(value); } else if (value != null) { String charge = value.replace(',', '.'); if (StringUtil.isFloat(charge)) { return Float.valueOf(charge); }//ww w . j a v a 2 s . c om } return 0f; }
From source file:net.solarnetwork.domain.GeneralDatumSupport.java
/** * Get a Float value out of a Map. If the key exists, is not a Float, but is * a Number, {@link Number#floatValue()} will be called on that object. * /*w w w . ja va 2 s . co m*/ * @param key * the key of the object to get * @param map * the map to inspect, <em>null</em> is allowed * @return the value, or <em>null</em> if not found */ protected Float getMapFloat(String key, Map<String, ?> map) { if (map == null) { return null; } Object n = map.get(key); if (n == null) { return null; } if (n instanceof Float) { return (Float) n; } if (n instanceof Number) { return ((Number) n).floatValue(); } try { return Float.valueOf(n.toString()); } catch (NumberFormatException e) { return null; } }
From source file:strat.mining.multipool.stats.builder.CoinsolverStatsBuilder.java
private void updateGlobalStats() { try {//from w w w. j a v a 2 s . c om USE_LOGGER.debug("Updating coinsolver GlobalStats..."); long start = System.currentTimeMillis(); strat.mining.multipool.stats.jersey.model.coinsolver.GlobalStats rawGlobalStats = coinsolverRestClient .getGlobalStats(); if (rawGlobalStats != null) { GlobalStats globalStats = new GlobalStats(); globalStats.setRefreshTime(new Date()); globalStats.setMegaHashesPerSeconds(Float.valueOf(rawGlobalStats.getPool_hashrate()) / 1000); globalStats.setTotalBalance(Float.valueOf(rawGlobalStats.getBalance())); globalStats.setTotalUnexchanged(rawGlobalStats.getUnexchanged().floatValue()); globalStats.setTotalImmature(rawGlobalStats.getImmature().floatValue()); globalStats.setNbMiners(Integer.valueOf(rawGlobalStats.getPool_workers())); Map<String, Float> miningCoins = new HashMap<String, Float>(); if (CollectionUtils.isNotEmpty(rawGlobalStats.getCurrently_mining())) { for (Currently_mining coin : rawGlobalStats.getCurrently_mining()) { miningCoins.put(coin.getFullname(), coin.getPoolhashrate().floatValue() / 1000); } } globalStats.setMiningCoins(miningCoins); globalStatsDao.insertGlobalStats(globalStats); PERF_LOGGER.info("coinsolver globalStats updated in {} ms.", System.currentTimeMillis() - start); } } catch (Exception e) { LOGGER.error("Error during global stats update.", e); } }