/** Return the first element of an iterator or null if no such element. * @param iter * @return An item or null. */ public static <T> T first(Iterator<T> iter) { return first(iter, (x)-> true ) ; }
/** Return the first element of an iterator or null if no such element. * @param iter * @return An item or null. */ public static <T> T first(Iterator<T> iter) { return first(iter, (x)-> true ) ; }
/** Skip to the first element meeting a condition and return that element. */ public T first(Predicate<T> filter) { return first(iterator, filter) ; }
public T first() { return first(iterator) ; }
public T first() { return first(iterator) ; }
/** Skip to the first element meeting a condition and return that element. */ public T first(Predicate<T> filter) { return first(iterator, filter) ; }
public T first(Filter<T> filter) { return first(iterator, filter) ; }
/** Return an element from a collection. */ public static <T> T oneElt(Collection<T> collection) { return Iter.first(collection.iterator()); } }
/** Return an element from a collection. */ public static <T> T oneElt(Collection<T> collection) { return Iter.first(collection.iterator()); } }
public static <T> T first(Collection<T> collection, Filter<T> filter) { return first(collection.iterator(), filter) ; }
@SuppressWarnings("deprecation") @Test public void first_03() { List<String> data = Arrays.asList("11", "AA", "BB", "CC"); assertEquals(null, Iter.first(data, filter)); }
@SuppressWarnings("deprecation") @Test public void first_02() { List<String> data = Arrays.asList("11", "A", "B", "C"); assertEquals("A", Iter.first(data, filter)); }
@Test public void first_01() { Iter<String> iter = Iter.nullIter(); assertEquals(null, Iter.first(iter, filter)); }
@Test public void dataset_02() { DatasetGraph dsg1 = datasetGraph ; ByteArrayOutputStream out = new ByteArrayOutputStream() ; StreamRDFWriter.write(out, dsg1, Lang.RDFTHRIFT) ; byte[] bytes = out.toByteArray() ; ByteArrayInputStream in = new ByteArrayInputStream(bytes) ; DatasetGraph dsg2 = DatasetGraphFactory.create() ; StreamRDF stream2 = StreamRDFLib.dataset(dsg2) ; BinRDF.inputStreamToStream(in, stream2) ; boolean b = IsoMatcher.isomorphic(dsg1, dsg2) ; assertTrue(b) ; // Stronger - same bNode and same as in original data. Node obj = Iter.first(dsg1.listGraphNodes(), Node::isBlank) ; termAsObject(dsg1, obj) ; }
@Test public void dataset_01() { DatasetGraph dsg1 = datasetGraph ; ByteArrayOutputStream out = new ByteArrayOutputStream() ; StreamRDF stream = BinRDF.streamToOutputStream(out) ; StreamOps.datasetToStream(dsg1, stream) ; byte[] bytes = out.toByteArray() ; ByteArrayInputStream in = new ByteArrayInputStream(bytes) ; DatasetGraph dsg2 = DatasetGraphFactory.create() ; StreamRDF stream2 = StreamRDFLib.dataset(dsg2) ; BinRDF.inputStreamToStream(in, stream2) ; boolean b = IsoMatcher.isomorphic(dsg1, dsg2) ; assertTrue(b) ; // Stronger - same bNode and same as in original data. Node obj = Iter.first(dsg1.listGraphNodes(), Node::isBlank) ; termAsObject(dsg1, obj) ; }