@Test public void testGetLiteral() { LiteralSupport literalSupport = new DefaultLiteralSupport(); assertNull(literalSupport.getLiteral("foo", null)); assertNull(literalSupport.getLiteral("1.0", null)); assertEquals(10, literalSupport.getLiteral("+10", null)); assertEquals(-2010, literalSupport.getLiteral("-2010", null)); assertEquals("foo", literalSupport.getLiteral("'foo'", null)); assertEquals("bar.me", literalSupport.getLiteral("\"bar.me\"", null)); assertEquals(10L, literalSupport.getLiteral("10L", null)); assertEquals(-2010L, literalSupport.getLiteral("-2010l", null)); assertNull(literalSupport.getLiteral("2.0", null)); assertEquals(Boolean.TRUE, literalSupport.getLiteral("true", null)); assertEquals(Boolean.FALSE, literalSupport.getLiteral("false", null)); }
@Override public Object getLiteral(String value, MustacheTagInfo tagInfo) { if (Strings.isEmpty(value)) { return null; } Object literal = null; if (Strings.isStringLiteralSeparator(value.charAt(0))) { literal = value.substring(1, value.length() - 1); } else if (value.equals("true")) { literal = Boolean.TRUE; } else if (value.equals("false")) { literal = Boolean.FALSE; } else if (integerLiteralPattern.matcher(value).matches()) { try { literal = Integer.parseInt(value); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse integer literal: " + value, e); } } else if (longLiteralPattern.matcher(value).matches()) { try { literal = Long .parseLong(value.substring(0, value.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse long literal: " + value, e); } } return literal; }
DefaultLiteralSupport extends AbstractConfigurationAware implements LiteralSupport { @Override public Object getLiteral(String value, MustacheTagInfo tagInfo) { if (Strings.isEmpty(value)) { return null; } Object literal = null; if (Strings.isStringLiteralSeparator(value.charAt(0))) { literal = value.substring(1, value.length() - 1); } else if (value.equals("true")) { literal = Boolean.TRUE; } else if (value.equals("false")) { literal = Boolean.FALSE; } else if (integerLiteralPattern.matcher(value).matches()) { try { literal = Integer.parseInt(value); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse integer literal: " + value, e); } } else if (longLiteralPattern.matcher(value).matches()) { try { literal = Long .parseLong(value.substring(0, value.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse long literal: " + value, e); } } return literal; } }
DefaultLiteralSupport extends AbstractConfigurationAware implements LiteralSupport { @Override public Object getLiteral(String value, MustacheTagInfo tagInfo) { if (Strings.isEmpty(value)) { return null; } Object literal = null; if (Strings.isStringLiteralSeparator(value.charAt(0))) { literal = value.substring(1, value.length() - 1); } else if (value.equals("true")) { literal = Boolean.TRUE; } else if (value.equals("false")) { literal = Boolean.FALSE; } else if (integerLiteralPattern.matcher(value).matches()) { try { literal = Integer.parseInt(value); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse integer literal: " + value, e); } } else if (longLiteralPattern.matcher(value).matches()) { try { literal = Long .parseLong(value.substring(0, value.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse long literal: " + value, e); } } return literal; }  }
DefaultLiteralSupport extends AbstractConfigurationAware implements LiteralSupport { @Override public Object getLiteral(String value, MustacheTagInfo tagInfo) { if (Strings.isEmpty(value)) { return null; } Object literal = null; if (Strings.isStringLiteralSeparator(value.charAt(0))) { literal = value.substring(1, value.length() - 1); } else if (value.equals("true")) { literal = Boolean.TRUE; } else if (value.equals("false")) { literal = Boolean.FALSE; } else if (integerLiteralPattern.matcher(value).matches()) { try { literal = Integer.parseInt(value); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse integer literal: " + value, e); } } else if (longLiteralPattern.matcher(value).matches()) { try { literal = Long .parseLong(value.substring(0, value.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse long literal: " + value, e); } } return literal; }  @Override Object getLiteral(String value, MustacheTagInfo tagInfo); }
DefaultLiteralSupport extends AbstractConfigurationAware implements LiteralSupport { @Override public Object getLiteral(String value, MustacheTagInfo tagInfo) { if (Strings.isEmpty(value)) { return null; } Object literal = null; if (Strings.isStringLiteralSeparator(value.charAt(0))) { literal = value.substring(1, value.length() - 1); } else if (value.equals("true")) { literal = Boolean.TRUE; } else if (value.equals("false")) { literal = Boolean.FALSE; } else if (integerLiteralPattern.matcher(value).matches()) { try { literal = Integer.parseInt(value); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse integer literal: " + value, e); } } else if (longLiteralPattern.matcher(value).matches()) { try { literal = Long .parseLong(value.substring(0, value.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse long literal: " + value, e); } } return literal; }  @Override Object getLiteral(String value, MustacheTagInfo tagInfo);  }