<commit_before>/**
 * Copyright 2010 CosmoCode GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.cosmocode.commons;

import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;

import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.ThreadSafe;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * Immutable implementation of {@link TimePeriod} using {@link Date}s.
 *
 * @since 1.21
 * @author <NAME>
 */
@Immutable
@ThreadSafe
@Beta
final class ImmutableDateTimePeriod extends AbstractDateTimePeriod {

    private final Date start;
    private final Date end;

    public ImmutableDateTimePeriod(final Date start, final Date end) {
        Preconditions.checkNotNull(start, "Start");
        Preconditions.checkNotNull(end, "End");

        // create new Date objects from given parameters to prevent later modifications
        this.start = new Date(start.getTime());
        this.end = new Date(end.getTime());
    }

    @Override
    public Date getStartsAt() {
        return new Date(start.getTime());
    }

    @Override
    public Date getEndsAt() {
        return new Date(end.getTime());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        } else if (o instanceof ImmutableDateTimePeriod) {
            final ImmutableDateTimePeriod that = ImmutableDateTimePeriod.class.cast(o);
            return start.equals(that.start) && end.equals(that.end);
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        int result = start.hashCode();
        result = 31 * result + end.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "ImmutableDateTimePeriod{" +
                "start=" + start +
                ", end=" + end +
                '}';
    }

}
<commit_msg>readded getStart and getEnd to ImmutableDateTimePeriod (possible performance reasons).<commit_after>/**
 * Copyright 2010 CosmoCode GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.cosmocode.commons;

import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;

import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.ThreadSafe;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * Immutable implementation of {@link TimePeriod} using {@link Date}s.
 *
 * @since 1.21
 * @author <NAME>
 */
@Immutable
@ThreadSafe
@Beta
final class ImmutableDateTimePeriod extends AbstractDateTimePeriod {

    private final Date start;
    private final Date end;

    public ImmutableDateTimePeriod(final Date start, final Date end) {
        Preconditions.checkNotNull(start, "Start");
        Preconditions.checkNotNull(end, "End");

        // create new Date objects from given parameters to prevent later modifications
        this.start = new Date(start.getTime());
        this.end = new Date(end.getTime());
    }

    @Override
    public Date getStartsAt() {
        // returns new Date to preserve immutability of start
        return new Date(start.getTime());
    }

    @Override
    public Date getEndsAt() {
        // returns new Date to preserve immutability of end
        return new Date(end.getTime());
    }

    @Override
    public long getStart(TimeUnit unit) {
        // overridden to avoid the overhead of getStartsAt()
        return unit.convert(start.getTime(), TimeUnit.MILLISECONDS);
    }

    @Override
    public long getEnd(TimeUnit unit) {
        // overridden to avoid the overhead of getEndsAt()
        return unit.convert(end.getTime(), TimeUnit.MILLISECONDS);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        } else if (o instanceof ImmutableDateTimePeriod) {
            final ImmutableDateTimePeriod that = ImmutableDateTimePeriod.class.cast(o);
            return start.equals(that.start) && end.equals(that.end);
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        int result = start.hashCode();
        result = 31 * result + end.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "ImmutableDateTimePeriod{" +
                "start=" + start +
                ", end=" + end +
                '}';
    }

}

{'fraction_non_alphanumeric': 0.09503753891228713, 'fraction_numerical': 0.004761032777879509, 'mean_word_length': 2.7257844474761255, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2652358', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1438, 'n_words': 484}