Merge branch 'master' into BAEL-4183-dependency-management-in-gradle

This commit is contained in:
Simone Cusimano
2020-10-20 08:58:08 +02:00
105 changed files with 335 additions and 368 deletions
+1 -1
View File
@@ -10,4 +10,4 @@ This module contains articles about algorithms. Some classes of algorithms, e.g.
- [Introduction to Minimax Algorithm](https://www.baeldung.com/java-minimax-algorithm)
- [How to Calculate Levenshtein Distance in Java?](https://www.baeldung.com/java-levenshtein-distance)
- [How to Find the Kth Largest Element in Java](https://www.baeldung.com/java-kth-largest-element)
- More articles: [[next -->]](/../algorithms-miscellaneous-2)
- More articles: [[next -->]](/algorithms-miscellaneous-2)
+1 -1
View File
@@ -14,4 +14,4 @@ This module contains articles about algorithms. Some classes of algorithms, e.g.
- [Displaying Money Amounts in Words](https://www.baeldung.com/java-money-into-words)
- [A Collaborative Filtering Recommendation System in Java](https://www.baeldung.com/java-collaborative-filtering-recommendations)
- [Implementing A* Pathfinding in Java](https://www.baeldung.com/java-a-star-pathfinding)
- More articles: [[<-- prev]](/../algorithms-miscellaneous-1) [[next -->]](/../algorithms-miscellaneous-3)
- More articles: [[<-- prev]](/algorithms-miscellaneous-1) [[next -->]](/algorithms-miscellaneous-3)
+1 -1
View File
@@ -15,5 +15,5 @@ This module contains articles about algorithms. Some classes of algorithms, e.g.
- [Maximum Subarray Problem](https://www.baeldung.com/java-maximum-subarray)
- [How to Merge Two Sorted Arrays](https://www.baeldung.com/java-merge-sorted-arrays)
- [Median of Stream of Integers using Heap](https://www.baeldung.com/java-stream-integers-median-using-heap)
- More articles: [[<-- prev]](/../algorithms-miscellaneous-4) [[next -->]](/../algorithms-miscellaneous-6)
- More articles: [[<-- prev]](/algorithms-miscellaneous-4) [[next -->]](/algorithms-miscellaneous-6)
+1 -1
View File
@@ -10,4 +10,4 @@
- [Implementing a 2048 Solver in Java](https://www.baeldung.com/2048-java-solver)
- [Finding Top K Elements in an Array](https://www.baeldung.com/java-array-top-elements)
- [Reversing a Linked List in Java](https://www.baeldung.com/java-reverse-linked-list)
- More articles: [[<-- prev]](/../algorithms-miscellaneous-5)
- More articles: [[<-- prev]](/algorithms-miscellaneous-5)
@@ -19,12 +19,12 @@ public class StudentDbService implements StudentService {
}
public Student update(Student student) {
logger.log(Level.INFO, "Updating sutdent in DB...");
logger.log(Level.INFO, "Updating student in DB...");
return student;
}
public String delete(String registrationId) {
logger.log(Level.INFO, "Deleteing sutdent in DB...");
logger.log(Level.INFO, "Deleting student in DB...");
return registrationId;
}
}
@@ -33,11 +33,15 @@ public class HashSetBenchmark {
private List<Employee> employeeList1 = new ArrayList<>();
private Set<Employee> employeeSet2 = new HashSet<>();
private List<Employee> employeeList2 = new ArrayList<>();
private Set<Employee> employeeSet3 = new HashSet<>();
private Set<Employee> employeeSet4 = new HashSet<>();
private long set1Size = 60000;
private long list1Size = 50000;
private long set2Size = 50000;
private long list2Size = 60000;
private long set3Size = 50000;
private long set4Size = 60000;
@Setup(Level.Trial)
public void setUp() {
@@ -57,6 +61,14 @@ public class HashSetBenchmark {
for (long i = 0; i < list2Size; i++) {
employeeList2.add(new Employee(i, RandomStringUtils.random(7, true, false)));
}
for (long i = 0; i < set3Size; i++) {
employeeSet3.add(new Employee(i, RandomStringUtils.random(7, true, false)));
}
for (long i = 0; i < set4Size; i++) {
employeeSet4.add(new Employee(i, RandomStringUtils.random(7, true, false)));
}
}
@@ -71,6 +83,11 @@ public class HashSetBenchmark {
public boolean given_SizeOfHashsetSmallerThanSizeOfCollection_When_RemoveAllFromHashSet_Then_BadPerformance(MyState state) {
return state.employeeSet2.removeAll(state.employeeList2);
}
@Benchmark
public boolean given_SizeOfHashsetSmallerThanSizeOfAnotherHashSet_When_RemoveAllFromHashSet_Then_GoodPerformance(MyState state) {
return state.employeeSet3.removeAll(state.employeeSet4);
}
public static void main(String[] args) throws Exception {
Options options = new OptionsBuilder().include(HashSetBenchmark.class.getSimpleName())
@@ -73,7 +73,7 @@ public class LivelockExample {
public void tryLock(Lock lock, long millis) {
try {
lock.tryLock(10, TimeUnit.MILLISECONDS);
lock.tryLock(millis, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
@@ -0,0 +1,37 @@
package com.baeldung.constantspatterns;
public class Calculator {
public static final double PI = 3.14159265359;
private static final double UPPER_LIMIT = 0x1.fffffffffffffP+1023;
public enum Operation {
ADD, SUBTRACT, DIVIDE, MULTIPLY
}
public double operateOnTwoNumbers(double numberOne, double numberTwo, Operation operation) {
if (numberOne > UPPER_LIMIT) {
throw new IllegalArgumentException("'numberOne' is too large");
}
if (numberTwo > UPPER_LIMIT) {
throw new IllegalArgumentException("'numberTwo' is too large");
}
double answer = 0;
switch (operation) {
case ADD:
answer = numberOne + numberTwo;
break;
case SUBTRACT:
answer = numberOne - numberTwo;
break;
case DIVIDE:
answer = numberOne / numberTwo;
break;
case MULTIPLY:
answer = numberOne * numberTwo;
break;
}
return answer;
}
}
@@ -0,0 +1,10 @@
package com.baeldung.constantspatterns;
public interface CalculatorConstants {
double PI = 3.14159265359;
double UPPER_LIMIT = 0x1.fffffffffffffP+1023;
enum Operation {
ADD, SUBTRACT, MULTIPLY, DIVIDE
};
}
@@ -0,0 +1,32 @@
package com.baeldung.constantspatterns;
public class GeometryCalculator implements CalculatorConstants {
public static final double UPPER_LIMIT = 100000000000000000000.0;
public double operateOnTwoNumbers(double numberOne, double numberTwo, Operation operation) {
if (numberOne > UPPER_LIMIT) {
throw new IllegalArgumentException("'numberOne' is too large");
}
if (numberTwo > UPPER_LIMIT) {
throw new IllegalArgumentException("'numberTwo' is too large");
}
double answer = 0;
switch (operation) {
case ADD:
answer = numberOne + numberTwo;
break;
case SUBTRACT:
answer = numberOne - numberTwo;
break;
case DIVIDE:
answer = numberOne / numberTwo;
break;
case MULTIPLY:
answer = numberOne * numberTwo;
break;
}
return answer;
}
}
@@ -0,0 +1,16 @@
package com.baeldung.constantspatterns.calculations;
public final class MathConstants {
public static final double PI = 3.14159265359;
static final double GOLDEN_RATIO = 1.6180;
static final double GRAVITATIONAL_ACCELERATION = 9.8;
static final double EULERS_NUMBER = 2.7182818284590452353602874713527;
public enum Operation {
ADD, SUBTRACT, DIVIDE, MULTIPLY
}
private MathConstants() {
}
}
@@ -0,0 +1,23 @@
package com.baeldung.constantspatterns;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Test;
public class ConstantPatternUnitTest {
@Test
public void givenTwoNumbersAndAdd_whenCallingCalculatorOperatOneTwoNumbers_thenCorrectAnswerReturned() {
Calculator calculator = new Calculator();
double expected = 4;
double answer = calculator.operateOnTwoNumbers(2, 2, Calculator.Operation.ADD);
assertEquals(expected, answer);
}
@Test
public void givenTwoNumbersAndAdd_whenCallingGeometryCalculatorOperatOneTwoNumbers_thenCorrectAnswerReturned() {
GeometryCalculator calculator = new GeometryCalculator();
double expected = 4;
double answer = calculator.operateOnTwoNumbers(2, 2, GeometryCalculator.Operation.ADD);
assertEquals(expected, answer);
}
}
@@ -3,7 +3,7 @@ package com.baeldung.hashing;
class SHACommonUtils {
public static String bytesToHex(byte[] hash) {
StringBuffer hexString = new StringBuffer();
StringBuilder hexString = new StringBuilder(2 * hash.length);
for (byte h : hash) {
String hex = Integer.toHexString(0xff & h);
if (hex.length() == 1)
-4
View File
@@ -104,16 +104,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
</plugins>
</build>
<properties>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<joda-money.version>1.0.1</joda-money.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
</properties>
</project>
@@ -51,4 +51,17 @@
<plexus-container-default.version>1.0-alpha-9</plexus-container-default.version>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-verifier-plugin</artifactId>
<version>${maven.verifier.version}</version>
<configuration>
<verificationFile>../input-resources/verifications.xml</verificationFile>
<failOnError>false</failOnError>
</configuration>
</plugin>
</plugins>
</build>
</project>
+1 -1
View File
@@ -15,7 +15,7 @@
</parent>
<modules>
<!--<module>custom-rule</module>--> <!-- Fixing in JAVA-2819 -->
<module>custom-rule</module>
<module>maven-enforcer</module>
</modules>
@@ -0,0 +1,29 @@
<?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>
<groupId>com.baeldung.core-java-persistence-2</groupId>
<artifactId>core-java-persistence-2</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>core-java-persistence-2</name>
<packaging>jar</packaging>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>persistence-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
</dependencies>
<properties>
<h2.version>1.4.200</h2.version>
</properties>
</project>
@@ -0,0 +1,13 @@
package com.baeldung.getdburl;
import java.sql.Connection;
import java.sql.DriverManager;
public class DBConfiguration {
public static Connection getConnection() throws Exception {
Class.forName("org.h2.Driver");
String url = "jdbc:h2:mem:testdb";
return DriverManager.getConnection(url, "user", "password");
}
}
@@ -0,0 +1,18 @@
package com.baeldung.getdburl;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.sql.Connection;
import org.junit.jupiter.api.Test;
class DBConfigurationUnitTest {
@Test
void givenConnectionObject_whenExtractMetaData_thenGetDbURL() throws Exception {
Connection connection = DBConfiguration.getConnection();
String dbUrl = connection.getMetaData().getURL();
assertEquals("jdbc:h2:mem:testdb", dbUrl);
}
}
@@ -76,10 +76,6 @@
<properties>
<flyway.configFiles>src/main/resources/application-${spring-boot.run.profiles}.properties</flyway.configFiles>
<!-- testing -->
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
<junit.version>4.13</junit.version>
</properties>
</project>
-4
View File
@@ -66,10 +66,6 @@
<flyway-core.version>5.2.3</flyway-core.version>
<flyway-maven-plugin.version>5.0.2</flyway-maven-plugin.version>
<!-- testing -->
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
<junit.version>4.13</junit.version>
</properties>
</project>
+1
View File
@@ -17,6 +17,7 @@
<module>apache-bookkeeper</module><!-- BAEL-2322 -->
<module>apache-cayenne</module>
<module>core-java-persistence</module>
<module>core-java-persistence-2</module>
<module>deltaspike</module>
<module>elasticsearch</module>
<module>flyway</module>
-4
View File
@@ -69,10 +69,6 @@
<r2dbc-h2.version>0.8.1.RELEASE</r2dbc-h2.version>
<h2.version>1.4.200</h2.version>
<!-- testing -->
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
<junit.version>4.13</junit.version>
</properties>
</project>
-4
View File
@@ -62,10 +62,6 @@
<jedis.version>3.3.0</jedis.version>
<epoll.version>4.1.50.Final</epoll.version>
<!-- testing -->
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
<junit.version>4.13</junit.version>
</properties>
</project>
@@ -40,10 +40,6 @@
<properties>
<mysql-connector-java.version>8.0.12</mysql-connector-java.version>
<!-- testing -->
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
<junit.version>4.13</junit.version>
</properties>
</project>
@@ -47,10 +47,6 @@
<start-class>com.baeldung.h2db.demo.server.SpringBootApp</start-class>
<db-util.version>1.0.4</db-util.version>
<!-- testing -->
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
<junit.version>4.13</junit.version>
</properties>
</project>
@@ -37,9 +37,5 @@
</dependencies>
<properties>
<!-- testing -->
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
<junit.version>4.13</junit.version>
</properties>
</project>
@@ -76,11 +76,6 @@
<properties>
<mockito.version>2.23.0</mockito.version>
<validation-api.version>2.0.1.Final</validation-api.version>
<!-- testing -->
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
<junit.version>4.13</junit.version>
</properties>
</project>
@@ -54,10 +54,6 @@
<spring-boot.version>2.2.6.RELEASE</spring-boot.version>
<cassandra-unit-spring.version>3.11.2.0</cassandra-unit-spring.version>
<!-- testing -->
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
<junit.version>4.13</junit.version>
</properties>
</project>
@@ -105,10 +105,6 @@
<cassandra-unit-shaded.version>2.1.9.2</cassandra-unit-shaded.version>
<hector-core.version>2.0-0</hector-core.version>
<!-- testing -->
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
<junit.version>4.13</junit.version>
</properties>
</project>

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