001/*
002 * The MIT License (MIT)
003 *
004 * Copyright (c) 2015-2024 decimal4j (tools4j), Marco Terzer
005 *
006 * Permission is hereby granted, free of charge, to any person obtaining a copy
007 * of this software and associated documentation files (the "Software"), to deal
008 * in the Software without restriction, including without limitation the rights
009 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
010 * copies of the Software, and to permit persons to whom the Software is
011 * furnished to do so, subject to the following conditions:
012 *
013 * The above copyright notice and this permission notice shall be included in all
014 * copies or substantial portions of the Software.
015 *
016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
017 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
018 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
019 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
020 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
021 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
022 * SOFTWARE.
023 */
024package org.decimal4j.factory;
025
026import java.math.BigDecimal;
027import java.math.BigInteger;
028import java.math.RoundingMode;
029
030import org.decimal4j.api.Decimal;
031import org.decimal4j.immutable.Decimal1f;
032import org.decimal4j.mutable.MutableDecimal1f;
033import org.decimal4j.scale.Scale1f;
034import org.decimal4j.scale.ScaleMetrics;
035
036/**
037 * The factory for decimals with scale 1 creating {@link Decimal1f} and
038 * {@link MutableDecimal1f} instances.
039 */
040public enum Factory1f implements DecimalFactory<Scale1f> {
041
042        /**
043         * Singleton factory instance for immutable and mutable decimals with scale 1.
044         */
045        INSTANCE;
046
047        @Override
048        public final Scale1f getScaleMetrics() {
049                return Scale1f.INSTANCE;
050        }
051        
052        @Override
053        public final int getScale() {
054                return Scale1f.SCALE;
055        }
056
057        @Override
058        public final Class<Decimal1f> immutableType() {
059                return Decimal1f.class;
060        }
061
062        @Override
063        public final Class<MutableDecimal1f> mutableType() {
064                return MutableDecimal1f.class;
065        }
066
067        @Override
068        public final DecimalFactory<?> deriveFactory(int scale) {
069                return Factories.getDecimalFactory(scale);
070        }
071        
072        @Override
073        public final <S extends ScaleMetrics> DecimalFactory<S> deriveFactory(S scaleMetrics) {
074                return Factories.getDecimalFactory(scaleMetrics);
075        }
076
077        @Override
078        public final Decimal1f valueOf(long value) {
079                return Decimal1f.valueOf(value);
080        }
081
082        @Override
083        public final Decimal1f valueOf(float value) {
084                return Decimal1f.valueOf(value);
085        }
086
087        @Override
088        public final Decimal1f valueOf(float value, RoundingMode roundingMode) {
089                return Decimal1f.valueOf(value, roundingMode);
090        }
091
092        @Override
093        public final Decimal1f valueOf(double value) {
094                return Decimal1f.valueOf(value);
095        }
096
097        @Override
098        public final Decimal1f valueOf(double value, RoundingMode roundingMode) {
099                return Decimal1f.valueOf(value, roundingMode);
100        }
101
102        @Override
103        public final Decimal1f valueOf(BigInteger value) {
104                return Decimal1f.valueOf(value);
105        }
106
107        @Override
108        public final Decimal1f valueOf(BigDecimal value) {
109                return Decimal1f.valueOf(value);
110        }
111
112        @Override
113        public final Decimal1f valueOf(BigDecimal value, RoundingMode roundingMode) {
114                return Decimal1f.valueOf(value, roundingMode);
115        }
116
117        @Override
118        public final Decimal1f valueOf(Decimal<?> value) {
119                return Decimal1f.valueOf(value);
120        }
121
122        @Override
123        public final Decimal1f valueOf(Decimal<?> value, RoundingMode roundingMode) {
124                return Decimal1f.valueOf(value, roundingMode);
125        }
126
127        @Override
128        public final Decimal1f parse(String value) {
129                return Decimal1f.valueOf(value);
130        }
131
132        @Override
133        public final Decimal1f parse(String value, RoundingMode roundingMode) {
134                return Decimal1f.valueOf(value, roundingMode);
135        }
136
137        @Override
138        public final Decimal1f valueOfUnscaled(long unscaledValue) {
139                return Decimal1f.valueOfUnscaled(unscaledValue);
140        }
141
142        @Override
143        public final Decimal1f valueOfUnscaled(long unscaledValue, int scale) {
144                return Decimal1f.valueOfUnscaled(unscaledValue, scale);
145        }
146
147        @Override
148        public final Decimal1f valueOfUnscaled(long unscaledValue, int scale, RoundingMode roundingMode) {
149                return Decimal1f.valueOfUnscaled(unscaledValue, scale, roundingMode);
150        }
151
152        @Override
153        public final Decimal1f[] newArray(int length) {
154                return new Decimal1f[length];
155        }
156
157        @Override
158        public final MutableDecimal1f newMutable() {
159                return new MutableDecimal1f();
160        }
161
162        @Override
163        public final MutableDecimal1f[] newMutableArray(int length) {
164                return new MutableDecimal1f[length];
165        }
166}