<commit_before>package utask.model.task;


import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.xml.bind.annotation.XmlElement;

import utask.commons.exceptions.IllegalValueException;
import utask.commons.util.DateUtil;

/**
 * Represents a timestamp in a task
 * Guarantees: immutable; is valid as declared in {@link #isValidTimestamp(String)}
 */
public class Timestamp {
    public static final String MESSAGE_TIMESTAMP_CONSTRAINTS =
            "Timestamps for tasks should be in format from HHMM to HHMM where HHMM is in the range of 0000 to 2359";
    public static final Pattern TIMESTAMP_VALIDATION_REGEX = Pattern.compile("^(?<from>(?:0[0-9]|1[0-9]|2[0-3])"
            + "(?:[0-5][0-9]))(?:\\sto\\s)(?<to>(?:0[0-9]|1[0-9]|2[0-3])(?:[0-5][0-9]))");
    public static final String TIMESTAMP_REMOVAL_VALIDATION_REGEX = "^[-]$";

    public static final String MATCHER_GROUP_FROM = "from";
    public static final String MATCHER_GROUP_TO = "to";

    private static final int TO_PARAM_IN_ARRAY = 1;
    private static final int FROM_PARAM_IN_ARRAY = 0;
    private static final String TIMESTAMP_DELIMITER = " to ";

//    public final String value;
    //Denotes that this will be the attribute we are interested to serialise in this class
    @XmlElement
    private final Date from;

    @XmlElement
    private final Date to;

    /**
     * Validates given timestamps.
     *
     * @throws IllegalValueException if given timestamps string is invalid.
     */
    public Timestamp(String deadline, String timestamp) throws IllegalValueException {
        assert deadline != null && !deadline.isEmpty();
        assert timestamp != null && !timestamp.isEmpty();

        String trimmedTimestamp = timestamp.trim();
        if (!isValidTimestamp(trimmedTimestamp)) {
            throw new IllegalValueException(MESSAGE_TIMESTAMP_CONSTRAINTS);
        }

        String[] str = timestamp.split(TIMESTAMP_DELIMITER);
        String fromString = str[FROM_PARAM_IN_ARRAY];
        String toString = str[TO_PARAM_IN_ARRAY];

        Date date = DateUtil.parseStringToDate(deadline).get();
        assert date != null : "Certainly sure that date will be valid as tested by deadline";

        from = DateUtil.addHHMMStringToDate((Date) date.clone(), fromString);
        to = DateUtil.addHHMMStringToDate((Date) date.clone(), toString);

//        this.value = trimmedTimestamp;
    }

    public Timestamp(String timestamp) throws IllegalValueException {
        assert timestamp != null && !timestamp.isEmpty();

        String trimmedTimestamp = timestamp.trim();
        if (!isValidTimestamp(trimmedTimestamp)) {
            throw new IllegalValueException(MESSAGE_TIMESTAMP_CONSTRAINTS);
        }

        if (timestamp.equals("-")) {
            String[] str = timestamp.split(TIMESTAMP_DELIMITER);
            String fromString = str[FROM_PARAM_IN_ARRAY];
            String toString = str[TO_PARAM_IN_ARRAY];

            Date date = DateUtil.getEmptyDate();

            from = DateUtil.addHHMMStringToDate((Date) date.clone(), fromString);
            to = DateUtil.addHHMMStringToDate((Date) date.clone(), toString);

        } else {
            from = null;
            to = null;
        }
    }

    private Timestamp() {
//        this.value = "";
        from = null;
        to = null;
    }

    public static Timestamp getEmptyTimestamp() {
        return new Timestamp();
    }

    public boolean isEmpty() {
//        return "".equals(value);
        return from == null || to == null;
    }

    /**
     * Returns if a given string is a valid timestamps.
     */
    public static boolean isValidTimestamp(String test) {
        Matcher matcher = TIMESTAMP_VALIDATION_REGEX.matcher(test);

        if (matcher.matches()) {
            int from = Integer.parseInt(matcher.group(MATCHER_GROUP_FROM));
            int to = Integer.parseInt(matcher.group(MATCHER_GROUP_TO));

            if (from < to) {
                return true;
            } else {
                return false;
            }
        }

        return test.matches(TIMESTAMP_REMOVAL_VALIDATION_REGEX);
    }

    @Override
    public String toString() {
        if (isEmpty()) {
            return "";
        } else {
            String fromDateInString = DateUtil.getFormattedTime(from);
            String toDateInString = DateUtil.getFormattedTime(to);
            return String.format("%s%s%s", fromDateInString, TIMESTAMP_DELIMITER, toDateInString);
        }
    }

    @Override
    public boolean equals(Object other) {
        return other == this // short circuit if same object
                || (other instanceof Timestamp // instanceof handles nulls
                && this.toString().equals(((Timestamp) other).toString())); // state check
    }

    @Override
    public int hashCode() {
        return toString().hashCode();
    }

}
<commit_msg>Update condition to checking for - in timestamp<commit_after>package utask.model.task;


import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.xml.bind.annotation.XmlElement;

