public static long unboxed(Long v) { return v == null ? 0 : v.longValue(); }
public static long unboxed(Long v) { return v == null ? 0 : v.longValue(); }
private long objectToKey(Object key) { return (long) ((Long) key).longValue(); }
@Override public ReadableInstant convert(Long source) { return new DateTime(source.longValue()); } }
/** * Removes and returns the value associated with {@code key}. If {@code key} is not in the map, * this method has no effect and returns zero. */ @CanIgnoreReturnValue public long remove(K key) { Long result = map.remove(key); return (result == null) ? 0L : result.longValue(); }
public long getLongProperty(String name) throws JMSException { Object value = this.properties.get(name); return (value instanceof Long) ? ((Long) value).longValue() : 0; }
/** * Updates the value currently associated with {@code key} with the specified function, and * returns the new value. If there is not currently a value associated with {@code key}, the * function is applied to {@code 0L}. * * @since 21.0 */ @CanIgnoreReturnValue public long updateAndGet(K key, LongUnaryOperator updaterFunction) { checkNotNull(updaterFunction); return map.compute( key, (k, value) -> updaterFunction.applyAsLong((value == null) ? 0L : value.longValue())); }
@Test public void defaultRefreshCheckDelay() throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG); Advised advised = (Advised) context.getBean("testBean"); AbstractRefreshableTargetSource targetSource = ((AbstractRefreshableTargetSource) advised.getTargetSource()); Field field = AbstractRefreshableTargetSource.class.getDeclaredField("refreshCheckDelay"); field.setAccessible(true); long delay = ((Long) field.get(targetSource)).longValue(); assertEquals(5000L, delay); }
private void assertNegativeLongEquals(String aLong) { assertEquals("Long did not parse", Long.MIN_VALUE, NumberUtils.parseNumber(aLong, Long.class).longValue()); }
private void assertLongEquals(String aLong) { assertEquals("Long did not parse", Long.MAX_VALUE, NumberUtils.parseNumber(aLong, Long.class).longValue()); }
@Test public void testQueryForLong() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getLong(1)).willReturn(87L); long l = this.template.queryForObject(sql, Long.class).longValue(); assertEquals("Return of a long", 87, l); verify(this.resultSet).close(); verify(this.statement).close(); }
@Test public void testQueryForLongWithArgs() throws Exception { String sql = "SELECT AGE FROM CUSTMR WHERE ID = ?"; given(this.resultSet.next()).willReturn(true, false); given(this.resultSet.getLong(1)).willReturn(87L); long l = this.template.queryForObject(sql, new Object[] {3}, Long.class).longValue(); assertEquals("Return of a long", 87, l); verify(this.preparedStatement).setObject(1, 3); verify(this.resultSet).close(); verify(this.preparedStatement).close(); }
@Test public void testQueryForLongWithParamBeanWithCollection() throws Exception { given(resultSet.getMetaData()).willReturn(resultSetMetaData); given(resultSet.next()).willReturn(true, false); given(resultSet.getLong(1)).willReturn(87L); BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(new ParameterCollectionBean(3, 5)); long l = template.queryForObject("SELECT AGE FROM CUSTMR WHERE ID IN (:ids)", params, Long.class).longValue(); assertEquals("Return of a long", 87, l); verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID IN (?, ?)"); verify(preparedStatement).setObject(1, 3); verify(preparedStatement).setObject(2, 5); }
@Test public void testQueryForLongWithParamBean() throws Exception { given(resultSet.getMetaData()).willReturn(resultSetMetaData); given(resultSet.next()).willReturn(true, false); given(resultSet.getLong(1)).willReturn(87L); BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(new ParameterBean(3)); long l = template.queryForObject("SELECT AGE FROM CUSTMR WHERE ID = :id", params, Long.class).longValue(); assertEquals("Return of a long", 87, l); verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?"); verify(preparedStatement).setObject(1, 3, Types.INTEGER); }
public void testGetDefaultValue() { assertEquals(false, Defaults.defaultValue(boolean.class).booleanValue()); assertEquals('\0', Defaults.defaultValue(char.class).charValue()); assertEquals(0, Defaults.defaultValue(byte.class).byteValue()); assertEquals(0, Defaults.defaultValue(short.class).shortValue()); assertEquals(0, Defaults.defaultValue(int.class).intValue()); assertEquals(0, Defaults.defaultValue(long.class).longValue()); assertEquals(0.0f, Defaults.defaultValue(float.class).floatValue()); assertEquals(0.0d, Defaults.defaultValue(double.class).doubleValue()); assertNull(Defaults.defaultValue(void.class)); assertNull(Defaults.defaultValue(String.class)); } }
public void testParse_maximumSize() { CacheBuilderSpec spec = parse("maximumSize=9000"); assertNull(spec.initialCapacity); assertEquals(9000, spec.maximumSize.longValue()); assertNull(spec.concurrencyLevel); assertNull(spec.keyStrength); assertNull(spec.valueStrength); assertNull(spec.writeExpirationTimeUnit); assertNull(spec.accessExpirationTimeUnit); assertCacheBuilderEquivalence( CacheBuilder.newBuilder().maximumSize(9000), CacheBuilder.from(spec)); }
public void testTryParse_radix() { for (int radix = Character.MIN_RADIX; radix <= Character.MAX_RADIX; radix++) { radixEncodeParseAndAssertEquals((long) 0, radix); radixEncodeParseAndAssertEquals((long) 8000, radix); radixEncodeParseAndAssertEquals((long) -8000, radix); radixEncodeParseAndAssertEquals(MAX_VALUE, radix); radixEncodeParseAndAssertEquals(MIN_VALUE, radix); assertNull("Radix: " + radix, Longs.tryParse("999999999999999999999999", radix)); assertNull( "Radix: " + radix, Longs.tryParse(BigInteger.valueOf(MAX_VALUE).add(BigInteger.ONE).toString(), radix)); assertNull( "Radix: " + radix, Longs.tryParse(BigInteger.valueOf(MIN_VALUE).subtract(BigInteger.ONE).toString(), radix)); } assertNull("Hex string and dec parm", Longs.tryParse("FFFF", 10)); assertEquals("Mixed hex case", 65535, Longs.tryParse("ffFF", 16).longValue()); }
public void testParse_maximumWeight() { CacheBuilderSpec spec = parse("maximumWeight=9000"); assertNull(spec.initialCapacity); assertEquals(9000, spec.maximumWeight.longValue()); assertNull(spec.concurrencyLevel); assertNull(spec.keyStrength); assertNull(spec.valueStrength); assertNull(spec.writeExpirationTimeUnit); assertNull(spec.accessExpirationTimeUnit); assertCacheBuilderEquivalence( CacheBuilder.newBuilder().maximumWeight(9000), CacheBuilder.from(spec)); }