Java Code Examples for java.util.Locale#GERMAN

The following examples show how to use java.util.Locale#GERMAN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateHolderTest.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void getBeginAndEndOfMonth()
{
  DateHolder dateHolder = new DateHolder(DatePrecision.DAY, DateHelper.UTC, Locale.GERMAN);
  dateHolder.setDate(1970, Calendar.NOVEMBER, 21, 4, 50, 23);
  assertEquals("1970-11-21 00:00:00.000", DateHelper.getForTestCase(dateHolder.getDate()));
  dateHolder.setBeginOfMonth();
  assertEquals("1970-11-01 00:00:00.000", DateHelper.getForTestCase(dateHolder.getDate()));
  dateHolder.setDate(1970, Calendar.NOVEMBER, 21, 4, 50, 23);
  assertEquals("1970-11-21 00:00:00.000", DateHelper.getForTestCase(dateHolder.getDate()));
  dateHolder.setEndOfMonth();
  assertEquals("1970-11-30 23:59:59.999", DateHelper.getForTestCase(dateHolder.getDate()));

  dateHolder = new DateHolder(DatePrecision.DAY, DateHelper.UTC, Locale.GERMAN);
  dateHolder.setDate(2007, Calendar.JANUARY, 21, 4, 50, 23);
  dateHolder.setEndOfMonth();
  assertEquals("2007-01-31 23:59:59.999", DateHelper.getForTestCase(dateHolder.getDate()));
  dateHolder.setDate(2007, Calendar.FEBRUARY, 1, 4, 50, 23);
  dateHolder.setEndOfMonth();
  assertEquals("2007-02-28 23:59:59.999", DateHelper.getForTestCase(dateHolder.getDate()));
  dateHolder.setDate(2004, Calendar.FEBRUARY, 1, 4, 50, 23);
  dateHolder.setEndOfMonth();
  assertEquals("2004-02-29 23:59:59.999", DateHelper.getForTestCase(dateHolder.getDate()));
}
 
Example 2
Source File: VoiceInstructionConfigTest.java    From graphhopper-navigation with Apache License 2.0 6 votes vote down vote up
@Test
public void germanInitialVICMetricTest() {
    InitialVoiceInstructionConfig configMetric = new InitialVoiceInstructionConfig(FOR_HIGHER_DISTANCE_PLURAL.metric, trMap, mtrMap, Locale.GERMAN, 4250, 250, DistanceUtils.Unit.METRIC);

    compareVoiceInstructionValues(
            4000,
            "Dem Straßenverlauf folgen für 4 Kilometer",
            configMetric.getConfigForDistance(5000, "abbiegen", " dann")
    );

    compareVoiceInstructionValues(
            4000,
            "Dem Straßenverlauf folgen für 4 Kilometer",
            configMetric.getConfigForDistance(4500, "abbiegen", " dann")
    );
}
 
Example 3
Source File: UserVOFactory.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * Allow the date to be in the raw form (yyyyMMdd) or translated to be translated
 * 
 * @param value
 * @param handler
 * @param locale
 * @return
 */
public static final String parseDate(String value, final Locale locale) {
    if (!StringHelper.containsNonWhitespace(value)) {
        return value;
    }

    boolean raw = true;
    for (int i = 0; i < value.length(); i++) {
        if (!Character.isDigit(value.charAt(i))) {
            raw = false;
            break;
        }
    }

    if (raw) {
        try {
            final DateFormat formater = new SimpleDateFormat("yyyyMMdd", Locale.GERMAN);
            final Date date = formater.parse(value);
            value = Formatter.getInstance(locale).formatDate(date);
        } catch (final ParseException e) {
            /* silently failed */
        }
    }
    return value;
}
 
Example 4
Source File: SmartQuotesTest.java    From citeproc-java with Apache License 2.0 5 votes vote down vote up
/**
 * Similar to {@link #apply()} but with German quotation marks
 */
