@Override default Spliterator<T> spliterator() { return Spliterators.spliteratorUnknownSize(iterator(), 0); } }
/** * Extract a user rating vector from a rating stream. * * @param ratings The rating stream. * @return The user rating vector. * @see #userRatingVector(Collection) */ public static Long2DoubleMap userRatingVector(@WillClose ObjectStream<? extends Rating> ratings) { return extractVector(ratings.iterator(), IdExtractor.ITEM, -1); }
@Test public void testWrapCollectionIterator() { ObjectStream<String> objectStream = ObjectStreams.wrap(Lists.newArrayList("foo", "bar")); try { List<String> strs = Lists.newArrayList(objectStream.iterator()); assertThat(strs, hasSize(2)); assertThat(strs, contains("foo", "bar")); } finally { objectStream.close(); } }
@Test public void testWrapEmptyCollection() { ObjectStream<?> objectStream = ObjectStreams.wrap(Collections.emptyList()); try { assertThat(objectStream.readObject(), nullValue()); try { objectStream.iterator().next(); fail("next should fail on empty stream"); } catch (NoSuchElementException e) { /* expected */ } } finally { objectStream.close(); } }
@Test public void testEmptyStream() { ObjectStream<String> cur = ObjectStreams.empty(); try { assertThat(cur.readObject(), nullValue()); try { cur.iterator().next(); fail("next() on empty stream should fail"); } catch (NoSuchElementException e) { /* expected */ } } finally { cur.close(); } }
@Override default Spliterator<T> spliterator() { return Spliterators.spliteratorUnknownSize(iterator(), 0); } }
/** * Extract a user rating vector from a rating stream. * * @param ratings The rating stream. * @return The user rating vector. * @see #userRatingVector(Collection) */ public static Long2DoubleMap userRatingVector(@WillClose ObjectStream<? extends Rating> ratings) { return extractVector(ratings.iterator(), IdExtractor.ITEM, -1); }