Subversion Repository Public Repository

litesoft

Diff Revisions 766 vs 767 for /trunk/Java/core/Anywhere/src/org/litesoft/codec/IntegerCodec.java

Diff revisions: vs.
  @@ -9,16 +9,13 @@
9 9 */
10 10 public class IntegerCodec
11 11 {
12 - private static final char NULL_AS_CHAR = SixBitCodec.ESCAPE;
13 - private static final String NULL_AS_STRING = Character.toString( NULL_AS_CHAR );
14 -
15 12 public interface Primitive
16 13 {
17 14 public @NotNull String encode( int pValue );
18 15
19 16 public int decode( @NotNull String pValue );
20 17
21 - public int decode( @NotNull CharSource pValue );
18 + public int decode( @NotNull CharSource pCharSource );
22 19 }
23 20
24 21 public static class SignedPrimitive implements Primitive
  @@ -47,9 +44,9 @@
47 44 }
48 45
49 46 @Override
50 - public int decode( @NotNull CharSource pValue )
47 + public int decode( @NotNull CharSource pCharSource )
51 48 {
52 - return toInt( new Decoder( pValue ).decode( 16, 16 ) );
49 + return toInt( new Decoder( pCharSource ).decode( 16, 16 ) );
53 50 }
54 51 }
55 52
  @@ -58,15 +55,15 @@
58 55 public static final Signed INSTANCE = new Signed();
59 56
60 57 @Override
61 - public @NotNull String encode( @Nullable Integer pValue )
58 + protected String encodeNonNull( Integer pValue )
62 59 {
63 - return (pValue == null) ? NULL_AS_STRING : SignedPrimitive.INSTANCE.encode( pValue );
60 + return SignedPrimitive.INSTANCE.encode( pValue );
64 61 }
65 62
66 63 @Override
67 - public @Nullable Integer decode( @NotNull CharSource pValue )
64 + protected Integer decodeNonNull( CharSource pCharSource )
68 65 {
69 - return isEscapeWithConsume( pValue ) ? null : SignedPrimitive.INSTANCE.decode( pValue );
66 + return SignedPrimitive.INSTANCE.decode( pCharSource );
70 67 }
71 68 }
72 69
  @@ -95,9 +92,9 @@
95 92 }
96 93
97 94 @Override
98 - public int decode( @NotNull CharSource pValue )
95 + public int decode( @NotNull CharSource pCharSource )
99 96 {
100 - return toInt( new Decoder( pValue ).decode( 0, 32 ) );
97 + return toInt( new Decoder( pCharSource ).decode( 0, 32 ) );
101 98 }
102 99 }
103 100
  @@ -106,26 +103,16 @@
106 103 public static final NonNegative INSTANCE = new NonNegative();
107 104
108 105 @Override
109 - public @NotNull String encode( @Nullable Integer pValue )
106 + protected String encodeNonNull( Integer pValue )
110 107 {
111 - return (pValue == null) ? NULL_AS_STRING : NonNegativePrimitive.INSTANCE.encode( pValue );
108 + return NonNegativePrimitive.INSTANCE.encode( pValue );
112 109 }
113 110
114 111 @Override
115 - public @Nullable Integer decode( @NotNull CharSource pValue )
116 - {
117 - return isEscapeWithConsume( pValue ) ? null : NonNegativePrimitive.INSTANCE.decode( pValue );
118 - }
119 - }
120 -
121 - private static boolean isEscapeWithConsume( CharSource pValue )
122 - {
123 - if ( pValue.peek() == NULL_AS_CHAR )
112 + protected Integer decodeNonNull( CharSource pCharSource )
124 113 {
125 - pValue.get(); // consume
126 - return true;
114 + return NonNegativePrimitive.INSTANCE.decode( pCharSource );
127 115 }
128 - return false;
129 116 }
130 117
131 118 private static int toInt( long pValue )