/** * Recode the incoming object to a String, compacting it into a * BCF2 string if the value is a list. * * @param value a String or List<String> to encode, or null * @return a non-null string to encode */ private String javaStringToBCF2String(final Object value) { if ( value == null ) return ""; else if (value instanceof List) { final List<String> l = (List<String>)value; return BCF2Utils.collapseStringList(l); } else if ( value.getClass().isArray() ) { final List<String> l = new ArrayList<String>(); Collections.addAll(l, (String[])value); return BCF2Utils.collapseStringList(l); } else return (String)value; } }
/** * Recode the incoming object to a String, compacting it into a * BCF2 string if the value is a list. * * @param value a String or List<String> to encode, or null * @return a non-null string to encode */ private String javaStringToBCF2String(final Object value) { if ( value == null ) return ""; else if (value instanceof List) { final List<String> l = (List<String>)value; return BCF2Utils.collapseStringList(l); } else if ( value.getClass().isArray() ) { final List<String> l = new ArrayList<String>(); Collections.addAll(l, (String[])value); return BCF2Utils.collapseStringList(l); } else return (String)value; } }
/** * Recode the incoming object to a String, compacting it into a * BCF2 string if the value is a list. * * @param value a String or List<String> to encode, or null * @return a non-null string to encode */ @Ensures("result != null") private String javaStringToBCF2String(final Object value) { if ( value == null ) return ""; else if (value instanceof List) { final List<String> l = (List<String>)value; return BCF2Utils.collapseStringList(l); } else if ( value.getClass().isArray() ) { final List<String> l = new ArrayList<String>(); Collections.addAll(l, (String[])value); return BCF2Utils.collapseStringList(l); } else return (String)value; } }
public final void encodeTyped(List<? extends Object> v, final BCF2Type type) throws IOException { if ( type == BCF2Type.CHAR && !v.isEmpty()) { final String s = BCF2Utils.collapseStringList((List<String>) v); v = stringToBytes(s); } encodeType(v.size(), type); encodeRawValues(v, type); }
public final void encodeTyped(List<? extends Object> v, final BCF2Type type) throws IOException { if ( type == BCF2Type.CHAR && !v.isEmpty()) { final String s = BCF2Utils.collapseStringList((List<String>) v); v = stringToBytes(s); } encodeType(v.size(), type); encodeRawValues(v, type); }
@Ensures("encodeStream.size() > old(encodeStream.size())") public final void encodeTyped(List<? extends Object> v, final BCF2Type type) throws IOException { if ( type == BCF2Type.CHAR && v.size() != 0 ) { final String s = BCF2Utils.collapseStringList((List<String>) v); v = stringToBytes(s); } encodeType(v.size(), type); encodeRawValues(v, type); }
@Test(dataProvider = "ListOfStrings") public void testEncodingListOfString(List<String> strings, String expected) throws IOException { final String collapsed = BCF2Utils.collapseStringList(strings); Assert.assertEquals(collapsed, expected); Assert.assertEquals(BCF2Utils.explodeStringList(collapsed), strings); }
@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); }