<commit_before>package org.motechproject.server.pillreminder.domain;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.motechproject.model.Time;

import java.text.SimpleDateFormat;
import java.util.*;

public class Dosage {
    private String id;
    private Time startTime;
    private Date currentDosageDate;
    private Set<Medicine> medicines;

    public Dosage() {
    }

    public Dosage(Time startTime, Set<Medicine> medicines) {
        this.id = UUID.randomUUID().toString();
        this.startTime = startTime;
        this.medicines = medicines;
        this.currentDosageDate = getStartDate();
    }

    public Set<Medicine> getMedicines() {
        return medicines;
    }

    public void setMedicines(Set<Medicine> medicines) {
        this.medicines = medicines;
    }

    public Time getStartTime() {
        return startTime;
    }

    public void setStartTime(Time startTime) {
        this.startTime = startTime;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Date getCurrentDosageDate() {
        return currentDosageDate;
    }

    public void setCurrentDosageDate(Date currentDosageDate) {
        this.currentDosageDate = currentDosageDate;
    }

    public boolean isTaken(Time dosageWindow) {
        String dosageDate = new SimpleDateFormat("dd/MM/yyyy").format(this.currentDosageDate);
        String today = new SimpleDateFormat("dd/MM/yyyy").format(new Date());
        return dosageDate.equals(today) && startTime.equals(dosageWindow);
    }

    @JsonIgnore
    public Date getStartDate() {
        List<Medicine> sortedList = new ArrayList<Medicine>(medicines);
        Collections.sort(sortedList, new Comparator<Medicine>() {
            @Override
            public int compare(Medicine o1, Medicine o2) {
                return o1.getStartDate().compareTo(o2.getStartDate());
            }
        });
        return sortedList.isEmpty() ? null : sortedList.get(0).getStartDate();
    }

    @JsonIgnore
    public Date getEndDate() {
        Set<Medicine> medicinesWithNonNullEndDate = getMedicinesWithNonNullEndDate();
        if (medicinesWithNonNullEndDate.isEmpty()) return null;

        List<Medicine> sortedList = new ArrayList<Medicine>(medicinesWithNonNullEndDate);
        Collections.sort(sortedList, new Comparator<Medicine>() {
            @Override
            public int compare(Medicine o1, Medicine o2) {
                return o2.getEndDate().compareTo(o1.getEndDate());
            }
        });
        return sortedList.isEmpty() ? null : sortedList.get(0).getEndDate();
    }

    private Set<Medicine> getMedicinesWithNonNullEndDate() {
        Set<Medicine> medicinesWithNonNullEndDate = new HashSet<Medicine>();
        for (Medicine medicine : medicines) {
            if (medicine.getEndDate() != null)
                medicinesWithNonNullEndDate.add(medicine);
        }
        return medicinesWithNonNullEndDate;
    }

    public void validate() {
        for (Medicine medicine : getMedicines()) {
            medicine.validate();
        }
    }

    public List<String> getMedicineNames() {
        List<String> medicineNames = new ArrayList<String>();
        for (Medicine medicine : medicines)
            medicineNames.add(medicine.getName());
        return medicineNames;
    }
}<commit_msg>#JsonIgnore to Dosage getMedicineNames <mano/vijay><commit_after>package org.motechproject.server.pillreminder.domain;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.motechproject.model.Time;

import java.text.SimpleDateFormat;
import java.util.*;

public class Dosage {
    private String id;
    private Time startTime;
    private Date currentDosageDate;
    private Set<Medicine> medicines;

    public Dosage() {
    }

    public Dosage(Time startTime, Set<Medicine> medicines) {
        this.id = UUID.randomUUID().toString();
        this.startTime = startTime;
        this.medicines = medicines;
        this.currentDosageDate = getStartDate();
    }

    public Set<Medicine> getMedicines() {
        return medicines;
    }

    public void setMedicines(Set<Medicine> medicines) {
        this.medicines = medicines;
    }

    public Time getStartTime() {
        return startTime;
    }

    public void setStartTime(Time startTime) {
        this.startTime = startTime;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Date getCurrentDosageDate() {
        return currentDosageDate;
    }

    public void setCurrentDosageDate(Date currentDosageDate) {
        this.currentDosageDate = currentDosageDate;
    }

    public boolean isTaken(Time dosageWindow) {
        String dosageDate = new SimpleDateFormat("dd/MM/yyyy").format(this.currentDosageDate);
        String today = new SimpleDateFormat("dd/MM/yyyy").format(new Date());
        return dosageDate.equals(today) && startTime.equals(dosageWindow);
    }

    @JsonIgnore
    public Date getStartDate() {
        List<Medicine> sortedList = new ArrayList<Medicine>(medicines);
        Collections.sort(sortedList, new Comparator<Medicine>() {
            @Override
            public int compare(Medicine o1, Medicine o2) {
                return o1.getStartDate().compareTo(o2.getStartDate());
            }
        });
        return sortedList.isEmpty() ? null : sortedList.get(0).getStartDate();
    }

    @JsonIgnore
    public Date getEndDate() {
        Set<Medicine> medicinesWithNonNullEndDate = getMedicinesWithNonNullEndDate();
        if (medicinesWithNonNullEndDate.isEmpty()) return null;

        List<Medicine> sortedList = new ArrayList<Medicine>(medicinesWithNonNullEndDate);
        Collections.sort(sortedList, new Comparator<Medicine>() {
            @Override
            public int compare(Medicine o1, Medicine o2) {
                return o2.getEndDate().compareTo(o1.getEndDate());
            }
        });
        return sortedList.isEmpty() ? null : sortedList.get(0).getEndDate();
    }

    private Set<Medicine> getMedicinesWithNonNullEndDate() {
        Set<Medicine> medicinesWithNonNullEndDate = new HashSet<Medicine>();
        for (Medicine medicine : medicines) {
            if (medicine.getEndDate() != null)
                medicinesWithNonNullEndDate.add(medicine);
        }
        return medicinesWithNonNullEndDate;
    }

    public void validate() {
        for (Medicine medicine : getMedicines()) {
            medicine.validate();
        }
    }

    @JsonIgnore
    public List<String> getMedicineNames() {
        List<String> medicineNames = new ArrayList<String>();
        for (Medicine medicine : medicines)
            medicineNames.add(medicine.getName());
        return medicineNames;
    }
}
{'fraction_non_alphanumeric': 0.10064648839259477, 'fraction_numerical': 0.0029385836027034967, 'mean_word_length': 2.689430894308943, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, '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': '2020916', 'n_tokens_mistral': 2042, 'n_tokens_neox': 1937, 'n_words': 393}