Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (c) 2009-2010 Mozilla Foundation |
michael@0 | 3 | * |
michael@0 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
michael@0 | 5 | * copy of this software and associated documentation files (the "Software"), |
michael@0 | 6 | * to deal in the Software without restriction, including without limitation |
michael@0 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
michael@0 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
michael@0 | 9 | * Software is furnished to do so, subject to the following conditions: |
michael@0 | 10 | * |
michael@0 | 11 | * The above copyright notice and this permission notice shall be included in |
michael@0 | 12 | * all copies or substantial portions of the Software. |
michael@0 | 13 | * |
michael@0 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
michael@0 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
michael@0 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
michael@0 | 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
michael@0 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
michael@0 | 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
michael@0 | 20 | * DEALINGS IN THE SOFTWARE. |
michael@0 | 21 | */ |
michael@0 | 22 | |
michael@0 | 23 | package nu.validator.htmlparser.impl; |
michael@0 | 24 | |
michael@0 | 25 | import nu.validator.htmlparser.annotation.Auto; |
michael@0 | 26 | |
michael@0 | 27 | |
michael@0 | 28 | public class StateSnapshot<T> implements TreeBuilderState<T> { |
michael@0 | 29 | |
michael@0 | 30 | private final @Auto StackNode<T>[] stack; |
michael@0 | 31 | |
michael@0 | 32 | private final @Auto StackNode<T>[] listOfActiveFormattingElements; |
michael@0 | 33 | |
michael@0 | 34 | private final @Auto int[] templateModeStack; |
michael@0 | 35 | |
michael@0 | 36 | private final T formPointer; |
michael@0 | 37 | |
michael@0 | 38 | private final T headPointer; |
michael@0 | 39 | |
michael@0 | 40 | private final T deepTreeSurrogateParent; |
michael@0 | 41 | |
michael@0 | 42 | private final int mode; |
michael@0 | 43 | |
michael@0 | 44 | private final int originalMode; |
michael@0 | 45 | |
michael@0 | 46 | private final boolean framesetOk; |
michael@0 | 47 | |
michael@0 | 48 | private final boolean needToDropLF; |
michael@0 | 49 | |
michael@0 | 50 | private final boolean quirks; |
michael@0 | 51 | |
michael@0 | 52 | /** |
michael@0 | 53 | * @param stack |
michael@0 | 54 | * @param listOfActiveFormattingElements |
michael@0 | 55 | * @param templateModeStack |
michael@0 | 56 | * @param formPointer |
michael@0 | 57 | * @param headPointer |
michael@0 | 58 | * @param deepTreeSurrogateParent |
michael@0 | 59 | * @param mode |
michael@0 | 60 | * @param originalMode |
michael@0 | 61 | * @param framesetOk |
michael@0 | 62 | * @param needToDropLF |
michael@0 | 63 | * @param quirks |
michael@0 | 64 | */ |
michael@0 | 65 | StateSnapshot(StackNode<T>[] stack, |
michael@0 | 66 | StackNode<T>[] listOfActiveFormattingElements, int[] templateModeStack, T formPointer, |
michael@0 | 67 | T headPointer, T deepTreeSurrogateParent, int mode, int originalMode, |
michael@0 | 68 | boolean framesetOk, boolean needToDropLF, boolean quirks) { |
michael@0 | 69 | this.stack = stack; |
michael@0 | 70 | this.listOfActiveFormattingElements = listOfActiveFormattingElements; |
michael@0 | 71 | this.templateModeStack = templateModeStack; |
michael@0 | 72 | this.formPointer = formPointer; |
michael@0 | 73 | this.headPointer = headPointer; |
michael@0 | 74 | this.deepTreeSurrogateParent = deepTreeSurrogateParent; |
michael@0 | 75 | this.mode = mode; |
michael@0 | 76 | this.originalMode = originalMode; |
michael@0 | 77 | this.framesetOk = framesetOk; |
michael@0 | 78 | this.needToDropLF = needToDropLF; |
michael@0 | 79 | this.quirks = quirks; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | /** |
michael@0 | 83 | * @see nu.validator.htmlparser.impl.TreeBuilderState#getStack() |
michael@0 | 84 | */ |
michael@0 | 85 | public StackNode<T>[] getStack() { |
michael@0 | 86 | return stack; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | /** |
michael@0 | 90 | * @see nu.validator.htmlparser.impl.TreeBuilderState#getTemplateModeStack() |
michael@0 | 91 | */ |
michael@0 | 92 | public int[] getTemplateModeStack() { |
michael@0 | 93 | return templateModeStack; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | /** |
michael@0 | 97 | * @see nu.validator.htmlparser.impl.TreeBuilderState#getListOfActiveFormattingElements() |
michael@0 | 98 | */ |
michael@0 | 99 | public StackNode<T>[] getListOfActiveFormattingElements() { |
michael@0 | 100 | return listOfActiveFormattingElements; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | /** |
michael@0 | 104 | * @see nu.validator.htmlparser.impl.TreeBuilderState#getFormPointer() |
michael@0 | 105 | */ |
michael@0 | 106 | public T getFormPointer() { |
michael@0 | 107 | return formPointer; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | /** |
michael@0 | 111 | * Returns the headPointer. |
michael@0 | 112 | * |
michael@0 | 113 | * @return the headPointer |
michael@0 | 114 | */ |
michael@0 | 115 | public T getHeadPointer() { |
michael@0 | 116 | return headPointer; |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | /** |
michael@0 | 120 | * Returns the deepTreeSurrogateParent. |
michael@0 | 121 | * |
michael@0 | 122 | * @return the deepTreeSurrogateParent |
michael@0 | 123 | */ |
michael@0 | 124 | public T getDeepTreeSurrogateParent() { |
michael@0 | 125 | return deepTreeSurrogateParent; |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | /** |
michael@0 | 129 | * Returns the mode. |
michael@0 | 130 | * |
michael@0 | 131 | * @return the mode |
michael@0 | 132 | */ |
michael@0 | 133 | public int getMode() { |
michael@0 | 134 | return mode; |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | /** |
michael@0 | 138 | * Returns the originalMode. |
michael@0 | 139 | * |
michael@0 | 140 | * @return the originalMode |
michael@0 | 141 | */ |
michael@0 | 142 | public int getOriginalMode() { |
michael@0 | 143 | return originalMode; |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | /** |
michael@0 | 147 | * Returns the framesetOk. |
michael@0 | 148 | * |
michael@0 | 149 | * @return the framesetOk |
michael@0 | 150 | */ |
michael@0 | 151 | public boolean isFramesetOk() { |
michael@0 | 152 | return framesetOk; |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | /** |
michael@0 | 156 | * Returns the needToDropLF. |
michael@0 | 157 | * |
michael@0 | 158 | * @return the needToDropLF |
michael@0 | 159 | */ |
michael@0 | 160 | public boolean isNeedToDropLF() { |
michael@0 | 161 | return needToDropLF; |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | /** |
michael@0 | 165 | * Returns the quirks. |
michael@0 | 166 | * |
michael@0 | 167 | * @return the quirks |
michael@0 | 168 | */ |
michael@0 | 169 | public boolean isQuirks() { |
michael@0 | 170 | return quirks; |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | /** |
michael@0 | 174 | * @see nu.validator.htmlparser.impl.TreeBuilderState#getListOfActiveFormattingElementsLength() |
michael@0 | 175 | */ |
michael@0 | 176 | public int getListOfActiveFormattingElementsLength() { |
michael@0 | 177 | return listOfActiveFormattingElements.length; |
michael@0 | 178 | } |
michael@0 | 179 | |
michael@0 | 180 | /** |
michael@0 | 181 | * @see nu.validator.htmlparser.impl.TreeBuilderState#getStackLength() |
michael@0 | 182 | */ |
michael@0 | 183 | public int getStackLength() { |
michael@0 | 184 | return stack.length; |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | /** |
michael@0 | 188 | * @see nu.validator.htmlparser.impl.TreeBuilderState#getTemplateModeStackLength() |
michael@0 | 189 | */ |
michael@0 | 190 | public int getTemplateModeStackLength() { |
michael@0 | 191 | return templateModeStack.length; |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | @SuppressWarnings("unused") private void destructor() { |
michael@0 | 195 | for (int i = 0; i < stack.length; i++) { |
michael@0 | 196 | stack[i].release(); |
michael@0 | 197 | } |
michael@0 | 198 | for (int i = 0; i < listOfActiveFormattingElements.length; i++) { |
michael@0 | 199 | if (listOfActiveFormattingElements[i] != null) { |
michael@0 | 200 | listOfActiveFormattingElements[i].release(); |
michael@0 | 201 | } |
michael@0 | 202 | } |
michael@0 | 203 | } |
michael@0 | 204 | } |