You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StringDecorator.java 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.data.util.sqlcontainer.query.generator.filter;
  5. import java.io.Serializable;
  6. /**
  7. * The StringDecorator knows how to produce a quoted string using the specified
  8. * quote start and quote end characters. It also handles grouping of a string
  9. * (surrounding it in parenthesis).
  10. *
  11. * Extend this class if you need to support special characters for grouping
  12. * (parenthesis).
  13. *
  14. * @author Vaadin Ltd
  15. */
  16. public class StringDecorator implements Serializable {
  17. private final String quoteStart;
  18. private final String quoteEnd;
  19. /**
  20. * Constructs a StringDecorator that uses the quoteStart and quoteEnd
  21. * characters to create quoted strings.
  22. *
  23. * @param quoteStart
  24. * the character denoting the start of a quote.
  25. * @param quoteEnd
  26. * the character denoting the end of a quote.
  27. */
  28. public StringDecorator(String quoteStart, String quoteEnd) {
  29. this.quoteStart = quoteStart;
  30. this.quoteEnd = quoteEnd;
  31. }
  32. /**
  33. * Surround a string with quote characters.
  34. *
  35. * @param str
  36. * the string to quote
  37. * @return the quoted string
  38. */
  39. public String quote(Object str) {
  40. return quoteStart + str + quoteEnd;
  41. }
  42. /**
  43. * Groups a string by surrounding it in parenthesis
  44. *
  45. * @param str
  46. * the string to group
  47. * @return the grouped string
  48. */
  49. public String group(String str) {
  50. return "(" + str + ")";
  51. }
  52. }