Skip to content

Commit

Permalink
iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
karolyiar committed Jun 29, 2015
1 parent b494b29 commit 59b2ce1
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 5 deletions.
64 changes: 64 additions & 0 deletions ilwisobject_test/test/ilwisobject_test/TestVertexIterator.java
@@ -0,0 +1,64 @@
package ilwisobject_test;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class TestVertexIterator {
private final static String workingDir = TestUtil.workingDir;

@BeforeClass
public static void onceExecutedBeforeAll() {
TestUtil.onceExecutedBeforeAll();
}

@Before
public void setUp() throws Exception {
ilwisobjects.disconnectIssueLogger();
Engine.setWorkingCatalog(workingDir+"feature/");
ilwisobjects.connectIssueLogger();
}

@AfterClass
public static void onceExecutedAfterAll() {
TestUtil.onceExecutedAfterAll();
}
@Test
public void vertexIterator() {
FeatureCoverage fc = new FeatureCoverage(workingDir+"feature/drainage.shp");

for(Feature feat : fc) {
VertexIterator baseIt = new VertexIterator(feat.geometry());
VertexIterator beginIt = baseIt.begin();
VertexIterator endIt = baseIt.end();

assertTrue( beginIt.compareTo(endIt) < 0 );

ArrayList<Coordinate> listA = new ArrayList<Coordinate>();
while (beginIt.compareTo(endIt) != 0) {
listA.add( beginIt.current() );
beginIt.add(1);
}

assertTrue( beginIt.compareTo(endIt) == 0 );

ArrayList<Coordinate> listB = new ArrayList<Coordinate>();
for (Coordinate c : feat.geometry()) {
listB.add(c);
}

assertTrue(listA.size() > 0);
assertEquals(listA.size(), listB.size());

for(int i=0;i<listA.size();++i) {
assertTrue(listA.get(0).equals(listB.get(0)));
}
}
}

}
14 changes: 11 additions & 3 deletions javaapi/ilwisobjects.i
Expand Up @@ -61,7 +61,7 @@

%rename(multiply) operator*=;
%rename(multiply) operator*;
%rename(equal) operator==;
%rename(equals) operator==;
%rename(notequal) operator!=;
%rename(toString) __str__;
%rename(increase) operator+=;
Expand All @@ -80,11 +80,18 @@


%typemap(javainterfaces) javaapi::FeatureCoverage "Iterable<Feature>";
%typemap(javaimports) javaapi::FeatureCoverage "import java.util.Iterator;";

%typemap(javainterfaces) javaapi::FeatureIterator "Iterator<Feature>";
%typemap(javaimports) javaapi::FeatureIterator "import java.util.Iterator;";

%typemap(javainterfaces) javaapi::Geometry "Iterable<Coordinate>";
%typemap(javainterfaces) javaapi::VertexIterator "Iterator<Coordinate>";
%typemap(javaimports) javaapi::VertexIterator "import java.util.Iterator;";

//%typemap(javainterfaces) javaapi::RasterCoverage "Iterable<Pixel>";
%typemap(javainterfaces) javaapi::PixelIterator "Iterator<Double>";
%typemap(javaimports) javaapi::PixelIterator "import java.util.Iterator;";
%typemap(javacode) javaapi::PixelIterator " public Double next() { return _next(); }";

%include "javaapi_extension.h"

%include "javaapi_object.h"
Expand Down Expand Up @@ -250,6 +257,7 @@
namespace std {
%template(vectori) vector<int>;
%template(vectord) vector<double>;
%template(vectorl) vector<quint32>;
%template (mapsd) map<std::string, double>;
%template (vectorvs) vector<std::vector<std::string> >;
%template (vectors) vector<std::string>;
Expand Down
7 changes: 6 additions & 1 deletion javaapi/javaapi_pixeliterator.cpp
Expand Up @@ -53,7 +53,7 @@ PixelIterator* PixelIterator::__iter__(){
return this;
}

double PixelIterator::__next__(){
double PixelIterator::_next(){
Ilwis::PixelIterator& iter = this->ptr();
if (iter.linearPosition() != this->_endposition){
double d = (*iter);
Expand All @@ -64,6 +64,11 @@ double PixelIterator::__next__(){
}
}

bool PixelIterator::hasNext() {
Ilwis::PixelIterator& iter = this->ptr();
return (iter.linearPosition() != this->_endposition);
}

bool PixelIterator::__bool__() const{
return (this->_coverage && this->_coverage->__bool__() && (bool)this->_ilwisPixelIterator && this->_ilwisPixelIterator->isValid());
}
Expand Down
3 changes: 2 additions & 1 deletion javaapi/javaapi_pixeliterator.h
Expand Up @@ -42,7 +42,8 @@ class PixelIterator{
* @return
*/
PixelIterator* __iter__();
double __next__();
double _next();
bool hasNext();
bool __bool__() const;
std::string __str__();
/**
Expand Down
4 changes: 4 additions & 0 deletions javaapi/javaapi_vertexiterator.cpp
Expand Up @@ -61,6 +61,10 @@ Coordinate VertexIterator::__next__(){
}
}

bool VertexIterator::hasNext() {
return ( this->compareTo(end()) != 0);
}

VertexIterator VertexIterator::operator +(int n){
VertexIterator iter(*this);
iter.ptr() += n;
Expand Down
1 change: 1 addition & 0 deletions javaapi/javaapi_vertexiterator.h
Expand Up @@ -26,6 +26,7 @@ class VertexIterator
std::string __str__() const;
VertexIterator* __iter__();
Coordinate __next__();
bool hasNext();

VertexIterator operator+(int n);
VertexIterator __radd__(int n);
Expand Down

0 comments on commit 59b2ce1

Please sign in to comment.