1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 // © 2022 and later: Unicode, Inc. and others. 3 // License & terms of use: http://www.unicode.org/copyright.html 4 5 package android.icu.text; 6 7 import java.util.Arrays; 8 import java.util.Collections; 9 import java.util.List; 10 11 /** 12 * Represents all the display options that are supported by CLDR such as grammatical case, noun 13 * class, ... etc. It currently supports enums, but may be extended in the future to have other 14 * types of data. It replaces a DisplayContext[] as a method parameter. 15 * <p> 16 * NOTE: This class is Immutable, and uses a Builder interface. 17 * <p>For example: 18 * {@code DisplayOptions x = 19 * DisplayOptions.builder() 20 * .setNounClass(NounClass.DATIVE) 21 * .setPluralCategory(PluralCategory.FEW) 22 * .build(); 23 * } 24 */ 25 public final class DisplayOptions { 26 private final GrammaticalCase grammaticalCase; 27 private final NounClass nounClass; 28 private final PluralCategory pluralCategory; 29 private final Capitalization capitalization; 30 private final NameStyle nameStyle; 31 private final DisplayLength displayLength; 32 private final SubstituteHandling substituteHandling; 33 DisplayOptions(Builder builder)34 private DisplayOptions(Builder builder) { 35 this.grammaticalCase = builder.grammaticalCase; 36 this.nounClass = builder.nounClass; 37 this.pluralCategory = builder.pluralCategory; 38 this.capitalization = builder.capitalization; 39 this.nameStyle = builder.nameStyle; 40 this.displayLength = builder.displayLength; 41 this.substituteHandling = builder.substituteHandling; 42 } 43 44 /** 45 * Creates a builder with the {@code UNDEFINED} value for all the parameters. 46 * 47 * @return Builder 48 */ builder()49 public static Builder builder() { 50 return new Builder(); 51 } 52 53 /** 54 * Creates a builder with the same parameters from this object. 55 * 56 * @return Builder 57 */ copyToBuilder()58 public Builder copyToBuilder() { 59 return new Builder(this); 60 } 61 62 /** 63 * Gets the grammatical case. 64 * 65 * @return GrammaticalCase 66 */ getGrammaticalCase()67 public GrammaticalCase getGrammaticalCase() { 68 return this.grammaticalCase; 69 } 70 71 /** 72 * Gets the noun class. 73 * 74 * @return NounClass 75 */ getNounClass()76 public NounClass getNounClass() { 77 return this.nounClass; 78 } 79 80 /** 81 * Gets the plural category. 82 * 83 * @return PluralCategory 84 */ getPluralCategory()85 public PluralCategory getPluralCategory() { 86 return this.pluralCategory; 87 } 88 89 /** 90 * Gets the capitalization. 91 * 92 * @return Capitalization 93 */ getCapitalization()94 public Capitalization getCapitalization() { 95 return this.capitalization; 96 } 97 98 /** 99 * Gets the name style. 100 * 101 * @return NameStyle 102 */ getNameStyle()103 public NameStyle getNameStyle() { 104 return this.nameStyle; 105 } 106 107 /** 108 * Gets the display length. 109 * 110 * @return DisplayLength 111 */ getDisplayLength()112 public DisplayLength getDisplayLength() { 113 return this.displayLength; 114 } 115 116 /** 117 * Gets the substitute handling. 118 * 119 * @return SubstituteHandling 120 */ getSubstituteHandling()121 public SubstituteHandling getSubstituteHandling() { 122 return this.substituteHandling; 123 } 124 125 /** 126 * Responsible for building {@code DisplayOptions}. 127 */ 128 public static class Builder { 129 private GrammaticalCase grammaticalCase; 130 private NounClass nounClass; 131 private PluralCategory pluralCategory; 132 private Capitalization capitalization; 133 private NameStyle nameStyle; 134 private DisplayLength displayLength; 135 private SubstituteHandling substituteHandling; 136 137 /** 138 * Creates a {@code DisplayOptions.Builder} with the default values. 139 */ Builder()140 private Builder() { 141 this.grammaticalCase = GrammaticalCase.UNDEFINED; 142 this.nounClass = NounClass.UNDEFINED; 143 this.pluralCategory = PluralCategory.UNDEFINED; 144 this.capitalization = Capitalization.UNDEFINED; 145 this.nameStyle = NameStyle.UNDEFINED; 146 this.displayLength = DisplayLength.UNDEFINED; 147 this.substituteHandling = SubstituteHandling.UNDEFINED; 148 } 149 150 /** 151 * Creates a {@code Builder} with all the information from a {@code DisplayOptions}. 152 * 153 * @param displayOptions Options to be copied. 154 */ Builder(DisplayOptions displayOptions)155 private Builder(DisplayOptions displayOptions) { 156 this.grammaticalCase = displayOptions.grammaticalCase; 157 this.nounClass = displayOptions.nounClass; 158 this.pluralCategory = displayOptions.pluralCategory; 159 this.capitalization = displayOptions.capitalization; 160 this.nameStyle = displayOptions.nameStyle; 161 this.displayLength = displayOptions.displayLength; 162 this.substituteHandling = displayOptions.substituteHandling; 163 } 164 165 /** 166 * Sets the grammatical case. 167 * 168 * @param grammaticalCase The grammatical case. 169 * @return Builder 170 */ setGrammaticalCase(GrammaticalCase grammaticalCase)171 public Builder setGrammaticalCase(GrammaticalCase grammaticalCase) { 172 this.grammaticalCase = grammaticalCase; 173 return this; 174 } 175 176 /** 177 * Sets the noun class. 178 * 179 * @param nounClass The noun class. 180 * @return Builder 181 */ setNounClass(NounClass nounClass)182 public Builder setNounClass(NounClass nounClass) { 183 this.nounClass = nounClass; 184 return this; 185 } 186 187 /** 188 * Sets the plural category. 189 * 190 * @param pluralCategory The plural category. 191 * @return Builder 192 */ setPluralCategory(PluralCategory pluralCategory)193 public Builder setPluralCategory(PluralCategory pluralCategory) { 194 this.pluralCategory = pluralCategory; 195 return this; 196 } 197 198 /** 199 * Sets the capitalization. 200 * 201 * @param capitalization The capitalization. 202 * @return Builder 203 */ setCapitalization(Capitalization capitalization)204 public Builder setCapitalization(Capitalization capitalization) { 205 this.capitalization = capitalization; 206 return this; 207 } 208 209 /** 210 * Sets the name style. 211 * 212 * @param nameStyle The name style. 213 * @return Builder 214 */ setNameStyle(NameStyle nameStyle)215 public Builder setNameStyle(NameStyle nameStyle) { 216 this.nameStyle = nameStyle; 217 return this; 218 } 219 220 /** 221 * Sets the display length. 222 * 223 * @param displayLength The display length. 224 * @return Builder 225 */ setDisplayLength(DisplayLength displayLength)226 public Builder setDisplayLength(DisplayLength displayLength) { 227 this.displayLength = displayLength; 228 return this; 229 } 230 231 /** 232 * Sets the substitute handling. 233 * 234 * @param substituteHandling The substitute handling. 235 * @return Builder 236 */ setSubstituteHandling(SubstituteHandling substituteHandling)237 public Builder setSubstituteHandling(SubstituteHandling substituteHandling) { 238 this.substituteHandling = substituteHandling; 239 return this; 240 } 241 242 /** 243 * Builds the display options. 244 * 245 * @return DisplayOptions 246 */ build()247 public DisplayOptions build() { 248 DisplayOptions displayOptions = new DisplayOptions(this); 249 return displayOptions; 250 } 251 } 252 253 /** 254 * Represents all the grammatical noun classes that are supported by CLDR. 255 */ 256 public enum NounClass { 257 /** 258 * A possible setting for NounClass. The noun class context to be used is unknown (this is the 259 * default value). 260 */ 261 UNDEFINED("undefined"), 262 /** 263 */ 264 OTHER("other"), 265 /** 266 */ 267 NEUTER("neuter"), 268 /** 269 */ 270 FEMININE("feminine"), 271 /** 272 */ 273 MASCULINE("masculine"), 274 /** 275 */ 276 ANIMATE("animate"), 277 /** 278 */ 279 INANIMATE("inanimate"), 280 /** 281 */ 282 PERSONAL("personal"), 283 /** 284 */ 285 COMMON("common"); 286 287 private final String identifier; 288 NounClass(String identifier)289 private NounClass(String identifier) { 290 this.identifier = identifier; 291 } 292 293 /** 294 * Unmodifiable List of all noun classes constants. List version of {@link #values()}. 295 */ 296 public static final List<NounClass> VALUES = 297 Collections.unmodifiableList(Arrays.asList(NounClass.values())); 298 299 /** 300 * @return the lowercase CLDR keyword string for the noun class. 301 */ getIdentifier()302 public final String getIdentifier() { 303 return this.identifier; 304 } 305 306 /** 307 * @param identifier in lower case such as "feminine" or "masculine" 308 * @return the plural category corresponding to the identifier, or {@code UNDEFINED} 309 */ fromIdentifier(String identifier)310 public static final NounClass fromIdentifier(String identifier) { 311 if (identifier == null) { 312 return NounClass.UNDEFINED; 313 } 314 315 for (NounClass nounClass : VALUES) { 316 if (identifier.equals(nounClass.getIdentifier())) { 317 return nounClass; 318 } 319 } 320 321 return NounClass.UNDEFINED; 322 } 323 } 324 325 /** 326 * Represents all the name styles. 327 */ 328 public enum NameStyle { 329 /** 330 * A possible setting for NameStyle. The NameStyle context to be used is unknown (this is the 331 * default value). 332 */ 333 UNDEFINED, 334 /** 335 * Use standard names when generating a locale name, e.g. en_GB displays as 'English (United 336 * Kingdom)'. 337 */ 338 STANDARD_NAMES, 339 340 /** 341 * Use dialect names, when generating a locale name, e.g. en_GB displays as 'British English'. 342 */ 343 DIALECT_NAMES; 344 345 /** 346 * Unmodifiable List of all name styles constants. List version of {@link #values()}. 347 */ 348 public static final List<NameStyle> VALUES = 349 Collections.unmodifiableList(Arrays.asList(NameStyle.values())); 350 } 351 352 /** 353 * Represents all the substitute handlings. 354 */ 355 public enum SubstituteHandling { 356 /** 357 * A possible setting for SubstituteHandling. The SubstituteHandling context to be used is 358 * unknown (this is the default value). 359 */ 360 UNDEFINED, 361 /** 362 * Returns a fallback value (e.g., the input code) when no data is available. This is the 363 * default behaviour. 364 */ 365 SUBSTITUTE, 366 367 /** 368 * Returns a null value when no data is available. 369 */ 370 NO_SUBSTITUTE; 371 372 /** 373 * Unmodifiable List of all substitute handlings constants. List version of {@link #values()}. 374 */ 375 public static final List<SubstituteHandling> VALUES = 376 Collections.unmodifiableList(Arrays.asList(SubstituteHandling.values())); 377 } 378 379 /** 380 * Represents all the display lengths. 381 */ 382 public enum DisplayLength { 383 /** 384 * A possible setting for DisplayLength. The DisplayLength context to be used is unknown (this 385 * is the default value). 386 */ 387 UNDEFINED, 388 /** 389 * Uses full names when generating a locale name, e.g. "United States" for US. 390 */ 391 LENGTH_FULL, 392 393 /** 394 * Use short names when generating a locale name, e.g. "U.S." for US. 395 */ 396 LENGTH_SHORT; 397 398 /** 399 * Unmodifiable List of all display lengths constants. List version of {@link #values()}. 400 */ 401 public static final List<DisplayLength> VALUES = 402 Collections.unmodifiableList(Arrays.asList(DisplayLength.values())); 403 } 404 405 /** 406 * Represents all the capitalization options. 407 */ 408 public enum Capitalization { 409 /** 410 * A possible setting for Capitalization. The capitalization context to be used is unknown (this 411 * is the default value). 412 */ 413 UNDEFINED, 414 415 /** 416 * The capitalization context if a date, date symbol or display name is to be formatted with 417 * capitalization appropriate for the beginning of a sentence. 418 */ 419 BEGINNING_OF_SENTENCE, 420 421 /** 422 * The capitalization context if a date, date symbol or display name is to be formatted with 423 * capitalization appropriate for the middle of a sentence. 424 */ 425 MIDDLE_OF_SENTENCE, 426 427 /** 428 * The capitalization context if a date, date symbol or display name is to be formatted with 429 * capitalization appropriate for stand-alone usage such as an isolated name on a calendar 430 * page. 431 */ 432 STANDALONE, 433 434 /** 435 * The capitalization context if a date, date symbol or display name is to be formatted with 436 * capitalization appropriate for a user-interface list or menu item. 437 */ 438 UI_LIST_OR_MENU; 439 440 /** 441 * Unmodifiable List of all the capitalizations constants. List version of {@link #values()}. 442 */ 443 public static final List<Capitalization> VALUES = 444 Collections.unmodifiableList(Arrays.asList(Capitalization.values())); 445 } 446 447 /** 448 * Standard CLDR plural category constants. See http://www.unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules 449 */ 450 public enum PluralCategory { 451 /** 452 * A possible setting for PluralCategory. The plural category context to be used is unknown 453 * (this is the default value). 454 */ 455 UNDEFINED("undefined"), 456 457 /** 458 */ 459 ZERO("zero"), 460 461 /** 462 */ 463 ONE("one"), 464 465 /** 466 */ 467 TWO("two"), 468 469 /** 470 */ 471 FEW("few"), 472 473 /** 474 */ 475 MANY("many"), 476 477 /** 478 */ 479 OTHER("other"); 480 481 private final String identifier; 482 PluralCategory(String identifier)483 private PluralCategory(String identifier) { 484 this.identifier = identifier; 485 } 486 487 /** 488 * Unmodifiable List of all plural categories constants. List version of {@link #values()}. 489 */ 490 public static final List<PluralCategory> VALUES = 491 Collections.unmodifiableList(Arrays.asList(PluralCategory.values())); 492 493 /** 494 * @return the lowercase CLDR keyword string for the plural category 495 */ getIdentifier()496 public final String getIdentifier() { 497 return this.identifier; 498 } 499 500 /** 501 * @param identifier in lower case such as "few" or "other" 502 * @return the plural category corresponding to the identifier, or {@code UNDEFINED} 503 */ fromIdentifier(String identifier)504 public static final PluralCategory fromIdentifier(String identifier) { 505 if (identifier == null) { 506 return PluralCategory.UNDEFINED; 507 } 508 509 for (PluralCategory pluralCategory : VALUES) { 510 if (identifier.equals(pluralCategory.getIdentifier())) { 511 return pluralCategory; 512 } 513 } 514 515 return PluralCategory.UNDEFINED; 516 } 517 } 518 519 /** 520 * Represents all the grammatical cases that are supported by CLDR. 521 */ 522 public enum GrammaticalCase { 523 /** 524 * A possible setting for GrammaticalCase. The grammatical case context to be used is unknown 525 * (this is the default value). 526 */ 527 UNDEFINED("undefined"), 528 529 /** 530 */ 531 ABLATIVE("ablative"), 532 533 /** 534 */ 535 ACCUSATIVE("accusative"), 536 537 /** 538 */ 539 COMITATIVE("comitative"), 540 541 /** 542 */ 543 DATIVE("dative"), 544 545 /** 546 */ 547 ERGATIVE("ergative"), 548 549 /** 550 */ 551 GENITIVE("genitive"), 552 553 /** 554 */ 555 INSTRUMENTAL("instrumental"), 556 557 /** 558 */ 559 LOCATIVE("locative"), 560 561 /** 562 */ 563 LOCATIVE_COPULATIVE("locative_copulative"), 564 565 /** 566 */ 567 NOMINATIVE("nominative"), 568 569 /** 570 */ 571 OBLIQUE("oblique"), 572 573 /** 574 */ 575 PREPOSITIONAL("prepositional"), 576 577 /** 578 */ 579 SOCIATIVE("sociative"), 580 581 /** 582 */ 583 VOCATIVE("vocative"); 584 585 private final String identifier; 586 GrammaticalCase(String identifier)587 private GrammaticalCase(String identifier) { 588 this.identifier = identifier; 589 } 590 591 /** 592 * Unmodifiable List of all grammatical cases constants. List version of {@link #values()}. 593 */ 594 public static final List<GrammaticalCase> VALUES = 595 Collections.unmodifiableList(Arrays.asList(GrammaticalCase.values())); 596 597 /** 598 * @return the lowercase CLDR keyword string for the grammatical case. 599 */ getIdentifier()600 public final String getIdentifier() { 601 return this.identifier; 602 } 603 604 /** 605 * @param identifier in lower case such as "dative" or "nominative" 606 * @return the plural category corresponding to the identifier, or {@code UNDEFINED} 607 */ fromIdentifier(String identifier)608 public static final GrammaticalCase fromIdentifier(String identifier) { 609 if (identifier == null) { 610 return GrammaticalCase.UNDEFINED; 611 } 612 613 for (GrammaticalCase grammaticalCase : VALUES) { 614 if (identifier.equals(grammaticalCase.getIdentifier())) { 615 return grammaticalCase; 616 } 617 } 618 619 return GrammaticalCase.UNDEFINED; 620 } 621 } 622 } 623