Refine search
@Override public int compare(int a, int b) { return Doubles.compare(values[a], values[b]); } }, new Swapper()
public void testAsList_subList_toArray_roundTrip() { double[] array = {(double) 0, (double) 1, (double) 2, (double) 3}; List<Double> list = Doubles.asList(array); assertTrue( Arrays.equals(new double[] {(double) 1, (double) 2}, Doubles.toArray(list.subList(1, 3)))); assertTrue(Arrays.equals(new double[] {}, Doubles.toArray(list.subList(2, 2)))); }
@Override public int hashCode() { int result = 1; for (int i = start; i < end; i++) { result = 31 * result + Doubles.hashCode(array[i]); } return result; }
@Test public void testNotEqualsByUnsignedDouble() throws Exception { String query = "SELECT a_unsigned_double -- and here comment\n" + "FROM aTable WHERE organization_id=? and a_unsigned_double != 0.0001d and a_unsigned_double <= 0.0002d"; Properties props = new Properties(TEST_PROPERTIES); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props); try { PreparedStatement statement = conn.prepareStatement(query); statement.setString(1, tenantId); ResultSet rs = statement.executeQuery(); assertTrue (rs.next()); assertTrue(Doubles.compare(rs.getDouble(1), 0.0002) == 0); assertFalse(rs.next()); } finally { conn.close(); } }
@Test public void testFloorDouble() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); ResultSet rs = conn.createStatement().executeQuery( "SELECT FLOOR(doub), FLOOR(doub, 1), FLOOR(doub, 2), FLOOR(doub, 3) FROM " + tableName); assertTrue(rs.next()); assertEquals(0, Doubles.compare(1, rs.getDouble(1))); assertEquals(0, Doubles.compare(1.2, rs.getDouble(2))); assertEquals(0, Doubles.compare(1.26, rs.getDouble(3))); assertEquals(0, Doubles.compare(1.264, rs.getDouble(4))); }
@ExpectWarning(value="RV_CHECK_COMPARETO_FOR_SPECIFIC_RETURN_VALUE", num = 9) public static int testGuavaPrimitiveCompareCalls() { int count = 0; if (Booleans.compare(false, true) == -1) count++; if (Chars.compare('a', 'b') == -1) count++; if (Doubles.compare(1, 2) == -1) count++; if (Floats.compare(1, 2) == -1) count++; if (Ints.compare(1, 2) == -1) count++; if (Longs.compare(1, 2) == -1) count++; if (Shorts.compare((short) 1, (short) 2) == -1) count++; if (SignedBytes.compare((byte) 1, (byte) 2) == -1) count++; if (UnsignedBytes.compare((byte) 1, (byte) 2) == -1) count++; return count; }
private static List<?> primitiveArrayToList(Object obj) { if (obj instanceof boolean[]) { return Booleans.asList((boolean[])obj); } else if (obj instanceof char[]) { return Chars.asList((char[])obj); } else if (obj instanceof byte[]) { return Bytes.asList((byte[])obj); } else if (obj instanceof short[]) { return Shorts.asList((short[])obj); } else if (obj instanceof int[]) { return Ints.asList((int[])obj); } else if (obj instanceof long[]) { return Longs.asList((long[])obj); } else if (obj instanceof float[]) { return Floats.asList((float[])obj); } else if (obj instanceof double[]) { return Doubles.asList((double[])obj); } return Collections.<Object>emptyList(); }
/** * This method converts this FunctionProperties instance to FlatBuffers representation * @param bufferBuilder * @return */ public int asFlatProperties(FlatBufferBuilder bufferBuilder) { int iname = bufferBuilder.createString(name); int ii = FlatProperties.createIVector(bufferBuilder, Ints.toArray(i)); int il = FlatProperties.createLVector(bufferBuilder, Longs.toArray(l)); int id = FlatProperties.createDVector(bufferBuilder, Doubles.toArray(d)); int arrays[] = new int[a.size()]; int cnt = 0; for (val array: a) { int off = array.toFlatArray(bufferBuilder); arrays[cnt++] = off; } int ia = FlatProperties.createAVector(bufferBuilder, arrays); return FlatProperties.createFlatProperties(bufferBuilder, iname, ii, il, id, ia); }
return Longs.compare(n, value.longValue()); } else if (value instanceof Double || value instanceof Float) { return compareDoubleToLong(n, value.longValue()); } else if (value instanceof Double || value instanceof Float) { return Doubles.compare(n, value.doubleValue()); } else { throw new ISE("Number was[%s]?!?", value.getClass().getName());
/** * Attempts to convert the provided string value to a numeric type, * trying Integer, Long and Double in order until successful. */ @Override public Object convert(String value) { if (value == null || value.isEmpty()) { return value; } Object result = Ints.tryParse(value); if (result != null) { return result; } result = Longs.tryParse(value); if (result != null) { return result; } result = Doubles.tryParse(value); if (result != null) { return result; } return value; }
@AndroidIncompatible // slow public void testPercentiles_indexes_varargsAll_computeInPlace() { double[] dataset = Doubles.toArray(PSEUDORANDOM_DATASET); List<Integer> indexes = new ArrayList<>(); ImmutableMap.Builder<Integer, Double> expectedBuilder = ImmutableMap.builder(); for (int index = 0; index <= 100; index++) { indexes.add(index); expectedBuilder.put(index, expectedLargeDatasetPercentile(index)); } Random random = new Random(770683168895677741L); Collections.shuffle(indexes, random); assertThat(percentiles().indexes(Ints.toArray(indexes)).computeInPlace(dataset)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactlyEntriesIn(expectedBuilder.build()); assertThat(dataset).usingExactEquality().containsExactlyElementsIn(PSEUDORANDOM_DATASET); }
aggregations.add(new Pair<>( QueryRunnerTestHelper.rowsCount, Longs.asList(186L, 186L, 837L) )); Pair<AggregatorFactory, List<?>> indexAggregation = new Pair<>( QueryRunnerTestHelper.indexDoubleSum, Doubles.asList(215679.82879638672D, 192046.1060180664D, 95606.57232284546D) ); aggregations.add(indexAggregation); aggregations.add(new Pair<>( QueryRunnerTestHelper.qualityUniques, Doubles.asList(QueryRunnerTestHelper.UNIQUES_2, QueryRunnerTestHelper.UNIQUES_2, QueryRunnerTestHelper.UNIQUES_9) )); aggregations.add(new Pair<>( new DoubleMaxAggregatorFactory("maxIndex", "index"), Doubles.asList(1743.92175D, 1870.061029D, 277.273533D) )); aggregations.add(new Pair<>( new DoubleMinAggregatorFactory("minIndex", "index"), Doubles.asList(792.3260498046875D, 545.9906005859375D, 59.02102279663086D) )); aggregations.add(new Pair<>( new LongSumAggregatorFactory("qlLong", "qualityLong"), Longs.asList(279000L, 279000L, 1171800L) )); aggregations.add(new Pair<>( new DoubleSumAggregatorFactory("qlFloat", "qualityLong"), Doubles.asList(279000.0, 279000.0, 1171800.0) ));
/** * Coerce the supplied object to an integer, parse it if necessary. * * @param obj Object to coerce * @return Object as an integer, <code>0</code> if the object is null or * cannot be parsed */ public static int toInteger(@Nullable Object obj) { if (obj == null) { return 0; } if (obj instanceof Number) { return ((Number)obj).intValue(); } String strObj = Coerce.sanitiseNumber(obj); Integer iParsed = Ints.tryParse(strObj); if (iParsed != null) { return iParsed; } Double dParsed = Doubles.tryParse(strObj); return dParsed != null ? dParsed.intValue() : 0; }
/** * Computes the quantile value of the given dataset. * * @param dataset the dataset to do the calculation on, which must be non-empty, which will be * cast to doubles (with any associated lost of precision), and which will not be mutated by * this call (it is copied instead) * @return the quantile value */ public double compute(Collection<? extends Number> dataset) { return computeInPlace(Doubles.toArray(dataset)); }
private static List<Double> asList(Double[] values) { double[] temp = new double[values.length]; for (int i = 0; i < values.length; i++) { temp[i] = checkNotNull(values[i]); // checkNotNull for GWT (do not optimize). } return Doubles.asList(temp); }
/** * Computes a hash code from attributes: {@code transactionName}, {@code totalDurationNanos}, {@code transactionCount}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + transactionName.hashCode(); h += (h << 5) + Doubles.hashCode(totalDurationNanos); h += (h << 5) + Longs.hashCode(transactionCount); return h; }
private void initDoublePredicate() { if (druidDoublePredicate != null) { return; } synchronized (initLock) { if (druidDoublePredicate != null) { return; } if (value == null) { druidDoublePredicate = DruidDoublePredicate.MATCH_NULL_ONLY; return; } final Double aDouble = Doubles.tryParse(value); if (aDouble == null) { druidDoublePredicate = DruidDoublePredicate.ALWAYS_FALSE; } else { final long bits = Double.doubleToLongBits(aDouble); druidDoublePredicate = input -> Double.doubleToLongBits(input) == bits; } } } }
/** * Returns the index of the first appearance of the value {@code target} in {@code array}. Note * that this always returns {@code -1} when {@code target} is {@code NaN}. * * @param array an array of {@code double} values, possibly empty * @param target a primitive {@code double} value * @return the least index {@code i} for which {@code array[i] == target}, or {@code -1} if no * such index exists. */ public static int indexOf(double[] array, double target) { return indexOf(array, target, 0, array.length); }