Created
September 5, 2012 01:44
-
-
Save dcolish/3628997 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/Makefile.am b/xapian-bindings/java/Makefile.am | |
| index e1adf65..2be037d 100644 | |
| --- a/xapian-bindings/java/Makefile.am | |
| +++ b/xapian-bindings/java/Makefile.am | |
| @@ -16,10 +16,10 @@ SmokeTest: SmokeTest.class | |
| if MAINTAINER_MODE | |
| .java.class: | |
| - $(JAVAC) -g -classpath $(srcdir)$(JAVA_PATHSEP). -d . $< | |
| + $(JAVAC) -g -classpath $(srcdir)$(JAVA_PATHSEP). -d . $(JFLAGS) $< | |
| else | |
| .java.class: | |
| - $(JAVAC) -classpath $(srcdir)$(JAVA_PATHSEP). -d . $< | |
| + $(JAVAC) -classpath $(srcdir)$(JAVA_PATHSEP). -d . $(JFLAGS) $< | |
| endif | |
| XAPIAN_SWIG_JAVA_SRCS=\ | |
| @@ -167,7 +167,7 @@ xapian_wrap.stamp: | |
| -include xapian_wrap.d | |
| -CLEANFILES += xapian_wrap.stamp | |
| +CLEANFILES += xapian_wrap.stamp xapian_wrap.cc xapian_wrap.h | |
| endif | |
| MAINTAINERCLEANFILES = $(BUILT_SOURCES) | |
| diff --git a/xapian-bindings/java/SmokeTest.java b/xapian-bindings/java/SmokeTest.java | |
| index 01a692b..2656afa 100644 | |
| --- a/xapian-bindings/java/SmokeTest.java | |
| +++ b/xapian-bindings/java/SmokeTest.java | |
| @@ -1,6 +1,7 @@ | |
| // Simple test that we can use xapian from java | |
| // | |
| // Copyright (C) 2005,2006,2007,2008,2011 Olly Betts | |
| +// Copyright (C) 2012 Dan Colish | |
| // | |
| // This program is free software; you can redistribute it and/or | |
| // modify it under the terms of the GNU General Public License as | |
| @@ -17,6 +18,8 @@ | |
| // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 | |
| // USA | |
| +import java.util.Iterator; | |
| + | |
| import org.xapian.*; | |
| // FIXME: need to sort out throwing wrapped Xapian::Error subclasses | |
| @@ -112,12 +115,12 @@ public class SmokeTest { | |
| System.err.println("Unexpected mset.size()"); | |
| System.exit(1); | |
| } | |
| - MSetIterator m_itor = mset.begin(); | |
| + | |
| Document m_doc = null; | |
| - long m_id; | |
| - while(m_itor.hasNext()) { | |
| - m_id = m_itor.next(); | |
| - if(m_itor.hasNext()) { | |
| + Long m_id; | |
| + for(Iterator<Long> it = mset.begin(); it.hasNext();) { | |
| + m_id = it.next(); | |
| + if (it.hasNext()) { | |
| m_doc = mset.getDocument(m_id); | |
| } | |
| } | |
| @@ -129,12 +132,13 @@ public class SmokeTest { | |
| } | |
| String term_str = ""; | |
| - TermIterator itor = enq.getMatchingTermsBegin(mset.getElement(0)); | |
| - while (itor.hasNext()) { | |
| - term_str += itor.next(); | |
| - if (itor.hasNext()) | |
| + for(TermIterator it = enq.getMatchingTermsBegin(mset.getElement(0)); | |
| + it.hasNext();) { | |
| + term_str += it.next(); | |
| + if (it.hasNext()) | |
| term_str += ' '; | |
| } | |
| + | |
| if (!term_str.equals("is there")) { | |
| System.err.println("Unexpected term_str"); | |
| System.exit(1); | |
| @@ -170,7 +174,6 @@ public class SmokeTest { | |
| int count = 0; | |
| for(ESetIterator eit = eset.begin(); eit.hasNext(); ) { | |
| - // for (int i = 0; i < eset.size(); i++) { | |
| if (eit.getTerm().charAt(0) == 'a') { | |
| System.err.println("MyExpandDecider wasn't used"); | |
| System.exit(1); | |
| diff --git a/xapian-bindings/java/java.i b/xapian-bindings/java/java.i | |
| index 1e0bc1d..93f79f6 100644 | |
| --- a/xapian-bindings/java/java.i | |
| +++ b/xapian-bindings/java/java.i | |
| @@ -76,6 +76,11 @@ | |
| %rename("accept") Xapian::MatchDecider::operator(); | |
| %rename("accept") Xapian::ExpandDecider::operator(); | |
| +%rename("MSetIterator_") Xapian::MSetIterator; | |
| +%ignore Xapian::MSetIterator_::next; | |
| + | |
| +%rename("MSetIterator") Xapian::MSetIteratorWrapper; | |
| + | |
| // By default, valueno is wrapped as long and "(long, bool)" collides with | |
| // some of SWIG/Java's machinery, so for now we wrap valueno as int to avoid | |
| // this problem. | |
| @@ -108,8 +113,12 @@ namespace Xapian { | |
| %ignore revision; | |
| // For compatibility with the original JNI wrappers. | |
| + | |
| // FIXME: These make use of the fact that the default ctor for PostingIterator, | |
| -// TermIterator, and ValueIterator produces an end iterator. | |
| +// termiterator, and ValueIterator produces an end iterator. | |
| + | |
| +// TODO:dc: Implement ListIterator for PostingIterator, TermIterator, | |
| +// ValueIterator, MSetIterator, and ESetIterator | |
| %extend PostingIterator { | |
| Xapian::docid next () { | |
| Xapian::docid tmp; | |
| @@ -169,22 +178,60 @@ namespace Xapian { | |
| bool hasNext() const { return !self->at_end(); } | |
| } | |
| - | |
| -%extend MSetIterator { | |
| - Xapian::docid next () { | |
| +/* Wrapper class for MsetIterator */ | |
| +class MSetIteratorWrapper { | |
| + MSetIterator_ begin, end; | |
| + public: | |
| + MSetIteratorWrapper(const Xapian::MSet &m) : begin(m.begin), end(m.end); | |
| +}; | |
| + | |
| +%extend MSetIteratorWrapper { | |
| + %javamethodmodifiers nextNative() "private"; | |
| + Xapian::docid nextNative () { | |
| Xapian::docid tmp; | |
| - if (!self->at_end()) { | |
| - tmp = (**self); | |
| - ++(*self); | |
| + if (self-begin != self->end) { | |
| + tmp = (**(self->begin)); | |
| + ++(*(self->begin)); | |
| } else { | |
| tmp = -1; | |
| } | |
| return tmp; | |
| } | |
| - bool hasNext() const { return !self->at_end(); } | |
| + bool hasNext() const { return self->begin != self->end; } | |
| +} | |
| } | |
| +%typemap(javaimports) Xapian::MSetIterator %{ | |
| + import java.util.NoSuchElementException; | |
| + import java.lang.UnsupportedOperationException; | |
| +%} | |
| + | |
| +%typemap(javainterfaces) Xapian::MSetIterator "java.util.Iterator<Long>" | |
| +%typemap(javacode) Xapian::MSetIterator %{ | |
| + public Long next() throws NoSuchElementException { | |
| + if (this.hasNext()) { | |
| + return Long.valueOf(this.nextNative()); | |
| + } else { | |
| + throw new NoSuchElementException(); | |
| + } | |
| + } | |
| + | |
| + public void remove() throws UnsupportedOperationException { | |
| + throw new UnsupportedOperationException(); | |
| + } | |
| +%} | |
| + | |
| +%ignore Xapian::MSet::begin; | |
| +%ignore Xapian::MSet::end; | |
| +%ignore Xapian::MSet::back; | |
| + | |
| +namespace Xapian { | |
| + %extend MSet { | |
| + Xapian::MSetIterator begin() { | |
| + return MSetIterator(*self); | |
| + } | |
| + } | |
| } | |
| #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