-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
527 additions
and
309 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
core/src/main/java/io/github/mmm/base/collection/AbstractIterator.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package io.github.mmm.base.collection; | ||
|
||
import java.util.Iterator; | ||
import java.util.NoSuchElementException; | ||
|
||
/** | ||
* Abstract base implementation of {@link Iterator} as reusable pattern to simplify implementations of {@link Iterator}. | ||
* Please carefully consider the following constraints before use: | ||
* <ul> | ||
* <li>This {@link Iterator} cannot iterate {@code null} elements.</li> | ||
* <li>Implementations extending {@link AbstractIterator} have to call {@link #findFirst()} at the end of their | ||
* constructor.</li> | ||
* <li>Finally, you only to do implement {@link #findNext()}.</li> | ||
* </ul> | ||
* | ||
* @param <E> type of the elements to {@link #next() iterate}. | ||
*/ | ||
public abstract class AbstractIterator<E> implements Iterator<E> { | ||
|
||
/** @see #next() */ | ||
private E next; | ||
|
||
/** | ||
* Has to be called from the constructor after initialization of fields to find the first element. | ||
*/ | ||
protected final void findFirst() { | ||
|
||
this.next = findNext(); | ||
} | ||
|
||
/** | ||
* @return the next element or {@code null} if done. | ||
*/ | ||
protected abstract E findNext(); | ||
|
||
@Override | ||
public final boolean hasNext() { | ||
|
||
return this.next != null; | ||
} | ||
|
||
@Override | ||
public final E next() { | ||
|
||
if (this.next == null) { | ||
throw new NoSuchElementException(); | ||
} else { | ||
E result = this.next; | ||
this.next = findNext(); | ||
return result; | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
|
||
return "Iterator at " + this.next; | ||
} | ||
|
||
} |
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
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
132 changes: 0 additions & 132 deletions
132
metainfo/src/main/java/io/github/mmm/base/metainfo/impl/InheritedMetaInfo.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.