You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2022/11/13 16:30:42 UTC
[sis] 01/02: Generalize `Numbers.isNumber(Class)` by checking also for types unknown to this static method.
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit f06c086e842fa9f13b9deeea0caa24a08489fab4
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Sun Nov 13 15:34:35 2022 +0100
Generalize `Numbers.isNumber(Class)` by checking also for types unknown to this static method.
---
.../src/main/java/org/apache/sis/util/iso/TypeNames.java | 2 +-
core/sis-utility/src/main/java/org/apache/sis/util/Numbers.java | 9 +++++----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/util/iso/TypeNames.java b/core/sis-metadata/src/main/java/org/apache/sis/util/iso/TypeNames.java
index a4da980c77..2c28bad824 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/util/iso/TypeNames.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/util/iso/TypeNames.java
@@ -99,7 +99,7 @@ final class TypeNames {
NameSpace ns = ogcNS;
search: if (CharSequence.class.isAssignableFrom(valueClass)) {
name = InternationalString.class.isAssignableFrom(valueClass) ? "FreeText" : "CharacterString";
- } else if (Numbers.isNumber(valueClass) || Number.class.isAssignableFrom(valueClass)) {
+ } else if (Numbers.isNumber(valueClass)) {
name = Numbers.isInteger(valueClass) ? "Integer" : "Real";
} else {
/*
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/Numbers.java b/core/sis-utility/src/main/java/org/apache/sis/util/Numbers.java
index 2f60997bf0..c0e337cb99 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/Numbers.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/Numbers.java
@@ -39,7 +39,7 @@ import static java.lang.Double.doubleToLongBits;
* Static methods working with {@link Number} objects, and a few primitive types by extension.
*
* @author Martin Desruisseaux (IRD, Geomatys)
- * @version 1.1
+ * @version 1.3
*
* @see org.apache.sis.math.MathFunctions
*
@@ -183,10 +183,10 @@ public final class Numbers extends Static {
/**
* Returns {@code true} if the given {@code type} is a floating point or an integer type.
* This method returns {@code true} if either {@link #isFloat(Class)} or {@link #isInteger(Class)}
- * returns {@code true} for the given argument.
+ * returns {@code true} for the given argument, or if the type is assignable to {@link Number}.
*
* @param type the primitive type or wrapper class to test (can be {@code null}).
- * @return {@code true} if {@code type} is a floating point or an integer type.
+ * @return {@code true} if {@code type} is a {@link Number} or a primitive floating point or integer type.
*
* @see #isFloat(Class)
* @see #isInteger(Class)
@@ -195,7 +195,8 @@ public final class Numbers extends Static {
*/
public static boolean isNumber(final Class<?> type) {
final Numbers mapping = MAPPING.get(type);
- return (mapping != null) && (mapping.isInteger | mapping.isFloat);
+ return ((mapping != null) && (mapping.isInteger | mapping.isFloat)) ||
+ ((type != null) && Number.class.isAssignableFrom(type));
}
/**