<commit_before>/*
 * Copyright (c) 2015, Matjaž <<EMAIL>> matjaz.it
 *
 * This Source Code Form is part of the project Numerus, a roman numeral
 * library for Java. The library and its source code may be found on:
 * https://github.com/MatjazDev/Numerus and http://matjaz.it/numerus
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/
 */
package it.matjaz.numerus.core;

import java.io.Serializable;
import java.util.Objects;

/**
 * Container for a {@link RomanNumeral} and its Integer value tied toghether.
 * <p>
 * This class keeps an {@link Integer} value and its representation in roman
 * numerals as a {@link RomanNumeral} always correctly correlated with each
 * other. Upon initialization or modification of one of the two members, the
 * other gets immediatly updated. The roman numeral is always syntactically
 * correct since it's a RomanNumeral.
 * <p>
 * Uses a private {@link RomanConverter} for the conversion of the fields.
 *
 * @author Matjaž <a href="mailto:<EMAIL>"><EMAIL></a>
 * <a href="http://matjaz.it">matjaz.it</a>
 */
public class RomanInteger extends Number implements Cloneable, Comparable<Number> {

    /**
     * The arabic value of the roman numeral.
     */
    private int value;

    /**
     * The representation of the value in roman numerals.
     */
    private RomanNumeral numeral;

    /**
     * The converter used to switch from roman numerals to integers.
     */
    private final RomanConverter converter;

    /**
     * Serializable class version number.
     * <p>
     * It is used during deserialization to verify that the sender and receiver
     * of a serialized object have loaded classes for that object that are
     * compatible with respect to serialization.
     * <p>
     * This UID is a date and all objects stored before this date won't be
     * compatible with older ones.
     * [<a href="http://c2.com/ppr/wiki/JavaIdioms/AlwaysDeclareSerialVersionUid.html">Source
     * of the idea</a>]
     *
     * @see Serializable
     */
    private static final long serialVersionUID = 20150421L;

    /**
     * Creates an uninitialized RomanInteger.
     * <p>
     * The int values is set to zero and the roman numeral is costructed with
     * the default {@link RomanNumeral} constructor.
     */
    public RomanInteger() {
        this.converter = new RomanConverter();
        this.value = 0;
        this.numeral = new RomanNumeral();
    }

    /**
     * Creates a RomanInteger using the given int value.
     * <p>
     * The value gets immediatly converted to its equivalent
     * {@link RomanNumeral}. If its out of range, and exception is thrown by the
     * {@link RomanConverter} and the object is not constructed.
     *
     * @param value of the RomanInteger
     */
    public RomanInteger(int value) {
        this.converter = new RomanConverter();
        setValueAndNumeral(value);
    }

    /**
     * Creates a RomanInteger using the given {@link RomanNumeral}.
     * <p>
     * The {@link RomanNumeral} gets immediatly converted to its equivalent int
     * values. If the {@link RomanNumeral} is not initialized, an
     * {@link IllegalArgumentException} is thrown and the object is not
     * constructed.
     *
     * @param numeral in roman numerals of the RomanInteger
     */
    public RomanInteger(RomanNumeral numeral) {
        this.converter = new RomanConverter();
        setNumeralAndValue(numeral);
    }

    /**
     * Private fields setter with int value used in constructors and setters.
     * <p>
     * Made for code reusal.
     *
     * @param value to be set along with its equivalent RomanNumeral.
     * @see #setValue(int)
     * @see #RomanInteger(int)
     */
    private void setValueAndNumeral(int value) {
        this.numeral = converter.integerToRomanNumeral(value);
        this.value = value;
    }

