Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Lazy-ifacting Version-based RDF generation
- Loading branch information
Showing
5 changed files
with
186 additions
and
27 deletions.
There are no files selected for viewing
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
56 changes: 56 additions & 0 deletions
56
fcrepo-kernel/src/main/java/org/fcrepo/kernel/utils/iterators/VersionIterator.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,56 @@ | ||
/** | ||
* Copyright 2013 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.fcrepo.kernel.utils.iterators; | ||
|
||
import java.util.Iterator; | ||
|
||
import javax.jcr.version.Version; | ||
|
||
import com.google.common.collect.ForwardingIterator; | ||
|
||
/** | ||
* Type-aware iterator to wrap the JCR NodeIterator | ||
* | ||
* @author ajs6f | ||
* @date Apr 20, 2013 | ||
*/ | ||
public class VersionIterator extends ForwardingIterator<Version> implements | ||
Iterable<Version> { | ||
|
||
private javax.jcr.version.VersionIterator i; | ||
|
||
/** | ||
* Wrap the NodeIterator with our generic version | ||
* | ||
* @param i | ||
*/ | ||
public VersionIterator(final javax.jcr.version.VersionIterator i) { | ||
this.i = i; | ||
} | ||
|
||
@Override | ||
public Iterator<Version> iterator() { | ||
return this; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
protected Iterator<Version> delegate() { | ||
return i; | ||
} | ||
|
||
} |
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
73 changes: 73 additions & 0 deletions
73
fcrepo-kernel/src/test/java/org/fcrepo/kernel/utils/iterators/VersionIteratorTest.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,73 @@ | ||
/** | ||
* Copyright 2013 DuraSpace, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.fcrepo.kernel.utils.iterators; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
import static org.mockito.MockitoAnnotations.initMocks; | ||
|
||
import javax.jcr.version.Version; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
|
||
public class VersionIteratorTest { | ||
|
||
@Mock | ||
javax.jcr.version.VersionIterator i; | ||
|
||
@Mock | ||
Version v1, v2; | ||
|
||
VersionIterator testIterator; | ||
|
||
@Before | ||
public void setUp() { | ||
initMocks(this); | ||
testIterator = new VersionIterator(i); | ||
} | ||
|
||
@Test | ||
public void testHasNext() { | ||
when(i.hasNext()).thenReturn(true, false); | ||
assertTrue(testIterator.hasNext()); | ||
assertFalse(testIterator.hasNext()); | ||
} | ||
|
||
@Test | ||
public void testNext() { | ||
when(i.next()).thenReturn(v1, v2); | ||
assertEquals(v1, testIterator.next()); | ||
assertEquals(v2, testIterator.next()); | ||
} | ||
|
||
@Test | ||
public void testRemove() { | ||
testIterator.remove(); | ||
verify(i).remove(); | ||
} | ||
|
||
@Test | ||
public void testIterator() { | ||
assertEquals(testIterator, testIterator.iterator()); | ||
} | ||
|
||
} |