<commit_before># comparator-factory

Creating comparators with code generation.

## Example

### Bean

```java
public class TestBean {

    private Integer i;
    private String s;
    private Date d;

	// getters are required, yet need not be required

	protected Date getD() {
        return d;
    }

    protected Integer getI() {
        return i;
    }

    protected String getS() {
        return s;
    }
    
    // ...
}
```

### Using factory

```java
Comparator<TestBean> c = ComparatorFactory.forClass(TestBean.class)
		.addProperty("i", Integer.class, false)
		.addProperty("s", String.class, false)
		.addProperty("d", Date.class, false)
		.generate();
```

This will generate a class on-the-fly, with logic equivalent to:

```java
class TestBeanComparator_$i_s_d implements Comparator<TestBean> {

	public int compare(TestBean b1, TestBean b2) {
		int c;
		
		c = ComparatorHelper.compare(b1.getI(), b2.getI());
		if (c != null) {
			return c;
		}	
		
		c = ComparatorHelper.compare(b1.getS(), b2.getS());
		if (c != null) {
			return c;
		}	
	
		c = ComparatorHelper.compare(b1.getD(), b2.getD());
		return c;
	}
}
```

## TODO

* Checks if properties themselves are ``Comparable``?
* Nested properties and/or comparators.<commit_msg>Fixed example with ascending/descending ordering<commit_after># comparator-factory

Creating comparators with code generation.

## Example

### Bean

```java
public class TestBean {

    private Integer i;
    private String s;
    private Date d;

	// getters are required, yet need not be required

	protected Date getD() {
        return d;
    }

    protected Integer getI() {
        return i;
    }

    protected String getS() {
        return s;
    }
    
    // ...
}
```

### Using factory

```java
Comparator<TestBean> c = ComparatorFactory.forClass(TestBean.class)
		.addProperty("i", Integer.class, false)
		.addProperty("s", String.class, true)
		.addProperty("d", Date.class, false)
		.generate();
```

This will generate a class on-the-fly, with logic equivalent to:

```java
class TestBeanComparator_$i_s_d implements Comparator<TestBean> {

	public int compare(TestBean b1, TestBean b2) {
		int c;
		
		c = -1 * ComparatorHelper.compare(b1.getI(), b2.getI());
		if (c != null) {
			return c;
		}	
		
		c = ComparatorHelper.compare(b1.getS(), b2.getS());
		if (c != null) {
			return c;
		}	
	
		c = -1 * ComparatorHelper.compare(b1.getD(), b2.getD());
		return c;
	}
}
```

## TODO

* Checks if properties themselves are ``Comparable``?
* Nested properties and/or comparators.
{'fraction_non_alphanumeric': 0.1369701726844584, 'fraction_numerical': 0.00706436420722135, 'mean_word_length': 3.071884984025559, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '847193', 'n_tokens_mistral': 920, 'n_tokens_neox': 844, 'n_words': 237}