    /**
     * Private fields setter with RomanNumeral used in constructors and setters.
     * <p>
     * Made for code reusal.
     *
     * @param numeral to be set along with its value.
     * @see #setNumeral(it.matjaz.numerus.core.RomanNumeral)
     * @see #RomanInteger(it.matjaz.numerus.core.RomanNumeral)
     */
    private void setNumeralAndValue(RomanNumeral numeral) {
        this.value = converter.romanNumeralToInteger(numeral);
        this.numeral = numeral;
    }
<commit_msg>Set RomanConverter as a static field for RomanInteger<commit_after>/*
 * Copyright (c) 2015, Matjaž <<EMAIL>> matjaz.it
 *
 * This Source Code Form is part of the project Numerus, a roman numeral
 * library for Java. The library and its source code may be found on:
 * https://github.com/MatjazDev/Numerus and http://matjaz.it/numerus
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/
 */
package it.matjaz.numerus.core;

import java.io.Serializable;
import java.util.Objects;

/**
 * Container for a {@link RomanNumeral} and its Integer value tied toghether.
 * <p>
 * This class keeps an {@link Integer} value and its representation in roman
 * numerals as a {@link RomanNumeral} always correctly correlated with each
 * other. Upon initialization or modification of one of the two members, the
 * other gets immediatly updated. The roman numeral is always syntactically
 * correct since it's a RomanNumeral.
 * <p>
 * Uses a private {@link RomanConverter} for the conversion of the fields.
 *
 * @author Matjaž <a href="mailto:<EMAIL>"><EMAIL></a>
 * <a href="http://matjaz.it">matjaz.it</a>
 */
public class RomanInteger extends Number implements Cloneable, Comparable<Number> {

    /**
     * The arabic value of the roman numeral.
     */
    private int value;

    /**
     * The representation of the value in roman numerals.
     */
    private RomanNumeral numeral;

    /**
     * The converter used to switch from roman numerals to integers.
     */
    private static final RomanConverter converter = new RomanConverter();

    /**
     * Serializable class version number.
     * <p>
     * It is used during deserialization to verify that the sender and receiver
     * of a serialized object have loaded classes for that object that are
     * compatible with respect to serialization.
     * <p>
     * This UID is a date and all objects stored before this date won't be
     * compatible with older ones.
     * [<a href="http://c2.com/ppr/wiki/JavaIdioms/AlwaysDeclareSerialVersionUid.html">Source
     * of the idea</a>]
     *
     * @see Serializable
     */
    private static final long serialVersionUID = 20150421L;

    /**
     * Creates an uninitialized RomanInteger.
     * <p>
     * The int values is set to zero and the roman numeral is costructed with
     * the default {@link RomanNumeral} constructor.
     */
    public RomanInteger() {
        this.value = 0;
        this.numeral = new RomanNumeral();
    }

    /**
     * Creates a RomanInteger using the given int value.
     * <p>
     * The value gets immediatly converted to its equivalent
     * {@link RomanNumeral}. If its out of range, and exception is thrown by the
     * {@link RomanConverter} and the object is not constructed.
     *
     * @param value of the RomanInteger
     */
    public RomanInteger(int value) {
        setValueAndNumeral(value);
    }

    /**
     * Creates a RomanInteger using the given {@link RomanNumeral}.
     * <p>
     * The {@link RomanNumeral} gets immediatly converted to its equivalent int
     * values. If the {@link RomanNumeral} is not initialized, an
     * {@link IllegalArgumentException} is thrown and the object is not
     * constructed.
     *
     * @param numeral in roman numerals of the RomanInteger
     */
    public RomanInteger(RomanNumeral numeral) {
        setNumeralAndValue(numeral);
    }

    /**
     * Private fields setter with int value used in constructors and setters.
     * <p>
     * Made for code reusal.
     *
     * @param value to be set along with its equivalent RomanNumeral.
     * @see #setValue(int)
     * @see #RomanInteger(int)
     */
    private void setValueAndNumeral(int value) {
        this.numeral = converter.integerToRomanNumeral(value);
        this.value = value;
    }

    /**
     * Private fields setter with RomanNumeral used in constructors and setters.
     * <p>
     * Made for code reusal.
     *
     * @param numeral to be set along with its value.
     * @see #setNumeral(it.matjaz.numerus.core.RomanNumeral)
     * @see #RomanInteger(it.matjaz.numerus.core.RomanNumeral)
     */
    private void setNumeralAndValue(RomanNumeral numeral) {
        this.value = converter.romanNumeralToInteger(numeral);
        this.numeral = numeral;
    }

{'fraction_non_alphanumeric': 0.0892636312535132, 'fraction_numerical': 0.004047217537942664, 'mean_word_length': 2.7678949597628124, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 2, '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': '6033107', 'n_tokens_mistral': 2650, 'n_tokens_neox': 2533, 'n_words': 951}