Created
March 26, 2013 05:06
-
-
Save dcolish/5243274 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/xapian-bindings/java/SmokeTest.java b/xapian-bindings/java/SmokeTest.java | |
index 2304aff..02778ec 100644 | |
--- a/xapian-bindings/java/SmokeTest.java | |
+++ b/xapian-bindings/java/SmokeTest.java | |
@@ -117,8 +117,7 @@ public class SmokeTest { | |
} | |
Document m_doc = null; | |
- for (MSetIterator it = mset.iterator(); it.hasNext();) { | |
- Long docid = it.next(); | |
+ for (Long docid : mset) { | |
m_doc = db.getDocument(docid); | |
} | |
diff --git a/xapian-bindings/java/java.i b/xapian-bindings/java/java.i | |
index 678632f..52780eb 100644 | |
--- a/xapian-bindings/java/java.i | |
+++ b/xapian-bindings/java/java.i | |
@@ -119,44 +119,49 @@ class Version { | |
} | |
} | |
- | |
-%rename("MSetIterator") Xapian::WrappedMSetIterator; | |
-%inline %{ | |
- namespace Xapian { | |
- class WrappedMSetIterator { | |
- Xapian::MSetIterator begin; | |
- Xapian::MSetIterator end; | |
- | |
- public: | |
- WrappedMSetIterator() { } | |
- WrappedMSetIterator(const Xapian::MSet &m) | |
- : begin(m.begin()), end(m.end()) { } | |
- bool hasNext() const { return begin != end; } | |
- Xapian::docid next() { return *(begin++); } | |
- }; | |
- } | |
-%} | |
- | |
%typemap(javaimports) Xapian::WrappedMSetIterator %{ | |
import java.util.NoSuchElementException; | |
import java.lang.UnsupportedOperationException; | |
+ import java.lang.IllegalStateException; | |
%} | |
%typemap(javainterfaces) Xapian::WrappedMSetIterator "java.util.Iterator<Long>" | |
%typemap(javacode) Xapian::WrappedMSetIterator %{ | |
+ | |
public Long next() throws NoSuchElementException { | |
if (this.hasNext()) { | |
- return this.next(); | |
+ return this.nextInteral(); | |
} else { | |
throw new NoSuchElementException(); | |
} | |
} | |
- public void remove() throws UnsupportedOperationException { | |
+ public void remove() throws UnsupportedOperationException, IllegalStateException { | |
throw new UnsupportedOperationException(); | |
} | |
%} | |
+%rename("MSetIterator") Xapian::WrappedMSetIterator; | |
+ | |
+%javamethodmodifiers Xapian::WrappedMSetIterator::nextInteral() "private"; | |
+%inline %{ | |
+ namespace Xapian { | |
+ class WrappedMSetIterator { | |
+ | |
+ Xapian::MSetIterator begin; | |
+ Xapian::MSetIterator end; | |
+ | |
+ public: | |
+ WrappedMSetIterator() { } | |
+ WrappedMSetIterator(const Xapian::MSet &m) | |
+ : begin(m.begin()), end(m.end()) { } | |
+ bool hasNext() const { return begin != end; } | |
+ Xapian::docid nextInteral() { return *(begin++); } | |
+ }; | |
+ } | |
+%} | |
+ | |
+ | |
namespace Xapian { | |
%ignore version_string; | |
@@ -231,11 +236,12 @@ namespace Xapian { | |
bool hasNext() const { return !self->at_end(); } | |
} | |
-%extend MSet { | |
- Xapian::WrappedMSetIterator iterator() { | |
- return Xapian::WrappedMSetIterator(*self); | |
+%typemap(javainterfaces) Xapian::MSet "java.lang.Iterable<Long>" | |
+%typemap(javacode) MSet %{ | |
+ public java.util.Iterator<Long> iterator() { | |
+ return new MSetIterator(this); | |
} | |
-} | |
+%} | |
} | |
#define XAPIAN_MIXED_SUBQUERIES_BY_ITERATOR_TYPEMAP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment