<commit_before>/**
 * Copyright 2010 - 2018 JetBrains s.r.o.
 *
 * 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 jetbrains.exodus.log;

import org.jetbrains.annotations.NotNull;

public class ExpiredLoggableInfo {

    public final long address;
    public final int length;

    public ExpiredLoggableInfo(@NotNull final Loggable loggable) {
        this.address = loggable.getAddress();
        this.length = loggable.length();
    }

    public ExpiredLoggableInfo(long address, int length) {
        this.address = address;
        this.length = length;
    }
}
<commit_msg>XD-738: paranoiac check of expired loggable's length isn't a natural number<commit_after>/**
 * Copyright 2010 - 2018 JetBrains s.r.o.
 *
 * 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 jetbrains.exodus.log;

import jetbrains.exodus.ExodusException;
import org.jetbrains.annotations.NotNull;

public class ExpiredLoggableInfo {

    private static final boolean EXPIRED_LOGGABLE_LENGTH_CHECK_OFF =
        Boolean.getBoolean("jetbrains.exodus.log.expiredLoggableLengthCheckOff");

    public final long address;
    public final int length;

    public ExpiredLoggableInfo(@NotNull final Loggable loggable) {
        this.address = loggable.getAddress();
        this.length = assertPositiveLength(loggable.length());
    }

    public ExpiredLoggableInfo(long address, int length) {
        this.address = address;
        this.length = assertPositiveLength(length);
    }

    private static int assertPositiveLength(int length) {
        if (!EXPIRED_LOGGABLE_LENGTH_CHECK_OFF && length < 1) {
            throw new ExodusException("Expired loggable length is negative or nil: " + length);
        }
        return length;
    }
}

{'fraction_non_alphanumeric': 0.0791681867931412, 'fraction_numerical': 0.010215249908792412, 'mean_word_length': 3.5247524752475248, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '6024015', 'n_tokens_mistral': 782, 'n_tokens_neox': 734, 'n_words': 273}