litesoft
@ 939
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
package org.litesoft.codec; import org.litesoft.charstreams.*; import org.litesoft.commonfoundation.annotations.*; public class PrimitiveBooleanCodec { public static final PrimitiveBooleanCodec INSTANCE = new PrimitiveBooleanCodec(); private PrimitiveBooleanCodec() { } public void encode( @NotNull CharSink pCharSink, boolean pValue ) { pCharSink.add( pValue ? 'T' : 'F' ); } public boolean decode( @NotNull CharSource pCharSource ) { char zChar = pCharSource.getRequired(); switch ( zChar ) { case 'T': return true; case 'F': return false; default: throw new IllegalArgumentException( "Unacceptable character '" + zChar + "': " + (int) zChar ); } } } |