@Test
public void german() {
    SmartQuotes sq = new SmartQuotes("\u201a", "\u2018", "\u201e", "\u201c", Locale.GERMAN);

    assertEquals("\u201etest\u201c", sq.apply("\"test\""));
    assertEquals("Der\u2014 \u201eTest\u201c", sq.apply("Der\u2014 \"Test\""));
    assertEquals("\u201atest\u2018", sq.apply("'test'"));
    assertEquals("Er kann\u2019s", sq.apply("Er kann's"));
    assertEquals("Marshiness von \u2018Ammercloth\u2019s",
            sq.apply("Marshiness von 'Ammercloth's"));
    assertEquals("\u201995", sq.apply("'95"));
    assertEquals("\u2034", sq.apply("'''"));
    assertEquals("\u2033", sq.apply("''"));
    assertEquals("\u201eBesser als ein 6\u20325\u2033 Wal.\u201c",
            sq.apply("\"Besser als ein 6'5\" Wal.\""));
    assertEquals("\u201eIch hab\u2019s auf \u201a#1\u2018 gesetzt!\u201c - Der 12\u2033 Schaumstofffinger von \u201993",
            sq.apply("\"Ich hab's auf '#1' gesetzt!\" - Der 12\" Schaumstofffinger von '93"));
    assertEquals("\u201eSag \u201awas?\u2018\u201c sagt der Mitarbeiter der Mill\u2019s Pet Barn.",
            sq.apply("\"Sag 'was?'\" sagt der Mitarbeiter der Mill's Pet Barn."));
    assertEquals("\u201eQuote?\u201c: Beschreibung",
            sq.apply("\"Quote?\": Beschreibung"));
    assertEquals("\u201aQuo Te?\u2018: Beschreibung",
            sq.apply("'Quo Te?': Beschreibung"));
    assertEquals("\u201eDe Poesjes van Kevin?\u201c: Irgendwas, irgendwas",
            sq.apply("\"De Poesjes van Kevin?\": Irgendwas, irgendwas"));
    assertEquals("Und dann platze es aus ihr heraus: \u201eIch dachte, du sagtest: \u201aIch mag keine 80er-Musik\u2018?\u201c",
            sq.apply("Und dann platze es aus ihr heraus: \"Ich dachte, du sagtest: 'Ich mag keine 80er-Musik'?\""));

    assertEquals("\u201985 war ein gutes Jahr. Die ganzen 80er waren so.",
            sq.apply("'85 war ein gutes Jahr. Die ganzen 80er waren so."));
}
 
Example 5
Source File: TestChronoField.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "localeList")
Locale[] data_localeList() {
    return new Locale[] {
            Locale.US,
            Locale.GERMAN,
            Locale.JAPAN,
            Locale.ROOT,
    };
}
 
Example 6
Source File: QueryFilter.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Locale is needed for lucene stemmers (hibernate search).
 * @return
 */
public Locale getLocale()
{
  if (locale == null) {
    return Locale.GERMAN;
  }
  return locale;
}
 
Example 7
Source File: TimePeriodTest.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testTimePeriod()
{
  final DateHolder date1 = new DateHolder(new Date(), DatePrecision.MINUTE, Locale.GERMAN);
  date1.setDate(1970, Calendar.NOVEMBER, 21, 0, 0, 0);

  final DateHolder date2 = new DateHolder(new Date(), DatePrecision.MINUTE, Locale.GERMAN);
  date2.setDate(1970, Calendar.NOVEMBER, 21, 10, 0, 0);

  TimePeriod timePeriod = new TimePeriod(date1.getDate(), date2.getDate());
  assertResultArray(new int[] {0, 10, 0}, timePeriod.getDurationFields());
  assertResultArray(new int[] {1, 2, 0}, timePeriod.getDurationFields(8));

  date2.setDate(1970, Calendar.NOVEMBER, 22, 0, 0, 0);
  timePeriod = new TimePeriod(date1.getDate(), date2.getDate());
  assertResultArray(new int[] {1, 0, 0}, timePeriod.getDurationFields());
  assertResultArray(new int[] {3, 0, 0}, timePeriod.getDurationFields(8));
  assertResultArray(new int[] {0, 24, 0}, timePeriod.getDurationFields(8, 25));
  assertResultArray(new int[] {3, 0, 0}, timePeriod.getDurationFields(8, 24));

  date2.setDate(1970, Calendar.NOVEMBER, 21, 23, 59, 59);
  timePeriod = new TimePeriod(date1.getDate(), date2.getDate());
  assertResultArray(new int[] {0, 23, 59}, timePeriod.getDurationFields());
  assertResultArray(new int[] {2, 7, 59}, timePeriod.getDurationFields(8));
  assertResultArray(new int[] {0, 23, 59}, timePeriod.getDurationFields(8, 24));
  assertResultArray(new int[] {2, 7, 59}, timePeriod.getDurationFields(8, 22));

  date2.setDate(1970, Calendar.NOVEMBER, 23, 5, 30, 0);
  timePeriod = new TimePeriod(date1.getDate(), date2.getDate());
  assertResultArray(new int[] {2, 5, 30}, timePeriod.getDurationFields());
  assertResultArray(new int[] {6, 5, 30}, timePeriod.getDurationFields(8));
  assertResultArray(new int[] {0, 53, 30}, timePeriod.getDurationFields(8, 54));
  assertResultArray(new int[] {6, 5, 30}, timePeriod.getDurationFields(8, 53));
}
 
