@Override public void formatValue(final ValueWithPos<String> pvalue) { setTextWithPos(IsbnUtil.isbn10FormatWithPos(pvalue)); }
@Override public void formatValue(final ValueWithPos<String> pvalue, final boolean fireEvents) { setTextWithPos(IsbnUtil.isbn10FormatWithPos(pvalue), fireEvents); }
/** * format isbn10 with separator signs. * * @param pstring string to format * @return formated string */ public static String isbn10Format(final String pstring) { if (pstring == null) { return null; } final ValueWithPos<String> formatedValue = isbn10FormatWithPos(new ValueWithPos<>(pstring, -1)); return formatedValue.getValue(); }
/** * format isbn10 with separator signs. * * @param pstring string to format * @return formated string */ public static String isbn10Format(final String pstring) { if (pstring == null) { return null; } final ValueWithPos<String> formatedValue = isbn10FormatWithPos(new ValueWithPos<>(pstring, -1)); return formatedValue.getValue(); }
/** * format isbn10 or 13 with separator signs. * * @param pentry string to format and cursor position * @return formated string with new cursor position */ public static ValueWithPos<String> isbnFormatWithPos(final ValueWithPos<String> pentry) { if (pentry == null) { return null; } final int length = isbnCompress(pentry.getValue()).length(); if (length > Isbn10Validator.ISBN10_LENGTH) { return isbn13FormatWithPos(pentry); } else { return isbn10FormatWithPos(pentry); } }
/** * format isbn10 or 13 with separator signs. * * @param pentry string to format and cursor position * @return formated string with new cursor position */ public static ValueWithPos<String> isbnFormatWithPos(final ValueWithPos<String> pentry) { if (pentry == null) { return null; } final int length = isbnCompress(pentry.getValue()).length(); if (length > Isbn10Validator.ISBN10_LENGTH) { return isbn13FormatWithPos(pentry); } else { return isbn10FormatWithPos(pentry); } }
/** * test formating isbn10 with position. */ @Test public void testIsbn10FormatWithPos() { Assert.assertNull("isbn format should be null", IsbnUtil.isbn10FormatWithPos(null)); for (final Entry<ValueWithPos<String>, ValueWithPos<String>> entry : IsbnUtilTestCases .getIsbn10FormatWithPosCases().entrySet()) { Assert.assertEquals("isbn format failed", entry.getKey(), IsbnUtil.isbn10FormatWithPos(entry.getValue())); } }
/** * test formating isbn10 with position. */ @Test public void testIsbn10FormatWithPos() { Assert.assertNull("isbn format should be null", IsbnUtil.isbn10FormatWithPos(null)); for (final Entry<ValueWithPos<String>, ValueWithPos<String>> entry : IsbnUtilTestCases .getIsbn10FormatWithPosCases().entrySet()) { Assert.assertEquals("isbn format failed", entry.getKey(), IsbnUtil.isbn10FormatWithPos(entry.getValue())); } }