RFR: JDK-8293776 : Adds CSS 4 and 8 digits hex coded Color [v13]
SWinxy
duke at openjdk.org
Thu Feb 23 18:45:15 UTC 2023
On Sun, 5 Feb 2023 09:55:27 GMT, ScientificWare <duke at openjdk.org> wrote:
>> This is referenced in Java Bug Database as
>> - [JDK-8293776 : Adds CSS 4 and 8 digits hex coded Color](https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8293776)
>>
>> This is tracked in JBS as
>> - [JDK-8293776 : Adds CSS 4 and 8 digits hex coded Color](https://bugs.openjdk.java.net/browse/JDK-8293776)
>>
>> Adds the 4 and 8 digits color hex notations to CSS.java, as described in :
>> CSS Color Module Level 4
>> W3C Candidate Recommendation Snapshot, 5 July 2022
>> [6.2 The RGB Hexadecimal Notations: `#RRGGBB`](https://www.w3.org/TR/css-color-4/#hex-notation)
>>
>> Designed from : [ScientificWare JDK-8293776 : Adds CSS 4 and 8 digits hex coded Color](https://github.com/scientificware/jdk/issues/13)
>
> ScientificWare has updated the pull request incrementally with two additional commits since the last revision:
>
> - Updates copyright date.
>
> Updates copyright date to 2023.
> - Updates copyright date.
>
> Updates copyright date to 2023.
I don't know if I like the use of Maps. I think I would prefer doing it via an enhanced switch. I've written a sketch of what I would write. Untested and probably *very* wrong, but I like it.
static Color hexToColor(String digits) {
if (digits.startsWith("#")) {
digits = digits.substring(1);
}
try {
int a = Integer.parseInt(digits, 16);
return switch (digits.length()) {
case 3 -> new Color((a & 0xF00) << 24 | (a & 0xF0) << 16 | (a & 0xF) << 8 | 0xFF);
case 4 -> new Color((a & 0xF000) << 24 | (a & 0xF00) << 16 | (a & 0xF0) << 8 | (a & 0xF));
case 6 -> new Color((a & 0xFF0000) << 24 | (a & 0xFF00) << 16 | (a & 0xFF) << 8 | 0xFF);
case 8 -> new Color(a);
default -> null;
}
} catch (NumberFormatException e) {
return null;
}
}
I don't like when PRs languish. It sucks.
-------------
PR: https://git.openjdk.org/jdk/pull/10317
More information about the client-libs-dev
mailing list