All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ibm.icu.impl.number.MicroProps Maven / Gradle / Ivy

Go to download

International Component for Unicode for Java (ICU4J) is a mature, widely used Java library providing Unicode and Globalization support

There is a newer version: 76.1
Show newest version
// © 2017 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
package com.ibm.icu.impl.number;

import java.util.List;

import com.ibm.icu.number.IntegerWidth;
import com.ibm.icu.number.NumberFormatter.DecimalSeparatorDisplay;
import com.ibm.icu.number.NumberFormatter.SignDisplay;
import com.ibm.icu.number.Precision;
import com.ibm.icu.text.DecimalFormatSymbols;
import com.ibm.icu.util.Measure;
import com.ibm.icu.util.MeasureUnit;

/**
 * MicroProps is the first MicroPropsGenerator that should be should be called,
 * producing an initialized MicroProps instance that will be passed on and
 * modified throughout the rest of the chain of MicroPropsGenerator instances.
 */
public class MicroProps implements Cloneable, MicroPropsGenerator {
    // Populated globally:
    public SignDisplay sign;
    public DecimalFormatSymbols symbols;
    public String nsName;
    public Padder padding;
    public DecimalSeparatorDisplay decimal;
    public IntegerWidth integerWidth;

    // Modifiers provided by the number formatting pipeline (when the value is known):

    // A Modifier provided by LongNameHandler, used for currency long names and
    // units. If there is no LongNameHandler needed, this should be an
    // null. (This is typically the third modifier applied.)
    public Modifier modOuter;

    // A Modifier for short currencies and compact notation. (This is typically
    // the second modifier applied.)
    public Modifier modMiddle;

    // A Modifier provided by ScientificHandler, used for scientific notation.
    // This is typically the first modifier applied.
    public Modifier modInner;

    public Precision rounder;
    public Grouper grouping;
    public boolean useCurrency;
    public String gender;

    // Internal fields:
    private final boolean immutable;

    // The MeasureUnit with which the output is represented. May also have
    // MeasureUnit.Complexity.MIXED complexity, in which case mixedMeasures comes into
    // play.
    public MeasureUnit outputUnit;

    /**
     * Contains all the measures.
     */
    public List mixedMeasures;

    /**
     * Points to quantity position, -1 if the position is not set yet.
     */
    public int indexOfQuantity = -1;

    private volatile boolean exhausted;

    /**
     * @param immutable
     *            Whether this MicroProps should behave as an immutable after construction with respect
     *            to the quantity chain.
     */
    public MicroProps(boolean immutable) {
        this.immutable = immutable;
    }

    /**
     * As MicroProps is the "base instance", this implementation of
     * MircoPropsGenerator.processQuantity() just ensures that the output
     * `micros` is correctly initialized.
     * 

* For the "safe" invocation of this function, micros must not be *this, * such that a copy of the base instance is made. For the "unsafe" path, * this function can be used only once, because the base MicroProps instance * will be modified and thus not be available for re-use. * * @param quantity The quantity for consideration and optional mutation. * @return an initialized MicroProps instance. */ @Override public MicroProps processQuantity(DecimalQuantity quantity) { if (immutable) { return (MicroProps) this.clone(); } else if (exhausted) { // Safety check throw new AssertionError("Cannot re-use a mutable MicroProps in the quantity chain"); } else { exhausted = true; return this; } } @Override public Object clone() { try { return super.clone(); } catch (CloneNotSupportedException e) { throw new AssertionError(e); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy