This commit is contained in:
Dhawal Kapil 2018-08-27 00:21:23 +05:30
commit 99719692b2
186 changed files with 2393 additions and 702 deletions

View File

@ -13,16 +13,11 @@
- [Strategy Design Pattern in Java 8](http://www.baeldung.com/java-strategy-pattern)
- [Exceptions in Java 8 Lambda Expressions](http://www.baeldung.com/java-lambda-exceptions)
- [Guide to Java 8 Comparator.comparing()](http://www.baeldung.com/java-8-comparator-comparing)
- [Introduction to the Java 8 Date/Time API](http://www.baeldung.com/java-8-date-time-intro)
- [Migrating to the New Java 8 Date Time API](http://www.baeldung.com/migrating-to-java-8-date-time-api)
- [Guide To Java 8 Optional](http://www.baeldung.com/java-optional)
- [Guide to the Java 8 forEach](http://www.baeldung.com/foreach-java)
- [Get the Current Date, Time and Timestamp in Java 8](http://www.baeldung.com/current-date-time-and-timestamp-in-java-8)
- [TemporalAdjuster in Java](http://www.baeldung.com/java-temporal-adjuster)
- [Finding Max/Min of a List or Collection](http://www.baeldung.com/java-collection-min-max)
- [Java Base64 Encoding and Decoding](http://www.baeldung.com/java-base64-encode-and-decode)
- [The Difference Between map() and flatMap()](http://www.baeldung.com/java-difference-map-and-flatmap)
- [Display All Time Zones With GMT And UTC in Java](http://www.baeldung.com/java-time-zones)
- [Copy a File with Java](http://www.baeldung.com/java-copy-file)
- [Static and Default Methods in Interfaces in Java](http://www.baeldung.com/java-static-default-methods)
- [Efficient Word Frequency Calculator in Java](http://www.baeldung.com/java-word-frequency)
@ -34,15 +29,10 @@
- [Finding Min/Max in an Array with Java](http://www.baeldung.com/java-array-min-max)
- [Internationalization and Localization in Java 8](http://www.baeldung.com/java-8-localization)
- [How to Find an Element in a List with Java](http://www.baeldung.com/find-list-element-java)
- [Measure Elapsed Time in Java](http://www.baeldung.com/java-measure-elapsed-time)
- [Java Optional orElse() vs orElseGet()](http://www.baeldung.com/java-optional-or-else-vs-or-else-get)
- [An Introduction to Java.util.Hashtable Class](http://www.baeldung.com/java-hash-table)
- [Method Parameter Reflection in Java](http://www.baeldung.com/java-parameter-reflection)
- [Java 8 Unsigned Arithmetic Support](http://www.baeldung.com/java-unsigned-arithmetic)
- [How to Get the Start and the End of a Day using Java](http://www.baeldung.com/java-day-start-end)
- [Generalized Target-Type Inference in Java](http://www.baeldung.com/java-generalized-target-type-inference)
- [Calculate Age in Java](http://www.baeldung.com/java-get-age)
- [Copy a List to Another List in Java](http://www.baeldung.com/java-copy-list-to-another)
- [Increment Date in Java](http://www.baeldung.com/java-increment-date)
- [Add Hours To a Date In Java](http://www.baeldung.com/java-add-hours-date)
- [Overriding System Time for Testing in Java](http://www.baeldung.com/java-override-system-time)

View File

@ -0,0 +1,23 @@
package com.baeldung.primitive;
public class BenchmarkRunner {
public static void main(String[] args) throws Exception {
new IntPrimitiveLookup().run();
new IntegerWrapperLookup().run();
new FloatPrimitiveLookup().run();
new FloatWrapperLookup().run();
new DoublePrimitiveLookup().run();
new DoubleWrapperLookup().run();
new ShortPrimitiveLookup().run();
new ShortWrapperLookup().run();
new BooleanPrimitiveLookup().run();
new BooleanWrapperLookup().run();
new CharPrimitiveLookup().run();
new CharacterWrapperLookup().run();
new BytePrimitiveLookup().run();
new ByteWrapperLookup().run();
new LongPrimitiveLookup().run();
new LongWrapperLookup().run();
}
}

View File

@ -0,0 +1,45 @@
package com.baeldung.primitive;
import org.openjdk.jmh.annotations.*;
@State(Scope.Thread)
public class BooleanPrimitiveLookup extends Lookup {
private boolean[] elements;
private final boolean pivot = false;
@Setup
@Override
public void prepare() {
elements = new boolean[s];
for (int i = 0; i < s - 1; i++) {
elements[i] = true;
}
elements[s - 1] = pivot;
}
@TearDown
@Override
public void clean() {
elements = null;
}
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int findPosition() {
int index = 0;
while (pivot != elements[index]) {
index++;
}
return index;
}
@Override
public String getSimpleClassName() {
return BooleanPrimitiveLookup.class.getSimpleName();
}
}

View File

@ -0,0 +1,45 @@
package com.baeldung.primitive;
import org.openjdk.jmh.annotations.*;
@State(Scope.Thread)
public class BooleanWrapperLookup extends Lookup {
private Boolean[] elements;
private final boolean pivot = false;
@Override
@Setup
public void prepare() {
elements = new Boolean[s];
for (int i = 0; i < s - 1; i++) {
elements[i] = true;
}
elements[s - 1] = pivot;
}
@Override
@TearDown
public void clean() {
elements = null;
}
@Override
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int findPosition() {
int index = 0;
Boolean pivotWrapper = pivot;
while (!pivotWrapper.equals(elements[index])) {
index++;
}
return index;
}
@Override
public String getSimpleClassName() {
return BooleanWrapperLookup.class.getSimpleName();
}
}

View File

@ -0,0 +1,46 @@
package com.baeldung.primitive;
import org.openjdk.jmh.annotations.*;
@State(Scope.Thread)
public class BytePrimitiveLookup extends Lookup {
private byte[] elements;
private final byte pivot = 2;
@Setup
@Override
public void prepare() {
byte common = 1;
elements = new byte[s];
for (int i = 0; i < s - 1; i++) {
elements[i] = common;
}
elements[s - 1] = pivot;
}
@TearDown
@Override
public void clean() {
elements = null;
}
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int findPosition() {
int index = 0;
while (pivot != elements[index]) {
index++;
}
return index;
}
@Override
public String getSimpleClassName() {
return BytePrimitiveLookup.class.getSimpleName();
}
}

View File

@ -0,0 +1,46 @@
package com.baeldung.primitive;
import org.openjdk.jmh.annotations.*;
@State(Scope.Thread)
public class ByteWrapperLookup extends Lookup {
private Byte[] elements;
private final byte pivot = 2;
@Override
@Setup
public void prepare() {
byte common = 1;
elements = new Byte[s];
for (int i = 0; i < s - 1; i++) {
elements[i] = common;
}
elements[s - 1] = pivot;
}
@Override
@TearDown
public void clean() {
elements = null;
}
@Override
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int findPosition() {
int index = 0;
Byte pivotWrapper = pivot;
while (!pivotWrapper.equals(elements[index])) {
index++;
}
return index;
}
@Override
public String getSimpleClassName() {
return ByteWrapperLookup.class.getSimpleName();
}
}

View File

@ -0,0 +1,46 @@
package com.baeldung.primitive;
import org.openjdk.jmh.annotations.*;
@State(Scope.Thread)
public class CharPrimitiveLookup extends Lookup {
private char[] elements;
private final char pivot = 'b';
@Setup
@Override
public void prepare() {
char common = 'a';
elements = new char[s];
for (int i = 0; i < s - 1; i++) {
elements[i] = common;
}
elements[s - 1] = pivot;
}
@TearDown
@Override
public void clean() {
elements = null;
}
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int findPosition() {
int index = 0;
while (pivot != elements[index]) {
index++;
}
return index;
}
@Override
public String getSimpleClassName() {
return CharPrimitiveLookup.class.getSimpleName();
}
}

View File

@ -0,0 +1,46 @@
package com.baeldung.primitive;
import org.openjdk.jmh.annotations.*;
@State(Scope.Thread)
public class CharacterWrapperLookup extends Lookup {
private Character[] elements;
private final char pivot = 'b';
@Override
@Setup
public void prepare() {
char common = 'a';
elements = new Character[s];
for (int i = 0; i < s - 1; i++) {
elements[i] = common;
}
elements[s - 1] = pivot;
}
@Override
@TearDown
public void clean() {
elements = null;
}
@Override
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int findPosition() {
int index = 0;
Character pivotWrapper = pivot;
while (!pivotWrapper.equals(elements[index])) {
index++;
}
return index;
}
@Override
public String getSimpleClassName() {
return CharacterWrapperLookup.class.getSimpleName();
}
}

View File

@ -0,0 +1,42 @@
package com.baeldung.primitive;
import org.openjdk.jmh.annotations.*;
@State(Scope.Thread)
public class DoublePrimitiveLookup extends Lookup {
private double[] elements;
private final double pivot = 2;
@Setup
@Override
public void prepare() {
double common = 1;
elements = new double[s];
for (int i = 0; i < s - 1; i++) {
elements[i] = common;
}
elements[s - 1] = pivot;
}
@TearDown
@Override
public void clean() {
elements = null;
}
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int findPosition() {
int index = 0;
while (pivot != elements[index]) {
index++;
}
return index;
}
@Override
public String getSimpleClassName() {
return DoublePrimitiveLookup.class.getSimpleName();
}
}

View File

@ -0,0 +1,45 @@
package com.baeldung.primitive;
import org.openjdk.jmh.annotations.*;
@State(Scope.Thread)
public class DoubleWrapperLookup extends Lookup {
private Double[] elements;
private final double pivot = 2d;
@Override
@Setup
public void prepare() {
double common = 1;
elements = new Double[s];
for (int i = 0; i < s - 1; i++) {
elements[i] = common;
}
elements[s - 1] = pivot;
}
@Override
@TearDown
public void clean() {
elements = null;
}
@Override
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int findPosition() {
int index = 0;
Double pivotWrapper = pivot;
while (!pivotWrapper.equals(elements[index])) {
index++;
}
return index;
}
@Override
public String getSimpleClassName() {
return DoubleWrapperLookup.class.getSimpleName();
}
}

View File

@ -0,0 +1,42 @@
package com.baeldung.primitive;
import org.openjdk.jmh.annotations.*;
@State(Scope.Thread)
public class FloatPrimitiveLookup extends Lookup {
private float[] elements;
private final float pivot = 2;
@Setup
@Override
public void prepare() {
int common = 1;
elements = new float[s];
for (int i = 0; i < s - 1; i++) {
elements[i] = common;
}
elements[s - 1] = pivot;
}
@TearDown
@Override
public void clean() {
elements = null;
}
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int findPosition() {
int index = 0;
while (pivot != elements[index]) {
index++;
}
return index;
}
@Override
public String getSimpleClassName() {
return FloatPrimitiveLookup.class.getSimpleName();
}
}

View File

@ -0,0 +1,43 @@
package com.baeldung.primitive;
import org.openjdk.jmh.annotations.*;
@State(Scope.Thread)
public class FloatWrapperLookup extends Lookup {
private Float[] elements;
private final float pivot = 2;
@Override
@Setup
public void prepare() {
float common = 1;
elements = new Float[s];
for (int i = 0; i < s - 1; i++) {
elements[i] = common;
}
elements[s - 1] = pivot;
}
@Override
@TearDown
public void clean() {
elements = null;
}
@Override
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int findPosition() {
int index = 0;
Float pivotWrapper = pivot;
while (!pivotWrapper.equals(elements[index])) {
index++;
}
return index;
}
@Override
public String getSimpleClassName() {
return FloatWrapperLookup.class.getSimpleName();
}
}

View File

@ -0,0 +1,45 @@
package com.baeldung.primitive;
import org.openjdk.jmh.annotations.*;
@State(Scope.Thread)
public class IntPrimitiveLookup extends Lookup {
private int[] elements;
private final int pivot = 2;
@Setup
@Override
public void prepare() {
int common = 1;
elements = new int[s];
for (int i = 0; i < s - 1; i++) {
elements[i] = common;
}
elements[s - 1] = pivot;
}
@TearDown
@Override
public void clean() {
elements = null;
}
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int findPosition() {
int index = 0;
while (pivot != elements[index]) {
index++;
}
return index;
}
@Override
public String getSimpleClassName() {
return IntPrimitiveLookup.class.getSimpleName();
}
}

View File

@ -0,0 +1,45 @@
package com.baeldung.primitive;
import org.openjdk.jmh.annotations.*;
@State(Scope.Thread)
public class IntegerWrapperLookup extends Lookup {
private Integer[] elements;
private final int pivot = 2;
@Override
@Setup
public void prepare() {
int common = 1;
elements = new Integer[s];
for (int i = 0; i < s - 1; i++) {
elements[i] = common;
}
elements[s - 1] = pivot;
}
@Override
@TearDown
public void clean() {
elements = null;
}
@Override
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int findPosition() {
int index = 0;
Integer pivotWrapper = pivot;
while (!pivotWrapper.equals(elements[index])) {
index++;
}
return index;
}
@Override
public String getSimpleClassName() {
return IntegerWrapperLookup.class.getSimpleName();
}
}

View File

@ -0,0 +1,42 @@
package com.baeldung.primitive;
import org.openjdk.jmh.annotations.*;
@State(Scope.Thread)
public class LongPrimitiveLookup extends Lookup {
private long[] elements;
private final long pivot = 2;
@Setup
@Override
public void prepare() {
long common = 1;
elements = new long[s];
for (int i = 0; i < s - 1; i++) {
elements[i] = common;
}
elements[s - 1] = pivot;
}
@TearDown
@Override
public void clean() {
elements = null;
}
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int findPosition() {
int index = 0;
while (pivot != elements[index]) {
index++;
}
return index;
}
@Override
public String getSimpleClassName() {
return LongPrimitiveLookup.class.getSimpleName();
}
}

View File

@ -0,0 +1,45 @@
package com.baeldung.primitive;
import org.openjdk.jmh.annotations.*;
@State(Scope.Thread)
public class LongWrapperLookup extends Lookup{
private Long[] elements;
private final long pivot = 2;
@Override
@Setup
public void prepare() {
long common = 1;
elements = new Long[s];
for (int i = 0; i < s - 1; i++) {
elements[i] = common;
}
elements[s - 1] = pivot;
}
@Override
@TearDown
public void clean() {
elements = null;
}
@Override
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int findPosition() {
int index = 0;
Long pivotWrapper = pivot;
while (!pivotWrapper.equals(elements[index])) {
index++;
}
return index;
}
@Override
public String getSimpleClassName() {
return LongWrapperLookup.class.getSimpleName();
}
}

View File

@ -0,0 +1,56 @@
package com.baeldung.primitive;
import org.openjdk.jmh.results.RunResult;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import java.util.Collection;
/**
* An abstract class that is to be extended by the classes that
* perform lookup in the arrays either of Java primitive types or their wrappers.
*/
public abstract class Lookup {
/**
* the array size
*/
final protected int s = 50000000;
/**
* Initialize the array: fill in the array with the same
* elements except for the last one.
*/
abstract public void prepare();
/**
* Free the array's reference.
*/
abstract public void clean();
/**
* Find the position of the element that is different from the others.
* By construction, it is the last array element.
*
* @return array's last element index
*/
abstract public int findPosition();
/**
* Get the name of the class that extends this one. It is needed in order
* to set up the benchmark.
*
* @return
*/
abstract public String getSimpleClassName();
Collection<RunResult> run() throws RunnerException {
Options opt = new OptionsBuilder()
.include(getSimpleClassName())
.forks(1)
.build();
return new Runner(opt).run();
}
}

View File

@ -0,0 +1,45 @@
package com.baeldung.primitive;
import org.openjdk.jmh.annotations.*;
@State(Scope.Thread)
public class ShortPrimitiveLookup extends Lookup {
private short[] elements;
private final short pivot = 2;
@Setup
@Override
public void prepare() {
short common = 1;
elements = new short[s];
for (int i = 0; i < s - 1; i++) {
elements[i] = common;
}
elements[s - 1] = pivot;
}
@TearDown
@Override
public void clean() {
elements = null;
}
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int findPosition() {
int index = 0;
while (pivot != elements[index]) {
index++;
}
return index;
}
@Override
public String getSimpleClassName() {
return ShortPrimitiveLookup.class.getSimpleName();
}
}

View File

@ -0,0 +1,46 @@
package com.baeldung.primitive;
import org.openjdk.jmh.annotations.*;
@State(Scope.Thread)
public class ShortWrapperLookup extends Lookup {
private Short[] elements;
private final short pivot = 2;
@Override
@Setup
public void prepare() {
short common = 1;
elements = new Short[s];
for (int i = 0; i < s - 1; i++) {
elements[i] = common;
}
elements[s - 1] = pivot;
}
@Override
@TearDown
public void clean() {
elements = null;
}
@Override
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int findPosition() {
int index = 0;
Short pivotWrapper = pivot;
while (!pivotWrapper.equals(elements[index])) {
index++;
}
return index;
}
@Override
public String getSimpleClassName() {
return ShortWrapperLookup.class.getSimpleName();
}
}

View File

@ -15,9 +15,7 @@
- [Introduction to Project Jigsaw](http://www.baeldung.com/project-jigsaw-java-modularity)
- [Java 9 Optional API Additions](http://www.baeldung.com/java-9-optional)
- [Java 9 Reactive Streams](http://www.baeldung.com/java-9-reactive-streams)
- [How to Get All Dates Between Two Dates?](http://www.baeldung.com/java-between-dates)
- [Java 9 java.util.Objects Additions](http://www.baeldung.com/java-9-objects-new)
- [Convert Date to LocalDate or LocalDateTime and Back](http://www.baeldung.com/java-date-to-localdate-and-localdatetime)
- [Java 9 Variable Handles Demistyfied](http://www.baeldung.com/java-variable-handles)
- [Exploring the New HTTP Client in Java 9](http://www.baeldung.com/java-9-http-client)
- [Method Handles in Java](http://www.baeldung.com/java-method-handles)
@ -25,3 +23,4 @@
- [A Guide to Java 9 Modularity](http://www.baeldung.com/java-9-modularity)
- [Optional orElse Optional](http://www.baeldung.com/java-optional-or-else-optional)
- [Java 9 java.lang.Module API](http://www.baeldung.com/java-9-module-api)
- [Iterate Through a Range of Dates in Java](https://www.baeldung.com/java-iterate-date-range)

View File

@ -47,7 +47,6 @@
- [How to Get a Name of a Method Being Executed?](http://www.baeldung.com/java-name-of-executing-method)
- [Dynamic Proxies in Java](http://www.baeldung.com/java-dynamic-proxies)
- [How to Copy an Array in Java](http://www.baeldung.com/java-array-copy)
- [Period and Duration in Java](http://www.baeldung.com/java-period-duration)
- [Converting a Stack Trace to a String in Java](http://www.baeldung.com/java-stacktrace-to-string)
- [Java Double Brace Initialization](http://www.baeldung.com/java-double-brace-initialization)
- [The StackOverflowError in Java](http://www.baeldung.com/java-stack-overflow-error)
@ -75,7 +74,6 @@
- [A Guide to Java Initialization](http://www.baeldung.com/java-initialization)
- [Implementing a Binary Tree in Java](http://www.baeldung.com/java-binary-tree)
- [A Guide to ThreadLocalRandom in Java](http://www.baeldung.com/java-thread-local-random)
- [RegEx for matching Date Pattern in Java](http://www.baeldung.com/java-date-regular-expressions)
- [Nested Classes in Java](http://www.baeldung.com/java-nested-classes)
- [A Guide to Java Loops](http://www.baeldung.com/java-loops)
- [Varargs in Java](http://www.baeldung.com/java-varargs)
@ -96,7 +94,6 @@
- [A Practical Guide to DecimalFormat](http://www.baeldung.com/java-decimalformat)
- [How to Detect the OS Using Java](http://www.baeldung.com/java-detect-os)
- [ASCII Art in Java](http://www.baeldung.com/ascii-art-in-java)
- [Handling Daylight Savings Time in Java](http://www.baeldung.com/java-daylight-savings)
- [Inheritance and Composition (Is-a vs Has-a relationship) in Java](http://www.baeldung.com/java-inheritance-composition)
- [Finding Max/Min of a List or Collection](http://www.baeldung.com/java-collection-min-max)
- [The "final" Keyword in Java](http://www.baeldung.com/java-final)
@ -110,7 +107,6 @@
- [Find Sum and Average in a Java Array](http://www.baeldung.com/java-array-sum-average)
- [Java List UnsupportedOperationException](http://www.baeldung.com/java-list-unsupported-operation-exception)
- [Type Erasure in Java Explained](http://www.baeldung.com/java-type-erasure)
- [Display All Time Zones With GMT And UTC in Java](http://www.baeldung.com/java-time-zones)
- [Join and Split Arrays and Collections in Java](http://www.baeldung.com/java-join-and-split)
- [Check If Two Lists are Equal in Java](http://www.baeldung.com/java-test-a-list-for-ordinality-and-equality)
- [Sending Emails with Java](http://www.baeldung.com/java-email)
@ -135,14 +131,11 @@
- [Guide to the this Java Keyword](http://www.baeldung.com/java-this)
- [Jagged Arrays In Java](http://www.baeldung.com/java-jagged-arrays)
- [Importance of Main Manifest Attribute in a Self-Executing JAR](http://www.baeldung.com/java-jar-executable-manifest-main-class)
- [Extracting Year, Month and Day from Date in Java](http://www.baeldung.com/java-year-month-day)
- [Get Date Without Time in Java](http://www.baeldung.com/java-date-without-time)
- [How to Get the File Extension of a File in Java](http://www.baeldung.com/java-file-extension)
- [Immutable Objects in Java](http://www.baeldung.com/java-immutable-object)
- [Console I/O in Java](http://www.baeldung.com/java-console-input-output)
- [Guide to the java.util.Arrays Class](http://www.baeldung.com/java-util-arrays)
- [Create a Custom Exception in Java](http://www.baeldung.com/java-new-custom-exception)
- [Guide to java.util.GregorianCalendar](http://www.baeldung.com/java-gregorian-calendar)
- [Java Global Exception Handler](http://www.baeldung.com/java-global-exception-handler)
- [Encrypting and Decrypting Files in Java](http://www.baeldung.com/java-cipher-input-output-stream)
- [How to Get the Size of an Object in Java](http://www.baeldung.com/java-size-of-object)

View File

@ -1,243 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>core-kotlin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>core-kotlin</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-kotlin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../parent-kotlin</relativePath>
</parent>
<repositories>
<repository>
<id>jcenter</id>
<url>http://jcenter.bintray.com</url>
</repository>
<repository>
<id>kotlin-ktor</id>
<url>https://dl.bintray.com/kotlin/ktor/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.jetbrains.spek</groupId>
<artifactId>spek-api</artifactId>
<version>1.1.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.spek</groupId>
<artifactId>spek-subject-extension</artifactId>
<version>1.1.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.spek</groupId>
<artifactId>spek-junit-platform-engine</artifactId>
<version>1.1.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>${commons-math3.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>khttp</groupId>
<artifactId>khttp</artifactId>
<version>${khttp.version}</version>
</dependency>
<dependency>
<groupId>com.nhaarman</groupId>
<artifactId>mockito-kotlin</artifactId>
<version>${mockito-kotlin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.salomonbrys.kodein</groupId>
<artifactId>kodein</artifactId>
<version>${kodein.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.beust</groupId>
<artifactId>klaxon</artifactId>
<version>${klaxon.version}</version>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>${commons-math3.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin-stdlib.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin-stdlib.version}</version>
</dependency>
<dependency>
<groupId>khttp</groupId>
<artifactId>khttp</artifactId>
<version>${khttp.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit</artifactId>
<version>${kotlin-test-junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin-reflect.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
<version>${kotlinx.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.spek</groupId>
<artifactId>spek-api</artifactId>
<version>1.1.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.spek</groupId>
<artifactId>spek-subject-extension</artifactId>
<version>1.1.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.spek</groupId>
<artifactId>spek-junit-platform-engine</artifactId>
<version>1.1.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.nhaarman</groupId>
<artifactId>mockito-kotlin</artifactId>
<version>${mockito-kotlin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.salomonbrys.kodein</groupId>
<artifactId>kodein</artifactId>
<version>${kodein.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.beust</groupId>
<artifactId>klaxon</artifactId>
<version>${klaxon.version}</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-netty</artifactId>
<version>${ktor.io.version}</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-gson</artifactId>
<version>${ktor.io.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin-maven-plugin.version}</version>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
<executions>
<!-- Replacing default-compile as it is treated specially
by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially
by maven -->
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>junit5</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<includes>
<include>**/*Test5.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin-maven-plugin.version>1.2.60</kotlin-maven-plugin.version>
<kotlin-test-junit.version>1.2.60</kotlin-test-junit.version>
<kotlin-stdlib.version>1.2.60</kotlin-stdlib.version>
<kotlin-reflect.version>1.2.60</kotlin-reflect.version>
<kotlinx.version>0.22.5</kotlinx.version>
<ktor.io.version>0.9.2</ktor.io.version>
<mockito-kotlin.version>1.5.0</mockito-kotlin.version>
<kodein.version>4.1.0</kodein.version>
<klaxon.version>3.0.4</klaxon.version>
<khttp.version>0.1.0</khttp.version>
<commons-math3.version>3.6.1</commons-math3.version>
<junit.platform.version>1.1.1</junit.platform.version>
<junit.vintage.version>5.2.0</junit.vintage.version>
<assertj.version>3.10.0</assertj.version>
</properties>
<properties>
<mockito-kotlin.version>1.5.0</mockito-kotlin.version>
<kodein.version>4.1.0</kodein.version>
<klaxon.version>3.0.4</klaxon.version>
<khttp.version>0.1.0</khttp.version>
<commons-math3.version>3.6.1</commons-math3.version>
<junit.platform.version>1.1.1</junit.platform.version>
<junit.vintage.version>5.2.0</junit.vintage.version>
<assertj.version>3.10.0</assertj.version>
</properties>
</project>

26
java-dates/.gitignore vendored Normal file
View File

@ -0,0 +1,26 @@
*.class
0.*
#folders#
/target
/neoDb*
/data
/src/main/webapp/WEB-INF/classes
*/META-INF/*
.resourceCache
# Packaged files #
*.jar
*.war
*.ear
# Files generated by integration tests
*.txt
backup-pom.xml
/bin/
/temp
#IntelliJ specific
.idea/
*.iml

24
java-dates/README.md Normal file
View File

@ -0,0 +1,24 @@
=========
## Java Dates Cookbooks and Examples
### Relevant Articles:
- [TemporalAdjuster in Java](http://www.baeldung.com/java-temporal-adjuster)
- [Handling Daylight Savings Time in Java](http://www.baeldung.com/java-daylight-savings)
- [Period and Duration in Java](http://www.baeldung.com/java-period-duration)
- [Difference Between Two Dates in Java](http://www.baeldung.com/java-date-difference)
- [RegEx for matching Date Pattern in Java](http://www.baeldung.com/java-date-regular-expressions)
- [Migrating to the New Java 8 Date Time API](http://www.baeldung.com/migrating-to-java-8-date-time-api)
- [Introduction to the Java 8 Date/Time API](http://www.baeldung.com/java-8-date-time-intro)
- [Get the Current Date, Time and Timestamp in Java 8](http://www.baeldung.com/current-date-time-and-timestamp-in-java-8)
- [Get Date Without Time in Java](http://www.baeldung.com/java-date-without-time)
- [How to Get All Dates Between Two Dates?](http://www.baeldung.com/java-between-dates)
- [Convert Date to LocalDate or LocalDateTime and Back](http://www.baeldung.com/java-date-to-localdate-and-localdatetime)
- [Display All Time Zones With GMT And UTC in Java](http://www.baeldung.com/java-time-zones)
- [Extracting Year, Month and Day from Date in Java](http://www.baeldung.com/java-year-month-day)
- [Guide to java.util.GregorianCalendar](http://www.baeldung.com/java-gregorian-calendar)
- [Measure Elapsed Time in Java](http://www.baeldung.com/java-measure-elapsed-time)
- [How to Get the Start and the End of a Day using Java](http://www.baeldung.com/java-day-start-end)
- [Calculate Age in Java](http://www.baeldung.com/java-get-age)
- [Increment Date in Java](http://www.baeldung.com/java-increment-date)
- [Add Hours To a Date In Java](http://www.baeldung.com/java-add-hours-date)

103
java-dates/pom.xml Normal file
View File

@ -0,0 +1,103 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>java-dates</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>java-dates</name>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-java</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<!-- test scoped -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda-time.version}</version>
</dependency>
<dependency>
<groupId>com.darwinsys</groupId>
<artifactId>hirondelle-date4j</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>java-dates</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<!-- util -->
<commons-lang3.version>3.5</commons-lang3.version>
<lombok.version>1.16.12</lombok.version>
<joda-time.version>2.10</joda-time.version>
<!-- testing -->
<assertj.version>3.6.1</assertj.version>
<maven.compiler.source>9</maven.compiler.source>
<maven.compiler.target>9</maven.compiler.target>
</properties>
</project>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@ -20,7 +20,7 @@ import com.baeldung.java9.datetime.DateToLocalDateConverter;
* @author abialas
*
*/
public class DateToLocalDateConverterTest {
public class DateToLocalDateConverterUnitTest {
@Test
public void shouldReturn10thNovember2010WhenConvertViaInstant() {

View File

@ -20,7 +20,7 @@ import com.baeldung.java9.datetime.DateToLocalDateTimeConverter;
* @author abialas
*
*/
public class DateToLocalDateTimeConverterTest {
public class DateToLocalDateTimeConverterUnitTest {
@Test
public void shouldReturn10thNovember2010time8hour20minWhenConvertViaInstant() {

View File

@ -18,7 +18,7 @@ import org.junit.Test;
* @author abialas
*
*/
public class LocalDateTimeToDateConverterTest {
public class LocalDateTimeToDateConverterUnitTest {
@Test
public void shouldReturn10thNovember2010time8hour20minWhenConvertViaInstant() {

View File

@ -18,7 +18,7 @@ import org.junit.Test;
* @author abialas
*
*/
public class LocalDateToDateConverterTest {
public class LocalDateToDateConverterUnitTest {
@Test
public void shouldReturn10thNovember2010WhenConvertViaInstant() {

View File

@ -8,7 +8,7 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class TimeApiTest {
public class TimeApiUnitTest {
@Test
public void givenGetDatesBetweenWithUsingJava7_WhenStartEndDate_thenDatesList() {

Some files were not shown because too many files have changed in this diff Show More