3

I'm using the Joiners class to make a Constraint. The Joiners class has methods like equal(), greaterThan(), lessThanOrEqual(), etc. I want to use a method such as "notEqual()" because I want to compare two objects of the same class, and assign a penalty if the value for a property is not the same. Please note that I use Joiners.lessThan(..id..) to ensure that I am comparing pairs of objects without doing it twice. This is an example of code I'd like to be able to write:

private Constraint someConflict(ConstraintFactory cf) {
    return cf.from(A.class)
        .join(A.class, // Pair the above A with this A
            Joiners.notEqual(A::getSomething), // ..if they have differing Something
            Joiners.lessThan(A::getId)) // ..and if the pair is unique (no reverse pairs)
        .penalizeConfigurable();
}

The "notEqual" will fail as it doesn't exist, obviously. Is there a way to do this? It seems logical that this kind of operation should be possible. If not, could I please be enlightened? Thanks in advance.

Gorzolimir
  • 31
  • 1

1 Answers1

1

Good question!

The Joiners methods equal(), greaterThan(), lessThanOrEqual(), etc use an index (= hash table). This means they are a lot faster for large dataset than without such an index. See the 2 images below. (This independent from the "incremental" aspect of scoring.)

We are not sure yet if it's a good idea to use an index for notEquals(). At the same time, we want to give the guarantee that all Joiners methods are using an index, except for filtering. So no notEquals(Bar::getFoo) if it's not indexed. Right now filtering((a, b) -> !a.getFoo().equals(b.getFoo())) works. Maybe we should add notEqualsFiltering(Bar::getFoo) as syntactic sugar?

slow

enter image description here

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120