<commit_before># Specification Pattern

[![Build Status](https://travis-ci.org/uetoyo/specific.java.svg?branch=master)](https://travis-ci.org/uetoyo/specific.java)

This package is in active development but incomplete.

## Simple use case

Simple use case: We have a person class with a birthdate attribute and we want to know if he is an adult.
The straigtforward approach is create the custom parametrized specification.

```java
import java.time.Period;
import java.time.LocalDate;

public class FluentSpecificationExample {

    public static void main(String[] args) {
       
        IsAdultPersonSpecification spec = new IsAdultPersonSpecification(18);
        
        Person p1 = new Person(LocalDate.of(1990, 1, 1));
        Person p2 = new Person(LocalDate.of(2016, 1, 1));
        
        System.out.println(spec.isSatisfiedBy(p1));
        System.out.println(spec.isSatisfiedBy(p2));
    }
}

class Person {
    
    private final LocalDate birthdate;

    public Person(final LocalDate birthdate) {
        // Check for `null` omitted.
        this.birthdate = birthdate;
    }

    public LocalDate getBirthdate() {
        return birthdate;
    }

    public int getAge() {
        return Period.between(birthdate, LocalDate.now()).getYears();
    }
}

class IsAdultPersonSpecification<T extends Person> {

    public final int limit;

    public IsAdultPersonSpecification(int limit) {
        this.limit = limit;
    }

    public boolean isSatisfiedBy(T candidate) {
        return candidate.getAge() >= limit;
    }
}
```<commit_msg>Mark the example as obsolete<commit_after># Specification Pattern

[![Build Status](https://travis-ci.org/uetoyo/specific.java.svg?branch=master)](https://travis-ci.org/uetoyo/specific.java)

## Simple use case

<s>
Simple use case: We have a person class with a birthdate attribute and we want to know if he is an adult.
The straigtforward approach is create the custom parametrized specification.

```java
import java.time.Period;
import java.time.LocalDate;

public class FluentSpecificationExample {

    public static void main(String[] args) {
       
        IsAdultPersonSpecification spec = new IsAdultPersonSpecification(18);
        
        Person p1 = new Person(LocalDate.of(1990, 1, 1));
        Person p2 = new Person(LocalDate.of(2016, 1, 1));
        
        System.out.println(spec.isSatisfiedBy(p1));
        System.out.println(spec.isSatisfiedBy(p2));
    }
}

class Person {
    
    private final LocalDate birthdate;

    public Person(final LocalDate birthdate) {
        // Check for `null` omitted.
        this.birthdate = birthdate;
    }

    public LocalDate getBirthdate() {
        return birthdate;
    }

    public int getAge() {
        return Period.between(birthdate, LocalDate.now()).getYears();
    }
}

class IsAdultPersonSpecification<T extends Person> {

    public final int limit;

    public IsAdultPersonSpecification(int limit) {
        this.limit = limit;
    }

    public boolean isSatisfiedBy(T candidate) {
        return candidate.getAge() >= limit;
    }
}
```
</s>
{'fraction_non_alphanumeric': 0.10074748131296718, 'fraction_numerical': 0.011699707507312317, 'mean_word_length': 3.0606860158311346, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 4, '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': '3123836', 'n_tokens_mistral': 965, 'n_tokens_neox': 897, 'n_words': 248}