@Test public void testResolveFigurative() { assertEquals("A", ValueUtil.resolveFigurative("'A'", 5, true)); assertEquals("9", ValueUtil.resolveFigurative("9", 5, true)); assertEquals("0", ValueUtil.resolveFigurative("zero", 5, true)); assertEquals(" ", ValueUtil.resolveFigurative("spaces", 5, true)); assertEquals("\"", ValueUtil.resolveFigurative("quote", 5, true)); assertEquals("'", ValueUtil.resolveFigurative("quote", 5, false)); assertEquals("'", ValueUtil.resolveFigurative("apost", 5, true)); assertEquals("0x0000000000", ValueUtil.resolveFigurative("LOW-VALUE", 5, true)); assertEquals("0xFFFFFFFFFF", ValueUtil.resolveFigurative("HIGH-VALUE", 5, true)); assertEquals("0x0000000000", ValueUtil.resolveFigurative("NULLS", 5, true)); assertEquals(" ", ValueUtil.resolveFigurative("ALL SPACES", 5, true)); assertEquals("00000", ValueUtil.resolveFigurative("ALL ZERO", 5, true)); assertEquals("0x0000000000", ValueUtil.resolveFigurative("ALL LOW-VALUE", 5, true)); assertEquals("AAAAA", ValueUtil.resolveFigurative("ALL 'A'", 5, true)); assertEquals("ABABA", ValueUtil.resolveFigurative("ALL 'AB'", 5, true)); }
public static String resolveFigurative( final String value, final int length, final boolean quoteIsQuote) { if (value == null || value.length() == 0) { return value; } String ucValue = value.toUpperCase(Locale.getDefault()); if (ucValue.matches("^ZERO(S|ES)?$")) { return "0"; } if (ucValue.matches("^SPACES?$")) { return " "; } if (ucValue.matches("^QUOTES?$")) { return quoteIsQuote ? "\"" : "\'"; } if (ucValue.matches("^APOST$")) { return "\'"; } if (ucValue.matches("^HIGH-VALUES?$")) { return fill("0x", "FF", length); } if (ucValue.matches("^LOW-VALUES?$")) { return fill("0x", "00", length); } if (ucValue.matches("^NULLS?$")) { return fill("0x", "00", length); } if (ucValue.startsWith("ALL ")) { String literal = value.substring("ALL ".length()); String resolvedLiteral = ValueUtil.resolveFigurative( literal, length, quoteIsQuote); if (resolvedLiteral.length() > 0 && resolvedLiteral.length() < length) { String filled = fill(null, resolvedLiteral, length / resolvedLiteral.length()); if (filled.length() < length) { return filled + resolvedLiteral.substring(0, length - filled.length()); } else { return filled; } } else { return resolvedLiteral; } } return stripDelimiters(value); }
ValueUtil { public static String resolveFigurative( final String value, final int length, final boolean quoteIsQuote) { if (value == null || value.length() == 0) { return value; } String ucValue = value.toUpperCase(Locale.getDefault()); if (ucValue.matches("^ZERO(S|ES)?$")) { return "0"; } if (ucValue.matches("^SPACES?$")) { return " "; } if (ucValue.matches("^QUOTES?$")) { return quoteIsQuote ? "\"" : "\'"; } if (ucValue.matches("^APOST$")) { return "\'"; } if (ucValue.matches("^HIGH-VALUES?$")) { return fill("0x", "FF", length); } if (ucValue.matches("^LOW-VALUES?$")) { return fill("0x", "00", length); } if (ucValue.matches("^NULLS?$")) { return fill("0x", "00", length); } if (ucValue.startsWith("ALL ")) { String literal = value.substring("ALL ".length()); String resolvedLiteral = ValueUtil.resolveFigurative( literal, length, quoteIsQuote); if (resolvedLiteral.length() > 0 && resolvedLiteral.length() < length) { String filled = fill(null, resolvedLiteral, length / resolvedLiteral.length()); if (filled.length() < length) { return filled + resolvedLiteral.substring(0, length - filled.length()); } else { return filled; } } else { return resolvedLiteral; } } return stripDelimiters(value); } }
ValueUtil { public static String resolveFigurative( final String value, final int length, final boolean quoteIsQuote) { if (value == null || value.length() == 0) { return value; } String ucValue = value.toUpperCase(Locale.getDefault()); if (ucValue.matches("^ZERO(S|ES)?$")) { return "0"; } if (ucValue.matches("^SPACES?$")) { return " "; } if (ucValue.matches("^QUOTES?$")) { return quoteIsQuote ? "\"" : "\'"; } if (ucValue.matches("^APOST$")) { return "\'"; } if (ucValue.matches("^HIGH-VALUES?$")) { return fill("0x", "FF", length); } if (ucValue.matches("^LOW-VALUES?$")) { return fill("0x", "00", length); } if (ucValue.matches("^NULLS?$")) { return fill("0x", "00", length); } if (ucValue.startsWith("ALL ")) { String literal = value.substring("ALL ".length()); String resolvedLiteral = ValueUtil.resolveFigurative( literal, length, quoteIsQuote); if (resolvedLiteral.length() > 0 && resolvedLiteral.length() < length) { String filled = fill(null, resolvedLiteral, length / resolvedLiteral.length()); if (filled.length() < length) { return filled + resolvedLiteral.substring(0, length - filled.length()); } else { return filled; } } else { return resolvedLiteral; } } return stripDelimiters(value); } private  ValueUtil(); }
ValueUtil { public static String resolveFigurative( final String value, final int length, final boolean quoteIsQuote) { if (value == null || value.length() == 0) { return value; } String ucValue = value.toUpperCase(Locale.getDefault()); if (ucValue.matches("^ZERO(S|ES)?$")) { return "0"; } if (ucValue.matches("^SPACES?$")) { return " "; } if (ucValue.matches("^QUOTES?$")) { return quoteIsQuote ? "\"" : "\'"; } if (ucValue.matches("^APOST$")) { return "\'"; } if (ucValue.matches("^HIGH-VALUES?$")) { return fill("0x", "FF", length); } if (ucValue.matches("^LOW-VALUES?$")) { return fill("0x", "00", length); } if (ucValue.matches("^NULLS?$")) { return fill("0x", "00", length); } if (ucValue.startsWith("ALL ")) { String literal = value.substring("ALL ".length()); String resolvedLiteral = ValueUtil.resolveFigurative( literal, length, quoteIsQuote); if (resolvedLiteral.length() > 0 && resolvedLiteral.length() < length) { String filled = fill(null, resolvedLiteral, length / resolvedLiteral.length()); if (filled.length() < length) { return filled + resolvedLiteral.substring(0, length - filled.length()); } else { return filled; } } else { return resolvedLiteral; } } return stripDelimiters(value); } private  ValueUtil(); static String resolveFigurative(
            final String value,
            final int length,
            final boolean quoteIsQuote); static String fill(
            final String prefix,
            final String charSequence,
            final int times); static String stripDelimiters(final String value); }
