diff options
| -rw-r--r-- | dotnet/Mammoth/Couscous/java/util/ArrayDeque.cs | 35 | ||||
| -rw-r--r-- | dotnet/Mammoth/Couscous/java/util/Deque.cs | 10 | ||||
| -rw-r--r-- | dotnet/Mammoth/Mammoth.csproj | 2 | ||||
| -rw-r--r-- | src/main/java/org/zwobble/mammoth/internal/xml/parsing/XmlParser.java | 16 |
4 files changed, 55 insertions, 8 deletions
diff --git a/dotnet/Mammoth/Couscous/java/util/ArrayDeque.cs b/dotnet/Mammoth/Couscous/java/util/ArrayDeque.cs new file mode 100644 index 0000000..df5447d --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/util/ArrayDeque.cs @@ -0,0 +1,35 @@ +namespace Mammoth.Couscous.java.util { + internal class ArrayDeque<T> : Deque<T> { + private readonly System.Collections.Generic.IList<T> _list = new System.Collections.Generic.List<T>(); + + public int size() { + return _list.Count; + } + + public T getFirst() { + if (_list.Count > 0) { + return _list[0]; + } else { + throw new NoSuchElementException(); + } + } + + public T getLast() { + if (_list.Count > 0) { + return _list[_list.Count - 1]; + } else { + throw new NoSuchElementException(); + } + } + + public void add(T value) { + _list.Add(value); + } + + public T removeLast() { + T value = getLast(); + _list.RemoveAt(_list.Count - 1); + return value; + } + } +} diff --git a/dotnet/Mammoth/Couscous/java/util/Deque.cs b/dotnet/Mammoth/Couscous/java/util/Deque.cs new file mode 100644 index 0000000..c954fce --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/util/Deque.cs @@ -0,0 +1,10 @@ +namespace Mammoth.Couscous.java.util { + internal interface Deque<T> { + int size(); + T getFirst(); + T getLast(); + + void add(T value); + T removeLast(); + } +} diff --git a/dotnet/Mammoth/Mammoth.csproj b/dotnet/Mammoth/Mammoth.csproj index 1c17a82..a49035c 100644 --- a/dotnet/Mammoth/Mammoth.csproj +++ b/dotnet/Mammoth/Mammoth.csproj @@ -60,8 +60,10 @@ <Compile Include="Couscous\java\util\function\Function.cs" /> <Compile Include="Couscous\java\util\function\Predicate.cs" /> <Compile Include="Couscous\java\util\function\Supplier.cs" /> + <Compile Include="Couscous\java\util\ArrayDeque.cs" /> <Compile Include="Couscous\java\util\ArrayList.cs" /> <Compile Include="Couscous\java\util\Collection.cs" /> + <Compile Include="Couscous\java\util\Deque.cs" /> <Compile Include="Couscous\java\util\HashMap.cs" /> <Compile Include="Couscous\java\util\HashSet.cs" /> <Compile Include="Couscous\java\util\Iterator.cs" /> diff --git a/src/main/java/org/zwobble/mammoth/internal/xml/parsing/XmlParser.java b/src/main/java/org/zwobble/mammoth/internal/xml/parsing/XmlParser.java index e0cc5b4..c76e989 100644 --- a/src/main/java/org/zwobble/mammoth/internal/xml/parsing/XmlParser.java +++ b/src/main/java/org/zwobble/mammoth/internal/xml/parsing/XmlParser.java @@ -5,8 +5,8 @@ import org.zwobble.mammoth.internal.xml.XmlElement; import org.zwobble.mammoth.internal.xml.XmlTextNode; import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; +import java.util.ArrayDeque; +import java.util.Deque; import java.util.Map; import static org.zwobble.mammoth.internal.util.Maps.eagerMapKeys; @@ -32,14 +32,14 @@ public class XmlParser { } private class NodeGenerator implements SimpleSaxHandler { - private final List<XmlElementBuilder> elementStack; + private final Deque<XmlElementBuilder> elementStack; public NodeGenerator() { - elementStack = new ArrayList<>(); + elementStack = new ArrayDeque<>(); } public XmlElement getRoot() { - return elementStack.get(0).build(); + return elementStack.getFirst().build(); } @Override @@ -63,14 +63,14 @@ public class XmlParser { @Override public void endElement() { if (elementStack.size() > 1) { - XmlElementBuilder element = elementStack.remove(elementStack.size() - 1); - elementStack.get(elementStack.size() - 1).addChild(element.build()); + XmlElementBuilder element = elementStack.removeLast(); + elementStack.getLast().addChild(element.build()); } } @Override public void characters(String string) { - elementStack.get(elementStack.size() - 1).addChild(new XmlTextNode(string)); + elementStack.getLast().addChild(new XmlTextNode(string)); } } } |
