@Test public void testCalcLengthFromPicture() { assertEquals(0, getLengthFromPicture("", false)); assertEquals(1, getLengthFromPicture("A", false)); assertEquals(2, getLengthFromPicture("AB", false)); assertEquals(3, getLengthFromPicture("ABE", false)); assertEquals(4, getLengthFromPicture("ABEG", false)); assertEquals(5, getLengthFromPicture("ABEGN", false)); assertEquals(5, getLengthFromPicture("ABEGNP", false)); assertEquals(5, getLengthFromPicture("ABEGNPS", false)); assertEquals(5, getLengthFromPicture("ABEGNPSV", false)); assertEquals(6, getLengthFromPicture("ABEGNPSVX", false)); assertEquals(7, getLengthFromPicture("ABEGNPSVXZ", false)); assertEquals(8, getLengthFromPicture("ABEGNPSVXZ9", false)); assertEquals(9, getLengthFromPicture("ABEGNPSVXZ90", false)); assertEquals(10, getLengthFromPicture("ABEGNPSVXZ90/", false)); assertEquals(11, getLengthFromPicture("ABEGNPSVXZ90/,", false)); assertEquals(12, getLengthFromPicture("ABEGNPSVXZ90/,.", false)); assertEquals(13, getLengthFromPicture("ABEGNPSVXZ90/,.+", false)); assertEquals(14, getLengthFromPicture("ABEGNPSVXZ90/,.+-", false)); assertEquals(16, getLengthFromPicture("ABEGNPSVXZ90/,.+-CR", false)); assertEquals(18, getLengthFromPicture("ABEGNPSVXZ90/,.+-CRDB", false)); assertEquals(19, getLengthFromPicture("ABEGNPSVXZ90/,.+-CRDB*", false)); assertEquals(20, getLengthFromPicture("ABEGNPSVXZ90/,.+-CRDB*$", false)); assertEquals(23, getLengthFromPicture("$$ABEGNPSVXZ90/,.+-CRDB*", false)); assertEquals(21, getLengthFromPicture("ABEGNPSVXZ90/,.+-CRDB*$", true)); assertEquals(9, getLengthFromPicture("X(9)", false)); assertEquals(14, getLengthFromPicture("X(14)", false)); assertEquals(149, getLengthFromPicture("X(149)", false)); assertEquals(1495, getLengthFromPicture("X(1495)", false)); }
public static int calcLengthFromPicture( final Map < Character, Integer > charNum, final boolean isSignSeparate, final String currencySign, final char currencySymbol, final boolean calcStorageLength) { int length = 0; Map < Character, Integer > charLen = new HashMap < Character, Integer >(); charLen.put('A', 1); charLen.put('B', 1); charLen.put('G', (calcStorageLength) ? 2 : 1); charLen.put('N', (calcStorageLength) ? 2 : 1); charLen.put('X', 1); charLen.put('P', 0); charLen.put('Z', 1); charLen.put('0', 1); charLen.put('/', 1); charLen.put('+', 1); charLen.put('-', 1); charLen.put('*', 1); charLen.put('C', 2); charLen.put('D', 2); charLen.put('.', 1); charLen.put(',', 1); charLen.put('9', 1); charLen.put('E', 1); charLen.put('S', (isSignSeparate) ? 1 : 0); charLen.put('V', 0); charLen.put(currencySymbol, 1); for (Map.Entry < Character, Integer > entry : charNum.entrySet()) { length += entry.getValue() * charLen.get(entry.getKey()); } if (currencySign.length() > 1 && charNum.get(currencySymbol) > 1) { length += currencySign.length() - 1; } return length; }
PictureUtil { public static int calcLengthFromPicture( final Map < Character, Integer > charNum, final boolean isSignSeparate, final String currencySign, final char currencySymbol, final boolean calcStorageLength) { int length = 0; Map < Character, Integer > charLen = new HashMap < Character, Integer >(); charLen.put('A', 1); charLen.put('B', 1); charLen.put('G', (calcStorageLength) ? 2 : 1); charLen.put('N', (calcStorageLength) ? 2 : 1); charLen.put('X', 1); charLen.put('P', 0); charLen.put('Z', 1); charLen.put('0', 1); charLen.put('/', 1); charLen.put('+', 1); charLen.put('-', 1); charLen.put('*', 1); charLen.put('C', 2); charLen.put('D', 2); charLen.put('.', 1); charLen.put(',', 1); charLen.put('9', 1); charLen.put('E', 1); charLen.put('S', (isSignSeparate) ? 1 : 0); charLen.put('V', 0); charLen.put(currencySymbol, 1); for (Map.Entry < Character, Integer > entry : charNum.entrySet()) { length += entry.getValue() * charLen.get(entry.getKey()); } if (currencySign.length() > 1 && charNum.get(currencySymbol) > 1) { length += currencySign.length() - 1; } return length; } }
PictureUtil { public static int calcLengthFromPicture( final Map < Character, Integer > charNum, final boolean isSignSeparate, final String currencySign, final char currencySymbol, final boolean calcStorageLength) { int length = 0; Map < Character, Integer > charLen = new HashMap < Character, Integer >(); charLen.put('A', 1); charLen.put('B', 1); charLen.put('G', (calcStorageLength) ? 2 : 1); charLen.put('N', (calcStorageLength) ? 2 : 1); charLen.put('X', 1); charLen.put('P', 0); charLen.put('Z', 1); charLen.put('0', 1); charLen.put('/', 1); charLen.put('+', 1); charLen.put('-', 1); charLen.put('*', 1); charLen.put('C', 2); charLen.put('D', 2); charLen.put('.', 1); charLen.put(',', 1); charLen.put('9', 1); charLen.put('E', 1); charLen.put('S', (isSignSeparate) ? 1 : 0); charLen.put('V', 0); charLen.put(currencySymbol, 1); for (Map.Entry < Character, Integer > entry : charNum.entrySet()) { length += entry.getValue() * charLen.get(entry.getKey()); } if (currencySign.length() > 1 && charNum.get(currencySymbol) > 1) { length += currencySign.length() - 1; } return length; } private  PictureUtil(); }
PictureUtil { public static int calcLengthFromPicture( final Map < Character, Integer > charNum, final boolean isSignSeparate, final String currencySign, final char currencySymbol, final boolean calcStorageLength) { int length = 0; Map < Character, Integer > charLen = new HashMap < Character, Integer >(); charLen.put('A', 1); charLen.put('B', 1); charLen.put('G', (calcStorageLength) ? 2 : 1); charLen.put('N', (calcStorageLength) ? 2 : 1); charLen.put('X', 1); charLen.put('P', 0); charLen.put('Z', 1); charLen.put('0', 1); charLen.put('/', 1); charLen.put('+', 1); charLen.put('-', 1); charLen.put('*', 1); charLen.put('C', 2); charLen.put('D', 2); charLen.put('.', 1); charLen.put(',', 1); charLen.put('9', 1); charLen.put('E', 1); charLen.put('S', (isSignSeparate) ? 1 : 0); charLen.put('V', 0); charLen.put(currencySymbol, 1); for (Map.Entry < Character, Integer > entry : charNum.entrySet()) { length += entry.getValue() * charLen.get(entry.getKey()); } if (currencySign.length() > 1 && charNum.get(currencySymbol) > 1) { length += currencySign.length() - 1; } return length; } private  PictureUtil(); static Map < Character, Integer > getPictureCharOccurences(
            final String picture, final char currencySymbol); static int calcLengthFromPicture(
            final Map < Character, Integer > charNum,
            final boolean isSignSeparate, final String currencySign,
            final char currencySymbol, final boolean calcStorageLength); static String getRegexFromPicture(final String picture,
            final String currencySign, final char currencySymbol); static List < PictureSymbol > parsePicture(final String picture,
            final char currencySymbol); }
