public void testLimit_illegalArgument() { try { FluentIterable<String> unused = FluentIterable.from(Lists.newArrayList("a", "b", "c")).limit(-1); fail("Passing negative number to limit(...) method should throw IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }
public void testLimit() { Iterable<String> iterable = Lists.newArrayList("foo", "bar", "baz"); FluentIterable<String> limited = FluentIterable.from(iterable).limit(2); assertEquals(ImmutableList.of("foo", "bar"), Lists.newArrayList(limited)); assertCanIterateAgain(limited); assertEquals("[foo, bar]", limited.toString()); }
@Nonnull @Override public Iterator<EncodedValue> iterator() { return FluentIterable.from(sortedStaticFields) .limit(lastIndex+1) .transform(GET_INITIAL_VALUE).iterator(); }
@Nonnull @Override public Iterator<BuilderEncodedValue> iterator() { return FluentIterable.from(sortedStaticFields) .limit(lastIndex+1) .transform(GET_INITIAL_VALUE).iterator(); }
public List<T> findAll(Integer number, Integer offset) { if (number == 0) { return FluentIterable.from(entities.values()).skip(offset).toList(); } return FluentIterable.from(entities.values()).skip(offset).limit(number).toList(); }
@Override public LoadedAttachment findAndLoadBySlug(final String slug) { return FluentIterable.from(entities.values()).filter(withSlug(slug)).transform(CAST_AS_LOADED_ATTACHMENT) .limit(1).first().orNull(); }
@Override public LoadedAttachment findAndLoadBySlugAndExtension(final String fileName, final String extension) { return FluentIterable.from(entities.values()).transform(CAST_AS_LOADED_ATTACHMENT) .filter(withExtension(extension)).limit(1).first().orNull(); }
@Override public Attachment findBySlugAndExtension(String fileName, String extension) { return FluentIterable.from(entities.values()) .filter(withExtension(extension)).limit(1).first().orNull(); }
public List<Product> findAllNotVariants(Integer number, Integer offset) { if (number == 0) { return FluentIterable.from(all()).filter(ON_SHELF).skip(offset).toList(); } return FluentIterable.from(all()).filter(ON_SHELF).skip(offset).limit(number) .toList(); }
public List<Order> findAllPaidOrAwaitingPayment(Integer number, Integer offset) { if (number == 0) { return FluentIterable.from(all()).filter(paidOrAwaitingPayment).skip(offset).toList(); } return FluentIterable.from(all()).filter(paidOrAwaitingPayment).skip(offset).limit(number).toList(); }
public List<Product> findAllOnShelf(Integer number, Integer offset) { if (number == 0) { return FluentIterable.from(all()).filter(ON_SHELF).skip(offset).toList(); } return FluentIterable.from(all()).filter(ON_SHELF).skip(offset).limit(number) .toList(); }
public List<Product> findForCollection(Collection collection, Integer number, Integer offset) { if (number == 0) { return FluentIterable.from(findAllForCollection(collection)).skip(offset).toList(); } return FluentIterable.from(findAllForCollection(collection)).skip(offset).limit(number).toList(); }
public List<Product> findAllWithTitleLike(String title, Integer number, Integer offset) { if (number == 0) { return FluentIterable.from(all()).filter(withTitleLike(title)).skip(offset).toList(); } return FluentIterable.from(all()).filter(withTitleLike(title)).skip(offset).limit(number) .toList(); }
public void testLimit_illegalArgument() { try { FluentIterable<String> unused = FluentIterable.from(Lists.newArrayList("a", "b", "c")).limit(-1); fail("Passing negative number to limit(...) method should throw IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }
public void testListImages() { final AtomicInteger found = new AtomicInteger(0); // DigitalOcean return 25 records per page by default. Inspect at most 2 pages assertTrue(api().list().concat().limit(50).allMatch(new Predicate<Image>() { @Override public boolean apply(Image input) { found.incrementAndGet(); return !isNullOrEmpty(input.name()); } }), "All images must have the 'name' field populated"); assertTrue(found.get() > 0, "Expected some images to be returned"); }
public void testLimit() { Iterable<String> iterable = Lists.newArrayList("foo", "bar", "baz"); FluentIterable<String> limited = FluentIterable.from(iterable).limit(2); assertEquals(ImmutableList.of("foo", "bar"), Lists.newArrayList(limited)); assertCanIterateAgain(limited); assertEquals("[foo, bar]", limited.toString()); }
public void testListSizes() { final AtomicInteger found = new AtomicInteger(0); // DigitalOcean return 25 records per page by default. Inspect at most 2 pages assertTrue(api().list().concat().limit(50).allMatch(new Predicate<Size>() { @Override public boolean apply(Size input) { found.incrementAndGet(); return !Strings.isNullOrEmpty(input.slug()); } }), "All sizes must have the 'slug' field populated"); assertTrue(found.get() > 0, "Expected some sizes to be returned"); }
public void testListActions() { final AtomicInteger found = new AtomicInteger(0); // DigitalOcean return 25 records per page by default. Inspect at most 2 pages assertTrue(api().list().concat().limit(50).allMatch(new Predicate<Action>() { @Override public boolean apply(Action input) { found.incrementAndGet(); return !isNullOrEmpty(input.type()); } }), "All actions must have the 'type' field populated"); assertTrue(found.get() > 0, "Expected some actions to be returned"); }
public void testListRegions() { final AtomicInteger found = new AtomicInteger(0); // DigitalOcean return 25 records per page by default. Inspect at most 2 pages assertTrue(api().list().concat().limit(50).allMatch(new Predicate<Region>() { @Override public boolean apply(Region input) { found.incrementAndGet(); return !Strings.isNullOrEmpty(input.slug()); } }), "All regions must have the 'slug' field populated"); assertTrue(found.get() > 0, "Expected some regions to be returned"); }