SortedSet > subset
in
Programming Questions
•
1 year ago
I'm interested in the subset from SortedSet, i only can't get it to work.
The project is huge so i made a small sketch for here to isolate the problem.
hope someone can helps
- import org.joda.time.*;
- // The type SortedSet is not generic; it cannot be parameterized with arguments
- // etc.
- SortedSet stuff = new TreeSet(new SomethingComparator());
- void setup() {
- for(int i = 1970; i < 2010; i++) {
- String dateString = i + "1212";
- LocalDate date = new LocalDate(dateString);
- stuff.add(new Something(date));
- }
- Something start = stuff.get(10);
- Something end = stuff.get(20);
- SortedSet<Something> test = balls.subset(start, end);
- for(Something s : test) {
- println(s.date);
- }
- }
- class Something {
- LocalDate date;
- Something(LocalDate date) {
- this.date = date;
- }
- }
- public class SomethingComparator implements Comparator<Something> {
- public SomethingComparator() {
- }
- public int compare(Something s1, Something s2) {
- return s1.date.compareTo(s2.date);
- }
- }
1