List of usage examples for java.lang Double longBitsToDouble
@HotSpotIntrinsicCandidate public static native double longBitsToDouble(long bits);
From source file:net.opentsdb.core.TsdbQuery.java
public static double getDoubleFromBytes(byte[] byteValues) { long tmpLongValue = getLongFromBytes(byteValues); return Double.longBitsToDouble(tmpLongValue); }
From source file:org.apache.hadoop.hive.serde2.lazybinary.fast.LazyBinaryDeserializeRead.java
@Override public double readDouble() throws IOException { // Last item -- ok to be at end. if (offset + 8 > end) { warnBeyondEof();/*from w ww . j a va 2 s. c o m*/ } double result = Double.longBitsToDouble(LazyBinaryUtils.byteArrayToLong(bytes, offset)); offset += 8; // Move past this NOT NULL field. fieldIndex++; // Every 8 fields we read a new NULL byte. if (fieldIndex < fieldCount) { if ((fieldIndex % 8) == 0) { // Get next null byte. if (offset >= end) { warnBeyondEof(); } nullByte = bytes[offset++]; } } return result; }
From source file:haven.Utils.java
public static double float64d(byte[] buf, int off) { return (Double.longBitsToDouble(int64d(buf, off))); }
From source file:net.gsantner.opoc.preference.SharedPreferencesPropertyBackend.java
public double getDouble(String key, double defaultValue, final SharedPreferences... pref) { return Double.longBitsToDouble(getLong(key, Double.doubleToRawLongBits(defaultValue), gp(pref))); }
From source file:org.apache.tajo.storage.v2.ScheduledInputStream.java
@Override public double readDouble() throws IOException { return Double.longBitsToDouble(readLong()); }
From source file:com.idylwood.utils.MathUtils.java
public static final double abs(final double d) { return Double.longBitsToDouble(Long.MAX_VALUE & Double.doubleToRawLongBits(d)); }
From source file:it.geosolutions.geocollect.android.core.mission.utils.SQLiteCascadeFeatureLoader.java
@Override public List<MissionFeature> loadInBackground() { if (this.db == null || this.db.dbversion().equals("unknown")) { Log.w(TAG, "Cannot open DB"); return null; }/*from w ww . j a va2 s.c o m*/ if (this.sourceTableName == null || this.sourceTableName.isEmpty()) { Log.w(TAG, "Table Name is empty"); return null; } // Default, reload anyway boolean reload = true; if (mPrefs != null) { // this must now specify a table, otherwise it blocks loading data for other tables long millis = mPrefs.getLong(LAST_UPDATE_PREF, 0L); if (millis > 0) { Date currentDate = new Date(); if (currentDate.getTime() - millis < UPDATE_THRESHOLD) { // Disable reload when too early Log.v(TAG, "Data is already updated"); reload = false; } } } if (this.pre_loader != null && reload) { List<Feature> fromPreLoader = this.pre_loader.loadInBackground(); if (fromPreLoader != null) { // TODO: load only paginated rows // TODO: truncate only paginated rows try { Stmt stmt = db.prepare("DELETE FROM '" + sourceTableName + "';"); stmt.step(); stmt.close(); } catch (jsqlite.Exception e) { Log.e(TAG, Log.getStackTraceString(e)); } if (!fromPreLoader.isEmpty()) { // Get the list of the fields HashMap<String, String> dbFieldValues = SpatialiteUtils.getPropertiesFields(db, sourceTableName); if (dbFieldValues != null) { Stmt stmt; String converted; long startTime = System.nanoTime(); StringBuilder columnNames = new StringBuilder(300); StringBuilder columnValues = new StringBuilder(300); columnNames.append(" ( ").append(Mission.ORIGIN_ID_STRING); columnValues.append(" ( ").append("'"); int namesToTruncate = columnNames.length(); int valuesToTruncate = columnValues.length(); long featureStartTime; long queryTime; long prefStartTime; long stopTime; StringBuilder loggerBuilder = new StringBuilder(300); for (Feature f : fromPreLoader) { featureStartTime = System.nanoTime(); columnValues.append(f.id).append("'"); for (Entry<String, String> e : dbFieldValues.entrySet()) { //Log.v(TAG, "Got -> "+e.getKey()+" : "+e.getValue()); converted = SpatialiteUtils.getSQLiteTypeFromString(e.getValue()); if (converted.equals("point") && f.geometry != null) { columnNames.append(", GEOMETRY"); // In JTS Point getX = longitude, getY = latitude columnValues.append(", MakePoint(").append(((Point) f.geometry).getX()) .append(",").append(((Point) f.geometry).getY()).append(", 4326)"); } else if (f.properties.containsKey(e.getKey()) && converted != null && f.properties.get(e.getKey()) != null) { columnNames.append(", ").append(e.getKey()); if (converted.equals("text") || converted.equals("blob") || !isNumeric(String.valueOf(f.properties.get(e.getKey())))) { columnValues.append(", '") .append(SpatialiteUtils .escape((String) f.properties.get(e.getKey()))) .append("' "); } else { columnValues.append(", ").append(f.properties.get(e.getKey())); } } } // add the geometry columnNames.append(" )"); columnValues.append(" )"); // TODO: Use prepared statements and group all the insert queries into a transaction for insertion speedup // This will need to get the schema beforehand, based on the JSON features String insertQuery = "INSERT INTO '" + sourceTableName + "' " + columnNames.toString() + " VALUES " + columnValues.toString() + ";"; queryTime = System.nanoTime(); if (BuildConfig.DEBUG) { loggerBuilder.append("Query created in: ") .append((queryTime - featureStartTime) / 1000000).append("ms\n"); } columnNames.setLength(namesToTruncate); columnValues.setLength(valuesToTruncate); try { stmt = db.prepare(insertQuery); long prepareTime = System.nanoTime(); if (BuildConfig.DEBUG) { loggerBuilder.append("Query prepared in: ") .append((prepareTime - queryTime) / 1000000).append("ms\n"); } stmt.step(); stmt.close(); long featureStopTime = System.nanoTime(); if (BuildConfig.DEBUG) { loggerBuilder.append("Feature inserted in: ") .append((featureStopTime - prepareTime) / 1000000).append("ms\n"); } } catch (Exception e1) { if (BuildConfig.DEBUG) { Log.e(TAG, Log.getStackTraceString(e1)); } } finally { if (BuildConfig.DEBUG) { Log.d(TAG, loggerBuilder.toString()); loggerBuilder.setLength(0); } } } prefStartTime = System.nanoTime(); // Update the "last update" time to prevent unnecessary downloads if (mPrefs != null) { SharedPreferences.Editor editor = mPrefs.edit(); Date currentDate = new Date(); editor.putLong(LAST_UPDATE_PREF, currentDate.getTime()); editor.commit(); } stopTime = System.nanoTime(); if (BuildConfig.DEBUG) { Log.d(TAG, "Pref updated in: " + (stopTime - prefStartTime) / 1000000 + "ms"); Log.d(TAG, "Database updated in: " + (stopTime - startTime) / 1000000 + "ms"); } } } //mData = fromPreLoader; } else { // error in the loader (no connectivity) } } // TODO: Load data into mData // Get the list of the fields // TODO: Can this call be done before the pre_loader block? // Are there any concurrent events that can modify the table schema before we read the data? HashMap<String, String> dbFieldValues = SpatialiteUtils.getPropertiesFields(db, sourceTableName); mData = new ArrayList<MissionFeature>(); // Reader for the Geometry field WKBReader wkbReader = new WKBReader(); if (dbFieldValues != null) { String converted; boolean hasGeometry = false; String columnNames = "SELECT ROWID "; // This is an SQLite standard column String filterString = ""; String orderString = ""; for (Entry<String, String> e : dbFieldValues.entrySet()) { //Log.v(TAG, "Got -> "+e.getKey()+" : "+e.getValue()); converted = SpatialiteUtils.getSQLiteTypeFromString(e.getValue()); if (converted != null) { if (converted.equals("point")) { // Only Points are supported columnNames = columnNames + ", ST_AsBinary(CastToXY(" + e.getKey() + ")) AS 'GEOMETRY'"; hasGeometry = true; } else { columnNames = columnNames + ", " + e.getKey(); } } } //Add Spatial filtering if (hasGeometry) { int filterSrid = mPrefs.getInt(FILTER_SRID, -1); // If the SRID is not defined, skip the filter if (filterSrid != -1) { double filterN = Double.longBitsToDouble(mPrefs.getLong(FILTER_N, Double.doubleToLongBits(0))); double filterS = Double.longBitsToDouble(mPrefs.getLong(FILTER_S, Double.doubleToLongBits(0))); double filterW = Double.longBitsToDouble(mPrefs.getLong(FILTER_W, Double.doubleToLongBits(0))); double filterE = Double.longBitsToDouble(mPrefs.getLong(FILTER_E, Double.doubleToLongBits(0))); filterString = " WHERE MbrIntersects(GEOMETRY, BuildMbr(" + filterW + ", " + filterN + ", " + filterE + ", " + filterS + ")) "; } //WHERE MbrIntersects(GEOMETRY, BuildMbr(8.75269101373853, 44.505790969141614, 9.039467060007173, 44.35415617743291)) } // TODO: Should the orderingField be mandatory to have the ordering? if (orderingField != null && !orderingField.isEmpty()) { boolean reverse = mPrefs.getBoolean(REVERSE_ORDER_PREF, false); boolean useDistance = mPrefs.getBoolean(ORDER_BY_DISTANCE, false); double posX = Double.longBitsToDouble(mPrefs.getLong(LOCATION_X, Double.doubleToLongBits(0))); double posY = Double.longBitsToDouble(mPrefs.getLong(LOCATION_Y, Double.doubleToLongBits(0))); if (useDistance) { columnNames = columnNames + ", Distance(ST_Transform(GEOMETRY,4326), MakePoint(" + posX + "," + posY + ", 4326)) * 111195 AS '" + MissionFeature.DISTANCE_VALUE_ALIAS + "'"; orderString = "ORDER BY " + MissionFeature.DISTANCE_VALUE_ALIAS; } else { orderString = "ORDER BY " + orderingField; } if (reverse) { orderString = orderString + " DESC"; } } String finalQuery = columnNames + " FROM '" + sourceTableName + "' " + filterString + " " + orderString + ";"; Log.v(TAG, finalQuery); loadMissionFeature(wkbReader, sourceTableName, finalQuery); } // Set the "Editing flag" if (formTableName != null && !formTableName.isEmpty()) { ArrayList<String> editingIds = new ArrayList<String>(); String query = "SELECT " + Mission.ORIGIN_ID_STRING + " FROM '" + formTableName + "';"; if (Database.complete(query)) { try { Stmt stmt = db.prepare(query); while (stmt.step()) { editingIds.add(stmt.column_string(0)); } stmt.close(); } catch (jsqlite.Exception e) { Log.e(TAG, Log.getStackTraceString(e)); } } else { if (BuildConfig.DEBUG) { Log.w(TAG, "Query is not complete: " + query); } } if (!editingIds.isEmpty()) { for (MissionFeature f : mData) { if (editingIds.contains(MissionUtils.getFeatureGCID(f))) { f.editing = true; } } } } /////////////////////// // Add the NEW items /////////////////////// Log.v(TAG, "Loading created missions from " + sourceTableName + MissionTemplate.NEW_NOTICE_SUFFIX); final ArrayList<MissionFeature> missions = MissionUtils .getMissionFeatures(sourceTableName + MissionTemplate.NEW_NOTICE_SUFFIX, db, getContext()); mData.addAll(missions); if (orderingField != null && !orderingField.isEmpty()) { boolean reverse = mPrefs.getBoolean(REVERSE_ORDER_PREF, false); boolean useDistance = mPrefs.getBoolean(ORDER_BY_DISTANCE, false); boolean preferEdited = mPrefs.getBoolean(PREFER_EDITED, false); Collections.sort(mData, new MissionFeatureSorter(orderingField, preferEdited, useDistance, reverse)); if (reverse) { Collections.reverse(mData); } } /////////////////////// // Icon Color if (priorityField != null && !priorityField.isEmpty() && priorityColours != null && !priorityColours.isEmpty()) { for (MissionFeature f : mData) { if (f.properties.containsKey(priorityField)) { f.displayColor = priorityColours.get(f.properties.get(priorityField)); } } } return mData; }
From source file:org.apache.lucene.index.FieldsReader.java
private NumericField loadNumericField(FieldInfo fi, int numeric) throws IOException { assert numeric != 0; switch (numeric) { case FieldsWriter.FIELD_IS_NUMERIC_INT: return new NumericField(fi.name, Field.Store.YES, fi.isIndexed).setIntValue(fieldsStream.readVVInt()); case FieldsWriter.FIELD_IS_NUMERIC_LONG: return new NumericField(fi.name, Field.Store.YES, fi.isIndexed).setLongValue(fieldsStream.readVVLong()); case FieldsWriter.FIELD_IS_NUMERIC_FLOAT: return new NumericField(fi.name, Field.Store.YES, fi.isIndexed) .setFloatValue(Float.intBitsToFloat(fieldsStream.readVVVInt())); case FieldsWriter.FIELD_IS_NUMERIC_DOUBLE: return new NumericField(fi.name, Field.Store.YES, fi.isIndexed) .setDoubleValue(Double.longBitsToDouble(fieldsStream.readVVVLong())); default:/*from ww w. j a v a 2 s . co m*/ throw new FieldReaderException("Invalid numeric type: " + Integer.toHexString(numeric)); } }
From source file:dk.statsbiblioteket.util.LineReader.java
@Override public double readDouble() throws IOException { return Double.longBitsToDouble(readInt()); }
From source file:fr.cs.examples.bodies.DEFile.java
/** Extract a double from a record. * <p>Double numbers are stored according to IEEE 754 standard, with * most significant byte first.</p> * @param record record to parse// w ww .ja v a2s . co m * @param offset offset of the double within the record * @param bigEndian if <code>true</code> the parsed double is extracted in big-endian * format, otherwise it is extracted in little-endian format * @return extracted double */ private static double extractDouble(final byte[] record, final int offset, final boolean bigEndian) { final long l8 = ((long) record[offset + 0]) & 0xffl; final long l7 = ((long) record[offset + 1]) & 0xffl; final long l6 = ((long) record[offset + 2]) & 0xffl; final long l5 = ((long) record[offset + 3]) & 0xffl; final long l4 = ((long) record[offset + 4]) & 0xffl; final long l3 = ((long) record[offset + 5]) & 0xffl; final long l2 = ((long) record[offset + 6]) & 0xffl; final long l1 = ((long) record[offset + 7]) & 0xffl; long l; if (bigEndian) { l = (l8 << 56) | (l7 << 48) | (l6 << 40) | (l5 << 32) | (l4 << 24) | (l3 << 16) | (l2 << 8) | l1; } else { l = (l1 << 56) | (l2 << 48) | (l3 << 40) | (l4 << 32) | (l5 << 24) | (l6 << 16) | (l7 << 8) | l8; } return Double.longBitsToDouble(l); }