daily pastebin goal
1%
SHARE
TWEET

Untitled

a guest Dec 18th, 2017 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package md2html;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.Collections;
  6. import java.util.List;
  7.  
  8. public abstract class ConvertableMarkup implements Interface {
  9.     private List<Interface> data;
  10.     protected StringBuilder text;
  11.  
  12.     protected ConvertableMarkup() {
  13.         this.data = new ArrayList<>();
  14.     }
  15.  
  16.     protected ConvertableMarkup(Interface... items) {
  17.         this.data = new ArrayList<>(Arrays.asList(items));
  18.     }
  19.  
  20.     protected ConvertableMarkup(List<Interface> data) {
  21.         this.data = data;
  22.     }
  23.  
  24.     protected ConvertableMarkup(String text) {
  25.         this.text = new StringBuilder(text);
  26.     }
  27.  
  28.     public void add(Interface item) {
  29.         data.add(item);
  30.     }
  31.  
  32.     public StringBuilder toHtml() {
  33.         StringBuilder sb = new StringBuilder();
  34.         for (Interface elem : data) {
  35.             sb.append(elem.toHtml());
  36.         }
  37.         return sb;
  38.     }
  39.  
  40.     public StringBuilder toMarkdown() {
  41.         StringBuilder sb = new StringBuilder();
  42.         for (Interface classes : data) {
  43.             sb.append(classes.toMarkdown());
  44.         }
  45.         return sb;
  46.     }
  47.  
  48.     public StringBuilder toTex() {
  49.         StringBuilder sb = new StringBuilder();
  50.         for (Interface classes : data) {
  51.             sb.append(classes.toTex());
  52.         }
  53.         return sb;
  54.     }
  55.  
  56.     public List<Interface> getData() {
  57.         if (data == null) {
  58.             return Collections.singletonList(new Text(text.toString()));
  59.         }
  60.         return data;
  61.     }
  62.  
  63.     public int size() {
  64.         return data.size();
  65.     }
  66.  
  67. }
RAW Paste Data
Top