This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-net.git
commit dd6e8cd60dc2528620e0f8c317dc5acf3e815697 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Fri Jun 23 08:57:22 2023 -0400 NntpThreadContainer.flush() now throws IllegalStateException instead of RuntimeException. --- ...readContainer.java => NntpThreadContainer.java} | 20 +++---- .../java/org/apache/commons/net/nntp/Threader.java | 62 +++++++++++----------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/main/java/org/apache/commons/net/nntp/ThreadContainer.java b/src/main/java/org/apache/commons/net/nntp/NntpThreadContainer.java similarity index 83% rename from src/main/java/org/apache/commons/net/nntp/ThreadContainer.java rename to src/main/java/org/apache/commons/net/nntp/NntpThreadContainer.java index cb461989..6aacf0d3 100644 --- a/src/main/java/org/apache/commons/net/nntp/ThreadContainer.java +++ b/src/main/java/org/apache/commons/net/nntp/NntpThreadContainer.java @@ -21,19 +21,19 @@ package org.apache.commons.net.nntp; * A placeholder utility class, used for constructing a tree of Threadables Original implementation by Jamie Zawinski. See the Grendel source for more details * <a href="http://lxr.mozilla.org/mozilla/source/grendel/sources/grendel/view/Threader.java#511">here</a> Threadable objects */ -class ThreadContainer { +class NntpThreadContainer { Threadable threadable; - ThreadContainer parent; -// ThreadContainer prev; - ThreadContainer next; - ThreadContainer child; + NntpThreadContainer parent; +// NntpThreadContainer prev; + NntpThreadContainer next; + NntpThreadContainer child; /** * * @param target * @return true if child is under self's tree. Detects circular references */ - boolean findChild(final ThreadContainer target) { + boolean findChild(final NntpThreadContainer target) { if (child == null) { return false; } @@ -43,13 +43,13 @@ class ThreadContainer { return child.findChild(target); } - // Copy the ThreadContainer tree structure down into the underlying Threadable objects - // (Make the Threadable tree look like the ThreadContainer tree) + // Copy the NntpThreadContainer tree structure down into the underlying Threadable objects + // (Make the Threadable tree look like the NntpThreadContainer tree) // TODO convert this to an iterative function - this can blow the stack // with very large Threadable trees void flush() { if (parent != null && threadable == null) { - throw new RuntimeException("no threadable in " + this.toString()); + throw new IllegalStateException("no threadable in " + this.toString()); } parent = null; @@ -81,7 +81,7 @@ class ThreadContainer { */ void reverseChildren() { if (child != null) { - ThreadContainer kid, prev, rest; + NntpThreadContainer kid, prev, rest; for (prev = null, kid = child, rest = kid.next; kid != null; prev = kid, kid = rest, rest = rest == null ? null : rest.next) { kid.next = prev; } diff --git a/src/main/java/org/apache/commons/net/nntp/Threader.java b/src/main/java/org/apache/commons/net/nntp/Threader.java index 6c1c2e88..62c311d4 100644 --- a/src/main/java/org/apache/commons/net/nntp/Threader.java +++ b/src/main/java/org/apache/commons/net/nntp/Threader.java @@ -36,12 +36,12 @@ public class Threader { * @param threadable * @param idTable */ - private void buildContainer(final Threadable threadable, final HashMap<String, ThreadContainer> idTable) { + private void buildContainer(final Threadable threadable, final HashMap<String, NntpThreadContainer> idTable) { String id = threadable.messageThreadId(); - ThreadContainer container = idTable.get(id); + NntpThreadContainer container = idTable.get(id); int bogusIdCount = 0; - // A ThreadContainer exists for this id already. This should be a forward reference, but may + // A NntpThreadContainer exists for this id already. This should be a forward reference, but may // be a duplicate id, in which case we will need to generate a bogus placeholder id if (container != null) { if (container.threadable != null) { // oops! duplicate ids... @@ -57,22 +57,22 @@ public class Threader { // No container exists for that message Id. Create one and insert it into the hash table. if (container == null) { - container = new ThreadContainer(); + container = new NntpThreadContainer(); container.threadable = threadable; idTable.put(id, container); } // Iterate through all the references and create ThreadContainers for any references that // don't have them. - ThreadContainer parentRef = null; + NntpThreadContainer parentRef = null; { final String[] references = threadable.messageThreadReferences(); for (final String refString : references) { - ThreadContainer ref = idTable.get(refString); + NntpThreadContainer ref = idTable.get(refString); // if this id doesn't have a container, create one if (ref == null) { - ref = new ThreadContainer(); + ref = new NntpThreadContainer(); idTable.put(refString, ref); } @@ -99,7 +99,7 @@ public class Threader { // a parent based on the other entries in that field. Now that we have the actual message, we can // throw away the old parent and use this new one if (container.parent != null) { - ThreadContainer rest, prev; + NntpThreadContainer rest, prev; for (prev = null, rest = container.parent.child; rest != null; prev = rest, rest = rest.next) { if (rest == container) { @@ -108,7 +108,7 @@ public class Threader { } if (rest == null) { - throw new RuntimeException("Didnt find " + container + " in parent" + container.parent); + throw new RuntimeException("Didnt find " + container + " in parent " + container.parent); } // Unlink this container from the parent's child list @@ -134,12 +134,12 @@ public class Threader { * Find the root set of all existing ThreadContainers * * @param idTable - * @return root the ThreadContainer representing the root node + * @return root the NntpThreadContainer representing the root node */ - private ThreadContainer findRootSet(final HashMap<String, ThreadContainer> idTable) { - final ThreadContainer root = new ThreadContainer(); - for (final Map.Entry<String, ThreadContainer> entry : idTable.entrySet()) { - final ThreadContainer c = entry.getValue(); + private NntpThreadContainer findRootSet(final HashMap<String, NntpThreadContainer> idTable) { + final NntpThreadContainer root = new NntpThreadContainer(); + for (final Map.Entry<String, NntpThreadContainer> entry : idTable.entrySet()) { + final NntpThreadContainer c = entry.getValue(); if (c.parent == null) { if (c.next != null) { throw new RuntimeException("c.next is " + c.next.toString()); @@ -156,19 +156,19 @@ public class Threader { * * @param root */ - private void gatherSubjects(final ThreadContainer root) { + private void gatherSubjects(final NntpThreadContainer root) { int count = 0; - for (ThreadContainer c = root.child; c != null; c = c.next) { + for (NntpThreadContainer c = root.child; c != null; c = c.next) { count++; } // TODO verify this will avoid rehashing - HashMap<String, ThreadContainer> subjectTable = new HashMap<>((int) (count * 1.2), (float) 0.9); + HashMap<String, NntpThreadContainer> subjectTable = new HashMap<>((int) (count * 1.2), (float) 0.9); count = 0; - for (ThreadContainer c = root.child; c != null; c = c.next) { + for (NntpThreadContainer c = root.child; c != null; c = c.next) { Threadable threadable = c.threadable; // No threadable? If so, it is a dummy node in the root set. @@ -184,7 +184,7 @@ public class Threader { continue; } - final ThreadContainer old = subjectTable.get(subj); + final NntpThreadContainer old = subjectTable.get(subj); // Add this container to the table iff: // - There exists no container with this subject @@ -207,7 +207,7 @@ public class Threader { // subjectTable is now populated with one entry for each subject which occurs in the // root set. Iterate over the root set, and gather together the difference. - ThreadContainer prev, c, rest; + NntpThreadContainer prev, c, rest; for (prev = null, c = root.child, rest = c.next; c != null; prev = c, c = rest, rest = (rest == null ? null : rest.next)) { Threadable threadable = c.threadable; @@ -223,7 +223,7 @@ public class Threader { continue; } - final ThreadContainer old = subjectTable.get(subj); + final NntpThreadContainer old = subjectTable.get(subj); if (old == c) { // That's us continue; @@ -240,7 +240,7 @@ public class Threader { if (old.threadable == null && c.threadable == null) { // both dummies - merge them - ThreadContainer tail; + NntpThreadContainer tail; for (tail = old.child; tail != null && tail.next != null; tail = tail.next) { // do nothing } @@ -262,11 +262,11 @@ public class Threader { } else { // else make the old and new messages be children of a new dummy container. // We create a new container object for old.msg and empty the old container - final ThreadContainer newc = new ThreadContainer(); + final NntpThreadContainer newc = new NntpThreadContainer(); newc.threadable = old.threadable; newc.child = old.child; - for (ThreadContainer tail = newc.child; tail != null; tail = tail.next) { + for (NntpThreadContainer tail = newc.child; tail != null; tail = tail.next) { tail.parent = newc; } @@ -294,8 +294,8 @@ public class Threader { * * @param parent */ - private void pruneEmptyContainers(final ThreadContainer parent) { - ThreadContainer container, prev, next; + private void pruneEmptyContainers(final NntpThreadContainer parent) { + NntpThreadContainer container, prev, next; for (prev = null, container = parent.child, next = container.next; container != null; prev = container, container = next, next = (container == null ? null : container.next)) { @@ -315,8 +315,8 @@ public class Threader { // Else if empty, with kids, and (not at root or only one kid) else if (container.threadable == null && (container.parent != null || container.child.next == null)) { // We have an invalid/expired message with kids. Promote the kids to this level. - ThreadContainer tail; - final ThreadContainer kids = container.child; + NntpThreadContainer tail; + final NntpThreadContainer kids = container.child; // Remove this container and replace with 'kids'. if (prev == null) { @@ -361,7 +361,7 @@ public class Threader { return null; } - HashMap<String, ThreadContainer> idTable = new HashMap<>(); + HashMap<String, NntpThreadContainer> idTable = new HashMap<>(); // walk through each Threadable element for (final Threadable t : messages) { @@ -374,7 +374,7 @@ public class Threader { return null; } - final ThreadContainer root = findRootSet(idTable); + final NntpThreadContainer root = findRootSet(idTable); idTable.clear(); idTable = null; @@ -387,7 +387,7 @@ public class Threader { throw new RuntimeException("root node has a next:" + root); } - for (ThreadContainer r = root.child; r != null; r = r.next) { + for (NntpThreadContainer r = root.child; r != null; r = r.next) { if (r.threadable == null) { r.threadable = r.child.threadable.makeDummy(); }