Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. package net.thoughtforge.cache.key;
  2.  
  3. public class KeyValueBuilder {
  4.  
  5. private static final String DEFAULT_ELEMENT_SEPERATOR = "/";
  6. private final String elementSeperator;
  7. private final StringBuffer keyValue;
  8.  
  9. public KeyValueBuilder() {
  10. keyValue = new StringBuffer();
  11. this.elementSeperator = DEFAULT_ELEMENT_SEPERATOR;
  12. }
  13.  
  14. public KeyValueBuilder(final String elementSeperator) {
  15. keyValue = new StringBuffer();
  16. this.elementSeperator = elementSeperator;
  17. }
  18.  
  19. public KeyValueBuilder addElement(final Boolean element) {
  20. if (keyValue.length() > 0) {
  21. keyValue.append(elementSeperator);
  22. }
  23. keyValue.append(Boolean.toString(element));
  24. return this;
  25. }
  26.  
  27. public KeyValueBuilder addElement(final Enum<?> element) {
  28. if (keyValue.length() > 0) {
  29. keyValue.append(elementSeperator);
  30. }
  31. keyValue.append(element.name());
  32. return this;
  33. }
  34.  
  35. public KeyValueBuilder addElement(final Integer element) {
  36. if (keyValue.length() > 0) {
  37. keyValue.append(elementSeperator);
  38. }
  39. keyValue.append(Integer.toString(element));
  40. return this;
  41. }
  42.  
  43. public KeyValueBuilder addElement(final String element) {
  44. if (keyValue.length() > 0) {
  45. keyValue.append(elementSeperator);
  46. }
  47. keyValue.append(element);
  48. return this;
  49. }
  50.  
  51. public String getKeyValue() {
  52. return keyValue.toString();
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement