X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FPartContainer.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FPartContainer.java;h=0000000000000000000000000000000000000000;hb=a50ce8a4da6ec513a97a2d0237e8ef9f640283cd;hp=3444d19e08fa9c09c745a3851c100400967c83a9;hpb=f6bb52d378645bf821febd6696bc69f250a92280;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/text/PartContainer.java b/src/main/java/net/pterodactylus/sone/text/PartContainer.java
deleted file mode 100644
index 3444d19..0000000
--- a/src/main/java/net/pterodactylus/sone/text/PartContainer.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Sone - PartContainer.java - Copyright © 2010â2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package net.pterodactylus.sone.text;
-
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.Deque;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Objects;
-
-import javax.annotation.Nonnull;
-
-/**
- * Part implementation that can contain an arbitrary amount of other parts.
- * Parts are added using the {@link #add(Part)} method and will be rendered in
- * the order they are added.
- *
- * @author David âBombeâ Roden
- */
-public class PartContainer implements Part, Iterable {
-
- private final List parts = new ArrayList();
-
- public void add(@Nonnull Part part) {
- parts.add(Objects.requireNonNull(part));
- }
-
- @Nonnull
- public Part getPart(int index) {
- return parts.get(index);
- }
-
- public void removePart(int index) {
- parts.remove(index);
- }
-
- public int size() {
- return parts.size();
- }
-
- @Override
- @Nonnull
- public String getText() {
- StringBuilder partText = new StringBuilder();
- for (Part part : parts) {
- partText.append(part.getText());
- }
- return partText.toString();
- }
-
- @Override
- @Nonnull
- @SuppressWarnings("synthetic-access")
- public Iterator iterator() {
- return new Iterator() {
-
- private Deque> partStack = new ArrayDeque>();
- private Part nextPart;
- private boolean foundNextPart;
- private boolean noNextPart;
-
- {
- partStack.push(parts.iterator());
- }
-
- private void findNext() {
- if (foundNextPart) {
- return;
- }
- noNextPart = true;
- while (!partStack.isEmpty()) {
- Iterator parts = partStack.pop();
- if (parts.hasNext()) {
- nextPart = parts.next();
- partStack.push(parts);
- if (nextPart instanceof PartContainer) {
- partStack.push(((PartContainer) nextPart).iterator());
- } else {
- noNextPart = false;
- break;
- }
- }
- }
- foundNextPart = true;
- }
-
- @Override
- public boolean hasNext() {
- findNext();
- return !noNextPart;
- }
-
- @Override
- public Part next() {
- findNext();
- if (noNextPart) {
- throw new NoSuchElementException();
- }
- foundNextPart = false;
- return nextPart;
- }
-
- @Override
- public void remove() {
- /* ignore. */
- }
-
- };
- }
-
-}