当前位置: 首页>>代码示例>>Java>>正文


Java IllegalFormatConversionException类代码示例

本文整理汇总了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;
}
 
开发者ID:ZalemSoftware,项目名称:Ymir,代码行数:23,代码来源:AndroidBugsUtils.java

示例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);
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:17,代码来源:DecimalType.java

示例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());
    }
}
 
开发者ID:wikimedia,项目名称:citolytics,代码行数:20,代码来源:ClickStreamTest.java

示例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();
}
 
开发者ID:yegor256,项目名称:cactoos,代码行数:9,代码来源:FormattedTextTest.java

示例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);
}
 
开发者ID:FTC7393,项目名称:state-machine-framework,代码行数:35,代码来源:OptionsFile.java

示例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;
}
 
开发者ID:FTC7393,项目名称:state-machine-framework,代码行数:48,代码来源:OptionsFile.java

示例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;
}
 
开发者ID:FTC7393,项目名称:state-machine-framework,代码行数:42,代码来源:OptionsFile.java

示例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;
}
 
开发者ID:oopcell,项目名称:AvoinApotti,代码行数:31,代码来源:AddressManagmentProvider.java

示例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);
    }
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:16,代码来源:DateTimePickerDialog.java

示例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
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:13,代码来源:IllegalFormatConversionExceptionTest.java

示例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());

}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:13,代码来源:IllegalFormatConversionExceptionTest.java

示例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());

}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:12,代码来源:IllegalFormatConversionExceptionTest.java

示例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());

}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:12,代码来源:IllegalFormatConversionExceptionTest.java

示例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());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:15,代码来源:IllegalFormatConversionExceptionTest.java

示例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);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:10,代码来源:IllegalFormatConversionExceptionTest.java


注:本文中的java.util.IllegalFormatConversionException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。