com.google.common.primitives.Floats Java Examples

The following examples show how to use com.google.common.primitives.Floats. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TensorUtil.java    From jpmml-tensorflow with GNU Affero General Public License v3.0 7 votes vote down vote up
static
public List<?> getValues(Tensor tensor){
	DataType dataType = tensor.dataType();

	switch(dataType){
		case FLOAT:
			return Floats.asList(TensorUtil.toFloatArray(tensor));
		case DOUBLE:
			return Doubles.asList(TensorUtil.toDoubleArray(tensor));
		case INT32:
			return Ints.asList(TensorUtil.toIntArray(tensor));
		case INT64:
			return Longs.asList(TensorUtil.toLongArray(tensor));
		case STRING:
			return Arrays.asList(TensorUtil.toStringArray(tensor));
		case BOOL:
			return Booleans.asList(TensorUtil.toBooleanArray(tensor));
		default:
			throw new IllegalArgumentException();
	}
}
 
Example #2
Source File: NotQueryIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testNotEqualsByUnsignedFloat() throws Exception {
    String query = "SELECT a_unsigned_float -- and here comment\n" + 
    "FROM aTable WHERE organization_id=? and a_unsigned_float != 0.01d and a_unsigned_float <= 0.02d";
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, tenantId);
        ResultSet rs = statement.executeQuery();
        assertTrue (rs.next());
        assertTrue(Floats.compare(rs.getFloat(1), 0.02f) == 0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example #3
Source File: NumericArithmeticIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testScanByUnsignedFloatValue() throws Exception {
    String query = "SELECT a_string, b_string, a_unsigned_float FROM " + tableName + " WHERE ?=organization_id and ?=a_unsigned_float";
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, getOrganizationId());
        statement.setFloat(2, 0.01f);
        ResultSet rs = statement.executeQuery();
        assertTrue (rs.next());
        assertEquals(rs.getString(1), A_VALUE);
        assertEquals(rs.getString("B_string"), B_VALUE);
        assertTrue(Floats.compare(rs.getFloat(3), 0.01f) == 0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example #4
Source File: ByteFragmentUtilsTest.java    From clickhouse-jdbc with Apache License 2.0 6 votes vote down vote up
@Test(dataProvider = "floatArray")
public void testParseArray(float[] array) throws Exception {
    String sourceString = "[" + Joiner.on(",").join(Iterables.transform(Floats.asList(array), new Function<Float, String>() {
        @Override
        public String apply(Float s) {
            return s.toString();
        }
    })) + "]";

    byte[] bytes = sourceString.getBytes(StreamUtils.UTF_8);
    ByteFragment fragment = new ByteFragment(bytes, 0, bytes.length);
    float[] parsedArray = (float[]) ByteFragmentUtils.parseArray(fragment, Float.class, 1);

    assertEquals(parsedArray.length, array.length);
    for (int i = 0; i < parsedArray.length; i++) {
        assertEquals(parsedArray[i], array[i]);
    }
}
 
Example #5
Source File: NumericArithmeticIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testScanByFloatValue() throws Exception {
    String query = "SELECT a_string, b_string, a_float FROM " + tableName + " WHERE ?=organization_id and ?=a_float";
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, getOrganizationId());
        statement.setFloat(2, 0.01f);
        ResultSet rs = statement.executeQuery();
        assertTrue (rs.next());
        assertEquals(rs.getString(1), A_VALUE);
        assertEquals(rs.getString("B_string"), B_VALUE);
        assertTrue(Floats.compare(rs.getFloat(3), 0.01f) == 0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example #6
Source File: PolygonBound.java    From bytebuffer-collections with Apache License 2.0 6 votes vote down vote up
@Override
public byte[] getCacheKey()
{
  ByteBuffer abscissaBuffer = ByteBuffer.allocate(abscissa.length * Floats.BYTES);
  abscissaBuffer.asFloatBuffer().put(abscissa);
  final byte[] abscissaCacheKey = abscissaBuffer.array();

  ByteBuffer ordinateBuffer = ByteBuffer.allocate(ordinate.length * Floats.BYTES);
  ordinateBuffer.asFloatBuffer().put(ordinate);
  final byte[] ordinateCacheKey = ordinateBuffer.array();

  final ByteBuffer cacheKey = ByteBuffer
      .allocate(1 + abscissaCacheKey.length + ordinateCacheKey.length + Ints.BYTES)
      .put(abscissaCacheKey)
      .put(ordinateCacheKey)
      .putInt(getLimit())
      .put(CACHE_TYPE_ID);

  return cacheKey.array();
}
 
Example #7
Source File: NotQueryIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testNotEqualsByUnsignedFloat() throws Exception {
    String query = "SELECT a_unsigned_float -- and here comment\n" + 
    "FROM " + tableName + " WHERE organization_id=? and a_unsigned_float != 0.01 and a_unsigned_float <= 0.02";
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, tenantId);
        ResultSet rs = statement.executeQuery();
        assertTrue (rs.next());
        assertTrue(Floats.compare(rs.getFloat(1), 0.02f) == 0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example #8
Source File: RectangularBound.java    From bytebuffer-collections with Apache License 2.0 6 votes vote down vote up
@Override
public byte[] getCacheKey()
{
  ByteBuffer minCoordsBuffer = ByteBuffer.allocate(minCoords.length * Floats.BYTES);
  minCoordsBuffer.asFloatBuffer().put(minCoords);
  final byte[] minCoordsCacheKey = minCoordsBuffer.array();

  ByteBuffer maxCoordsBuffer = ByteBuffer.allocate(maxCoords.length * Floats.BYTES);
  maxCoordsBuffer.asFloatBuffer().put(maxCoords);
  final byte[] maxCoordsCacheKey = maxCoordsBuffer.array();

  final ByteBuffer cacheKey = ByteBuffer
      .allocate(1 + minCoordsCacheKey.length + maxCoordsCacheKey.length + Ints.BYTES)
      .put(minCoordsCacheKey)
      .put(maxCoordsCacheKey)
      .putInt(limit)
      .put(CACHE_TYPE_ID);
  return cacheKey.array();
}
 
Example #9
Source File: LengthDeserializer.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
private Length deserializeSingleElement(JsonElement json)
{
    if (json.isJsonPrimitive())
    {
        JsonPrimitive primitive = json.getAsJsonPrimitive();
        if (primitive.isString())
        {
            String value = primitive.getAsString();
            if (value.endsWith("%"))
            {
                value = value.substring(0, value.length() - 1);
                Float percentValue = Floats.tryParse(value);
                if (percentValue != null)
                    return relative(percentValue / 100f);
            }
        } else
        {
            return absolute(json.getAsInt());
        }
    }

    return Length.ZERO;
}
 
Example #10
Source File: JavaClassProcessor.java    From ArchUnit with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"}) // NOTE: We assume the component type matches the list
private Object toArray(Class<?> componentType, List<Object> values) {
    if (componentType == boolean.class) {
        return Booleans.toArray((Collection) values);
    } else if (componentType == byte.class) {
        return Bytes.toArray((Collection) values);
    } else if (componentType == short.class) {
        return Shorts.toArray((Collection) values);
    } else if (componentType == int.class) {
        return Ints.toArray((Collection) values);
    } else if (componentType == long.class) {
        return Longs.toArray((Collection) values);
    } else if (componentType == float.class) {
        return Floats.toArray((Collection) values);
    } else if (componentType == double.class) {
        return Doubles.toArray((Collection) values);
    } else if (componentType == char.class) {
        return Chars.toArray((Collection) values);
    }
    return values.toArray((Object[]) Array.newInstance(componentType, values.size()));
}
 
Example #11
Source File: LabelImageTensorflowOutputConverter.java    From tensorflow-spring-cloud-stream-app-starters with Apache License 2.0 6 votes vote down vote up
private List<Integer> topKProbabilities(final float[] labelProbabilities, int k) {

		List<Integer> list = new ArrayList<>(labelProbabilities.length);
		for (int i = 0; i < labelProbabilities.length; i++) {
			list.add(i);
		}

		List<Integer> topK = new Ordering<Integer>() {
			@Override
			public int compare(Integer left, Integer right) {
				return Floats.compare(labelProbabilities[left], labelProbabilities[right]);
			}
		}.greatestOf(list, k);

		return topK;
	}
 
Example #12
Source File: StaticUtil.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
public SimpleMvelFilter(long line, String column, Object simpleValue, Map<String, Object> variables, String expression) {
	this.line = line;
	this.column = column;
	this.value = simpleValue;
          this.condition = String.valueOf(value);
	this.variables = new HashMap<>(variables);
          this.variables.put(SIMPLE_VALUE_ARG, value);

          if((value instanceof Double && !Doubles.isFinite((Double)value))
                  || (value instanceof Float && !Floats.isFinite((Float)value))) {
              expression = SIMPLE_FLOAT_VALUE_EXPRESSION;
          }

          try {
              this.compiledCondition = compileExpression(expression);
          } catch(Exception e) {
              throw new MvelException(line, column, e);
   	}
}
 
Example #13
Source File: ImmutableNode.java    From bytebuffer-collections with Apache License 2.0 6 votes vote down vote up
public ImmutableNode(
    int numDims,
    int initialOffset,
    int offsetFromInitial,
    ByteBuffer data,
    BitmapFactory bitmapFactory
)
{
  this.bitmapFactory = bitmapFactory;
  this.numDims = numDims;
  this.initialOffset = initialOffset;
  this.offsetFromInitial = offsetFromInitial;
  short header = data.getShort(initialOffset + offsetFromInitial);
  this.isLeaf = (header & 0x8000) != 0;
  this.numChildren = (short) (header & 0x7FFF);
  final int sizePosition = initialOffset + offsetFromInitial + HEADER_NUM_BYTES + 2 * numDims * Floats.BYTES;
  int bitmapSize = data.getInt(sizePosition);
  this.childrenOffset = initialOffset
                        + offsetFromInitial
                        + HEADER_NUM_BYTES
                        + 2 * numDims * Floats.BYTES
                        + Ints.BYTES
                        + bitmapSize;

  this.data = data;
}
 
Example #14
Source File: EvaluationRequireBuilder.java    From junitperf with Apache License 2.0 6 votes vote down vote up
/**
 * 转换需求的 map
 * @param percentiles 百分比信息数组
 * @return map
 */
private Map<Integer, Float> parseRequirePercentilesMap(String[] percentiles) {
    Map<Integer, Float> percentilesMap = Maps.newHashMap();
    if(ArrayUtil.isNotEmpty(percentiles)) {
        try {
            for(String percent : percentiles) {
                String[] strings = percent.split(":");
                //消耗时间
                Integer left = Ints.tryParse(strings[0]);
                //百分比例
                Float right = Floats.tryParse(strings[1]);
                percentilesMap.put(left, right);
            }
        } catch (Exception e) {
            throw new IllegalArgumentException("Percentiles format is error! please like this: 80:50000.");
        }
    }

    return percentilesMap;
}
 
Example #15
Source File: Ideas_2011_08_01.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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;

}
 
Example #16
Source File: NotQueryIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testNotEqualsByFloat() throws Exception {
    String query = "SELECT a_float -- and here comment\n" + 
    "FROM aTable WHERE organization_id=? and a_float != 0.01d and a_float <= 0.02d";
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, tenantId);
        ResultSet rs = statement.executeQuery();
        assertTrue (rs.next());
        assertTrue(Floats.compare(rs.getFloat(1), 0.02f) == 0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example #17
Source File: ArithmeticQueryTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testSumUnsignedFloat() throws Exception {
    initSumDoubleValues(null);
    String query = "SELECT SUM(uf) FROM SumDoubleTest";
    Properties props = new Properties(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
    try {
        PreparedStatement statement = conn.prepareStatement(query);
        ResultSet rs = statement.executeQuery();
        assertTrue (rs.next());
        assertTrue(Floats.compare(rs.getFloat(1), 0.15f)==0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example #18
Source File: ArithmeticQueryTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testSumFloat() throws Exception {
    initSumDoubleValues(null);
    String query = "SELECT SUM(f) FROM SumDoubleTest";
    Properties props = new Properties(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
    try {
        PreparedStatement statement = conn.prepareStatement(query);
        ResultSet rs = statement.executeQuery();
        assertTrue (rs.next());
        assertTrue(Floats.compare(rs.getFloat(1), 0.15f)==0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example #19
Source File: QueryTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testNotEqualsByUnsignedFloat() throws Exception {
    String query = "SELECT a_unsigned_float -- and here comment\n" + 
    "FROM aTable WHERE organization_id=? and a_unsigned_float != 0.01d and a_unsigned_float <= 0.02d";
    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(Floats.compare(rs.getFloat(1), 0.02f) == 0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example #20
Source File: QueryTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testNotEqualsByFloat() throws Exception {
    String query = "SELECT a_float -- and here comment\n" + 
    "FROM aTable WHERE organization_id=? and a_float != 0.01d and a_float <= 0.02d";
    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(Floats.compare(rs.getFloat(1), 0.02f) == 0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example #21
Source File: ScanQueryIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testScanByFloatValue() throws Exception {
    String query = "SELECT a_string, b_string, a_float FROM aTable WHERE ?=organization_id and ?=a_float";
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, tenantId);
        statement.setFloat(2, 0.01f);
        ResultSet rs = statement.executeQuery();
        assertTrue (rs.next());
        assertEquals(rs.getString(1), A_VALUE);
        assertEquals(rs.getString("B_string"), B_VALUE);
        assertTrue(Floats.compare(rs.getFloat(3), 0.01f) == 0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example #22
Source File: ScanQueryIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testScanByUnsignedFloatValue() throws Exception {
    String query = "SELECT a_string, b_string, a_unsigned_float FROM aTable WHERE ?=organization_id and ?=a_unsigned_float";
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, tenantId);
        statement.setFloat(2, 0.01f);
        ResultSet rs = statement.executeQuery();
        assertTrue (rs.next());
        assertEquals(rs.getString(1), A_VALUE);
        assertEquals(rs.getString("B_string"), B_VALUE);
        assertTrue(Floats.compare(rs.getFloat(3), 0.01f) == 0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example #23
Source File: QueryTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testScanByUnsignedFloatValue() throws Exception {
    String query = "SELECT a_string, b_string, a_unsigned_float FROM aTable WHERE ?=organization_id and ?=a_unsigned_float";
    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);
        statement.setFloat(2, 0.01f);
        ResultSet rs = statement.executeQuery();
        assertTrue (rs.next());
        assertEquals(rs.getString(1), A_VALUE);
        assertEquals(rs.getString("B_string"), B_VALUE);
        assertTrue(Floats.compare(rs.getFloat(3), 0.01f) == 0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example #24
Source File: QueryTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testScanByFloatValue() throws Exception {
    String query = "SELECT a_string, b_string, a_float FROM aTable WHERE ?=organization_id and ?=a_float";
    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);
        statement.setFloat(2, 0.01f);
        ResultSet rs = statement.executeQuery();
        assertTrue (rs.next());
        assertEquals(rs.getString(1), A_VALUE);
        assertEquals(rs.getString("B_string"), B_VALUE);
        assertTrue(Floats.compare(rs.getFloat(3), 0.01f) == 0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example #25
Source File: NotQueryIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testNotEqualsByFloat() throws Exception {
    String query = "SELECT a_float -- and here comment\n" + 
    "FROM " + tableName + " WHERE organization_id=? and a_float != CAST(0.01 AS FLOAT) and a_float <= CAST(0.02 AS FLOAT)";
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, tenantId);
        ResultSet rs = statement.executeQuery();
        assertTrue (rs.next());
        assertTrue(Floats.compare(rs.getFloat(1), 0.02f) == 0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example #26
Source File: ArithmeticQueryIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testSumFloat() throws Exception {
    initSumDoubleValues(null, getUrl());
    String query = "SELECT SUM(f) FROM SumDoubleTest";
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {
        PreparedStatement statement = conn.prepareStatement(query);
        ResultSet rs = statement.executeQuery();
        assertTrue (rs.next());
        assertTrue(Floats.compare(rs.getFloat(1), 0.15f)==0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example #27
Source File: ArithmeticQueryIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testSumUnsignedFloat() throws Exception {
    initSumDoubleValues(null, getUrl());
    String query = "SELECT SUM(uf) FROM SumDoubleTest";
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {
        PreparedStatement statement = conn.prepareStatement(query);
        ResultSet rs = statement.executeQuery();
        assertTrue (rs.next());
        assertTrue(Floats.compare(rs.getFloat(1), 0.15f)==0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example #28
Source File: SmartUriAdapter.java    From rya with Apache License 2.0 6 votes vote down vote up
private static IRI determineType(final String data) {
    if (Ints.tryParse(data) != null) {
        return XMLSchema.INTEGER;
    } else if (Doubles.tryParse(data) != null) {
        return XMLSchema.DOUBLE;
    } else if (Floats.tryParse(data) != null) {
        return XMLSchema.FLOAT;
    } else if (isShort(data)) {
        return XMLSchema.SHORT;
    } else if (Longs.tryParse(data) != null) {
        return XMLSchema.LONG;
    } if (Boolean.parseBoolean(data)) {
        return XMLSchema.BOOLEAN;
    } else if (isByte(data)) {
        return XMLSchema.BYTE;
    } else if (isDate(data)) {
        return XMLSchema.DATETIME;
    } else if (isUri(data)) {
        return XMLSchema.ANYURI;
    }

    return XMLSchema.STRING;
}
 
Example #29
Source File: ArithmeticQueryIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testSumFloat() throws Exception {
    String tableName = "TBL_" + generateUniqueName();
    initSumDoubleValues(tableName, null, getUrl());
    String query = "SELECT SUM(f) FROM " + tableName ;
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {
        PreparedStatement statement = conn.prepareStatement(query);
        ResultSet rs = statement.executeQuery();
        assertTrue (rs.next());
        assertTrue(Floats.compare(rs.getFloat(1), 0.15f)==0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example #30
Source File: ArithmeticQueryIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testSumUnsignedFloat() throws Exception {
    String tableName = "TBL_" + generateUniqueName();
    initSumDoubleValues(tableName, null, getUrl());
    String query = "SELECT SUM(uf) FROM " + tableName;
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {
        PreparedStatement statement = conn.prepareStatement(query);
        ResultSet rs = statement.executeQuery();
        assertTrue (rs.next());
        assertTrue(Floats.compare(rs.getFloat(1), 0.15f)==0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}