Consumer.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (c) 2000, 2001, 2006 Per M.A. Bothner and Brainfood Inc.
  2. // This is free software; for terms and warranty disclaimer see ./COPYING.
  3. package gnu.lists;
  4. /** A Consumer is something that will accept data (output),
  5. * and do something with it.
  6. * A consumer is like a SAX DocumentHandler or a PrintWriter,
  7. * but more abstract. If a Sequence class impleemnts Consumer,
  8. * then data "written" to the sequence will be inserted in the sequence.
  9. * <p>
  10. * <em>Note:</em> This interface is not quite final. For example it is
  11. * probable we will add methods for comments, processing instructions, etc.
  12. */
  13. public interface Consumer
  14. extends Appendable
  15. /* #ifdef JAVA8 */
  16. , java.util.function.Consumer<Object>,
  17. java.util.function.IntConsumer,
  18. java.util.function.LongConsumer,
  19. java.util.function.DoubleConsumer
  20. /* #endif */
  21. {
  22. public void writeBoolean(boolean v);
  23. public void writeFloat(float v);
  24. public void writeDouble(double v);
  25. public void writeInt(int v);
  26. public void writeLong(long v);
  27. public void startDocument();
  28. public void endDocument();
  29. public void startElement(Object type);
  30. public void endElement();
  31. /** Write a attribute for the current element.
  32. * This is only allowed immediately after a startElement. */
  33. public void startAttribute(Object attrType);
  34. /** End of an attribute or end of an actual parameter.
  35. * The former use matches a startAttribute; the latter may not,
  36. * and can be used to separate parameters in a parameter list.
  37. * This double duty suggsts the method should at least be re-named. */
  38. public void endAttribute();
  39. public void writeObject(Object v);
  40. /** True if consumer is ignoring rest of element.
  41. * The producer can use this information to skip ahead. */
  42. public boolean ignoring();
  43. public void write(int ch);
  44. public void write(String string);
  45. public void write(CharSequence string, int start, int length);
  46. public void write(char[] buf, int start, int length);
  47. public Consumer append (char c);
  48. public Consumer append (CharSequence csq);
  49. public Consumer append (CharSequence csq, int start, int end);
  50. /* #ifdef JAVA8 */
  51. default public void accept(Object t) { writeObject(t); }
  52. default public void accept(int t) { writeInt(t); }
  53. default public void accept(long t) { writeLong(t); }
  54. default public void accept(double t) { writeDouble(t); }
  55. /* #endif */
  56. }