TOCReference.java 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package me.ag2s.epublib.domain;
  2. import java.io.Serializable;
  3. import java.util.ArrayList;
  4. import java.util.Comparator;
  5. import java.util.List;
  6. /**
  7. * An item in the Table of Contents.
  8. *
  9. * @see TableOfContents
  10. *
  11. * @author paul
  12. */
  13. public class TOCReference extends TitledResourceReference
  14. implements Serializable {
  15. private static final long serialVersionUID = 5787958246077042456L;
  16. private List<TOCReference> children;
  17. private static final Comparator<TOCReference> COMPARATOR_BY_TITLE_IGNORE_CASE = (tocReference1, tocReference2) -> String.CASE_INSENSITIVE_ORDER.compare(tocReference1.getTitle(), tocReference2.getTitle());
  18. @Deprecated
  19. public TOCReference() {
  20. this(null, null, null);
  21. }
  22. public TOCReference(String name, Resource resource) {
  23. this(name, resource, null);
  24. }
  25. public TOCReference(String name, Resource resource, String fragmentId) {
  26. this(name, resource, fragmentId, new ArrayList<>());
  27. }
  28. public TOCReference(String title, Resource resource, String fragmentId,
  29. List<TOCReference> children) {
  30. super(resource, title, fragmentId);
  31. this.children = children;
  32. }
  33. @SuppressWarnings("unused")
  34. public static Comparator<TOCReference> getComparatorByTitleIgnoreCase() {
  35. return COMPARATOR_BY_TITLE_IGNORE_CASE;
  36. }
  37. public List<TOCReference> getChildren() {
  38. return children;
  39. }
  40. public TOCReference addChildSection(TOCReference childSection) {
  41. this.children.add(childSection);
  42. return childSection;
  43. }
  44. public void setChildren(List<TOCReference> children) {
  45. this.children = children;
  46. }
  47. }