/** * Inverse operation of collapseStringList. * * ",s1,s2,s3" => ["s1", "s2", "s3"] * * * @param collapsed * @return */ public static List<String> explodeStringList(final String collapsed) { assert isCollapsedString(collapsed); final String[] exploded = collapsed.substring(1).split(","); return Arrays.asList(exploded); }
/** * Inverse operation of collapseStringList. * * ",s1,s2,s3" => ["s1", "s2", "s3"] * * * @param collapsed * @return */ public static List<String> explodeStringList(final String collapsed) { assert isCollapsedString(collapsed); final String[] exploded = collapsed.substring(1).split(","); return Arrays.asList(exploded); }
/** * Inverse operation of collapseStringList. * * ",s1,s2,s3" => ["s1", "s2", "s3"] * * * @param collapsed * @return */ @Requires({"collapsed != null", "isCollapsedString(collapsed)"}) @Ensures("result != null") public static List<String> explodeStringList(final String collapsed) { assert isCollapsedString(collapsed); final String[] exploded = collapsed.substring(1).split(","); return Arrays.asList(exploded); }
private final Object decodeLiteralString(final int size) { assert size > 0; // TODO -- assumes size > 0 final byte[] bytes = new byte[size]; // TODO -- in principle should just grab bytes from underlying array try { recordStream.read(bytes); int goodLength = 0; for ( ; goodLength < bytes.length ; goodLength++ ) if ( bytes[goodLength] == 0 ) break; if ( goodLength == 0 ) return null; else { final String s = new String(bytes, 0, goodLength); return BCF2Utils.isCollapsedString(s) ? BCF2Utils.explodeStringList(s) : s; } } catch ( IOException e ) { throw new TribbleException("readByte failure", e); } }
private final Object decodeLiteralString(final int size) { assert size > 0; // TODO -- assumes size > 0 final byte[] bytes = new byte[size]; // TODO -- in principle should just grab bytes from underlying array try { recordStream.read(bytes); int goodLength = 0; for ( ; goodLength < bytes.length ; goodLength++ ) if ( bytes[goodLength] == 0 ) break; if ( goodLength == 0 ) return null; else { final String s = new String(bytes, 0, goodLength); return BCF2Utils.isCollapsedString(s) ? BCF2Utils.explodeStringList(s) : s; } } catch ( IOException e ) { throw new TribbleException("readByte failure", e); } }
private final Object decodeLiteralString(final int size) { assert size > 0; // TODO -- assumes size > 0 final byte[] bytes = new byte[size]; // TODO -- in principle should just grab bytes from underlying array try { recordStream.read(bytes); int goodLength = 0; for ( ; goodLength < bytes.length ; goodLength++ ) if ( bytes[goodLength] == 0 ) break; if ( goodLength == 0 ) return null; else { final String s = new String(bytes, 0, goodLength); return BCF2Utils.isCollapsedString(s) ? BCF2Utils.explodeStringList(s) : s; } } catch ( IOException e ) { throw new TribbleException("readByte failure", e); } }
@Test(dataProvider = "CollapseExpandTest") public void testCollapseExpandTest(final List<String> in, final String expectedCollapsed, final boolean isCollapsed) { final String actualCollapsed = BCF2Utils.collapseStringList(in); Assert.assertEquals(actualCollapsed, expectedCollapsed); Assert.assertEquals(BCF2Utils.isCollapsedString(actualCollapsed), isCollapsed); if ( isCollapsed ) Assert.assertEquals(BCF2Utils.explodeStringList(actualCollapsed), in); }