本文整理了Java中org.apache.sis.util.Numbers.wrap()
方法的一些代码示例,展示了Numbers.wrap()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Numbers.wrap()
方法的具体详情如下:
包路径:org.apache.sis.util.Numbers
类名称:Numbers
方法名:wrap
[英]Wraps the given floating-point value in a Number of the specified class. The given type shall be one of Byte, Short, Integer, Long, Float, Double, BigInteger and BigDecimal classes. Furthermore, the given value shall be convertible to the given class without precision lost, otherwise an IllegalArgumentException will be thrown.
[中]将给定的浮点值包装在指定类的数字中。给定的类型应为字节、短、整数、长、浮点、双精度、大整数和大十进制类之一。此外,给定的值应可转换为给定的类,而不会丢失精度,否则将抛出IllegalArgumentException。
代码示例来源:origin: org.apache.sis.core/sis-utility
/** Returns the increment between all consecutive values */
@Override public Number increment(final double tolerance) {
return Numbers.wrap(increment, type);
}
代码示例来源:origin: org.apache.sis.core/sis-utility
/** Returns the increment between all consecutive values */
@Override public Number increment(final double tolerance) {
return Numbers.wrap(increment, type);
}
代码示例来源:origin: apache/sis
/** Returns the increment between all consecutive values */
@Override public Number increment(final double tolerance) {
return Numbers.wrap(increment, type);
}
代码示例来源:origin: org.apache.sis.core/sis-utility
/** Computes the minimal and maximal values in this vector. */
@SuppressWarnings({"unchecked","rawtypes"})
@Override public NumberRange<?> range() {
double min = first;
double max = first + increment * (length - 1);
if (max < min) {
min = max;
max = first;
}
return new NumberRange(type, Numbers.wrap(min, type), true, Numbers.wrap(max, type), true);
}
}
代码示例来源:origin: org.apache.sis.core/sis-utility
/** Computes the minimal and maximal values in this vector. */
@SuppressWarnings({"unchecked","rawtypes"})
@Override public NumberRange<?> range() {
long min = first;
long max = first + increment * (length - 1);
if (max < min) {
min = max;
max = first;
}
return new NumberRange(type, Numbers.wrap(min, type), true, Numbers.wrap(max, type), true);
}
}
代码示例来源:origin: apache/sis
/** Computes the minimal and maximal values in this vector. */
@SuppressWarnings({"unchecked","rawtypes"})
@Override public NumberRange<?> range() {
long min = first;
long max = first + increment * (length - 1);
if (max < min) {
min = max;
max = first;
}
return new NumberRange(type, Numbers.wrap(min, type), true, Numbers.wrap(max, type), true);
}
}
代码示例来源:origin: org.apache.sis.core/sis-utility
/** Computes the value at the given index. */
@Override public Number get(final int index) {
return Numbers.wrap(doubleValue(index), type);
}
代码示例来源:origin: org.apache.sis.core/sis-referencing
/**
* Wraps the given value in a type compatible with the expected value class, if possible.
*
* @throws IllegalArgumentException if the given value can not be converted to the given type.
*/
@SuppressWarnings("unchecked")
private static Number wrap(final double value, final Class<?> valueClass) throws IllegalArgumentException {
if (Number.class.isAssignableFrom(valueClass)) {
return Numbers.wrap(value, (Class<? extends Number>) valueClass);
} else {
return Numerics.valueOf(value);
}
}
代码示例来源:origin: apache/sis
/** Computes the value at the given index. */
@Override public Number get(final int index) {
return Numbers.wrap(longValue(index), type);
}
代码示例来源:origin: org.apache.sis.core/sis-utility
/** Computes the value at the given index. */
@Override public Number get(final int index) {
return Numbers.wrap(longValue(index), type);
}
代码示例来源:origin: apache/sis
/**
* Wraps the given value in a type compatible with the expected value class, if possible.
*
* @throws IllegalArgumentException if the given value can not be converted to the given type.
*/
@SuppressWarnings("unchecked")
private static Number wrap(final double value, final Class<?> valueClass) throws IllegalArgumentException {
if (Number.class.isAssignableFrom(valueClass)) {
return Numbers.wrap(value, (Class<? extends Number>) valueClass);
} else {
return Numerics.valueOf(value);
}
}
代码示例来源:origin: apache/sis
/** Computes the value at the given index. */
@Override public Number get(final int index) {
return Numbers.wrap(doubleValue(index), type);
}
代码示例来源:origin: org.apache.sis.core/sis-referencing
/**
* Initializes the fields used for cached values: {@link #zero}, {@link #one} and the {@link #parameters} array.
* The later is not assigned to the {@code parameters} field, but rather returned.
* Caller shall assign himself the returned value to the {@link #parameters} field.
*
* <p>This method is invoked by constructor and on deserialization.</p>
*/
@SuppressWarnings({"unchecked", "rawtypes"})
private <T> ParameterDescriptor<T>[] createCache() {
if (Number.class.isAssignableFrom(elementType)) try {
one = (E) Numbers.wrap(1, (Class) elementType);
zero = (E) Numbers.wrap(0, (Class) elementType);
} catch (IllegalArgumentException e) {
// Ignore - zero and one will be left to null.
}
int length = 1;
for (int i = Math.min(rank(), CACHE_RANK); --i >= 0;) {
length *= CACHE_SIZE;
}
return new ParameterDescriptor[length];
}
代码示例来源:origin: apache/sis
/**
* Initializes the fields used for cached values: {@link #zero}, {@link #one} and the {@link #parameters} array.
* The later is not assigned to the {@code parameters} field, but rather returned.
* Caller shall assign himself the returned value to the {@link #parameters} field.
*
* <p>This method is invoked by constructor and on deserialization.</p>
*/
@SuppressWarnings({"unchecked", "rawtypes"})
private <T> ParameterDescriptor<T>[] createCache() {
if (Number.class.isAssignableFrom(elementType)) try {
one = (E) Numbers.wrap(1, (Class) elementType);
zero = (E) Numbers.wrap(0, (Class) elementType);
} catch (IllegalArgumentException e) {
// Ignore - zero and one will be left to null.
}
int length = 1;
for (int i = Math.min(rank(), CACHE_RANK); --i >= 0;) {
length *= CACHE_SIZE;
}
return new ParameterDescriptor[length];
}
代码示例来源:origin: apache/sis
/**
* Tests {@link Numbers#wrap(double, Class)}.
*/
@Test
public void testWrap() {
final double value = 10;
assertEquals(Byte .valueOf((byte) 10), wrap(value, Byte .class));
assertEquals(Short .valueOf((short) 10), wrap(value, Short .class));
assertEquals(Integer.valueOf( 10), wrap(value, Integer.class));
assertEquals(Long .valueOf((long) 10), wrap(value, Long .class));
assertEquals(Float .valueOf((float) 10), wrap(value, Float .class));
assertEquals(Double .valueOf((double) 10), wrap(value, Double .class));
try {
final Integer n = wrap(4.5, Integer.class);
fail("Expected an exception but got " + n);
} catch (IllegalArgumentException e) {
// This is the expected exception.
assertTrue(e.getMessage().contains("Integer"));
}
}
}
代码示例来源:origin: apache/sis
long stop = maximum.longValue() - 1;
while (value <= stop) {
noDataValues.add(Numbers.wrap(value, widestClass));
内容来源于网络,如有侵权,请联系作者删除!