@Test void givenASingleNumberToRangeShouldReturnOneRange() { List<MessageRange> ranges = MessageRange.toRanges(Arrays.asList(MessageUid.of(1L))); assertThat(ranges).containsExactly(MessageUid.of(1).toRange()); }
public static List<MessageRange> toRanges(Collection<MessageUid> uidsCol) { List<MessageRange> ranges = new ArrayList<>(); List<MessageUid> uids = new ArrayList<>(uidsCol); Collections.sort(uids); long firstUid = 0; int a = 0; for (int i = 0; i < uids.size(); i++) { long u = uids.get(i).asLong(); if (i == 0) { firstUid = u; if (uids.size() == 1) { ranges.add(MessageUid.of(firstUid).toRange()); } } else { if ((firstUid + a + 1) != u) { ranges.add(MessageRange.range(MessageUid.of(firstUid), MessageUid.of(firstUid + a))); firstUid = u; a = 0; if (uids.size() <= i + 1) { ranges.add(MessageUid.of(firstUid).toRange()); } } else { a++; if (uids.size() <= i + 1) { ranges.add(MessageRange.range(MessageUid.of(firstUid), MessageUid.of(firstUid + a))); break; } } } } return ranges; }
MessageRange implements Iterable<MessageUid> { public static List<MessageRange> toRanges(Collection<MessageUid> uidsCol) { List<MessageRange> ranges = new ArrayList<>(); List<MessageUid> uids = new ArrayList<>(uidsCol); Collections.sort(uids); long firstUid = 0; int a = 0; for (int i = 0; i < uids.size(); i++) { long u = uids.get(i).asLong(); if (i == 0) { firstUid = u; if (uids.size() == 1) { ranges.add(MessageUid.of(firstUid).toRange()); } } else { if ((firstUid + a + 1) != u) { ranges.add(MessageRange.range(MessageUid.of(firstUid), MessageUid.of(firstUid + a))); firstUid = u; a = 0; if (uids.size() <= i + 1) { ranges.add(MessageUid.of(firstUid).toRange()); } } else { a++; if (uids.size() <= i + 1) { ranges.add(MessageRange.range(MessageUid.of(firstUid), MessageUid.of(firstUid + a))); break; } } } } return ranges; } }
MessageRange implements Iterable<MessageUid> { public static List<MessageRange> toRanges(Collection<MessageUid> uidsCol) { List<MessageRange> ranges = new ArrayList<>(); List<MessageUid> uids = new ArrayList<>(uidsCol); Collections.sort(uids); long firstUid = 0; int a = 0; for (int i = 0; i < uids.size(); i++) { long u = uids.get(i).asLong(); if (i == 0) { firstUid = u; if (uids.size() == 1) { ranges.add(MessageUid.of(firstUid).toRange()); } } else { if ((firstUid + a + 1) != u) { ranges.add(MessageRange.range(MessageUid.of(firstUid), MessageUid.of(firstUid + a))); firstUid = u; a = 0; if (uids.size() <= i + 1) { ranges.add(MessageUid.of(firstUid).toRange()); } } else { a++; if (uids.size() <= i + 1) { ranges.add(MessageRange.range(MessageUid.of(firstUid), MessageUid.of(firstUid + a))); break; } } } } return ranges; } protected  MessageRange(Type type, MessageUid minValue, MessageUid maxValue); }
MessageRange implements Iterable<MessageUid> { public static List<MessageRange> toRanges(Collection<MessageUid> uidsCol) { List<MessageRange> ranges = new ArrayList<>(); List<MessageUid> uids = new ArrayList<>(uidsCol); Collections.sort(uids); long firstUid = 0; int a = 0; for (int i = 0; i < uids.size(); i++) { long u = uids.get(i).asLong(); if (i == 0) { firstUid = u; if (uids.size() == 1) { ranges.add(MessageUid.of(firstUid).toRange()); } } else { if ((firstUid + a + 1) != u) { ranges.add(MessageRange.range(MessageUid.of(firstUid), MessageUid.of(firstUid + a))); firstUid = u; a = 0; if (uids.size() <= i + 1) { ranges.add(MessageUid.of(firstUid).toRange()); } } else { a++; if (uids.size() <= i + 1) { ranges.add(MessageRange.range(MessageUid.of(firstUid), MessageUid.of(firstUid + a))); break; } } } } return ranges; } protected  MessageRange(Type type, MessageUid minValue, MessageUid maxValue); static MessageRange one(MessageUid uid); static MessageRange all(); static MessageRange range(MessageUid from, MessageUid to); static MessageRange from(MessageUid from); Type getType(); MessageUid getUidFrom(); MessageUid getUidTo(); boolean includes(MessageUid uid); String toString(); static List<MessageRange> toRanges(Collection<MessageUid> uidsCol); @Override Iterator<MessageUid> iterator(); List<MessageRange> split(int maxItems); @Override int hashCode(); @Override boolean equals(Object obj); }
MessageRange implements Iterable<MessageUid> { public static List<MessageRange> toRanges(Collection<MessageUid> uidsCol) { List<MessageRange> ranges = new ArrayList<>(); List<MessageUid> uids = new ArrayList<>(uidsCol); Collections.sort(uids); long firstUid = 0; int a = 0; for (int i = 0; i < uids.size(); i++) { long u = uids.get(i).asLong(); if (i == 0) { firstUid = u; if (uids.size() == 1) { ranges.add(MessageUid.of(firstUid).toRange()); } } else { if ((firstUid + a + 1) != u) { ranges.add(MessageRange.range(MessageUid.of(firstUid), MessageUid.of(firstUid + a))); firstUid = u; a = 0; if (uids.size() <= i + 1) { ranges.add(MessageUid.of(firstUid).toRange()); } } else { a++; if (uids.size() <= i + 1) { ranges.add(MessageRange.range(MessageUid.of(firstUid), MessageUid.of(firstUid + a))); break; } } } } return ranges; } protected  MessageRange(Type type, MessageUid minValue, MessageUid maxValue); static MessageRange one(MessageUid uid); static MessageRange all(); static MessageRange range(MessageUid from, MessageUid to); static MessageRange from(MessageUid from); Type getType(); MessageUid getUidFrom(); MessageUid getUidTo(); boolean includes(MessageUid uid); String toString(); static List<MessageRange> toRanges(Collection<MessageUid> uidsCol); @Override Iterator<MessageUid> iterator(); List<MessageRange> split(int maxItems); @Override int hashCode(); @Override boolean equals(Object obj);  }