當前位置: 首頁>>代碼示例>>Java>>正文


Java Locale.ROOT屬性代碼示例

本文整理匯總了Java中java.util.Locale.ROOT屬性的典型用法代碼示例。如果您正苦於以下問題:Java Locale.ROOT屬性的具體用法?Java Locale.ROOT怎麽用?Java Locale.ROOT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在java.util.Locale的用法示例。


在下文中一共展示了Locale.ROOT屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: computeLocalizedLevelName

private String computeLocalizedLevelName(Locale newLocale) {
    ResourceBundle rb = ResourceBundle.getBundle(resourceBundleName, newLocale);
    final String localizedName = rb.getString(name);

    final boolean isDefaultBundle = defaultBundle.equals(resourceBundleName);
    if (!isDefaultBundle) return localizedName;

    // This is a trick to determine whether the name has been translated
    // or not. If it has not been translated, we need to use Locale.ROOT
    // when calling toUpperCase().
    final Locale rbLocale = rb.getLocale();
    final Locale locale =
            Locale.ROOT.equals(rbLocale)
            || name.equals(localizedName.toUpperCase(Locale.ROOT))
            ? Locale.ROOT : rbLocale;

    // ALL CAPS in a resource bundle's message indicates no translation
    // needed per Oracle translation guideline.  To workaround this
    // in Oracle JDK implementation, convert the localized level name
    // to uppercase for compatibility reason.
    return Locale.ROOT.equals(locale) ? name : localizedName.toUpperCase(locale);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:22,代碼來源:Level.java

示例2: toLocaleArray

public static Locale[] toLocaleArray(Set<String> tags) {
    Locale[] locs = new Locale[tags.size() + 1];
    int index = 0;
    locs[index++] = Locale.ROOT;
    for (String tag : tags) {
        switch (tag) {
        case "ja-JP-JP":
            locs[index++] = JRELocaleConstants.JA_JP_JP;
            break;
        case "th-TH-TH":
            locs[index++] = JRELocaleConstants.TH_TH_TH;
            break;
        default:
            locs[index++] = Locale.forLanguageTag(tag);
            break;
        }
    }
    return locs;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:19,代碼來源:LocaleProviderAdapter.java

示例3: parse

/**
 * Parse the string describing a locale into a {@link Locale} object
 */
public static Locale parse(String localeStr) {
    final String[] parts = localeStr.split("_", -1);
    switch (parts.length) {
        case 3:
            // lang_country_variant
            return new Locale(parts[0], parts[1], parts[2]);
        case 2:
            // lang_country
            return new Locale(parts[0], parts[1]);
        case 1:
            if ("ROOT".equalsIgnoreCase(parts[0])) {
                return Locale.ROOT;
            }
            // lang
            return new Locale(parts[0]);
        default:
            throw new IllegalArgumentException("Can't parse locale: [" + localeStr + "]");
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:LocaleUtils.java

示例4: toBundleName

@Override
public String toBundleName(String baseName, Locale locale) {
	if (locale == Locale.ROOT) return baseName;

	String language = locale.getLanguage();
	String script = locale.getScript();
	String country = locale.getCountry();
	String variant = locale.getVariant();

	if (Objects.equals(language, "") && Objects.equals(country, "") && Objects.equals(variant, "")) return baseName;

	StringBuilder sb = new StringBuilder(baseName);
	if (!baseName.endsWith("/"))
		sb.append('_');
	if (!Objects.equals(script, "")) if (!Objects.equals(variant, ""))
		sb.append(language).append('_').append(script).append('_').append(country).append('_').append(variant);
	else if (!Objects.equals(country, ""))
		sb.append(language).append('_').append(script).append('_').append(country);
	else sb.append(language).append('_').append(script);
	else if (!Objects.equals(variant, ""))
		sb.append(language).append('_').append(country).append('_').append(variant);
	else if (!Objects.equals(country, "")) sb.append(language).append('_').append(country);
	else sb.append(language);
	return sb.toString();

}
 
開發者ID:HuajiStudio,項目名稱:ChessMaster,代碼行數:26,代碼來源:UTF8Control.java

示例5: getDays

private List<Day> getDays(Elements tableHeaderCells) throws ParseException {
    List<Day> days = new ArrayList<>();

    for (int i = 2; i < 7; i++) {
        String[] dayHeaderCell = tableHeaderCells.get(i).html().split("<br>");

        SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy", Locale.ROOT);
        Date d = sdf.parse(dayHeaderCell[1].trim());
        sdf.applyPattern("yyyy-MM-dd");

        Day day = new Day();
        day.setDayName(dayHeaderCell[0]);
        day.setDate(sdf.format(d));

        if (tableHeaderCells.get(i).hasClass("free-day")) {
            day.setFreeDay(true);
            day.setFreeDayName(dayHeaderCell[2]);
        }

        days.add(day);
    }

    return days;
}
 
開發者ID:wulkanowy,項目名稱:wulkanowy,代碼行數:24,代碼來源:Timetable.java

示例6: getStrictStandardDateFormatter

public static FormatDateTimeFormatter getStrictStandardDateFormatter() {
    // 2014/10/10
    DateTimeFormatter shortFormatter = new DateTimeFormatterBuilder()
            .appendFixedDecimal(DateTimeFieldType.year(), 4)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2)
            .toFormatter()
            .withZoneUTC();

    // 2014/10/10 12:12:12
    DateTimeFormatter longFormatter = new DateTimeFormatterBuilder()
            .appendFixedDecimal(DateTimeFieldType.year(), 4)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2)
            .appendLiteral(' ')
            .appendFixedSignedDecimal(DateTimeFieldType.hourOfDay(), 2)
            .appendLiteral(':')
            .appendFixedSignedDecimal(DateTimeFieldType.minuteOfHour(), 2)
            .appendLiteral(':')
            .appendFixedSignedDecimal(DateTimeFieldType.secondOfMinute(), 2)
            .toFormatter()
            .withZoneUTC();

    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder().append(longFormatter.withZone(DateTimeZone.UTC).getPrinter(), new DateTimeParser[]{longFormatter.getParser(), shortFormatter.getParser(), new EpochTimeParser(true)});

    return new FormatDateTimeFormatter("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis", builder.toFormatter().withZone(DateTimeZone.UTC), Locale.ROOT);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:31,代碼來源:Joda.java

示例7: getDateTest

@Test
public void getDateTest() throws Exception {
    DateFormat format = new SimpleDateFormat("dd.MM.yyyy", Locale.ROOT);
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date date = format.parse("31.07.2017");

    Assert.assertEquals(date, TimeUtils.getDate(636370560000000000L));
}
 
開發者ID:wulkanowy,項目名稱:wulkanowy,代碼行數:8,代碼來源:TimeUtilsTest.java

示例8: readObject

/**
 * Reads the default serializable fields, provides default values for objects
 * in older serial versions, and initializes non-serializable fields.
 * If <code>serialVersionOnStream</code>
 * is less than 1, initializes <code>monetarySeparator</code> to be
 * the same as <code>decimalSeparator</code> and <code>exponential</code>
 * to be 'E'.
 * If <code>serialVersionOnStream</code> is less than 2,
 * initializes <code>locale</code>to the root locale, and initializes
 * If <code>serialVersionOnStream</code> is less than 3, it initializes
 * <code>exponentialSeparator</code> using <code>exponential</code>.
 * Sets <code>serialVersionOnStream</code> back to the maximum allowed value so that
 * default serialization will work properly if this object is streamed out again.
 * Initializes the currency from the intlCurrencySymbol field.
 *
 * @since JDK 1.1.6
 */
private void readObject(ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    if (serialVersionOnStream < 1) {
        // Didn't have monetarySeparator or exponential field;
        // use defaults.
        monetarySeparator = decimalSeparator;
        exponential       = 'E';
    }
    if (serialVersionOnStream < 2) {
        // didn't have locale; use root locale
        locale = Locale.ROOT;
    }
    if (serialVersionOnStream < 3) {
        // didn't have exponentialSeparator. Create one using exponential
        exponentialSeparator = Character.toString(exponential);
    }
    serialVersionOnStream = currentSerialVersion;

    if (intlCurrencySymbol != null) {
        try {
             currency = Currency.getInstance(intlCurrencySymbol);
        } catch (IllegalArgumentException e) {
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:43,代碼來源:DecimalFormatSymbols.java

示例9: doXContentBody

@Override
protected void doXContentBody(XContentBuilder builder, boolean includeDefaults, Params params) throws IOException {
    super.doXContentBody(builder, includeDefaults, params);

    if (includeDefaults || fieldType().numericPrecisionStep() != Defaults.PRECISION_STEP_64_BIT) {
        builder.field("precision_step", fieldType().numericPrecisionStep());
    }
    builder.field("format", fieldType().dateTimeFormatter().format());
    if (includeDefaults || fieldType().nullValueAsString() != null) {
        builder.field("null_value", fieldType().nullValueAsString());
    }
    if (includeInAll != null) {
        builder.field("include_in_all", includeInAll);
    } else if (includeDefaults) {
        builder.field("include_in_all", false);
    }

    if (includeDefaults || fieldType().timeUnit() != Defaults.TIME_UNIT) {
        builder.field("numeric_resolution", fieldType().timeUnit().name().toLowerCase(Locale.ROOT));
    }
    // only serialize locale if needed, ROOT is the default, so no need to serialize that case as well...
    if (fieldType().dateTimeFormatter().locale() != null && fieldType().dateTimeFormatter().locale() != Locale.ROOT) {
        builder.field("locale", fieldType().dateTimeFormatter().locale());
    } else if (includeDefaults) {
        if (fieldType().dateTimeFormatter().locale() == null) {
            builder.field("locale", Locale.ROOT);
        } else {
            builder.field("locale", fieldType().dateTimeFormatter().locale());
        }
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:31,代碼來源:DateFieldMapper.java

示例10: format

/**
 * Returns the formatted message for an exception with the specified messages.
 */
public static String format(String heading, Collection<Message> errorMessages) {
    try (Formatter fmt = new Formatter(Locale.ROOT)) {
        fmt.format(heading).format(":%n%n");
        int index = 1;
        boolean displayCauses = getOnlyCause(errorMessages) == null;

        for (Message errorMessage : errorMessages) {
            fmt.format("%s) %s%n", index++, errorMessage.getMessage());

            List<Object> dependencies = errorMessage.getSources();
            for (int i = dependencies.size() - 1; i >= 0; i--) {
                Object source = dependencies.get(i);
                formatSource(fmt, source);
            }

            Throwable cause = errorMessage.getCause();
            if (displayCauses && cause != null) {
                StringWriter writer = new StringWriter();
                cause.printStackTrace(new PrintWriter(writer));
                fmt.format("Caused by: %s", writer.getBuffer());
            }

            fmt.format("%n");
        }

        if (errorMessages.size() == 1) {
            fmt.format("1 error");
        } else {
            fmt.format("%s errors", errorMessages.size());
        }

        return fmt.toString();
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:37,代碼來源:Errors.java

示例11: data_localeList

@DataProvider(name = "localeList")
Locale[] data_localeList() {
    return new Locale[] {
            Locale.US,
            Locale.GERMAN,
            Locale.JAPAN,
            Locale.ROOT,
    };
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:TestChronoField.java

示例12: format

/**
 * Formats a filter and handles encoding of special characters in the value arguments using the
 * &lt;valueencoding&gt; rule as described in <a href="http://www.ietf.org/rfc/rfc4515.txt">RFC 4515</a>.
 * <p>
 * Example of filter template format: <code>(&amp;(cn={0})(uid={1}))</code>
 * 
 * @param filterTemplate the filter with placeholders
 * @param values the values to encode and substitute
 * @return the formatted filter with escaped values
 * @throws IllegalArgumentException if the number of values does not match the number of placeholders in the template
 */
public static String format( String filterTemplate, String... values )
{
    if ( values == null )
    {
        values = EMPTY;
    }

    MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT );

    // check element count and argument count
    Format[] formats = mf.getFormatsByArgumentIndex();
    if ( formats.length != values.length )
    {
        // TODO: I18n
        String msg = "Filter template {0} has {1} placeholders but {2} arguments provided.";
        throw new IllegalArgumentException( I18n.format( msg, filterTemplate, formats.length, values.length ) );
    }

    // encode arguments
    for ( int i = 0; i < values.length; i++ )
    {
        values[i] = encodeFilterValue( values[i] );
    }

    // format the filter
    return mf.format( values );
}
 
開發者ID:apache,項目名稱:directory-ldap-api,代碼行數:38,代碼來源:FilterEncoder.java

示例13: getDisplayLocaleOfSubtypeLocale

@Nonnull
public static Locale getDisplayLocaleOfSubtypeLocale(@Nonnull final String localeString) {
    if (NO_LANGUAGE.equals(localeString)) {
        return sResources.getConfiguration().locale;
    }
    if (sExceptionalLocaleDisplayedInRootLocale.containsKey(localeString)) {
        return Locale.ROOT;
    }
    return LocaleUtils.constructLocaleFromString(localeString);
}
 
開發者ID:sergeychilingaryan,項目名稱:AOSP-Kayboard-7.1.2,代碼行數:10,代碼來源:SubtypeLocaleUtils.java

示例14: readObject

/**
 * Reads the default serializable fields, provides default values for objects
 * in older serial versions, and initializes non-serializable fields.
 * If <code>serialVersionOnStream</code>
 * is less than 1, initializes <code>monetarySeparator</code> to be
 * the same as <code>decimalSeparator</code> and <code>exponential</code>
 * to be 'E'.
 * If <code>serialVersionOnStream</code> is less than 2,
 * initializes <code>locale</code>to the root locale, and initializes
 * If <code>serialVersionOnStream</code> is less than 3, it initializes
 * <code>exponentialSeparator</code> using <code>exponential</code>.
 * Sets <code>serialVersionOnStream</code> back to the maximum allowed value so that
 * default serialization will work properly if this object is streamed out again.
 * Initializes the currency from the intlCurrencySymbol field.
 *
 * @since  1.1.6
 */
private void readObject(ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    if (serialVersionOnStream < 1) {
        // Didn't have monetarySeparator or exponential field;
        // use defaults.
        monetarySeparator = decimalSeparator;
        exponential       = 'E';
    }
    if (serialVersionOnStream < 2) {
        // didn't have locale; use root locale
        locale = Locale.ROOT;
    }
    if (serialVersionOnStream < 3) {
        // didn't have exponentialSeparator. Create one using exponential
        exponentialSeparator = Character.toString(exponential);
    }
    serialVersionOnStream = currentSerialVersion;

    if (intlCurrencySymbol != null) {
        try {
             currency = Currency.getInstance(intlCurrencySymbol);
        } catch (IllegalArgumentException e) {
        }
        currencyInitialized = true;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:44,代碼來源:DecimalFormatSymbols.java

示例15: generateDatedExportFileName

public static String generateDatedExportFileName() {
    Calendar now = Calendar.getInstance();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT);

    return String.format("%s_%s.%s", EXPORT_FILENAME_PREFIX, dateFormat.format(now.getTime()), EXPORT_FILENAME_SUFFIX);
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:6,代碼來源:SettingsExporter.java


注:本文中的java.util.Locale.ROOT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。