List of usage examples for java.lang Float toString
public static String toString(float f)
From source file:com.koda.integ.hbase.test.BlockCacheSimpleRegionTests.java
@Override protected void setUp() throws IOException { if (region != null) return;/* w w w.ja v a2s.co m*/ // Init columns CQQ = new byte[5][]; for (int i = 0; i < CQQ.length; i++) { CQQ[i] = ("cq" + i).getBytes(); } HColumnDescriptor desc = new HColumnDescriptor(CF); desc.setCacheDataOnWrite(true); desc.setCacheIndexesOnWrite(true); desc.setCacheBloomsOnWrite(true); desc.setBlocksize(BLOCK_SIZE); desc.setBloomFilterType(BloomType.ROW); Configuration conf = TEST_UTIL.getConfiguration(); conf.set(OffHeapBlockCache.BLOCK_CACHE_MEMORY_SIZE, Long.toString(cacheSize)); conf.set(OffHeapBlockCache.BLOCK_CACHE_IMPL, cacheImplClass); conf.set(OffHeapBlockCache.BLOCK_CACHE_YOUNG_GEN_FACTOR, Float.toString(youngGenFactor)); conf.set(OffHeapBlockCache.BLOCK_CACHE_COMPRESSION, cacheCompression); conf.set(OffHeapBlockCache.BLOCK_CACHE_OVERFLOW_TO_EXT_STORAGE_ENABLED, Boolean.toString(cacheOverflowEnabled)); conf.set("io.storefile.bloom.block.size", Integer.toString(BLOOM_BLOCK_SIZE)); conf.set("hfile.block.cache.size", "0.5"); conf.set(OffHeapBlockCache.BLOCK_CACHE_EVICTION, "LRU"); region = TEST_UTIL.createTestRegion(TABLE_NAME, desc); populateData(); cache = new CacheConfig(conf).getBlockCache(); LOG.info("Block cache: " + cache.getClass().getName() + "Size=" + cache.getCurrentSize()); }
From source file:org.apache.hadoop.hbase.regionserver.TestJoinedScanners.java
@Test public void testJoinedScanners() throws Exception { String dataNodeHosts[] = new String[] { "host1", "host2", "host3" }; int regionServersCount = 3; HBaseTestingUtility htu = new HBaseTestingUtility(); final int DEFAULT_BLOCK_SIZE = 1024 * 1024; htu.getConfiguration().setLong("dfs.blocksize", DEFAULT_BLOCK_SIZE); htu.getConfiguration().setInt("dfs.replication", 1); htu.getConfiguration().setLong("hbase.hregion.max.filesize", 322122547200L); MiniHBaseCluster cluster = null;/*from w w w . j av a 2 s. c o m*/ try { cluster = htu.startMiniCluster(1, regionServersCount, dataNodeHosts); byte[][] families = { cf_essential, cf_joined }; byte[] tableName = Bytes.toBytes(this.getClass().getSimpleName()); HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName)); for (byte[] family : families) { HColumnDescriptor hcd = new HColumnDescriptor(family); hcd.setDataBlockEncoding(blockEncoding); desc.addFamily(hcd); } htu.getHBaseAdmin().createTable(desc); HTable ht = new HTable(htu.getConfiguration(), tableName); long rows_to_insert = 1000; int insert_batch = 20; long time = System.nanoTime(); Random rand = new Random(time); LOG.info("Make " + Long.toString(rows_to_insert) + " rows, total size = " + Float.toString(rows_to_insert * valueWidth / 1024 / 1024) + " MB"); byte[] val_large = new byte[valueWidth]; List<Put> puts = new ArrayList<Put>(); for (long i = 0; i < rows_to_insert; i++) { Put put = new Put(Bytes.toBytes(Long.toString(i))); if (rand.nextInt(100) <= selectionRatio) { put.add(cf_essential, col_name, flag_yes); } else { put.add(cf_essential, col_name, flag_no); } put.add(cf_joined, col_name, val_large); puts.add(put); if (puts.size() >= insert_batch) { ht.put(puts); puts.clear(); } } if (puts.size() >= 0) { ht.put(puts); puts.clear(); } LOG.info( "Data generated in " + Double.toString((System.nanoTime() - time) / 1000000000.0) + " seconds"); boolean slow = true; for (int i = 0; i < 10; ++i) { runScanner(ht, slow); slow = !slow; } ht.close(); } finally { if (cluster != null) { htu.shutdownMiniCluster(); } } }
From source file:edu.stanford.muse.index.NER.java
public static void readLocationsWG() { InputStream is = null;//w w w .j ava 2s .c o m try { is = new GZIPInputStream(NER.class.getClassLoader().getResourceAsStream("WG.locations.txt.gz")); LineNumberReader lnr = new LineNumberReader(new InputStreamReader(is, "UTF-8")); while (true) { String line = lnr.readLine(); if (line == null) break; StringTokenizer st = new StringTokenizer(line, "\t"); if (st.countTokens() == 4) { String locationName = st.nextToken(); String canonicalName = locationName.toLowerCase(); if (locationsToSuppress.contains(canonicalName)) continue; String lat = st.nextToken(); String longi = st.nextToken(); String pop = st.nextToken(); long popl = Long.parseLong(pop); float latf = ((float) Integer.parseInt(lat)) / 100.0f; float longif = ((float) Integer.parseInt(longi)) / 100.0f; Long existingPop = populations.get(canonicalName); if (existingPop == null || popl > existingPop) { populations.put(canonicalName, popl); locations.put(canonicalName, new LocationInfo(locationName, Float.toString(latf), Float.toString(longif))); } } } if (is != null) is.close(); } catch (Exception e) { log.warn("Unable to read World Gazetteer file, places info may be inaccurate"); log.debug(Util.stackTrace(e)); } }
From source file:com.ratebeer.android.api.command.PostRatingCommand.java
@Override public CommandResult execute(ApiConnection apiConnection) { try {/*w w w . ja v a 2 s . com*/ ApiConnection.ensureLogin(apiConnection, getUserSettings()); // NOTE: Maybe use the API call to http://www.ratebeer.com/m/m_saverating.asp, but it should be checked // whether this allows updating of a rating too // NOTE: We get an HTTP 302 (moved temporarily) response if everything is okay (to redirect us) String result = apiConnection.post( ratingID <= 0 ? "http://www.ratebeer.com/saverating.asp" : "http://www.ratebeer.com/updaterating.asp", Arrays.asList(new BasicNameValuePair("BeerID", Integer.toString(beerId)), new BasicNameValuePair("RatingID", ratingID <= 0 ? "" : Integer.toString(ratingID)), new BasicNameValuePair("OrigDate", origDate == null ? "" : origDate), new BasicNameValuePair("aroma", Integer.toString(aroma)), new BasicNameValuePair("appearance", Integer.toString(appearance)), new BasicNameValuePair("flavor", Integer.toString(taste)), new BasicNameValuePair("palate", Integer.toString(palate)), new BasicNameValuePair("overall", Integer.toString(overall)), new BasicNameValuePair("totalscore", Float.toString(getTotal())), new BasicNameValuePair("Comments", comment)), HttpURLConnection.HTTP_MOVED_TEMP); if (result.indexOf(POST_SUCCESS) >= 0) { return new CommandSuccessResult(this); } else { return new CommandFailureResult(this, new ApiException(ApiException.ExceptionType.CommandFailed, "The rating was posted, but the returned HTML did not contain the unique success string.")); } } catch (ApiException e) { return new CommandFailureResult(this, e); } }
From source file:org.apache.axis2.databinding.utils.ConverterUtil.java
public static String convertToString(float i) { return Float.toString(i); }
From source file:org.apache.tika.parser.jdbc.JDBCTableReader.java
private void handleCell(ResultSetMetaData rsmd, int i, ContentHandler handler, ParseContext context) throws SQLException, IOException, SAXException { switch (rsmd.getColumnType(i)) { case Types.BLOB: handleBlob(tableName, rsmd.getColumnName(i), rows, results, i, handler, context); break;/* w ww.jav a 2 s .c o m*/ case Types.CLOB: handleClob(tableName, rsmd.getColumnName(i), rows, results, i, handler, context); break; case Types.BOOLEAN: handleBoolean(results, i, handler); break; case Types.DATE: handleDate(results, i, handler); break; case Types.TIMESTAMP: handleTimeStamp(results, i, handler); break; case Types.INTEGER: handleInteger(results, i, handler); break; case Types.FLOAT: //this is necessary to handle rounding issues in presentation //Should we just use getString(i)? float f = results.getFloat(i); if (!results.wasNull()) { addAllCharacters(Float.toString(f), handler); } break; case Types.DOUBLE: double d = results.getDouble(i); if (!results.wasNull()) { addAllCharacters(Double.toString(d), handler); } break; default: String s = results.getString(i); if (!results.wasNull()) { addAllCharacters(s, handler); } break; } }
From source file:com.mutu.gpstracker.streaming.CustomUpload.java
@Override public void onReceive(Context context, Intent intent) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); String prefUrl = preferences.getString(ApplicationPreferenceActivity.CUSTOMUPLOAD_URL, "http://www.example.com"); Integer prefBacklog = Integer.valueOf(preferences .getString(ApplicationPreferenceActivity.CUSTOMUPLOAD_BACKLOG, CUSTOMUPLOAD_BACKLOG_DEFAULT)); Location loc = intent.getParcelableExtra(Constants.EXTRA_LOCATION); Uri trackUri = intent.getParcelableExtra(Constants.EXTRA_TRACK); String buildUrl = prefUrl;//from ww w . j a va2s . co m buildUrl = buildUrl.replace("@LAT@", Double.toString(loc.getLatitude())); buildUrl = buildUrl.replace("@LON@", Double.toString(loc.getLongitude())); buildUrl = buildUrl.replace("@ID@", trackUri.getLastPathSegment()); buildUrl = buildUrl.replace("@TIME@", Long.toString(loc.getTime())); buildUrl = buildUrl.replace("@SPEED@", Float.toString(loc.getSpeed())); buildUrl = buildUrl.replace("@ACC@", Float.toString(loc.getAccuracy())); buildUrl = buildUrl.replace("@ALT@", Double.toString(loc.getAltitude())); buildUrl = buildUrl.replace("@BEAR@", Float.toString(loc.getBearing())); HttpClient client = new DefaultHttpClient(); URI uploadUri; try { uploadUri = new URI(buildUrl); HttpGet currentRequest = new HttpGet(uploadUri); sRequestBacklog.add(currentRequest); if (sRequestBacklog.size() > prefBacklog) { sRequestBacklog.poll(); } while (!sRequestBacklog.isEmpty()) { HttpGet request = sRequestBacklog.peek(); HttpResponse response = client.execute(request); sRequestBacklog.poll(); StatusLine status = response.getStatusLine(); if (status.getStatusCode() != 200) { throw new IOException("Invalid response from server: " + status.toString()); } clearNotification(context); } } catch (URISyntaxException e) { notifyError(context, e); } catch (ClientProtocolException e) { notifyError(context, e); } catch (IOException e) { notifyError(context, e); } }
From source file:com.stratio.ingestion.sink.cassandra.EventParserTest.java
@Test public void shouldParsePrimitiveTypes() throws Exception { Object integer = EventParser.parseValue("1", DataType.Name.INT); assertThat(integer).isInstanceOf(Integer.class).isEqualTo(1); integer = EventParser.parseValue(Integer.toString(Integer.MAX_VALUE), DataType.Name.INT); assertThat(integer).isInstanceOf(Integer.class).isEqualTo(Integer.MAX_VALUE); integer = EventParser.parseValue(Integer.toString(Integer.MIN_VALUE), DataType.Name.INT); assertThat(integer).isInstanceOf(Integer.class).isEqualTo(Integer.MIN_VALUE); integer = EventParser.parseValue(" 1 2 ", DataType.Name.INT); assertThat(integer).isInstanceOf(Integer.class).isEqualTo(12); Object counter = EventParser.parseValue("1", DataType.Name.COUNTER); assertThat(counter).isEqualTo(1L);// w ww . j av a 2s . c o m counter = EventParser.parseValue(Long.toString(Long.MAX_VALUE), DataType.Name.COUNTER); assertThat(counter).isEqualTo(Long.MAX_VALUE); counter = EventParser.parseValue(Long.toString(Long.MIN_VALUE), DataType.Name.COUNTER); assertThat(counter).isEqualTo(Long.MIN_VALUE); counter = EventParser.parseValue(" 1 2 ", DataType.Name.COUNTER); assertThat(counter).isEqualTo(12L); Object _float = EventParser.parseValue("1", DataType.Name.FLOAT); assertThat(_float).isInstanceOf(Float.class).isEqualTo(1f); _float = EventParser.parseValue("1.0", DataType.Name.FLOAT); assertThat(_float).isInstanceOf(Float.class).isEqualTo(1f); _float = EventParser.parseValue(Float.toString(Float.MAX_VALUE), DataType.Name.FLOAT); assertThat(_float).isInstanceOf(Float.class).isEqualTo(Float.MAX_VALUE); _float = EventParser.parseValue(Float.toString(Float.MIN_VALUE), DataType.Name.FLOAT); assertThat(_float).isInstanceOf(Float.class).isEqualTo(Float.MIN_VALUE); _float = EventParser.parseValue(" 1 . 0 ", DataType.Name.FLOAT); assertThat(_float).isInstanceOf(Float.class).isEqualTo(1f); Object _double = EventParser.parseValue("1", DataType.Name.DOUBLE); assertThat(_double).isInstanceOf(Double.class).isEqualTo(1.0); _double = EventParser.parseValue("0", DataType.Name.DOUBLE); assertThat(_double).isInstanceOf(Double.class).isEqualTo(0.0); _double = EventParser.parseValue(Double.toString(Double.MAX_VALUE), DataType.Name.DOUBLE); assertThat(_double).isInstanceOf(Double.class).isEqualTo(Double.MAX_VALUE); _double = EventParser.parseValue(Double.toString(Double.MIN_VALUE), DataType.Name.DOUBLE); assertThat(_double).isInstanceOf(Double.class).isEqualTo(Double.MIN_VALUE); _double = EventParser.parseValue(" 1 . 0 ", DataType.Name.DOUBLE); assertThat(_double).isInstanceOf(Double.class).isEqualTo(1.0); for (DataType.Name type : Arrays.asList(DataType.Name.BIGINT)) { Object bigInteger = EventParser.parseValue("1", type); assertThat(bigInteger).isInstanceOf(Long.class).isEqualTo(1L); bigInteger = EventParser.parseValue("0", type); assertThat(bigInteger).isInstanceOf(Long.class).isEqualTo(0L); bigInteger = EventParser.parseValue(Long.toString(Long.MAX_VALUE), type); assertThat(bigInteger).isInstanceOf(Long.class).isEqualTo(Long.MAX_VALUE); bigInteger = EventParser.parseValue(Long.toString(Long.MIN_VALUE), type); assertThat(bigInteger).isInstanceOf(Long.class).isEqualTo(Long.MIN_VALUE); } for (DataType.Name type : Arrays.asList(DataType.Name.VARINT)) { Object bigInteger = EventParser.parseValue("1", type); assertThat(bigInteger).isInstanceOf(BigInteger.class).isEqualTo(BigInteger.ONE); bigInteger = EventParser.parseValue("0", type); assertThat(bigInteger).isInstanceOf(BigInteger.class).isEqualTo(BigInteger.ZERO); bigInteger = EventParser.parseValue( BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2L)).toString(), type); assertThat(bigInteger).isInstanceOf(BigInteger.class) .isEqualTo(BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2L))); bigInteger = EventParser.parseValue( BigInteger.valueOf(Long.MIN_VALUE).multiply(BigInteger.valueOf(2L)).toString(), type); assertThat(bigInteger).isInstanceOf(BigInteger.class) .isEqualTo(BigInteger.valueOf(Long.MIN_VALUE).multiply(BigInteger.valueOf(2L))); } Object bigDecimal = EventParser.parseValue("1", DataType.Name.DECIMAL); assertThat(bigDecimal).isInstanceOf(BigDecimal.class).isEqualTo(BigDecimal.valueOf(1)); bigDecimal = EventParser.parseValue("0", DataType.Name.DECIMAL); assertThat(bigDecimal).isInstanceOf(BigDecimal.class).isEqualTo(BigDecimal.valueOf(0)); bigDecimal = EventParser.parseValue( BigDecimal.valueOf(Double.MAX_VALUE).multiply(BigDecimal.valueOf(2)).toString(), DataType.Name.DECIMAL); assertThat(bigDecimal).isInstanceOf(BigDecimal.class) .isEqualTo(BigDecimal.valueOf(Double.MAX_VALUE).multiply(BigDecimal.valueOf(2))); bigDecimal = EventParser.parseValue( BigDecimal.valueOf(Double.MIN_VALUE).multiply(BigDecimal.valueOf(2)).toString(), DataType.Name.DECIMAL); assertThat(bigDecimal).isInstanceOf(BigDecimal.class) .isEqualTo(BigDecimal.valueOf(Double.MIN_VALUE).multiply(BigDecimal.valueOf(2))); bigDecimal = EventParser.parseValue(" 1 2 ", DataType.Name.DECIMAL); assertThat(bigDecimal).isInstanceOf(BigDecimal.class).isEqualTo(BigDecimal.valueOf(12)); Object string = EventParser.parseValue("string", DataType.Name.TEXT); assertThat(string).isInstanceOf(String.class).isEqualTo("string"); Object bool = EventParser.parseValue("true", DataType.Name.BOOLEAN); assertThat(bool).isInstanceOf(Boolean.class).isEqualTo(true); Object addr = EventParser.parseValue("192.168.1.1", DataType.Name.INET); assertThat(addr).isInstanceOf(InetAddress.class).isEqualTo(InetAddress.getByName("192.168.1.1")); UUID randomUUID = UUID.randomUUID(); Object uuid = EventParser.parseValue(randomUUID.toString(), DataType.Name.UUID); assertThat(uuid).isInstanceOf(UUID.class).isEqualTo(randomUUID); }
From source file:com.koda.integ.hbase.test.BlockCacheStorageSimpleRegionTests.java
@Override protected void setUp() throws IOException { if (region != null) return;//from w w w . ja va 2 s . c o m // Init columns CQQ = new byte[5][]; for (int i = 0; i < CQQ.length; i++) { CQQ[i] = ("cq" + i).getBytes(); } HColumnDescriptor desc = new HColumnDescriptor(CF); desc.setCacheDataOnWrite(true); desc.setCacheIndexesOnWrite(true); desc.setCacheBloomsOnWrite(true); desc.setBlocksize(BLOCK_SIZE); desc.setBloomFilterType(BloomType.ROW); Configuration conf = TEST_UTIL.getConfiguration(); conf.set(OffHeapBlockCache.BLOCK_CACHE_MEMORY_SIZE, Long.toString(cacheSize)); conf.set(OffHeapBlockCache.BLOCK_CACHE_IMPL, cacheImplClass); conf.set(OffHeapBlockCache.BLOCK_CACHE_YOUNG_GEN_FACTOR, Float.toString(youngGenFactor)); conf.set(OffHeapBlockCache.BLOCK_CACHE_COMPRESSION, cacheCompression); //conf.set(OffHeapBlockCache.BLOCK_CACHE_OVERFLOW_TO_EXT_STORAGE_ENABLED, Boolean.toString(cacheOverflowEnabled)); conf.set("io.storefile.bloom.block.size", Integer.toString(BLOOM_BLOCK_SIZE)); conf.set("hfile.block.cache.size", "0.5"); // Enable File Storage conf.set(FileExtStorage.FILE_STORAGE_FILE_SIZE_LIMIT, Integer.toString((int) fileSizeLimit)); conf.set(FileExtStorage.FILE_STORAGE_MAX_SIZE, Long.toString(fileStoreSize)); conf.set(OffHeapBlockCache.BLOCK_CACHE_OVERFLOW_TO_EXT_STORAGE_ENABLED, Boolean.toString(true)); conf.set(OffHeapBlockCache.BLOCK_CACHE_EXT_STORAGE_IMPL, FileExtStorage.class.getName()); conf.set(FileExtStorage.FILE_STORAGE_BASE_DIR, dataDir); conf.set(OffHeapBlockCache.BLOCK_CACHE_TEST_MODE, Boolean.toString(true)); conf.set(OffHeapBlockCache.BLOCK_CACHE_EXT_STORAGE_MEMORY_SIZE, Long.toString(extRefCacheSize)); region = TEST_UTIL.createTestRegion(TABLE_NAME, desc); populateData(); cache = new CacheConfig(conf).getBlockCache(); LOG.info("Block cache: " + cache.getClass().getName() + "Size=" + cache.getCurrentSize()); }
From source file:kiv.janecekz.ma.ToneFragment.java
@Override public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) { if (arg0.equals(input) && (arg1 == EditorInfo.IME_ACTION_DONE)) { boolean b = pl.setFreq(Float.parseFloat(((SpannableStringBuilder) arg0.getText()).toString())); if (!b) { arg0.setText(Float.toString(pl.getFreq())); } else {/*from www.jav a2 s . c o m*/ pl.togglePlay(); // FIXME: What if only push the enter? if (actualFreqView != null) { actualFreqView.setTextColor(getView().getResources().getColor(R.color.blue)); actualFreqView = null; } } } return true; }