<commit_before>package com.flash3388.flashlib.time;

import com.flash3388.flashlib.util.CompareResult;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

public class Time implements Comparable<Time> {

    public static final long INVALID_VALUE = -1L;
    public static final Time INVALID = new Time(INVALID_VALUE, TimeUnit.MILLISECONDS);

    private final long mValue;
    private final TimeUnit mUnit;

    public Time(long value, TimeUnit unit) {
        mValue = value;
        mUnit = Objects.requireNonNull(unit, "time unit");
    }

    public static Time milliseconds(long timeMs) {
        return new Time(timeMs, TimeUnit.MILLISECONDS);
    }

    public static Time seconds(long timeSeconds) {
        return new Time(timeSeconds, TimeUnit.SECONDS);
    }

    public static Time seconds(double timeSeconds) {
        return milliseconds((long) (timeSeconds * 1000));
    }

    public static Time minutes(long timeMinutes) {
        return new Time(timeMinutes, TimeUnit.MINUTES);
    }

    public static Time minutes(double timeMinutes) {
        return seconds(timeMinutes * 60);
    }

    public long value() {
        return mValue;
    }

    public TimeUnit unit() {
        return mUnit;
    }

    public Time toUnit(TimeUnit newTimeUnit) {
        if (!isValid()) {
            return new Time(INVALID_VALUE, newTimeUnit);
        }

        if (mUnit == newTimeUnit) {
            return this;
        }

        long valueInWantedUnits = newTimeUnit.convert(mValue, mUnit);
        return new Time(valueInWantedUnits, newTimeUnit);
    }

    public long valueAsMillis() {
        return toUnit(TimeUnit.MILLISECONDS).value();
    }

    public boolean isValid() {
        return mValue >= 0;
    }

    public Time add(Time other) {
        long newValue = mValue + other.toUnit(mUnit).value();
        return new Time(newValue, mUnit);
    }

    public Time sub(Time other) {
        long newValue = mValue - other.toUnit(mUnit).value();
        return new Time(newValue, mUnit);
    }

    public boolean before(Time other) {
        return compareTo(other) == CompareResult.SMALLER_THAN.value();
    }

    public boolean after(Time other) {
        return compareTo(other) == CompareResult.GREATER_THAN.value();
    }

    public boolean equals(Time other) {
        return compareTo(other) == CompareResult.EQUAL_TO.value();
    }

    @Override
    public boolean equals(Object obj) {
        return obj instanceof Time && equals((Time) obj);
    }

    @Override
    public int compareTo(Time other) {
        long otherValue = other.toUnit(mUnit).value();

        if (mValue > otherValue) {
            return CompareResult.GREATER_THAN.value();
        }
        if (mValue < otherValue) {
            return CompareResult.SMALLER_THAN.value();
        }

        return CompareResult.EQUAL_TO.value();
    }

    @Override
    public String toString() {
        return String.format("%d [%s]", mValue, mUnit.name());
    }
}<commit_msg>added hashcode method<commit_after>package com.flash3388.flashlib.time;

import com.flash3388.flashlib.util.CompareResult;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

public class Time implements Comparable<Time> {

    public static final long INVALID_VALUE = -1L;
    public static final Time INVALID = new Time(INVALID_VALUE, TimeUnit.MILLISECONDS);

    private final long mValue;
    private final TimeUnit mUnit;

    public Time(long value, TimeUnit unit) {
        mValue = value;
        mUnit = Objects.requireNonNull(unit, "time unit");
    }

    public static Time milliseconds(long timeMs) {
        return new Time(timeMs, TimeUnit.MILLISECONDS);
    }

    public static Time seconds(long timeSeconds) {
        return new Time(timeSeconds, TimeUnit.SECONDS);
    }

    public static Time seconds(double timeSeconds) {
        return milliseconds((long) (timeSeconds * 1000));
    }

    public static Time minutes(long timeMinutes) {
        return new Time(timeMinutes, TimeUnit.MINUTES);
    }

    public static Time minutes(double timeMinutes) {
        return seconds(timeMinutes * 60);
    }

    public long value() {
        return mValue;
    }

    public TimeUnit unit() {
        return mUnit;
    }

    public Time toUnit(TimeUnit newTimeUnit) {
        if (!isValid()) {
            return new Time(INVALID_VALUE, newTimeUnit);
        }

        if (mUnit == newTimeUnit) {
            return this;
        }

        long valueInWantedUnits = newTimeUnit.convert(mValue, mUnit);
        return new Time(valueInWantedUnits, newTimeUnit);
    }

    public long valueAsMillis() {
        return toUnit(TimeUnit.MILLISECONDS).value();
    }

    public boolean isValid() {
        return mValue >= 0;
    }

    public Time add(Time other) {
        long newValue = mValue + other.toUnit(mUnit).value();
        return new Time(newValue, mUnit);
    }

    public Time sub(Time other) {
        long newValue = mValue - other.toUnit(mUnit).value();
        return new Time(newValue, mUnit);
    }

    public boolean before(Time other) {
        return compareTo(other) == CompareResult.SMALLER_THAN.value();
    }

    public boolean after(Time other) {
        return compareTo(other) == CompareResult.GREATER_THAN.value();
    }

    public boolean equals(Time other) {
        return compareTo(other) == CompareResult.EQUAL_TO.value();
    }

    @Override
    public int compareTo(Time other) {
        long otherValue = other.toUnit(mUnit).value();

        if (mValue > otherValue) {
            return CompareResult.GREATER_THAN.value();
        }
        if (mValue < otherValue) {
            return CompareResult.SMALLER_THAN.value();
        }

        return CompareResult.EQUAL_TO.value();
    }

    @Override
    public boolean equals(Object obj) {
        return obj instanceof Time && equals((Time) obj);
    }

    @Override
    public int hashCode() {
        return Objects.hash(mValue, mUnit);
    }

    @Override
    public String toString() {
        return String.format("%d [%s]", mValue, mUnit.name());
    }
}
{'fraction_non_alphanumeric': 0.09995068222916324, 'fraction_numerical': 0.005260562222587539, 'mean_word_length': 2.5495915985997666, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '3018196', 'n_tokens_mistral': 1840, 'n_tokens_neox': 1750, 'n_words': 447}