<commit_before>/**
 * Copyright (c) 2012, 2014, <NAME> (<NAME>), <NAME> and others by the @author tag.
 *
 * 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 org.javamoney.moneta.spi;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import javax.money.NumberValue;

/**
 * This enumeration provides general utility functions supporting conversion of number types to BigDecimal.
 */
public enum ConvertBigDecimal {
    /** Conversion from integral numeric types, short, int, long. */
	INTEGER {
		@Override
		BigDecimal getDecimal(Number num) {
			return BigDecimal.valueOf(num.longValue());
		}
	},
    /** Conversion for floating point numbers. */
    FLUCTUAGE {
		@Override
		BigDecimal getDecimal(Number num) {
			return new BigDecimal(num.toString());
		}
	},
    /** Conversion from BigInteger. */
    BIGINTEGER {
		@Override
		BigDecimal getDecimal(Number num) {
			return new BigDecimal((BigInteger) num);
		}
	},
    /** Conversion from NumberValue. */
    NUMBERVALUE {
		@Override
		BigDecimal getDecimal(Number num) {
			BigDecimal result = ((NumberValue)num).numberValue(BigDecimal.class);
			return isScaleZero(result);
		}
	},
    /** Conversion from BigDecimal. */
    BIGDECIMAL {
		@Override
		BigDecimal getDecimal(Number num) {
			BigDecimal result = ((BigDecimal)num);
			return isScaleZero(result);
		}
	},
    /** COnversion from BigDecimal, extended. */
    BIGDECIMAL_EXTENDS {
		@Override
		BigDecimal getDecimal(Number num) {
			BigDecimal result = ((BigDecimal)num).stripTrailingZeros();
			return isScaleZero(result);
		}
	},
    /** Default conversion based on String, if everything else ffailed. */
	DEFAULT {
		@Override
		BigDecimal getDecimal(Number num) {
			BigDecimal result = null;
			try {
				result = new BigDecimal(num.toString());
			} catch (NumberFormatException ignored) {
			}
			result = Optional.ofNullable(result).orElse(
					BigDecimal.valueOf(num.doubleValue()));
			return isScaleZero(result);
		}
	};
	
	
	abstract BigDecimal getDecimal(Number num);
	
	static BigDecimal of(Number num) {
		Objects.requireNonNull(num, "Number is required.");
		return factory(num).getDecimal(num);
	}<commit_msg>Fix a Typo ConvertBigDecimal#DEFAULT<commit_after>/**
 * Copyright (c) 2012, 2014, <NAME> (<NAME>), <NAME> and others by the @author tag.
 *
 * 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 org.javamoney.moneta.spi;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import javax.money.NumberValue;

/**
 * This enumeration provides general utility functions supporting conversion of number types to BigDecimal.
 */
public enum ConvertBigDecimal {
    /** Conversion from integral numeric types, short, int, long. */
	INTEGER {
		@Override
		BigDecimal getDecimal(Number num) {
			return BigDecimal.valueOf(num.longValue());
		}
	},
    /** Conversion for floating point numbers. */
    FLUCTUAGE {
		@Override
		BigDecimal getDecimal(Number num) {
			return new BigDecimal(num.toString());
		}
	},
    /** Conversion from BigInteger. */
    BIGINTEGER {
		@Override
		BigDecimal getDecimal(Number num) {
			return new BigDecimal((BigInteger) num);
		}
	},
    /** Conversion from NumberValue. */
    NUMBERVALUE {
		@Override
		BigDecimal getDecimal(Number num) {
			BigDecimal result = ((NumberValue)num).numberValue(BigDecimal.class);
			return isScaleZero(result);
		}
	},
    /** Conversion from BigDecimal. */
    BIGDECIMAL {
		@Override
		BigDecimal getDecimal(Number num) {
			BigDecimal result = ((BigDecimal)num);
			return isScaleZero(result);
		}
	},
    /** COnversion from BigDecimal, extended. */
    BIGDECIMAL_EXTENDS {
		@Override
		BigDecimal getDecimal(Number num) {
			BigDecimal result = ((BigDecimal)num).stripTrailingZeros();
			return isScaleZero(result);
		}
	},
    /** Default conversion based on String, if everything else failed. */
	DEFAULT {
		@Override
		BigDecimal getDecimal(Number num) {
			BigDecimal result = null;
			try {
				result = new BigDecimal(num.toString());
			} catch (NumberFormatException ignored) {
			}
			result = Optional.ofNullable(result).orElse(
					BigDecimal.valueOf(num.doubleValue()));
			return isScaleZero(result);
		}
	};
	
	
	abstract BigDecimal getDecimal(Number num);
	
	static BigDecimal of(Number num) {
		Objects.requireNonNull(num, "Number is required.");
		return factory(num).getDecimal(num);
	}
{'fraction_non_alphanumeric': 0.10808466342817488, 'fraction_numerical': 0.004163775156141568, 'mean_word_length': 3.9105621805792166, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3631782', 'n_tokens_mistral': 1812, 'n_tokens_neox': 1652, 'n_words': 505}