1

I'm trying to find a list of objects that are after a certain DateTime. In order to do so, I've created the following query:

return foos.retrieve(QueryFactory.equal(EXPIRY_INDEX, new DateTime()));

I then created the following index:

public static final Attribute<Foo, DateTime> EXPIRY_INDEX = new SimpleAttribute<Foo, DateTime>() {
        @Override
        public DateTime getValue(Foo foo, QueryOptions queryOptions) {
            return foo.getEXPIRY();
        }
};

So far all good, except, the equal(...) method will invoke DateTime.equals(...) as far as I know which will ultimately return false all the time. What I need is a way to call DateTime.isAfterNow(...) or DateTime.isAfter(...).

How can I find all elements in a collection that have a DateTime after right now?

Hooli
  • 1,135
  • 3
  • 19
  • 46

1 Answers1

1

If I understand correctly, you should use a greaterThan() query instead of an equals() query.

These will rely on Comparable.compareTo(), instead of Object.equals(). So it should work if your DateTime object implements the Comparable interface properly.

npgall
  • 2,979
  • 1
  • 24
  • 24