Skip to content

Commit 27af9e2

Browse files
committed
Submit all code for code-java-string branch
1 parent c6df8af commit 27af9e2

File tree

83 files changed

+3202
-0
lines changed

Some content is hidden

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

83 files changed

+3202
-0
lines changed

.idea/compiler.xml

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/thriftCompiler.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.ossez.java9.compactstring;
2+
3+
import java.util.List;
4+
import java.util.stream.IntStream;
5+
6+
import static java.util.stream.Collectors.toList;
7+
8+
public class CompactStringDemo {
9+
10+
public static void main(String[] args) {
11+
long startTime = System.currentTimeMillis();
12+
List strings = IntStream.rangeClosed(1, 10_000_000).mapToObj(Integer::toString).collect(toList());
13+
long totalTime = System.currentTimeMillis() - startTime;
14+
System.out.println("Generated " + strings.size() + " strings in " + totalTime + " ms.");
15+
16+
startTime = System.currentTimeMillis();
17+
String appended = (String) strings.stream().limit(100_000).reduce("", (left, right) -> left.toString() + right.toString());
18+
totalTime = System.currentTimeMillis() - startTime;
19+
System.out.println("Created string of length " + appended.length() + " in " + totalTime + " ms.");
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.ossez.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.ossez.localization;
2+
3+
import com.ibm.icu.text.MessageFormat;
4+
5+
import java.util.List;
6+
import java.util.Locale;
7+
import java.util.ResourceBundle;
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.ossez.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.ossez.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+
}

0 commit comments

Comments
 (0)