本文整理汇总了Java中java.util.IllegalFormatConversionException类的典型用法代码示例。如果您正苦于以下问题:Java IllegalFormatConversionException类的具体用法?Java IllegalFormatConversionException怎么用?Java IllegalFormatConversionException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IllegalFormatConversionException类属于java.util包,在下文中一共展示了IllegalFormatConversionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResources
import java.util.IllegalFormatConversionException; //导入依赖的package包/类
@Override
public Resources getResources() {
if(wrappedResources == null) {
Resources r = super.getResources();
wrappedResources = new Resources(r.getAssets(), r.getDisplayMetrics(), r.getConfiguration()) {
@NonNull
@Override
public String getString(int id, Object... formatArgs) throws NotFoundException {
try {
return super.getString(id, formatArgs);
} catch (IllegalFormatConversionException ifce) {
Log.e("DatePickerDialogFix", "IllegalFormatConversionException Fixed!", ifce);
String template = super.getString(id);
template = template.replaceAll("%" + ifce.getConversion(), "%s");
return String.format(getConfiguration().locale, template, formatArgs);
}
}
};
}
return wrappedResources;
}
示例2: format
import java.util.IllegalFormatConversionException; //导入依赖的package包/类
public String format(String pattern) {
// The value could be an integer value. Try to convert to BigInteger in
// order to have access to more conversion formats.
try {
return String.format(pattern, value.toBigIntegerExact());
} catch (ArithmeticException ae) {
// Could not convert to integer value without loss of
// information. Fall through to default behavior.
} catch (IllegalFormatConversionException ifce) {
// The conversion is not valid for the type BigInteger. This
// happens, if the format is like "%.1f" but the value is an
// integer. Fall through to default behavior.
}
return String.format(pattern, value);
}
示例3: testMathExpressionCPI
import java.util.IllegalFormatConversionException; //导入依赖的package包/类
@Test
public void testMathExpressionCPI() throws Exception {
double score = 0.5;
int inLinks = 10;
int articleCount = 1000;
String cpiExpr = "%1$f*Math.log(%3$d/%2$d)";
try {
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
double cpi = (double) engine.eval(String.format(cpiExpr, score, inLinks, articleCount));
assertEquals("Invalid CPI score", 2.302585092994046, cpi, 0);
} catch(ScriptException | IllegalFormatConversionException e) {
throw new Exception("Cannot evaluate CPI script expression: " + cpiExpr + "; Exception: " + e.getMessage());
}
}
示例4: ensuresThatFormatterFails
import java.util.IllegalFormatConversionException; //导入依赖的package包/类
@Test(expected = IllegalFormatConversionException.class)
public void ensuresThatFormatterFails() throws IOException {
new FormattedText(
new TextOf("Local time: %d"),
Locale.ROOT,
Calendar.getInstance()
).asString();
}
示例5: set
import java.util.IllegalFormatConversionException; //导入依赖的package包/类
/**
* set a value in the map
*
* @param tag the name of the value
* @param object the Object to put into the map
*/
public <T> void set(String tag, T object) {
//if the object is null, add a null value to the map
if (object == null) {
values.put(tag, null);
return;
}
//get the class to convert to
Class<T> clazz = (Class<T>) object.getClass();
//get the converter for the specified class
Converter<T> converter = converters.getConverter(clazz);
//throw an error if there is no converter for the class
if (converter == null) {
throw new MissingResourceException("No converter given.", converters.getClass().getName(), clazz.getName());
}
//convert the value to a string
String string = converter.toString(object);
//if the result is null, throw an exception
if (string == null) throw new IllegalFormatConversionException((char) 0, clazz);
//add the key-value pair to the values map
values.put(tag, string);
}
示例6: getArray
import java.util.IllegalFormatConversionException; //导入依赖的package包/类
/**
*
* @param tag the name of the value
* @param clazz the class to convert to
* @param separator the string to separate the array elements with (not a
* regex)
* @return an array of the specified type
* @throws IllegalArgumentException if there is no converter for the given
* type
*/
public <T> T[] getArray(String tag, Class<T> clazz, String separator) {
//get the converter for the specified class
Converter<T> converter = converters.getConverter(clazz);
//throw an error if there is no converter for the class
if (converter == null) {
throw new MissingResourceException("No converter given.", converters.getClass().getName(), clazz.getName());
}
if (!values.containsKey(tag)) {
throw new IllegalArgumentException();
}
//get the value from the map
String string = values.get(tag);
//if the input is null, return null
if (string == null) return null;
//separate the string into parts. use the separator as a literal string, not a regex
String[] parts = string.split(Pattern.quote(separator));
T[] results = (T[]) Array.newInstance(clazz, parts.length);
for (int i=0; i<parts.length; i++) {
String part = parts[i];
//convert the string to the object
T result = converter.fromString(part);
//if the result is null, throw an exception
if (result == null) throw new IllegalFormatConversionException((char) 0, clazz);
results[i] = result;
}
return results;
}
示例7: get
import java.util.IllegalFormatConversionException; //导入依赖的package包/类
/**
* @param tag the name of the value
* @param clazz the class to convert to
* @return the value converted to the specified type
* @throws MissingResourceException if there is no converter for the given
* type
* @throws IllegalArgumentException if there is no value with the given tag
* @throws IllegalFormatConversionException if the string could not be
* converted to the specified object
*/
public <T> T get(String tag, Class<T> clazz) {
if (clazz == null) {
throw new IllegalArgumentException("clazz cannot be null.");
}
//get the converter for the specified class
Converter<T> converter = converters.getConverter(clazz);
//throw an error if there is no converter for the class
if (converter == null) {
throw new MissingResourceException("No converter given.", converters.getClass().getName(), clazz.getName());
}
if (!values.containsKey(tag)) {
throw new IllegalArgumentException();
}
//get the value from the map
String string = values.get(tag);
//if the input is null, return null
if (string == null) return null;
//convert the string to the object
T result = converter.fromString(string);
//if the result is null, throw an exception
if (result == null) throw new IllegalFormatConversionException((char) 0, clazz);
return result;
}
示例8: getLatitudeLogitude
import java.util.IllegalFormatConversionException; //导入依赖的package包/类
public double[] getLatitudeLogitude(IAddress searchCriteria) throws DomainRuntimeException
{
String[] l_latlong = getLatitudeLogitude(searchCriteria,LatitudeLogitudeFormat.DEGREES);
double[] l_dLatLong = new double[2];
if (l_latlong != null)
{
if (l_latlong.length == 2)
{
if (l_latlong[0] == null || l_latlong[1] == null)
return null;
try
{
//we have two entries to convert
if (l_latlong[0] != null && l_latlong[0] != "")
l_dLatLong[0] = Double.parseDouble(l_latlong[0]);
if (l_latlong[1] != null && l_latlong[1] != "")
l_dLatLong[1] = Double.parseDouble(l_latlong[1]);
}
catch (IllegalFormatConversionException e)
{
throw new DomainRuntimeException(e.getMessage());
}
return l_dLatLong;
}
}
return null;
}
示例9: getString
import java.util.IllegalFormatConversionException; //导入依赖的package包/类
@NonNull
@Override
public String getString(int id, Object... formatArgs) throws NotFoundException {
try {
return super.getString(id, formatArgs);
} catch (IllegalFormatConversionException conversationException) {
String template = super.getString(id);
char conversion = conversationException.getConversion();
// Trying to replace either all digit patterns (%d) or first one (%1$d).
template = template.replaceAll(Pattern.quote("%" + conversion), "%s")
.replaceAll(Pattern.quote("%1$" + conversion), "%s");
return String.format(getLocale(), template, formatArgs);
}
}
示例10: test_illegalFormatConversionException
import java.util.IllegalFormatConversionException; //导入依赖的package包/类
/**
* @tests java.util.IllegalFormatConversionException#IllegalFormatConversionException(char,
* Class)
*/
public void test_illegalFormatConversionException() {
try {
new IllegalFormatConversionException(' ', null);
fail("should throw NullPointerExcetpion.");
} catch (NullPointerException e) {
// desired
}
}
示例11: test_getArgumentClass
import java.util.IllegalFormatConversionException; //导入依赖的package包/类
/**
* @tests java.util.IllegalFormatConversionException#getArgumentClass()
*/
public void test_getArgumentClass() {
char c = '*';
Class<String> argClass = String.class;
IllegalFormatConversionException illegalFormatConversionException = new IllegalFormatConversionException(
c, argClass);
assertEquals(argClass, illegalFormatConversionException
.getArgumentClass());
}
示例12: test_getConversion
import java.util.IllegalFormatConversionException; //导入依赖的package包/类
/**
* @tests java.util.IllegalFormatConversionException#getConversion()
*/
public void test_getConversion() {
char c = '*';
Class<String> argClass = String.class;
IllegalFormatConversionException illegalFormatConversionException = new IllegalFormatConversionException(
c, argClass);
assertEquals(c, illegalFormatConversionException.getConversion());
}
示例13: test_getMessage
import java.util.IllegalFormatConversionException; //导入依赖的package包/类
/**
* @tests java.util.IllegalFormatConversionException#getMessage()
*/
public void test_getMessage() {
char c = '*';
Class<String> argClass = String.class;
IllegalFormatConversionException illegalFormatConversionException = new IllegalFormatConversionException(
c, argClass);
assertTrue(null != illegalFormatConversionException.getMessage());
}
示例14: assertDeserialized
import java.util.IllegalFormatConversionException; //导入依赖的package包/类
public void assertDeserialized(Serializable initial,
Serializable deserialized) {
SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
deserialized);
IllegalFormatConversionException initEx = (IllegalFormatConversionException) initial;
IllegalFormatConversionException desrEx = (IllegalFormatConversionException) deserialized;
assertEquals("ArgumentClass", initEx.getArgumentClass(), desrEx
.getArgumentClass());
assertEquals("Conversion", initEx.getConversion(), desrEx
.getConversion());
}
示例15: testSerializationCompatibility
import java.util.IllegalFormatConversionException; //导入依赖的package包/类
/**
* @tests serialization/deserialization compatibility with RI.
*/
public void testSerializationCompatibility() throws Exception {
SerializationTest.verifyGolden(this,
new IllegalFormatConversionException('*', String.class),
exComparator);
}