• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GENERATED SOURCE. DO NOT MODIFY. */
2 // © 2017 and later: Unicode, Inc. and others.
3 // License & terms of use: http://www.unicode.org/copyright.html#License
4 package ohos.global.icu.number;
5 
6 import java.math.BigDecimal;
7 import java.text.AttributedCharacterIterator;
8 
9 import ohos.global.icu.impl.FormattedStringBuilder;
10 import ohos.global.icu.impl.FormattedValueStringBuilderImpl;
11 import ohos.global.icu.impl.Utility;
12 import ohos.global.icu.impl.number.DecimalQuantity;
13 import ohos.global.icu.text.ConstrainedFieldPosition;
14 import ohos.global.icu.text.FormattedValue;
15 import ohos.global.icu.text.PluralRules.IFixedDecimal;
16 
17 /**
18  * The result of a number formatting operation. This class allows the result to be exported in several
19  * data types, including a String, an AttributedCharacterIterator, and a BigDecimal.
20  *
21  * Instances of this class are immutable and thread-safe.
22  *
23  * @see NumberFormatter
24  */
25 public class FormattedNumber implements FormattedValue {
26     final FormattedStringBuilder string;
27     final DecimalQuantity fq;
28 
FormattedNumber(FormattedStringBuilder nsb, DecimalQuantity fq)29     FormattedNumber(FormattedStringBuilder nsb, DecimalQuantity fq) {
30         this.string = nsb;
31         this.fq = fq;
32     }
33 
34     /**
35      * {@inheritDoc}
36      */
37     @Override
toString()38     public String toString() {
39         return string.toString();
40     }
41 
42     /**
43      * {@inheritDoc}
44      */
45     @Override
length()46     public int length() {
47         return string.length();
48     }
49 
50     /**
51      * {@inheritDoc}
52      */
53     @Override
charAt(int index)54     public char charAt(int index) {
55         return string.charAt(index);
56     }
57 
58     /**
59      * {@inheritDoc}
60      */
61     @Override
subSequence(int start, int end)62     public CharSequence subSequence(int start, int end) {
63         return string.subString(start, end);
64     }
65 
66     /**
67      * {@inheritDoc}
68      */
69     @Override
appendTo(A appendable)70     public <A extends Appendable> A appendTo(A appendable) {
71         return Utility.appendTo(string, appendable);
72     }
73 
74     /**
75      * {@inheritDoc}
76      */
77     @Override
nextPosition(ConstrainedFieldPosition cfpos)78     public boolean nextPosition(ConstrainedFieldPosition cfpos) {
79         return FormattedValueStringBuilderImpl.nextPosition(string, cfpos, null);
80     }
81 
82     /**
83      * {@inheritDoc}
84      */
85     @Override
toCharacterIterator()86     public AttributedCharacterIterator toCharacterIterator() {
87         return FormattedValueStringBuilderImpl.toCharacterIterator(string, null);
88     }
89 
90     /**
91      * Export the formatted number as a BigDecimal. This endpoint is useful for obtaining the exact
92      * number being printed after scaling and rounding have been applied by the number formatting
93      * pipeline.
94      *
95      * @return A BigDecimal representation of the formatted number.
96      * @see NumberFormatter
97      */
toBigDecimal()98     public BigDecimal toBigDecimal() {
99         return fq.toBigDecimal();
100     }
101 
102     /**
103      * @deprecated This API is ICU internal only.
104      * @hide draft / provisional / internal are hidden on OHOS
105      */
106     @Deprecated
getFixedDecimal()107     public IFixedDecimal getFixedDecimal() {
108         return fq;
109     }
110 }