⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 localeconverter.java

📁 xstream是一个把java object序列化成xml文件的开源库,轻便好用
💻 JAVA
字号:
package com.thoughtworks.xstream.converters.extended;import com.thoughtworks.xstream.converters.basic.AbstractBasicConverter;import java.util.Locale;/** * Converts a java.util.Locale to a string. * * @author Jose A. Illescas * @author Joe Walnes */public class LocaleConverter extends AbstractBasicConverter {    public boolean canConvert(Class type) {        return type.equals(Locale.class);    }    protected Object fromString(String str) {        int[] underscorePositions = underscorePositions(str);        String language, country, variant;        if (underscorePositions[0] == -1) { // "language"            language = str;            country = "";            variant = "";        } else if (underscorePositions[1] == -1) { // "language_country"            language = str.substring(0, underscorePositions[0]);            country = str.substring(underscorePositions[0] + 1);            variant = "";        } else { // "language_country_variant"            language = str.substring(0, underscorePositions[0]);            country = str.substring(underscorePositions[0] + 1, underscorePositions[1]);            variant = str.substring(underscorePositions[1] + 1);        }        return new Locale(language, country, variant);    }    private int[] underscorePositions(String in) {        int[] result = new int[2];        for (int i = 0; i < result.length; i++) {            int last = i == 0 ? 0 : result[i - 1];            result[i] = in.indexOf('_', last + 1);        }        return result;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -