diff --git a/advanced/attributes/src/main/java/org/arakhne/afc/attrs/attr/AttributeType.java b/advanced/attributes/src/main/java/org/arakhne/afc/attrs/attr/AttributeType.java index daf2a009a..19589567c 100644 --- a/advanced/attributes/src/main/java/org/arakhne/afc/attrs/attr/AttributeType.java +++ b/advanced/attributes/src/main/java/org/arakhne/afc/attrs/attr/AttributeType.java @@ -30,10 +30,7 @@ import java.net.URISyntaxException; import java.net.UnknownHostException; import java.util.Calendar; -import java.util.Collections; import java.util.Date; -import java.util.HashMap; -import java.util.Map; import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -151,55 +148,43 @@ public enum AttributeType { private static final String NAME_RESOURCE_FILE; + private String localizedName; + static { final String pName = AttributeType.class.getPackage().getName(); NAME_RESOURCE_FILE = pName + ".types"; //$NON-NLS-1$ } - /** FactoryMap collection. + /** Replies the name of this type (localized). * + * @return the localized name of this type. */ - private static final Map FACTORY_MAP = - Collections.unmodifiableMap(new HashMap() {{ - put(AttributeType.INTEGER, () -> Locale.getStringFrom(NAME_RESOURCE_FILE, "INTEGER")); //$NON-NLS-1$ - put(AttributeType.REAL, () -> Locale.getStringFrom(NAME_RESOURCE_FILE, "FLOAT")); //$NON-NLS-1$ - put(AttributeType.STRING, () -> Locale.getStringFrom(NAME_RESOURCE_FILE, "STRING")); //$NON-NLS-1$ - put(AttributeType.BOOLEAN, () -> Locale.getStringFrom(NAME_RESOURCE_FILE, "BOOLEAN")); //$NON-NLS-1$ - put(AttributeType.DATE, () -> Locale.getStringFrom(NAME_RESOURCE_FILE, "DATE")); //$NON-NLS-1$ - put(AttributeType.OBJECT, () -> Locale.getStringFrom(NAME_RESOURCE_FILE, "OBJECT")); //$NON-NLS-1$ - put(AttributeType.TIMESTAMP, () -> Locale.getStringFrom(NAME_RESOURCE_FILE, "TIMESTAMP")); //$NON-NLS-1$ - put(AttributeType.POINT3D, () -> Locale.getStringFrom(NAME_RESOURCE_FILE, "POINT3D")); //$NON-NLS-1$ - put(AttributeType.POINT, () -> Locale.getStringFrom(NAME_RESOURCE_FILE, "POINT2D")); //$NON-NLS-1$ - put(AttributeType.COLOR, () -> Locale.getStringFrom(NAME_RESOURCE_FILE, "COLOR")); //$NON-NLS-1$ - put(AttributeType.IMAGE, () -> Locale.getStringFrom(NAME_RESOURCE_FILE, "ICON")); //$NON-NLS-1$ - put(AttributeType.POLYLINE, () -> Locale.getStringFrom(NAME_RESOURCE_FILE, "POLYLINE")); //$NON-NLS-1$ - put(AttributeType.POLYLINE3D, () -> Locale.getStringFrom(NAME_RESOURCE_FILE, "POLYLINE3D")); //$NON-NLS-1$ - put(AttributeType.UUID, () -> Locale.getStringFrom(NAME_RESOURCE_FILE, "UUID")); //$NON-NLS-1$ - put(AttributeType.URL, () -> Locale.getStringFrom(NAME_RESOURCE_FILE, "URL")); //$NON-NLS-1$ - put(AttributeType.URI, () -> Locale.getStringFrom(NAME_RESOURCE_FILE, "URI")); //$NON-NLS-1$ - put(AttributeType.INET_ADDRESS, () -> Locale.getStringFrom(NAME_RESOURCE_FILE, "INET_ADDRESS")); //$NON-NLS-1$ - put(AttributeType.ENUMERATION, () -> Locale.getStringFrom(NAME_RESOURCE_FILE, "ENUMERATION")); //$NON-NLS-1$ - put(AttributeType.TYPE, () -> Locale.getStringFrom(NAME_RESOURCE_FILE, "TYPE")); //$NON-NLS-1$ - }}); + @Pure + public String getLocalizedName() { + if (this.localizedName == null) { + this.localizedName = Locale.getStringWithDefaultFrom(NAME_RESOURCE_FILE, name(), null); + if (this.localizedName == null) { + this.localizedName = Locale.getStringFrom(NAME_RESOURCE_FILE, "OTHER"); //$NON-NLS-1$ + } + } + return this.localizedName; + } /** Replies the name of this type (localized). * * @return the localized name of this type. + * @deprecated since 13.0, see {@link #getLocalizedName()} */ @Pure - @SuppressWarnings({"checkstyle:returncount"}) + @Deprecated public String getName() { - final StringFactory stringFactory = FACTORY_MAP.get(this); - if (stringFactory != null) { - return stringFactory.createString(); - } - return Locale.getStringFrom(NAME_RESOURCE_FILE, "OTHER"); //$NON-NLS-1$ + return getLocalizedName(); } @Pure @Override public String toString() { - return getName(); + return getLocalizedName(); } /** Replies the Attribute type that corresponds to the @@ -934,12 +919,4 @@ private static InetAddress getInetAddressFromCharacterSequence(Object obj) { return Point3D[].class.cast(obj); } - /** Represents a Java type. - * @mavenartifactid $ArtifactId$ - * @mavengroupid $GroupId$ - */ - @FunctionalInterface - private interface StringFactory { - String createString(); - } } diff --git a/advanced/attributes/src/main/resources/org/arakhne/afc/attrs/types.properties b/advanced/attributes/src/main/resources/org/arakhne/afc/attrs/types.properties index 038b870da..995fe33b0 100644 --- a/advanced/attributes/src/main/resources/org/arakhne/afc/attrs/types.properties +++ b/advanced/attributes/src/main/resources/org/arakhne/afc/attrs/types.properties @@ -2,13 +2,13 @@ BOOLEAN = Boolean COLOR = Color DATE = Date ENUMERATION = Enumeration -FLOAT = Float +REAL = Floating point number ICON = Icon INET_ADDRESS = Internet Address INTEGER = Integer OBJECT = Object OTHER = Other -POINT2D = Point 2d +POINT = Point 2d POINT3D = Point 3d POLYLINE = Polyline 2d POLYLINE3D = Polyline 3d diff --git a/advanced/attributes/src/main/resources/org/arakhne/afc/attrs/types_es.properties b/advanced/attributes/src/main/resources/org/arakhne/afc/attrs/types_es.properties deleted file mode 100644 index 11e895955..000000000 --- a/advanced/attributes/src/main/resources/org/arakhne/afc/attrs/types_es.properties +++ /dev/null @@ -1,20 +0,0 @@ -BOOLEAN = Booleano -COLOR = Color -DATE = Fecha -ENUMERATION = Enumeración -FLOAT = Número decimal -ICON = Icono -INET_ADDRESS = Número Internet -INTEGER = Número entero -OBJECT = Asunto -OTHER = Otro -POINT2D = Punto 2d -POINT3D = Punto 3d -POLYLINE = Poly-línea 2d -POLYLINE3D = Poly-línea 3d -STRING = Cadena de caracteres -TIMESTAMP = Estampilla -TYPE = Tipo Java -UUID = Identificación único universal -URI = Identificador uniforme de recursos -URL = Localizador de recurso uniforme \ No newline at end of file diff --git a/advanced/attributes/src/main/resources/org/arakhne/afc/attrs/types_fr.properties b/advanced/attributes/src/main/resources/org/arakhne/afc/attrs/types_fr.properties index 639482e94..dfda931b1 100644 --- a/advanced/attributes/src/main/resources/org/arakhne/afc/attrs/types_fr.properties +++ b/advanced/attributes/src/main/resources/org/arakhne/afc/attrs/types_fr.properties @@ -2,13 +2,13 @@ BOOLEAN = Bool COLOR = Couleur DATE = Date ENUMERATION = Enumeration -FLOAT = Nombre décimal +REAL = Nombre décimal ICON = Icône INET_ADDRESS = Addresse Internet INTEGER = Nombre entier OBJECT = Objet OTHER = Autre -POINT2D = Point 2d +POINT = Point 2d POINT3D = Point 3d POLYLINE = Poly-ligne 2d POLYLINE3D = Poly-ligne 3d diff --git a/advanced/attributes/src/test/java/org/arakhne/afc/attrs/attr/AttributeTypeTest.java b/advanced/attributes/src/test/java/org/arakhne/afc/attrs/attr/AttributeTypeTest.java index 19cddeebf..4ea9104da 100644 --- a/advanced/attributes/src/test/java/org/arakhne/afc/attrs/attr/AttributeTypeTest.java +++ b/advanced/attributes/src/test/java/org/arakhne/afc/attrs/attr/AttributeTypeTest.java @@ -66,7 +66,7 @@ protected static void assertNullException(AttributeType type, Object value) { @Test public void getName() { for(AttributeType type : AttributeType.values()) { - String name = type.getName(); + String name = type.getLocalizedName(); assertNotNull(name); assertNotSame("", name); //$NON-NLS-1$ } @@ -1168,4 +1168,12 @@ public void isAssignableFrom() { assertTrue(AttributeType.ENUMERATION.isAssignableFrom(AttributeType.ENUMERATION)); } + @Test + public void getLocalizedName() { + for (AttributeType type : AttributeType.values()) { + String name = type.getLocalizedName(); + assertNotEquals("Invalid attribute name", "OTHER", name); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + } diff --git a/advanced/attributes/src/test/java/org/arakhne/afc/attrs/attr/AttributeValueTest.java b/advanced/attributes/src/test/java/org/arakhne/afc/attrs/attr/AttributeValueTest.java index 37a031b37..6c0d735de 100644 --- a/advanced/attributes/src/test/java/org/arakhne/afc/attrs/attr/AttributeValueTest.java +++ b/advanced/attributes/src/test/java/org/arakhne/afc/attrs/attr/AttributeValueTest.java @@ -3359,7 +3359,7 @@ public void parse() { v = AttributeValueImpl.parse("java.lang.String"); //$NON-NLS-1$ assertSame(AttributeType.TYPE, v.getType()); - v = AttributeValueImpl.parse(AttributeType.class.getName()+"."+AttributeType.ENUMERATION.toString()); //$NON-NLS-1$ + v = AttributeValueImpl.parse(AttributeType.class.getName()+"."+AttributeType.ENUMERATION.name()); //$NON-NLS-1$ assertSame(AttributeType.ENUMERATION, v.getType()); v = AttributeValueImpl.parse("3eade434-b267-4ffa-a574-2e2cbff0151a"); //$NON-NLS-1$ diff --git a/core/testtools/src/main/java/org/arakhne/afc/testtools/AbstractTestCase.java b/core/testtools/src/main/java/org/arakhne/afc/testtools/AbstractTestCase.java index 0a29bf8a1..c118d9d80 100644 --- a/core/testtools/src/main/java/org/arakhne/afc/testtools/AbstractTestCase.java +++ b/core/testtools/src/main/java/org/arakhne/afc/testtools/AbstractTestCase.java @@ -209,6 +209,30 @@ public static void assertNotEquals(String message, int expected, int actual) { } } + /** Test if the actual value is not equal to the expected value with + * a distance of epsilon. + * + * @param expected the expected value. + * @param actual the actual value. + */ + public static void assertNotEquals(Object expected, Object actual) { + assertNotEquals(null, expected, actual); + } + + /** Test if the actual value is not equal to the expected value with + * a distance of epsilon. + * + * @param message the error message. + * @param expected the expected value. + * @param actual the actual value. + */ + public static void assertNotEquals(String message, Object expected, Object actual) { + if (!Objects.equals(expected, actual)) { + throw new junit.framework.ComparisonFailure(message, + Objects.toString(expected), Objects.toString(actual)); + } + } + /** Test if the given value is not a number. * * @param value the value to test.