private List<MailboxAnnotation> filterItemsBySize(List<MailboxAnnotation> mailboxAnnotations, final Optional<Integer> maxsize) { Predicate<MailboxAnnotation> lowerPredicate = annotation -> maxsize .map(maxSizeInput -> (annotation.size() <= maxSizeInput)) .orElse(true); return mailboxAnnotations.stream() .filter(lowerPredicate) .collect(Guavate.toImmutableList()); }
private Optional<Integer> getMaxSizeOfOversizedItems(List<MailboxAnnotation> mailboxAnnotations, final Integer maxsize) { Predicate<MailboxAnnotation> filterOverSizedAnnotation = annotation -> annotation.size() > maxsize; ImmutableSortedSet<Integer> overLimitSizes = mailboxAnnotations.stream() .filter(filterOverSizedAnnotation) .map(MailboxAnnotation::size) .collect(Guavate.toImmutableSortedSet(Comparator.reverseOrder())); if (overLimitSizes.isEmpty()) { return Optional.empty(); } return Optional.of(overLimitSizes.first()); }
private boolean canInsertOrUpdate(MailboxId mailboxId, MailboxAnnotation annotation, AnnotationMapper annotationMapper) throws AnnotationException { if (annotation.size() > limitAnnotationSize) { throw new AnnotationException("annotation too big."); } if (!annotationMapper.exist(mailboxId, annotation) && annotationMapper.countAnnotations(mailboxId) >= limitOfAnnotations) { throw new AnnotationException("too many annotations."); } return true; }
@Test public void sizeOfNilAnnotationShouldBeZero() throws Exception { MailboxAnnotation mailboxAnnotation = MailboxAnnotation.nil(ANNOTATION_KEY); assertThat(mailboxAnnotation.size()).isEqualTo(0); }
@Test public void sizeOfAnnotationShouldBeReturnLengthOfValue() throws Exception { MailboxAnnotation mailboxAnnotation = MailboxAnnotation.newInstance(ANNOTATION_KEY, ANNOTATION_VALUE); assertThat(mailboxAnnotation.size()).isEqualTo(8); }