@Test public void testPaddingNeeded() throws Exception { assertEquals("000123", padder.pad("123", 6)); }
public String pad(String data, int maxLength) throws ISOException { StringBuilder padded = new StringBuilder(maxLength); int len = data.length(); if (len > maxLength) { throw new ISOException("Data is too long. Max = " + maxLength); } else { for (int i = maxLength - len; i > 0; i--) { padded.append(pad); } padded.append(data); } return padded.toString(); }
LeftPadder implements Padder { public String pad(String data, int maxLength) throws ISOException { StringBuilder padded = new StringBuilder(maxLength); int len = data.length(); if (len > maxLength) { throw new ISOException("Data is too long. Max = " + maxLength); } else { for (int i = maxLength - len; i > 0; i--) { padded.append(pad); } padded.append(data); } return padded.toString(); } }
LeftPadder implements Padder { public String pad(String data, int maxLength) throws ISOException { StringBuilder padded = new StringBuilder(maxLength); int len = data.length(); if (len > maxLength) { throw new ISOException("Data is too long. Max = " + maxLength); } else { for (int i = maxLength - len; i > 0; i--) { padded.append(pad); } padded.append(data); } return padded.toString(); } LeftPadder(char pad); }
LeftPadder implements Padder { public String pad(String data, int maxLength) throws ISOException { StringBuilder padded = new StringBuilder(maxLength); int len = data.length(); if (len > maxLength) { throw new ISOException("Data is too long. Max = " + maxLength); } else { for (int i = maxLength - len; i > 0; i--) { padded.append(pad); } padded.append(data); } return padded.toString(); } LeftPadder(char pad); String pad(String data, int maxLength); String unpad(String paddedData); }
LeftPadder implements Padder { public String pad(String data, int maxLength) throws ISOException { StringBuilder padded = new StringBuilder(maxLength); int len = data.length(); if (len > maxLength) { throw new ISOException("Data is too long. Max = " + maxLength); } else { for (int i = maxLength - len; i > 0; i--) { padded.append(pad); } padded.append(data); } return padded.toString(); } LeftPadder(char pad); String pad(String data, int maxLength); String unpad(String paddedData); static final LeftPadder ZERO_PADDER; }