Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
[APPFRAMEWORK-29] ResourceConverter - Support all Java number literal formats Created: 19/Sep/07 Updated: 20/Sep/07 Resolved: 20/Sep/07 Status: Project: Component/s: Affects Version/s: Fix Version/s: Resolved appframework www current Type: Reporter: Resolution: Labels: Remaining Estimate: Time Spent: Original Estimate: Environment: Improvement hansmuller Fixed None Not Specified Issuezilla Id: 29 milestone 1 Priority: Assignee: Votes: Major appframework-issues 0 Not Specified Not Specified Operating System: All Platform: All Description Request for enhancement of @Resource field to support hexiadeimal, octal or binary string expression on resource file. In now, @Resource annotated field can be injected only decimal string expression on resource file. The application handling binary data (e.g. network application) needs resource of hexadecimal. I have two proposal to modify implementation of ResourceConverter.java, 1) Use decode method of Integer/Long/Short/Byte. 2) Use parseXX method with radix parameter (XX:Integer/Long/Short/Byte) case 1) string expression in resource file is as decode method specification. (e.g. 0xff, 0123, ...) case 2) string expression in resource file is change value <separator> radix e.g. hexadecimal -> 7fff&16 ('&' is separator, '16' is radix) In this mail, attached above two case pathes. ResourceConverter.java.patch1 : case1 ResourceConverter.java.patch2 : case2 – TAKAHASHI,Toru [email protected] Patches: Index: src/org/jdesktop/application/ResourceConverter.java =================================================================== — src/org/jdesktop/application/ResourceConverter.java (revision 114) +++ src/org/jdesktop/application/ResourceConverter.java (working copy) @@ -211,7 +211,7 @@ } @Override protected Number parseString(String s) throws NumberFormatException { - return Byte.parseByte(s); + return Byte.decode(s); } } @@ -221,7 +221,7 @@ } @Override protected Number parseString(String s) throws NumberFormatException { - return Integer.parseInt(s); + return Integer.decode(s); } } @@ -231,7 +231,7 @@ } @Override protected Number parseString(String s) throws NumberFormatException { - return Long.parseLong(s); + return Long.decode(s); } } @@ -241,7 +241,7 @@ } @Override protected Number parseString(String s) throws NumberFormatException { - return Short.parseShort(s); + return Short.decode(s); } } Index: src/org/jdesktop/application/ResourceConverter.java =================================================================== — src/org/jdesktop/application/ResourceConverter.java (revision 114) +++ src/org/jdesktop/application/ResourceConverter.java (working copy) @@ -168,12 +168,19 @@ super(type); this.primitiveType = primitiveType; } protected abstract Number parseString(String s) throws NumberFormatException; + protected abstract Number parseString(String s, int radix) throws NumberFormatException; @Override public Object parseString(String s, ResourceMap ignore) throws ResourceConverterException { + String[] splited = s.split("&"); + int radix; + if (splited.length > 1) { + radix = Integer.parseInt(splited[1]); + } else { + radix = 10; + } try { - return parseString(s); + return parseString(splited[0], radix); } catch (NumberFormatException e) { throw new ResourceConverterException("invalid " + type.getSimpleName(), s, e); @@ 190,7 +197,7 @@ super(Float.class, float.class); } @Override protected Number parseString(String s) throws NumberFormatException Unknown macro: {+ protected Number parseString(String s, int ignore) throwsNumberFormatException { return Float.parseFloat(s); } } @@ -200,7 +207,7 @@ super(Double.class, double.class); } @Override protected Number parseString(String s) throws NumberFormatException Unknown macro: {+ protected Number parseString(String s, int ignore) throwsNumberFormatException { return Double.parseDouble(s); } } @@ -210,8 +217,8 @@ super(Byte.class, byte.class); } @Override protected Number parseString(String s) throws NumberFormatException { return Byte.parseByte(s); + protected Number parseString(String s, int radix) throws NumberFormatException { + return Byte.parseByte(s, radix); } } @@ -220,8 +227,8 @@ super(Integer.class, int.class); } @Override protected Number parseString(String s) throws NumberFormatException { return Integer.parseInt(s); + protected Number parseString(String s, int radix) throws NumberFormatException { + return Integer.parseInt(s, radix); } } @@ -230,8 +237,8 @@ super(Long.class, long.class); } @Override protected Number parseString(String s) throws NumberFormatException { return Long.parseLong(s); + protected Number parseString(String s, int radix) throws NumberFormatException { + return Long.parseLong(s, radix); } } @@ -240,8 +247,8 @@ super(Short.class, short.class); } @Override protected Number parseString(String s) throws NumberFormatException { return Short.parseShort(s); + protected Number parseString(String s, int radix) throws NumberFormatException { + return Short.parseShort(s, radix); } } Comments Comment by hansmuller [ 19/Sep/07 ] This seems like a sensible refinement for the integer resource converters; I assume that you're suggesting that we combine both enhancements. I'm not familiar with the number&radix syntax for integers, is that an established convention for network apps? Since it's a small and apparently safe change, I'll include it in the next release unless someone objects. Comment by hansmuller [ 20/Sep/07 ] Support for this feature will be included in 1.01 Generated at Thu May 04 01:21:15 UTC 2017 using JIRA 6.2.3#6260sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.