public enum ConversionCategory extends Enum<ConversionCategory>
Format
annotation to indicate the valid
types that may be passed as a format parameter. For example:
The annotation indicates that the format string requires any Object as the first parameter (@Format({ConversionCategory.GENERAL, ConversionCategory.INT}) String f = "String '%s' has length %d"; String.format(f, "Example", 7);
GENERAL
) and an integer as the second parameter (INT
).Format
Enum Constant and Description |
---|
CHAR
Use if the parameter is of a basic types which represent Unicode characters: char, Character,
byte, Byte, short, and Short.
|
CHAR_AND_INT
In a format string, multiple conversions may be applied to the same parameter.
|
FLOAT
Use if the parameter is is a floating-point type: float, Float, double, Double, and
BigDecimal.
|
GENERAL
Use if the parameter can be of any type.
|
INT
Use if the parameter is is an integral type: byte, Byte, short, Short, int and Integer, long,
Long, and BigInteger.
|
INT_AND_TIME |
NULL
Use if no object of any type can be passed as parameter.
|
TIME
Use if the parameter is is a type which is capable of encoding a date or time: long, Long,
Calendar, and Date.
|
UNUSED
Use if a parameter is not used by the formatter.
|
Modifier and Type | Field and Description |
---|---|
String |
chars |
Class<? extends Object>[] |
types |
Modifier and Type | Method and Description |
---|---|
static ConversionCategory |
fromConversionChar(char c)
Use this function to get the category associated with a conversion character.
|
static ConversionCategory |
intersect(ConversionCategory a,
ConversionCategory b)
Use this function to get the intersection of two categories.
|
static boolean |
isSubsetOf(ConversionCategory a,
ConversionCategory b) |
String |
toString()
Returns a pretty printed
ConversionCategory . |
static ConversionCategory |
union(ConversionCategory a,
ConversionCategory b)
Use this function to get the union of two categories.
|
static ConversionCategory |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static ConversionCategory[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final ConversionCategory GENERAL
public static final ConversionCategory CHAR
public static final ConversionCategory INT
public static final ConversionCategory FLOAT
public static final ConversionCategory TIME
public static final ConversionCategory CHAR_AND_INT
format("Test %1$c %1$d", (int)42);In this example, the first parameter is interpreted as both a character and an int, therefore the parameter must be compatible with both conversion, and can therefore neither be char nor long. This intersection of conversions is called CHAR_AND_INT.
One other conversion intersection is interesting, namely the intersection of INT and TIME, resulting in INT_AND_TIME.
All other intersection either lead to an already existing type, or NULL, in which case it is illegal to pass object's of any type as parameter.
public static final ConversionCategory INT_AND_TIME
public static final ConversionCategory NULL
format("Test %1$f %1$d", null);Only null can be legally passed, passing a value such as 4 or 4.2 would lead to an exception.
public static final ConversionCategory UNUSED
format("Test %1$s %3$s", "a","unused","b");Only the first "a" and third "b" parameters are used, the second "unused" parameter is ignored.
public static ConversionCategory[] values()
for (ConversionCategory c : ConversionCategory.values()) System.out.println(c);
public static ConversionCategory valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic static ConversionCategory fromConversionChar(char c)
ConversionCategory.fromConversionChar('d') == ConversionCategory.INT;
public static boolean isSubsetOf(ConversionCategory a, ConversionCategory b)
public static ConversionCategory intersect(ConversionCategory a, ConversionCategory b)
ConversionCategory.intersect(INT, TIME) == INT_AND_TIME;
public static ConversionCategory union(ConversionCategory a, ConversionCategory b)
ConversionCategory.union(INT, TIME) == GENERAL;
@Pure public String toString()
ConversionCategory
.toString
in class Enum<ConversionCategory>