Compare commits
29
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27af9e2f8c | ||
|
|
c6df8af1e0 | ||
|
|
b9bf30f350 | ||
|
|
08abc1855a | ||
|
|
25cff75966 | ||
|
|
c56e58379a | ||
|
|
0803488d88 | ||
|
|
b7d0d45f28 | ||
|
|
de42646567 | ||
|
|
61bb6834e6 | ||
|
|
ed00ae8a6b | ||
|
|
ad2ca48135 | ||
|
|
ed4af4389d | ||
|
|
85b63c6f8d | ||
|
|
f08da063e7 | ||
|
|
5b3ef027b1 | ||
|
|
6926189ba0 | ||
|
|
abf6ebb6e5 | ||
|
|
f50cfa7686 | ||
|
|
5523c5fe67 | ||
|
|
c63d207c77 | ||
|
|
173bb5ef7d | ||
|
|
f2200288e7 | ||
|
|
f731671503 | ||
|
|
be05ebb0d3 | ||
|
|
f0cf866d20 | ||
|
|
3c9061cc47 | ||
|
|
a709139646 | ||
|
|
d66dad8fae |
Generated
+38
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="true" />
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="codebank" />
|
||||
<module name="core-java-collections-list" />
|
||||
<module name="core-java-streams" />
|
||||
<module name="assertion-libraries" />
|
||||
<module name="core-java-io" />
|
||||
<module name="core-java-annotations" />
|
||||
<module name="core-java-8-2" />
|
||||
<module name="core-java-numbers" />
|
||||
<module name="discourse" />
|
||||
<module name="core-java-11-2" />
|
||||
<module name="core-java-strings" />
|
||||
<module name="core-java-11" />
|
||||
<module name="core-java-collections-list-2" />
|
||||
<module name="core-java-collections" />
|
||||
<module name="core-java-datetime-conversion" />
|
||||
<module name="core-java-collections-list-3" />
|
||||
<module name="core-java-8" />
|
||||
<module name="junit-5-basics" />
|
||||
<module name="core-java-collections-3" />
|
||||
<module name="core-java-collections-2" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
<component name="JavacSettings">
|
||||
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||
<module name="core-java-streams" options="-parameters" />
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+52
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-11-2/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-11-2/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-11/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-11/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-8-2/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-8-2/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-8/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-8/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-annotations/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-annotations/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-2/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-2/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-3/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-3/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-list-2/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-list-2/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-list-3/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-list-3/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-list/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections-list/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-collections/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-datetime-conversion/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-datetime-conversion/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-io/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-io/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-numbers/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-numbers/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-streams/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-streams/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-strings/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/core-java-strings/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/core-java-modules/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/testing-modules/assertion-libraries/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/testing-modules/assertion-libraries/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/testing-modules/junit-5-basics/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/testing-modules/junit-5-basics/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/testing-modules/junit-5-basics/src/test/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/testing-modules/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/testing-modules/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/toolkits/codebank/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/toolkits/codebank/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/toolkits/discourse/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/toolkits/discourse/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+20
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ThriftCompiler">
|
||||
<compilers />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
tools {
|
||||
maven 'maven 3.8.4'
|
||||
jdk 'OpenJDK-11'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Build') {
|
||||
steps {
|
||||
echo 'Building..'
|
||||
sh 'mvn clean package'
|
||||
}
|
||||
}
|
||||
stage('Test') {
|
||||
steps {
|
||||
echo 'Testing..'
|
||||
}
|
||||
}
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
echo 'Deploying....'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
## Core Java Modules
|
||||
## Java 核心模块(Core Java)
|
||||
|
||||
This module contains modules about core Java
|
||||
本模块中包含有关 Java 核心(Core Java)有关的内容。
|
||||
|
||||
## Relevant articles:
|
||||
## 相关文章
|
||||
|
||||
- [Understanding the NumberFormatException in Java](https://www.baeldung.com/java-number-format-exception)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
=========
|
||||
## Annotation(注解)
|
||||
Java 注解(Annotation)又称 Java 标注,是 JDK5.0 引入的一种注释机制。
|
||||
|
||||
## Core Java Cookbooks and Examples
|
||||
Java 语言中的类、方法、变量、参数和包等都可以被标注。和 Javadoc 不同,Java 标注可以通过反射获取标注内容。在编译器生成类文件时,标注可以被嵌入到字节码中。Java 虚拟机可以保留标注内容,在运行时可以获取到标注内容 。 当然它也支持自定义 Java 标注。
|
||||
|
||||
### 相关的文章:
|
||||
- [Java @Override Annotation](https://www.baeldung.com/java-override)
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
<groupId>com.ossez.core-java-modules</groupId>
|
||||
<artifactId>core-java-modules</artifactId>
|
||||
<version>0.0.2-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
@@ -34,6 +33,7 @@
|
||||
|
||||
<properties>
|
||||
<jol-core.version>0.10</jol-core.version>
|
||||
<commons-exec.version>1.3</commons-exec.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.ossez.collections.collections.arraylistvsvector;
|
||||
package com.ossez.collections.arraylistvsvector;
|
||||
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.ossez.collections.collections.arraylistvsvector;
|
||||
package com.ossez.collections.arraylistvsvector;
|
||||
|
||||
public class Employee {
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.ossez.collections.collections.arraylistvsvector;
|
||||
package com.ossez.collections.arraylistvsvector;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.ossez.collections.collections.containsperformance;
|
||||
package com.ossez.collections.containsperformance;
|
||||
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.ossez.collections.collections.containsperformance;
|
||||
package com.ossez.collections.containsperformance;
|
||||
|
||||
public class Employee {
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.ossez.collections.collections.iterators;
|
||||
package com.ossez.collections.iterators;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package com.ossez.collections.collections.removeallperformance;
|
||||
package com.ossez.collections.removeallperformance;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@@ -6,7 +6,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.ossez.collections.collections.containsperformance.Employee;
|
||||
import com.ossez.collections.containsperformance.Employee;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.ossez.collections.collections.sortingcomparison;
|
||||
package com.ossez.collections.sortingcomparison;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
package com.ossez.collections.iterators;
|
||||
|
||||
import static com.ossez.collections.collections.iterators.Iterators.failFast1;
|
||||
import static com.ossez.collections.collections.iterators.Iterators.failFast2;
|
||||
import static com.ossez.collections.collections.iterators.Iterators.failSafe1;
|
||||
import static com.ossez.collections.iterators.Iterators.failFast1;
|
||||
import static com.ossez.collections.iterators.Iterators.failFast2;
|
||||
import static com.ossez.collections.iterators.Iterators.failSafe1;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## Java 数字(Number)
|
||||
|
||||
这个模块中包含有关 Java 数字(Number)有关的文章。
|
||||
本模块中包含有关 Java 数字(Number)有关的文章。
|
||||
|
||||
### 相关文章
|
||||
- [理解 Java 中的 NumberFormatException 异常](https://www.ossez.com/t/java-numberformatexception/13986)
|
||||
|
||||
@@ -8,10 +8,9 @@
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.ossez</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<groupId>com.ossez.core-java-modules</groupId>
|
||||
<artifactId>core-java-modules</artifactId>
|
||||
<version>0.0.2-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
@@ -49,7 +48,7 @@
|
||||
|
||||
<properties>
|
||||
<icu4j.version>61.1</icu4j.version>
|
||||
<maven.compiler.release>15</maven.compiler.release>
|
||||
<maven.compiler.release>11</maven.compiler.release>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.ossez.java9.compactstring;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
public class CompactStringDemo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
List strings = IntStream.rangeClosed(1, 10_000_000).mapToObj(Integer::toString).collect(toList());
|
||||
long totalTime = System.currentTimeMillis() - startTime;
|
||||
System.out.println("Generated " + strings.size() + " strings in " + totalTime + " ms.");
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
String appended = (String) strings.stream().limit(100_000).reduce("", (left, right) -> left.toString() + right.toString());
|
||||
totalTime = System.currentTimeMillis() - startTime;
|
||||
System.out.println("Created string of length " + appended.length() + " in " + totalTime + " ms.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.ossez.localization;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class App {
|
||||
|
||||
/**
|
||||
* Runs all available formatter
|
||||
* @throws ParseException
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
List<Locale> locales = Arrays.asList(new Locale[] { Locale.UK, Locale.ITALY, Locale.FRANCE, Locale.forLanguageTag("pl-PL") });
|
||||
Localization.run(locales);
|
||||
JavaSEFormat.run(locales);
|
||||
ICUFormat.run(locales);
|
||||
}
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.ossez.localization;
|
||||
|
||||
import com.ibm.icu.text.MessageFormat;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class ICUFormat {
|
||||
|
||||
public static String getLabel(Locale locale, Object[] data) {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle("formats", locale);
|
||||
String format = bundle.getString("label-icu");
|
||||
MessageFormat formatter = new MessageFormat(format, locale);
|
||||
return formatter.format(data);
|
||||
}
|
||||
|
||||
public static void run(List<Locale> locales) {
|
||||
System.out.println("ICU formatter");
|
||||
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Alice", "female", 0 })));
|
||||
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Alice", "female", 1 })));
|
||||
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Alice", "female", 2 })));
|
||||
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Alice", "female", 3 })));
|
||||
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Bob", "male", 0 })));
|
||||
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Bob", "male", 1 })));
|
||||
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Bob", "male", 2 })));
|
||||
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { "Bob", "male", 3 })));
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.ossez.localization;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class JavaSEFormat {
|
||||
|
||||
public static String getLabel(Locale locale, Object[] data) {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle("formats", locale);
|
||||
final String pattern = bundle.getString("label");
|
||||
final MessageFormat formatter = new MessageFormat(pattern, locale);
|
||||
return formatter.format(data);
|
||||
}
|
||||
|
||||
public static void run(List<Locale> locales) {
|
||||
System.out.println("Java formatter");
|
||||
final Date date = new Date(System.currentTimeMillis());
|
||||
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { date, "Alice", 0 })));
|
||||
locales.forEach(locale -> System.out.println(getLabel(locale, new Object[] { date, "Alice", 2 })));
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.ossez.localization;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class Localization {
|
||||
|
||||
public static String getLabel(Locale locale) {
|
||||
final ResourceBundle bundle = ResourceBundle.getBundle("messages", locale);
|
||||
return bundle.getString("label");
|
||||
}
|
||||
|
||||
public static void run(List<Locale> locales) {
|
||||
locales.forEach(locale -> System.out.println(getLabel(locale)));
|
||||
}
|
||||
|
||||
}
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
package com.ossez.stringperformance;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.options.Options;
|
||||
import org.openjdk.jmh.runner.options.OptionsBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@BenchmarkMode(Mode.SingleShotTime)
|
||||
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||
@Measurement(batchSize = 100000, iterations = 10)
|
||||
@Warmup(batchSize = 100000, iterations = 10)
|
||||
@State(Scope.Thread)
|
||||
public class StringPerformance {
|
||||
|
||||
protected String baeldung = "baeldung";
|
||||
protected String longString = "Hello baeldung, I am a bit longer than other Strings";
|
||||
protected String formatString = "hello %s, nice to meet you";
|
||||
protected String formatDigit = "%d";
|
||||
protected String emptyString = " ";
|
||||
protected String result = "";
|
||||
|
||||
protected int sampleNumber = 100;
|
||||
|
||||
protected Pattern spacePattern = Pattern.compile(emptyString);
|
||||
protected Pattern longPattern = Pattern.compile(longString);
|
||||
protected List<String> stringSplit = new ArrayList<>();
|
||||
protected List<String> stringTokenizer = new ArrayList<>();
|
||||
|
||||
@Benchmark
|
||||
public String benchmarkStringDynamicConcat() {
|
||||
result += baeldung;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public StringBuilder benchmarkStringBuilder() {
|
||||
StringBuilder stringBuilder = new StringBuilder(result);
|
||||
stringBuilder.append(baeldung);
|
||||
return stringBuilder;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public StringBuffer benchmarkStringBuffer() {
|
||||
StringBuffer stringBuffer = new StringBuffer(result);
|
||||
stringBuffer.append(baeldung);
|
||||
return stringBuffer;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String benchmarkStringConstructor() {
|
||||
String result = new String("baeldung");
|
||||
return result;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String benchmarkStringLiteral() {
|
||||
String result = "baeldung";
|
||||
return result;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String benchmarkStringFormat_s() {
|
||||
return String.format(formatString, baeldung);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String benchmarkStringConcat() {
|
||||
result = result.concat(baeldung);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String benchmarkStringIntern() {
|
||||
return baeldung.intern();
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String benchmarkStringReplace() {
|
||||
return longString.replace("average", " average !!!");
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String benchmarkStringUtilsReplace() {
|
||||
return StringUtils.replace(longString, "average", " average !!!");
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public List<String> benchmarkGuavaSplitter() {
|
||||
return Splitter.on(" ").trimResults()
|
||||
.omitEmptyStrings()
|
||||
.splitToList(longString);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String [] benchmarkStringSplit() {
|
||||
return longString.split(emptyString);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String [] benchmarkStringSplitPattern() {
|
||||
return spacePattern.split(longString, 0);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public List benchmarkStringTokenizer() {
|
||||
StringTokenizer st = new StringTokenizer(longString);
|
||||
while (st.hasMoreTokens()) {
|
||||
stringTokenizer.add(st.nextToken());
|
||||
}
|
||||
return stringTokenizer;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public List benchmarkStringIndexOf() {
|
||||
int pos = 0, end;
|
||||
while ((end = longString.indexOf(' ', pos)) >= 0) {
|
||||
stringSplit.add(longString.substring(pos, end));
|
||||
pos = end + 1;
|
||||
}
|
||||
//Add last token of string
|
||||
stringSplit.add(longString.substring(pos));
|
||||
return stringSplit;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String benchmarkIntegerToString() {
|
||||
return Integer.toString(sampleNumber);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String benchmarkStringValueOf() {
|
||||
return String.valueOf(sampleNumber);
|
||||
}
|
||||
|
||||
|
||||
@Benchmark
|
||||
public String benchmarkStringConvertPlus() {
|
||||
return sampleNumber + "";
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public String benchmarkStringFormat_d() {
|
||||
return String.format(formatDigit, sampleNumber);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public boolean benchmarkStringEquals() {
|
||||
return longString.equals(baeldung);
|
||||
}
|
||||
|
||||
|
||||
@Benchmark
|
||||
public boolean benchmarkStringEqualsIgnoreCase() {
|
||||
return longString.equalsIgnoreCase(baeldung);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public boolean benchmarkStringMatches() {
|
||||
return longString.matches(baeldung);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public boolean benchmarkPrecompiledMatches() {
|
||||
return longPattern.matcher(baeldung).matches();
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public int benchmarkStringCompareTo() {
|
||||
return longString.compareTo(baeldung);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public boolean benchmarkStringIsEmpty() {
|
||||
return longString.isEmpty();
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public boolean benchmarkStringLengthZero() {
|
||||
return longString.length() == 0;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Options options = new OptionsBuilder()
|
||||
.include(StringPerformance.class.getSimpleName()).threads(1)
|
||||
.forks(1).shouldFailOnError(true)
|
||||
.shouldDoGC(true)
|
||||
.jvmArgs("-server").build();
|
||||
new Runner(options).run();
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,2 @@
|
||||
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}.
|
||||
label-icu={0} has sent you {2, plural, =0 {no messages} =1 {a message} other {{2, number, integer} messages}}.
|
||||
@@ -0,0 +1,2 @@
|
||||
label={0, date, short}, {1}{2, choice, 0# ne|0<} vous a envoy\u00e9 {2, choice, 0#aucun message|1#un message|2#deux messages|2<{2,number,integer} messages}.
|
||||
label-icu={0} {2, plural, =0 {ne } other {}}vous a envoy\u00e9 {2, plural, =0 {aucun message} =1 {un message} other {{2, number, integer} messages}}.
|
||||
@@ -0,0 +1,2 @@
|
||||
label={0, date, short} {1} ti ha inviato {2, choice, 0#nessun messagio|1#un messaggio|2#due messaggi|2<{2, number, integer} messaggi}.
|
||||
label-icu={0} {2, plural, =0 {non } other {}}ti ha inviato {2, plural, =0 {nessun messaggio} =1 {un messaggio} other {{2, number, integer} messaggi}}.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user