@Test public void testPadLengthTooShort() throws Exception { try { padder.pad("123", 2); fail("Padding a string longer than the available width should throw an exception"); } catch (Exception asIExpected) { } }
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; }