DiscriminableDiscriminator

A DiscriminableDiscriminator discriminates objects that implement the Discriminable interface. Discriminators exist for a wide variety of Java built-in types, but not for any generic object. This Discriminator discriminates Discriminable objects by calling the object's getDiscriminableProperties() method to obtain a list of property names to discriminate. Then it delegates to a PropertiesDiscriminator to discriminate the objects based on the values of those properties.

Example

Given the class...

public class Widget implements Discriminable
{
    private int a;
    private int b;
    public Widget(int a, int b) {this.a = a; this.b = b;}
    public int getA() { return a; }
    public int getB() { return b; }
    public int getResult() { return a + b; }
    public List<String> getDiscriminableProperties() {
       return Arrays.asList("result");
    }
}
            

... and the input...

  • {new Widget(1, 2), new Widget(2, 1), new Widget(5, 0), new Widget(5, 1), new Widget(3, 3), new Widget(0, 0), new Widget(4, 4), new Widget(5, 4)}

... a DiscriminableDiscriminator returns the following equivalence classes:

  • {Widget(5, 0)} - result 5
  • {Widget(0, 0)} - result 0
  • {Widget(4, 4)} - result 8
  • {Widget(5, 4)} - result 9
  • {Widget(1, 2), Widget(2, 1)} - result 3
  • {Widget(5, 1), Widget(3, 3)} - result 6