ValueUtil { public static String resolveFigurative( final String value, final int length, final boolean quoteIsQuote) { if (value == null || value.length() == 0) { return value; } String ucValue = value.toUpperCase(Locale.getDefault()); if (ucValue.matches("^ZERO(S|ES)?$")) { return "0"; } if (ucValue.matches("^SPACES?$")) { return " "; } if (ucValue.matches("^QUOTES?$")) { return quoteIsQuote ? "\"" : "\'"; } if (ucValue.matches("^APOST$")) { return "\'"; } if (ucValue.matches("^HIGH-VALUES?$")) { return fill("0x", "FF", length); } if (ucValue.matches("^LOW-VALUES?$")) { return fill("0x", "00", length); } if (ucValue.matches("^NULLS?$")) { return fill("0x", "00", length); } if (ucValue.startsWith("ALL ")) { String literal = value.substring("ALL ".length()); String resolvedLiteral = ValueUtil.resolveFigurative( literal, length, quoteIsQuote); if (resolvedLiteral.length() > 0 && resolvedLiteral.length() < length) { String filled = fill(null, resolvedLiteral, length / resolvedLiteral.length()); if (filled.length() < length) { return filled + resolvedLiteral.substring(0, length - filled.length()); } else { return filled; } } else { return resolvedLiteral; } } return stripDelimiters(value); } private  ValueUtil(); static String resolveFigurative(
            final String value,
            final int length,
            final boolean quoteIsQuote); static String fill(
            final String prefix,
            final String charSequence,
            final int times); static String stripDelimiters(final String value);  }