You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2010/05/08 18:39:32 UTC
svn commit: r942413 - in
/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching:
GroupMappingIterator.java PermutationIterator.java
Author: reto
Date: Sat May 8 16:39:32 2010
New Revision: 942413
URL: http://svn.apache.org/viewvc?rev=942413&view=rev
Log:
throwing NoSuchElementException instead of returning null in iterators
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/GroupMappingIterator.java
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/PermutationIterator.java
Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/GroupMappingIterator.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/GroupMappingIterator.java?rev=942413&r1=942412&r2=942413&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/GroupMappingIterator.java (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/GroupMappingIterator.java Sat May 8 16:39:32 2010
@@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
+import java.util.NoSuchElementException;
import java.util.Set;
/**
@@ -51,6 +52,9 @@ class GroupMappingIterator<T,U> implemen
}
private GroupMappingIterator(Map<Set<T>, Set<U>> matchingGroups) {
+ if (matchingGroups.size() == 0) {
+ throw new IllegalArgumentException("matchingGroups must not be empty");
+ }
restMap = new HashMap<Set<T>, Set<U>>();
boolean first = true;
for (Map.Entry<Set<T>, Set<U>> entry : matchingGroups.entrySet()) {
@@ -73,14 +77,16 @@ class GroupMappingIterator<T,U> implemen
@Override
public Map<T, U> next() {
- Map<T, U> restPart = currentRestPartIter.next();
- if (restPart == null) {
+ Map<T, U> restPart;
+ if (currentRestPartIter.hasNext()) {
+ restPart = currentRestPartIter.next();
+ } else {
if (firstPartIter.hasNext()) {
currentFirstPart = firstPartIter.next();
- currentRestPartIter = new GroupMappingIterator<T, U>(restMap);
+ currentRestPartIter = create(restMap);
restPart = currentRestPartIter.next();
} else {
- return null;
+ throw new NoSuchElementException();
}
}
Map<T, U> result = new HashMap<T, U>(restPart);
Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/PermutationIterator.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/PermutationIterator.java?rev=942413&r1=942412&r2=942413&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/PermutationIterator.java (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/PermutationIterator.java Sat May 8 16:39:32 2010
@@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.NoSuchElementException;
/**
*
@@ -56,6 +57,9 @@ class PermutationIterator<T> implements
@Override
public List<T> next() {
List<T> result = next;
+ if (result == null) {
+ throw new NoSuchElementException();
+ }
prepareNext();
return result;
}