import utask.commons.exceptions.IllegalValueException;
import utask.commons.util.DateUtil;

/**
 * Represents a timestamp in a task
 * Guarantees: immutable; is valid as declared in {@link #isValidTimestamp(String)}
 */
public class Timestamp {
    public static final String MESSAGE_TIMESTAMP_CONSTRAINTS =
            "Timestamps for tasks should be in format from HHMM to HHMM where HHMM is in the range of 0000 to 2359";
    public static final Pattern TIMESTAMP_VALIDATION_REGEX = Pattern.compile("^(?<from>(?:0[0-9]|1[0-9]|2[0-3])"
            + "(?:[0-5][0-9]))(?:\\sto\\s)(?<to>(?:0[0-9]|1[0-9]|2[0-3])(?:[0-5][0-9]))");
    public static final String TIMESTAMP_REMOVAL_VALIDATION_REGEX = "^[-]$";

    public static final String MATCHER_GROUP_FROM = "from";
    public static final String MATCHER_GROUP_TO = "to";

    private static final int TO_PARAM_IN_ARRAY = 1;
    private static final int FROM_PARAM_IN_ARRAY = 0;
    private static final String TIMESTAMP_DELIMITER = " to ";

//    public final String value;
    //Denotes that this will be the attribute we are interested to serialise in this class
    @XmlElement
    private final Date from;

    @XmlElement
    private final Date to;

    /**
     * Validates given timestamps.
     *
     * @throws IllegalValueException if given timestamps string is invalid.
     */
    public Timestamp(String deadline, String timestamp) throws IllegalValueException {
        assert deadline != null && !deadline.isEmpty();
        assert timestamp != null && !timestamp.isEmpty();

        String trimmedTimestamp = timestamp.trim();
        if (!isValidTimestamp(trimmedTimestamp)) {
            throw new IllegalValueException(MESSAGE_TIMESTAMP_CONSTRAINTS);
        }

        String[] str = timestamp.split(TIMESTAMP_DELIMITER);
        String fromString = str[FROM_PARAM_IN_ARRAY];
        String toString = str[TO_PARAM_IN_ARRAY];

        Date date = DateUtil.parseStringToDate(deadline).get();
        assert date != null : "Certainly sure that date will be valid as tested by deadline";

        from = DateUtil.addHHMMStringToDate((Date) date.clone(), fromString);
        to = DateUtil.addHHMMStringToDate((Date) date.clone(), toString);

//        this.value = trimmedTimestamp;
    }

    public Timestamp(String timestamp) throws IllegalValueException {
        assert timestamp != null && !timestamp.isEmpty();

        String trimmedTimestamp = timestamp.trim();
        if (!isValidTimestamp(trimmedTimestamp)) {
            throw new IllegalValueException(MESSAGE_TIMESTAMP_CONSTRAINTS);
        }

        if (timestamp.equals("-")) {
            from = null;
            to = null;
        } else {
            String[] str = timestamp.split(TIMESTAMP_DELIMITER);
            String fromString = str[FROM_PARAM_IN_ARRAY];
            String toString = str[TO_PARAM_IN_ARRAY];

            Date date = DateUtil.getEmptyDate();

            from = DateUtil.addHHMMStringToDate((Date) date.clone(), fromString);
            to = DateUtil.addHHMMStringToDate((Date) date.clone(), toString);
        }
    }

    private Timestamp() {
//        this.value = "";
        from = null;
        to = null;
    }

    public static Timestamp getEmptyTimestamp() {
        return new Timestamp();
    }

    public boolean isEmpty() {
//        return "".equals(value);
        return from == null || to == null;
    }

    /**
     * Returns if a given string is a valid timestamps.
     */
    public static boolean isValidTimestamp(String test) {
        Matcher matcher = TIMESTAMP_VALIDATION_REGEX.matcher(test);

        if (matcher.matches()) {
            int from = Integer.parseInt(matcher.group(MATCHER_GROUP_FROM));
            int to = Integer.parseInt(matcher.group(MATCHER_GROUP_TO));

            if (from < to) {
                return true;
            } else {
                return false;
            }
        }

        return test.matches(TIMESTAMP_REMOVAL_VALIDATION_REGEX);
    }

    @Override
    public String toString() {
        if (isEmpty()) {
            return "";
        } else {
            String fromDateInString = DateUtil.getFormattedTime(from);
            String toDateInString = DateUtil.getFormattedTime(to);
            return String.format("%s%s%s", fromDateInString, TIMESTAMP_DELIMITER, toDateInString);
        }
    }

    @Override
    public boolean equals(Object other) {
        return other == this // short circuit if same object
                || (other instanceof Timestamp // instanceof handles nulls
                && this.toString().equals(((Timestamp) other).toString())); // state check
    }

    @Override
    public int hashCode() {
        return toString().hashCode();
    }

}

{'fraction_non_alphanumeric': 0.1076829392063331, 'fraction_numerical': 0.007307419060184716, 'mean_word_length': 2.6016081871345027, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '519731', 'n_tokens_mistral': 2815, 'n_tokens_neox': 2731, 'n_words': 706}