[ https://issues.apache.org/jira/browse/CODEC-325?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17914730#comment-17914730 ]
Gary D. Gregory edited comment on CODEC-325 at 1/20/25 5:01 PM: ---------------------------------------------------------------- How about this: {code:java} /** * Sets the decode table to use Base32 hexadecimal if {@code true}, otherwise use the Base32 alphabet. * <p> * This overrides a value previously set with {@link #setEncodeTable(byte...)}. * </p> * * @param useHex use Base32 hexadecimal if {@code true}, otherwise use the Base32 alphabet. * @return this instance. * @since 1.18.0 */ public Builder setHexDecodeTable(final boolean useHex) { return setEncodeTable(decodeTable(useHex)); } /** * Sets the encode table to use Base32 hexadecimal if {@code true}, otherwise use the Base32 alphabet. * <p> * This overrides a value previously set with {@link #setEncodeTable(byte...)}. * </p> * * @param useHex use Base32 hexadecimal if {@code true}, otherwise use the Base32 alphabet. * @return this instance. * @since 1.18.0 */ public Builder setHexEncodeTable(final boolean useHex) { return setEncodeTable(encodeTable(useHex)); } ... private static byte[] decodeTable(final boolean useHex) { return useHex ? HEX_DECODE_TABLE : DECODE_TABLE; } private static byte[] encodeTable(final boolean useHex) { return useHex ? HEX_ENCODE_TABLE : ENCODE_TABLE; } {code} ? was (Author: garydgregory): How about this: {code:java} /** * Sets the decode table to use Base32 hexadecimal if {@code true}, otherwise use the Base32 alphabet. * <p> * This overrides a value previously set with {@link #setEncodeTable(byte...)}. * </p> * * @param useHex use Base32 hexadecimal if {@code true}, otherwise use the Base32 alphabet. * @return this instance. * @since 1.18.0 */ public Builder setHexDecodeTable(final boolean useHex) { return setEncodeTable(decodeTable(useHex)); } /** * Sets the encode table to use Base32 hexadecimal if {@code true}, otherwise use the Base32 alphabet. * <p> * This overrides a value previously set with {@link #setEncodeTable(byte...)}. * </p> * * @param useHex use Base32 hexadecimal if {@code true}, otherwise use the Base32 alphabet. * @return this instance. * @since 1.18.0 */ public Builder setHexEncodeTable(final boolean useHex) { return setEncodeTable(encodeTable(useHex)); } {code} ? > Base32 builder: make it easier to use the hex encoding table > ------------------------------------------------------------ > > Key: CODEC-325 > URL: https://issues.apache.org/jira/browse/CODEC-325 > Project: Commons Codec > Issue Type: Wish > Reporter: Julian Reschke > Priority: Minor > > In our (Jackrabbit) quest to remove Guava dependencies, we started using the > commons-codec Base32 class. > I first started with the Builder, but noted that using hexEncoding is a bit > ... complicated. Other than with the constructor: > > https://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/binary/Base32.html#%3Cinit%3E(boolean) > we need to specify the actual encoding table (a nice feature to have), but > use one of the two known tables requires actually copying the table over. > It would be nice if there either was a shortcut (using a boolean as before), > or if the two "known" tables could be made visible to the caller (either > using public constants, or some convenience methods). > Best regards, Julian -- This message was sent by Atlassian Jira (v8.20.10#820010)