\r
\r
public abstract class CacheGen<G extends XGen<G>> {\r
- public static final int NO_FLAGS = 0x0;\r
- public final static int PRETTY = 0x1;\r
- public final static int XML = 0x2;\r
- public final static int HTML4 = 0x4;\r
- public final static int HTML5 = 0x8;\r
+ public static final int NO_FLAGS = 0x0;\r
+ public final static int PRETTY = 0x1;\r
+ public final static int XML = 0x2;\r
+ public final static int HTML4 = 0x4;\r
+ public final static int HTML5 = 0x8;\r
\r
- \r
- private ArrayList<Section<G>> sections = new ArrayList<Section<G>>();\r
- private int flags;\r
- private final Thematic thematic;\r
+ \r
+ private ArrayList<Section<G>> sections = new ArrayList<>();\r
+ private int flags;\r
+ private final Thematic thematic;\r
\r
- public CacheGen(int flags, Code<G> code) throws APIException, IOException {\r
- this.flags = flags;\r
- final XGenBuff<G> buff = new XGenBuff<G>(flags,this);\r
- // Run to gather Strings and Code Class Segments\r
- buff.run(new Cache<G>() {\r
- @Override\r
- public void dynamic(G hgen, Code<G> code) {\r
- sections.add(buff.newSection());\r
- sections.add(new Dynamic(hgen.getIndent(),code));\r
- }\r
- },code);\r
- sections.add(buff.newSection());\r
- \r
- // If Code implements thematic, set for later\r
- thematic = code instanceof Thematic?(Thematic)code:null;\r
+ public CacheGen(int flags, Code<G> code) throws APIException, IOException {\r
+ this.flags = flags;\r
+ final XGenBuff<G> buff = new XGenBuff<G>(flags,this);\r
+ // Run to gather Strings and Code Class Segments\r
+ buff.run(new Cache<G>() {\r
+ @Override\r
+ public void dynamic(G hgen, Code<G> code) {\r
+ sections.add(buff.newSection());\r
+ sections.add(new Dynamic(hgen.getIndent(),code));\r
+ }\r
+ },code);\r
+ sections.add(buff.newSection());\r
+ \r
+ // If Code implements thematic, set for later\r
+ thematic = code instanceof Thematic?(Thematic)code:null;\r
\r
- }\r
- \r
- public abstract G create(int htmlStyle, Writer w);\r
+ }\r
+ \r
+ public abstract G create(int htmlStyle, Writer w);\r
\r
- public void replay(State<Env> state, Trans trans, OutputStream os, String theme) throws IOException, APIException {\r
- replay(state, trans, new OutputStreamWriter(os), theme);\r
- }\r
- \r
- public void replay(State<Env> state, Trans trans,Writer w, String theme) throws IOException, APIException {\r
- if(thematic!=null) {\r
- theme = thematic.themeResolve(theme);\r
- }\r
- /* Theme\r
- trans.setTheme(theme);\r
- int htmlStyle = state.htmlVer(theme);\r
- */\r
- \r
- XGenBuff<G> buff = new XGenBuff<G>(flags,this);\r
- \r
- // forward\r
- int indent = 0;\r
- Section<G> s;\r
- int i=0;\r
- @SuppressWarnings("unchecked")\r
- Section<G>[] reverse = new Section[sections.size()];\r
- for(Section<G> section : sections) {\r
- s = section.use(state, trans, buff); // note, doesn't change cached, only dynamic, which is created for thread\r
- int tempIndent = s.getIndent();\r
- s.setIndent(indent);\r
- s.forward(w);\r
- s.setIndent(tempIndent);\r
- indent = tempIndent;\r
- reverse[i++]=s;\r
- }\r
+ public void replay(State<Env> state, Trans trans, OutputStream os, String theme) throws IOException, APIException {\r
+ replay(state, trans, new OutputStreamWriter(os), theme);\r
+ }\r
+ \r
+ public void replay(State<Env> state, Trans trans,Writer w, String theme) throws IOException, APIException {\r
+ if(thematic!=null) {\r
+ theme = thematic.themeResolve(theme);\r
+ }\r
+ /* Theme\r
+ trans.setTheme(theme);\r
+ int htmlStyle = state.htmlVer(theme);\r
+ */\r
+ \r
+ XGenBuff<G> buff = new XGenBuff<G>(flags,this);\r
+ \r
+ // forward\r
+ int indent = 0;\r
+ Section<G> s;\r
+ int i=0;\r
+ @SuppressWarnings("unchecked")\r
+ Section<G>[] reverse = new Section[sections.size()];\r
+ for(Section<G> section : sections) {\r
+ s = section.use(state, trans, buff); // note, doesn't change cached, only dynamic, which is created for thread\r
+ int tempIndent = s.getIndent();\r
+ s.setIndent(indent);\r
+ s.forward(w);\r
+ s.setIndent(tempIndent);\r
+ indent = tempIndent;\r
+ reverse[i++]=s;\r
+ }\r
\r
- for(--i;i>=0;--i) {\r
- reverse[i].back(w);\r
- }\r
- w.flush();\r
- }\r
- \r
- private class Dynamic extends Section<G> {\r
- private Code<G> code;\r
- \r
- public Dynamic(int indent, Code<G> code) {\r
- this.code = code;\r
- this.indent = indent;\r
- }\r
+ for(--i;i>=0;--i) {\r
+ reverse[i].back(w);\r
+ }\r
+ w.flush();\r
+ }\r
+ \r
+ private class Dynamic extends Section<G> {\r
+ private Code<G> code;\r
+ \r
+ public Dynamic(int indent, Code<G> code) {\r
+ this.code = code;\r
+ this.indent = indent;\r
+ }\r
\r
- @SuppressWarnings("unchecked")\r
- public Section<G> use(State<Env> state, Trans trans, XGenBuff<G> buff) throws APIException, IOException {\r
- // Clone Dynamic to make Thread Safe\r
- Dynamic d = new Dynamic(indent,code);\r
- buff.setIndent(indent);\r
- if(code instanceof DynamicCode) {\r
- buff.run(state,trans,Cache.Null.singleton(), (DynamicCode<G,?,? extends Trans>)code);\r
- } else {\r
- buff.run((Cache<G>)Cache.Null.singleton(), code);\r
- }\r
- Section<G> s = buff.newSection();\r
- d.indent = s.indent;\r
- d.forward = s.forward;\r
- d.backward = s.backward;\r
- return d;\r
- }\r
- }\r
+ @SuppressWarnings("unchecked")\r
+ public Section<G> use(State<Env> state, Trans trans, XGenBuff<G> buff) throws APIException, IOException {\r
+ // Clone Dynamic to make Thread Safe\r
+ Dynamic d = new Dynamic(indent,code);\r
+ buff.setIndent(indent);\r
+ if(code instanceof DynamicCode) {\r
+ buff.run(state,trans,Cache.Null.singleton(), (DynamicCode<G,?,? extends Trans>)code);\r
+ } else {\r
+ buff.run((Cache<G>)Cache.Null.singleton(), code);\r
+ }\r
+ Section<G> s = buff.newSection();\r
+ d.indent = s.indent;\r
+ d.forward = s.forward;\r
+ d.backward = s.backward;\r
+ return d;\r
+ }\r
+ }\r
}\r