Subversion Repository Public Repository

litesoft

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

Diff revisions: vs.
  @@ -2,7 +2,7 @@
2 2
3 3 import java.util.*;
4 4
5 - import org.litesoft.codec.*;
5 + import org.litesoft.codec.StringCodec;
6 6
7 7 /**
8 8 * Code to support converting a list of Strings to a single String and back.
  @@ -12,7 +12,7 @@
12 12 /**
13 13 * Pack the passed Strings into a single String.
14 14 *
15 - * @return "" if null passed OR no strings, individual nulls treated as ""
15 + * @return "" if null passed OR no strings
16 16 */
17 17 public static String pack( String... pStrings )
18 18 {
  @@ -22,7 +22,7 @@
22 22 /**
23 23 * Pack the passed Strings into a single String.
24 24 *
25 - * @return "" if null passed OR no strings, individual nulls treated as ""
25 + * @return "" if null passed OR no strings
26 26 */
27 27 public static String pack( List<String> pStrings )
28 28 {
  @@ -31,7 +31,7 @@
31 31 StringBuilder zSB = new StringBuilder();
32 32 for ( String zString : pStrings )
33 33 {
34 - appendString( zSB, zString );
34 + zSB.append( StringCodec.INSTANCE.encode( zString ) );
35 35 }
36 36 return zSB.toString();
37 37 }
  @@ -41,13 +41,11 @@
41 41 /**
42 42 * Unpack the passed String into multiple Strings.
43 43 *
44 - * @return empty if minimumListSize < 1 AND null or "" passed, otherwise the
45 - * list will be at least minimumListSize (or 1 if minimumListSize <
46 - * 1) and no entries will be null.
44 + * @return list will be at least minimumListSize (or 1 if minimumListSize <1)
47 45 */
48 46 public static List<String> unpack( String pPacked, int pMinimumListSize )
49 47 {
50 - List<String> zResults = new ArrayList<String>();
48 + List<String> zResults = new ArrayList<String>( Math.max( pMinimumListSize, 1 ) );
51 49 if ( pPacked != null )
52 50 {
53 51 if ( (pPacked = pPacked.trim()).length() != 0 )
  @@ -55,38 +53,14 @@
55 53 CharSource zCS = new CharSource( pPacked );
56 54 do
57 55 {
58 - zResults.add( parseString( zCS ) );
56 + zResults.add( StringCodec.INSTANCE.decode( zCS ) );
59 57 }
60 58 while ( zCS.anyRemaining() );
61 59 }
62 60 }
63 - while ( zResults.size() < pMinimumListSize )
64 - {
65 - zResults.add( "" );
66 - }
67 61 return zResults;
68 62 }
69 63
70 - private static String parseString( CharSource pCS )
71 - {
72 - int zLength = IntegerCodec.NonNegativePrimitive.INSTANCE.decode( pCS );
73 - if ( zLength == 0 )
74 - {
75 - return "";
76 - }
77 - StringBuilder zSB = new StringBuilder();
78 - while ( zLength-- > 0 )
79 - {
80 - zSB.append( pCS.getRequired() );
81 - }
82 - return zSB.toString();
83 - }
84 -
85 - private static void appendString( StringBuilder pSB, String pString )
86 - {
87 - pSB.append( IntegerCodec.NonNegativePrimitive.INSTANCE.encode( pString.length() ) ).append( pString );
88 - }
89 -
90 64 private static List<String> normalize( List<String> pStrings )
91 65 {
92 66 if ( pStrings != null )