Skip to content

Commit 618c0dd

Browse files
authored
Merge branch 'master' into bael-2882-bis
2 parents 4bf210f + 0f4dafe commit 618c0dd

90 files changed

Lines changed: 1842 additions & 63 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core-java-8-2/.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
*.class
2+
3+
0.*
4+
5+
#folders#
6+
/target
7+
/neoDb*
8+
/data
9+
/src/main/webapp/WEB-INF/classes
10+
*/META-INF/*
11+
.resourceCache
12+
13+
# Packaged files #
14+
*.jar
15+
*.war
16+
*.ear
17+
18+
# Files generated by integration tests
19+
backup-pom.xml
20+
/bin/
21+
/temp
22+
23+
#IntelliJ specific
24+
.idea/
25+
*.iml

core-java-8-2/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@
2121
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2222
<maven.compiler.source>1.8</maven.compiler.source>
2323
<maven.compiler.target>1.8</maven.compiler.target>
24+
<icu.version>64.2</icu.version>
2425
</properties>
2526

2627
<dependencies>
28+
<dependency>
29+
<groupId>com.ibm.icu</groupId>
30+
<artifactId>icu4j</artifactId>
31+
<version>${icu.version}</version>
32+
</dependency>
33+
2734
</dependencies>
2835

2936
<build>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.jarArguments;
2+
3+
public class JarExample {
4+
5+
public static void main(String[] args) {
6+
System.out.println("Hello Baeldung Reader in JarExample!");
7+
8+
if(args == null) {
9+
System.out.println("You have not provided any arguments!");
10+
}else {
11+
System.out.println("There are "+args.length+" argument(s)!");
12+
for(int i=0; i<args.length; i++) {
13+
System.out.println("Argument("+(i+1)+"):" + args[i]);
14+
}
15+
}
16+
}
17+
18+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.localization;
2+
3+
import java.text.ParseException;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
import java.util.Locale;
7+
8+
public class App {
9+
10+
/**
11+
* Runs all available formatter
12+
* @throws ParseException
13+
*/
14+
public static void main(String[] args) {
15+
List<Locale> locales = Arrays.asList(new Locale[] { Locale.UK, Locale.ITALY, Locale.FRANCE, Locale.forLanguageTag("pl-PL") });
16+
Localization.run(locales);
17+
JavaSEFormat.run(locales);
18+
ICUFormat.run(locales);
19+
}
20+
21+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.baeldung.localization;
2+
3+
import java.util.List;
4+
import java.util.Locale;
5+
import java.util.ResourceBundle;
6+
7+
import com.ibm.icu.text.MessageFormat;
8+
9+
public class ICUFormat {
10+
11+
public static String getLabel(Locale locale, Object[] data) {
12+
ResourceBundle bundle = ResourceBundle.getBundle("formats", locale);
13+
String format = bundle.getString("label-icu");
14+
MessageFormat formatter = new MessageFormat(format, locale);
15+
return formatter.format(data);
16+
}
17+
18+
public static void run(List<Locale> locales) {
19+
System.out.println("ICU formatter");
20+
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Alice", "female", 0 })));
21+
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Alice", "female", 1 })));
22+
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Alice", "female", 2 })));
23+
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Alice", "female", 3 })));
24+
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Bob", "male", 0 })));
25+
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Bob", "male", 1 })));
26+
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Bob", "male", 2 })));
27+
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Bob", "male", 3 })));
28+
}
29+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.baeldung.localization;
2+
3+
import java.text.MessageFormat;
4+
import java.util.Date;
5+
import java.util.List;
6+
import java.util.Locale;
7+
import java.util.ResourceBundle;
8+
9+
public class JavaSEFormat {
10+
11+
public static String getLabel(Locale locale, Object[] data) {
12+
ResourceBundle bundle = ResourceBundle.getBundle("formats", locale);
13+
final String pattern = bundle.getString("label");
14+
final MessageFormat formatter = new MessageFormat(pattern, locale);
15+
return formatter.format(data);
16+
}
17+
18+
public static void run(List<Locale> locales) {
19+
System.out.println("Java formatter");
20+
final Date date = new Date(System.currentTimeMillis());
21+
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { date, "Alice", 0 })));
22+
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { date, "Alice", 2 })));
23+
}
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.localization;
2+
3+
import java.util.List;
4+
import java.util.Locale;
5+
import java.util.ResourceBundle;
6+
7+
public class Localization {
8+
9+
public static String getLabel(Locale locale) {
10+
final ResourceBundle bundle = ResourceBundle.getBundle("messages", locale);
11+
return bundle.getString("label");
12+
}
13+
14+
public static void run(List<Locale> locales) {
15+
locales.forEach(locale -> System.out.println(getLabel(locale)));
16+
}
17+
18+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Main-Class: com.baeldung.jarArguments.JarExample
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
label=On {0, date, short} {1} has sent you {2, choice, 0#no messages|1#a message|2#two messages|2<{2,number,integer} messages}.
2+
label-icu={0} has sent you {2, plural, =0 {no messages} =1 {a message} other {{2, number, integer} messages}}.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
label={0, date, short}, {1}{2, choice, 0# ne|0<} vous a envoyé {2, choice, 0#aucun message|1#un message|2#deux messages|2<{2,number,integer} messages}.
2+
label-icu={0} {2, plural, =0 {ne } other {}}vous a envoyé {2, plural, =0 {aucun message} =1 {un message} other {{2, number, integer} messages}}.

0 commit comments

Comments
 (0)