Example 8
Source File: DateHolderTest.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void ensurePrecision()
{
  final DateHolder dateHolder = new DateHolder(DatePrecision.DAY, DateHelper.UTC, Locale.GERMAN);
  assertPrecision("1970-11-21 00:00:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 50, 23);
  dateHolder.setPrecision(DatePrecision.HOUR_OF_DAY);
  assertPrecision("1970-11-21 04:00:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 50, 23);
  dateHolder.setPrecision(DatePrecision.MINUTE);
  assertPrecision("1970-11-21 04:50:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 50, 23);
  dateHolder.setPrecision(DatePrecision.MINUTE_15);
  assertPrecision("1970-11-21 04:00:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 00, 00);
  assertPrecision("1970-11-21 04:00:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 7, 59);
  assertPrecision("1970-11-21 04:15:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 8, 00);
  assertPrecision("1970-11-21 04:15:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 15, 00);
  assertPrecision("1970-11-21 04:15:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 22, 59);
  assertPrecision("1970-11-21 04:30:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 23, 00);
  assertPrecision("1970-11-21 04:30:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 30, 00);
  assertPrecision("1970-11-21 04:30:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 37, 59);
  assertPrecision("1970-11-21 04:45:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 38, 00);
  assertPrecision("1970-11-21 04:45:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 45, 00);
  assertPrecision("1970-11-21 04:45:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 52, 59);
  assertPrecision("1970-11-21 05:00:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 53, 00);
  dateHolder.setPrecision(DatePrecision.MINUTE_5);
  assertPrecision("1970-11-21 04:00:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 02, 59);
  assertPrecision("1970-11-21 04:05:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 03, 00);
  assertPrecision("1970-11-21 04:50:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 48, 00);
  assertPrecision("1970-11-21 04:50:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 52, 59);
  assertPrecision("1970-11-21 04:55:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 53, 00);
  assertPrecision("1970-11-21 04:55:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 57, 59);
  assertPrecision("1970-11-21 05:00:00.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 58, 00);
  dateHolder.setPrecision(DatePrecision.SECOND);
  assertPrecision("1970-11-21 04:50:23.000", dateHolder, 1970, Calendar.NOVEMBER, 21, 4, 50, 23);
}
 
Example 9
Source File: PriceConverterTest.java    From development with Apache License 2.0 5 votes vote down vote up
@Test
public void testParse_MaximumFractionDigits_DE() throws Exception {
    PriceConverter converter = new PriceConverter(Locale.GERMAN);
    Assert.assertEquals(Locale.GERMAN, converter.getActiveLocale());

    BigDecimal d = converter
            .parse("50.000,11111111111111111111111111111111111111111111111111");
    assertEquals(new BigDecimal(
            "50000.11111111111111111111111111111111111111111111111111"), d);
}
 
Example 10
Source File: JulSimpleFormatterParser.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
@Override
public void initParsingContext(ParsingContext parsingContext) {
  SimpleDateFormat[] datePatterns = {new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH),
    new SimpleDateFormat("MMM d, yyyy h:mm:ss a", Locale.ENGLISH), new SimpleDateFormat("dd.MM.yyyy HH:mm:ss", Locale.GERMAN),
    new SimpleDateFormat("dd-MM-yyyy HH:mm:ss", new Locale("en")), new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss", new Locale("en")),
    new SimpleDateFormat("dd MMM yyyy HH:mm:ss", new Locale("fr"))
  };
  parsingContext.getCustomConextProperties().put(DATE_PATTERNS, datePatterns);

}
 
Example 11
Source File: AbstractBaseDOTest.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
private FooDO createFooDO(final int createdDayOfMonth, final int lastUpdateDateOfMonth, final boolean deleted, final boolean testBoolean, final String testString)
{
  final FooDO obj = new FooDO();
  final DateHolder dateHolder = new DateHolder(DatePrecision.SECOND, Locale.GERMAN);
  obj.setId(42);
  dateHolder.setDate(1970, Calendar.NOVEMBER, createdDayOfMonth, 4, 50, 0);
  obj.setCreated(dateHolder.getDate());
  dateHolder.setDate(1970, Calendar.NOVEMBER, lastUpdateDateOfMonth, 4, 50, 0);
  obj.setLastUpdate(dateHolder.getDate());
  obj.setDeleted(deleted);
  obj.setTestBoolean(testBoolean);
  obj.setTestString(testString);
  return obj;
}
 
Example 12
Source File: TestResultFormatterTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldUseDecimalCommaForGerman() {
  TestResultFormatter formatter =
      new TestResultFormatter(
          new Ansi(false),
          Verbosity.COMMANDS,
          TestResultSummaryVerbosity.of(false, false),
          Locale.GERMAN,
          Optional.of(logPath),
          TimeZone.getTimeZone("America/Los_Angeles"));

  TestCaseSummary summary =
      new TestCaseSummary(
          "com.example.FooTest",
          ImmutableList.of(
              new TestResultSummary(
                  "com.example.FooTest",
                  "successTest",
                  ResultType.SUCCESS,
                  12300,
                  /*message*/ null,
                  /*stacktrace*/ null,
                  "good stdout",
                  "good stderr")));
  TestResults results = FakeTestResults.of(ImmutableList.of(summary));
  ImmutableList.Builder<String> builder = ImmutableList.builder();

  formatter.reportResult(builder, results);

  assertEquals(
      "PASS     12,3s  1 Passed   0 Skipped   0 Failed   com.example.FooTest", toString(builder));
}
 
Example 13
Source File: TestChronoField.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "localeList")
Locale[] data_localeList() {
    return new Locale[] {
            Locale.US,
            Locale.GERMAN,
            Locale.JAPAN,
            Locale.ROOT,
    };
}
 
Example 14
Source File: SentenceCleaner.java    From newsleak with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
	super.initialize(context);
	log = context.getLogger();
	log.setLevel(Level.ALL);
	dfs = new DateFormatSymbols(Locale.GERMAN);
	monthNames = new HashSet<String>(Arrays.asList(dfs.getMonths()));
}
 
Example 15
Source File: RMBTMainActivity.java    From open-rmbt with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param toFile
 */
public void redirectSystemOutput(boolean toFile) {
    try {
    	if (toFile) {
    		Log.i(DEBUG_TAG,"redirecting sysout to file");
    		//Redirecting console output and runtime exceptions to file (System.out.println)
    		File f = new File(Environment.getExternalStorageDirectory(), "qosdebug");
    		if (!f.exists()) {
    			f.mkdir();
    		}
        
    		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd", Locale.GERMAN);
    		//PrintStream fileStream = new PrintStream(new File(f, sdf.format(new Date()) + ".txt"));
    		PrintStream fileStream = new DebugPrintStream(new File(f, sdf.format(new Date()) + ".txt"));
         
    		//System.setOut(fileStream);
            System.setErr(fileStream);
    	}
    	else {        		
    		//Redirecting console output and runtime exceptions to default output stream
            //System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
            //System.setErr(new PrintStream(new FileOutputStream(FileDescriptor.err)));
            //Log.i(DEBUG_TAG,"redirecting sysout to default");
    	}
    }
    catch (Exception e) {
    	e.printStackTrace();
    }
}
 
Example 16
Source File: PriceConverterTest.java    From development with Apache License 2.0 5 votes vote down vote up
@Test
public void testParse_GermanLocaleOwnOutput() throws Exception {
    PriceConverter converter = new PriceConverter(Locale.GERMAN);
    Assert.assertEquals(Locale.GERMAN, converter.getActiveLocale());
    long price = 50L;
    String valueToDisplay = converter.getValueToDisplay(new BigDecimal(
            price), true);
    BigDecimal valueToStore = converter.parse(valueToDisplay);
    checkEquals("50.00", valueToStore);
}
 
Example 17
Source File: ParseSqlTimeTest.java    From super-csv with Apache License 2.0 4 votes vote down vote up
/**
 * Tests construction (using the Locale constructor) with a null date format (should throw an Exception).
 */
@Test(expected = NullPointerException.class)
public void testLocaleConstructorWithNullDateFormat() {
	new ParseSqlTime(null, false, Locale.GERMAN);
}
 
Example 18
Source File: MessageCatalog.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private Locale getLocale(String localeName) {
    String language, country;
    int index;

    index = localeName.indexOf('_');
    if (index == -1) {
        //
        // Special case the builtin JDK languages
        //
        if (localeName.equals("de"))
            return Locale.GERMAN;
        if (localeName.equals("en"))
            return Locale.ENGLISH;
        if (localeName.equals("fr"))
            return Locale.FRENCH;
        if (localeName.equals("it"))
            return Locale.ITALIAN;
        if (localeName.equals("ja"))
            return Locale.JAPANESE;
        if (localeName.equals("ko"))
            return Locale.KOREAN;
        if (localeName.equals("zh"))
            return Locale.CHINESE;

        language = localeName;
        country = "";
    } else {
        if (localeName.equals("zh_CN"))
            return Locale.SIMPLIFIED_CHINESE;
        if (localeName.equals("zh_TW"))
            return Locale.TRADITIONAL_CHINESE;

        //
        // JDK also has constants for countries:  en_GB, en_US, en_CA,
        // fr_FR, fr_CA, de_DE, ja_JP, ko_KR.  We don't use those.
        //
        language = localeName.substring(0, index);
        country = localeName.substring(index + 1);
    }

    return new Locale(language, country);
}
 
Example 19
Source File: MessageCatalog.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private Locale getLocale(String localeName) {
    String language, country;
    int index;

    index = localeName.indexOf('_');
    if (index == -1) {
        //
        // Special case the builtin JDK languages
        //
        if (localeName.equals("de"))
            return Locale.GERMAN;
        if (localeName.equals("en"))
            return Locale.ENGLISH;
        if (localeName.equals("fr"))
            return Locale.FRENCH;
        if (localeName.equals("it"))
            return Locale.ITALIAN;
        if (localeName.equals("ja"))
            return Locale.JAPANESE;
        if (localeName.equals("ko"))
            return Locale.KOREAN;
        if (localeName.equals("zh"))
            return Locale.CHINESE;

        language = localeName;
        country = "";
    } else {
        if (localeName.equals("zh_CN"))
            return Locale.SIMPLIFIED_CHINESE;
        if (localeName.equals("zh_TW"))
            return Locale.TRADITIONAL_CHINESE;

        //
        // JDK also has constants for countries:  en_GB, en_US, en_CA,
        // fr_FR, fr_CA, de_DE, ja_JP, ko_KR.  We don't use those.
        //
        language = localeName.substring(0, index);
        country = localeName.substring(index + 1);
    }

    return new Locale(language, country);
}
 
Example 20
Source File: ParseDateTest.java    From super-csv with Apache License 2.0 4 votes vote down vote up
/**
 * Tests construction (using the Locale constructor) with a null date format (should throw an Exception).
 */
@Test(expected = NullPointerException.class)
public void testLocaleConstructorWithNullDateFormat() {
	new ParseDate(null, false, Locale.GERMAN);
}