/soc/2012/michael/android: 695ed6faa0b0: Made PurpleBlistNode it...

Michael Zangl michael at soc.pidgin.im
Tue Jul 17 11:17:05 EDT 2012


Changeset: 695ed6faa0b0d18f75028dc84526e4e725f2abf3
Author:	 Michael Zangl <michael at soc.pidgin.im>
Date:	 2012-07-08 11:39 +0200
Branch:	 soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/695ed6faa0b0

Description:

Made PurpleBlistNode iterable.

diffstat:

 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/NodeIterrator.java   |  33 ++++++++++
 android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistNode.java |   9 ++-
 2 files changed, 41 insertions(+), 1 deletions(-)

diffs (68 lines):

diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/NodeIterrator.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/NodeIterrator.java
new file mode 100644
--- /dev/null
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/NodeIterrator.java
@@ -0,0 +1,33 @@
+package im.pidgin.libpurple.blist;
+
+import java.util.Iterator;
+
+public class NodeIterrator implements Iterator<PurpleBlistNode> {
+
+	private PurpleBlistNode next;
+
+	public NodeIterrator(PurpleBlistNode blistNode) {
+		next = blistNode.getFirstChild();
+	}
+
+	@Override
+	public boolean hasNext() {
+		return next != null;
+	}
+
+	@Override
+	public PurpleBlistNode next() {
+		if (next == null) {
+			throw new IllegalStateException();
+		}
+		PurpleBlistNode result = next;
+		next = next.getNextSibling();
+		return result;
+	}
+
+	@Override
+	public void remove() {
+		throw new UnsupportedOperationException();
+	}
+
+}
diff --git a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistNode.java b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistNode.java
--- a/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistNode.java
+++ b/android/workspace/im.pidgin.libpurple/src/im/pidgin/libpurple/blist/PurpleBlistNode.java
@@ -5,13 +5,15 @@
 import im.pidgin.libpurple.core.CoreManager;
 import im.pidgin.libpurple.core.PeeredPurpleManaged;
 
+import java.util.Iterator;
+
 /**
  * This is a primitive Buddy list node.
  * 
  * @author michaelz
  * 
  */
-public class PurpleBlistNode extends PeeredPurpleManaged {
+public class PurpleBlistNode extends PeeredPurpleManaged implements Iterable<PurpleBlistNode> {
 
 	protected PurpleBlistNode(long nativePointer, CoreManager manager) {
 		super(nativePointer, manager);
@@ -82,4 +84,9 @@
 	protected long getNativePointer() {
 		return super.getNativePointer();
 	}
+
+	@Override
+	public Iterator<PurpleBlistNode> iterator() {
+		return new NodeIterrator(this);
+	}
 }



More information about the Commits mailing list