PictureUtil { public static int calcLengthFromPicture( final Map < Character, Integer > charNum, final boolean isSignSeparate, final String currencySign, final char currencySymbol, final boolean calcStorageLength) { int length = 0; Map < Character, Integer > charLen = new HashMap < Character, Integer >(); charLen.put('A', 1); charLen.put('B', 1); charLen.put('G', (calcStorageLength) ? 2 : 1); charLen.put('N', (calcStorageLength) ? 2 : 1); charLen.put('X', 1); charLen.put('P', 0); charLen.put('Z', 1); charLen.put('0', 1); charLen.put('/', 1); charLen.put('+', 1); charLen.put('-', 1); charLen.put('*', 1); charLen.put('C', 2); charLen.put('D', 2); charLen.put('.', 1); charLen.put(',', 1); charLen.put('9', 1); charLen.put('E', 1); charLen.put('S', (isSignSeparate) ? 1 : 0); charLen.put('V', 0); charLen.put(currencySymbol, 1); for (Map.Entry < Character, Integer > entry : charNum.entrySet()) { length += entry.getValue() * charLen.get(entry.getKey()); } if (currencySign.length() > 1 && charNum.get(currencySymbol) > 1) { length += currencySign.length() - 1; } return length; } private  PictureUtil(); static Map < Character, Integer > getPictureCharOccurences(
            final String picture, final char currencySymbol); static int calcLengthFromPicture(
            final Map < Character, Integer > charNum,
            final boolean isSignSeparate, final String currencySign,
            final char currencySymbol, final boolean calcStorageLength); static String getRegexFromPicture(final String picture,
            final String currencySign, final char currencySymbol); static List < PictureSymbol > parsePicture(final String picture,
            final char currencySymbol);  }