Skip to content

Commit 998d02b

Browse files
committed
Merge remote-tracking branch 'eugenp/master'
2 parents 86c9b89 + 166534c commit 998d02b

90 files changed

Lines changed: 2621 additions & 543 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.

‎README.md‎

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,22 @@
22
The "REST with Spring" Classes
33
==============================
44

5-
Here's the Master Class of REST With Spring (price changes permanently next Friday): <br/>
6-
**[>> THE REST WITH SPRING MASTER CLASS](http://www.baeldung.com/rest-with-spring-course?utm_source=github&utm_medium=social&utm_content=tutorials&utm_campaign=rws#master-class)**
5+
Here's the Master Class of REST With Spring (along with the newly announced Boot 2 material): <br/>
6+
**[>> THE REST WITH SPRING - MASTER CLASS](http://www.baeldung.com/rest-with-spring-course?utm_source=github&utm_medium=social&utm_content=tutorials&utm_campaign=rws#master-class)**
77

88
And here's the Master Class of Learn Spring Security: <br/>
9-
**[>> LEARN SPRING SECURITY MASTER CLASS](http://www.baeldung.com/learn-spring-security-course?utm_source=github&utm_medium=social&utm_content=tutorials&utm_campaign=lss#master-class)**
9+
**[>> LEARN SPRING SECURITY - MASTER CLASS](http://www.baeldung.com/learn-spring-security-course?utm_source=github&utm_medium=social&utm_content=tutorials&utm_campaign=lss#master-class)**
1010

1111

1212

13-
Spring Tutorials
13+
Java and Spring Tutorials
1414
================
1515

16-
This project is **a collection of small and focused tutorials** each covering a single and well defined area of development.
17-
Most of the tutorial projects are focused on the `Spring Framework` (and `Spring Security`).
16+
This project is **a collection of small and focused tutorials** - each covering a single and well defined area of development in the Java ecosystem.
17+
A strong focus of these is, of course, the Spring Framework - Spring, Spring Boot and Spring Securiyt.
1818
In additional to Spring, the following technologies are in focus: `core Java`, `Jackson`, `HttpClient`, `Guava`.
1919

20+
2021
Building the project
2122
====================
2223
To do the full build, do: `mvn install -Pdefault -Dgib.enabled=false`
23-
24-
25-
Working with the code in Eclipse
26-
================================
27-
Any IDE can be used to work with the projects, but if you're using Eclipse, consider the following.
28-
29-
- import the included **formatter** in Eclipse:
30-
`https://github.com/eugenp/tutorials/tree/master/eclipse`
31-
32-
33-
CI - Jenkins
34-
================================
35-
This tutorials project is being built **[>> HERE](https://rest-security.ci.cloudbees.com/job/tutorials-unit/)**
36-
37-
### Relevant Articles:
38-
================================
39-
40-
- [Apache Maven Standard Directory Layout](http://www.baeldung.com/maven-directory-structure)
41-
- [Apache Maven Tutorial](http://www.baeldung.com/maven)
42-
- [Designing a User Friendly Java Library](http://www.baeldung.com/design-a-user-friendly-java-library)

‎algorithms/src/main/java/com/baeldung/algorithms/kthlargest/FindKthLargest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public int findKthElementByRandomizedQuickSelect(Integer[] arr, int left, int ri
9898

9999
private int randomPartition(Integer arr[], int left, int right) {
100100
int n = right - left + 1;
101-
int pivot = (int) (Math.random()) % n;
101+
int pivot = (int) (Math.random() * n);
102102
swap(arr, left + pivot, right);
103103
return partition(arr, left, right);
104104
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.baeldung.algorithms.quicksort;
2+
3+
public class QuickSort {
4+
5+
public static void quickSort(int arr[], int begin, int end)
6+
{
7+
if (begin < end) {
8+
int partitionIndex = partition(arr, begin, end);
9+
10+
// Recursively sort elements of the 2 sub-arrays
11+
quickSort(arr, begin, partitionIndex-1);
12+
quickSort(arr, partitionIndex+1, end);
13+
}
14+
}
15+
16+
private static int partition(int arr[], int begin, int end)
17+
{
18+
int pivot = arr[end];
19+
int i = (begin-1);
20+
21+
for (int j=begin; j<end; j++)
22+
{
23+
if (arr[j] <= pivot) {
24+
i++;
25+
26+
int swapTemp = arr[i];
27+
arr[i] = arr[j];
28+
arr[j] = swapTemp;
29+
}
30+
}
31+
32+
int swapTemp = arr[i+1];
33+
arr[i+1] = arr[end];
34+
arr[end] = swapTemp;
35+
36+
return i+1;
37+
}
38+
39+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.baeldung.algorithms.quicksort;
2+
3+
public class ThreeWayQuickSort {
4+
5+
public static void threeWayQuickSort(int[] a, int begin, int end)
6+
{
7+
if (end <= begin) return;
8+
9+
// partition
10+
int i = begin;
11+
int less = begin;
12+
int greater = end;
13+
14+
while (i <= greater){
15+
if (a[i] < a[less]) {
16+
int tmp = a[i];
17+
a[i] = a[less];
18+
a[less] = tmp;
19+
20+
i++;
21+
less++;
22+
}
23+
else if (a[less] < a[i]) {
24+
int tmp = a[i];
25+
a[i] = a[greater];
26+
a[greater] = tmp;
27+
28+
greater--;
29+
}
30+
else {
31+
i++;
32+
}
33+
}
34+
35+
threeWayQuickSort(a, begin, less - 1);
36+
threeWayQuickSort(a, greater + 1, end);
37+
}
38+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.baeldung.algorithms.quicksort;
2+
3+
import com.baeldung.algorithms.quicksort.QuickSort;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
public class QuickSortUnitTest {
8+
9+
@Test
10+
public void givenIntegerArray_whenSortedWithQuickSort_thenGetSortedArray() {
11+
int[] actual = { 9, 5, 1, 0, 6, 2, 3, 4, 7, 8 };
12+
int[] expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
13+
QuickSort.quickSort(actual, 0, actual.length-1);
14+
Assert.assertArrayEquals(expected, actual);
15+
}
16+
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.baeldung.algorithms.quicksort;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
public class ThreeWayQuickSortUnitTest {
7+
8+
@Test
9+
public void givenIntegerArray_whenSortedWithThreeWayQuickSort_thenGetSortedArray() {
10+
int[] actual = { 3, 5, 5, 5, 3, 7, 7, 3, 5, 5, 7, 3, 3 };
11+
int[] expected = { 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 7, 7, 7 };
12+
ThreeWayQuickSort.threeWayQuickSort(actual, 0, actual.length-1);
13+
Assert.assertArrayEquals(expected, actual);
14+
}
15+
}

‎apache-geode/pom.xml‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.baeldung</groupId>
8+
<artifactId>apache-geode</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<parent>
12+
<groupId>com.baeldung</groupId>
13+
<artifactId>parent-modules</artifactId>
14+
<version>1.0.0-SNAPSHOT</version>
15+
</parent>
16+
17+
<properties>
18+
<geode.core>1.6.0</geode.core>
19+
</properties>
20+
<build>
21+
<plugins>
22+
<plugin>
23+
<groupId>org.apache.maven.plugins</groupId>
24+
<artifactId>maven-compiler-plugin</artifactId>
25+
<configuration>
26+
<source>1.8</source>
27+
<target>1.8</target>
28+
</configuration>
29+
</plugin>
30+
</plugins>
31+
</build>
32+
33+
<dependencies>
34+
<dependency>
35+
<groupId>org.apache.geode</groupId>
36+
<artifactId>geode-core</artifactId>
37+
<version>${geode.core}</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>junit</groupId>
41+
<artifactId>junit</artifactId>
42+
<version>RELEASE</version>
43+
</dependency>
44+
</dependencies>
45+
46+
</project>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.baeldung.geode;
2+
3+
import java.io.Serializable;
4+
import java.util.Objects;
5+
6+
public class Customer implements Serializable {
7+
8+
private static final long serialVersionUID = -7482516011038799900L;
9+
10+
private CustomerKey key;
11+
private String firstName;
12+
private String lastName;
13+
private Integer age;
14+
15+
public Customer() {
16+
}
17+
18+
public Customer(String firstName, String lastName, int age) {
19+
this.firstName = firstName;
20+
this.lastName = lastName;
21+
this.age = age;
22+
}
23+
24+
public Customer(CustomerKey key, String firstName, String lastName, int age) {
25+
this(firstName, lastName, age);
26+
this.key = key;
27+
}
28+
29+
// setters and getters
30+
31+
public static long getSerialVersionUID() {
32+
return serialVersionUID;
33+
}
34+
35+
public String getFirstName() {
36+
return firstName;
37+
}
38+
39+
public void setFirstName(String firstName) {
40+
this.firstName = firstName;
41+
}
42+
43+
public String getLastName() {
44+
return lastName;
45+
}
46+
47+
public void setLastName(String lastName) {
48+
this.lastName = lastName;
49+
}
50+
51+
public Integer getAge() {
52+
return age;
53+
}
54+
55+
public void setAge(Integer age) {
56+
this.age = age;
57+
}
58+
59+
@Override
60+
public String toString() {
61+
return "Customer{" + "firstName='" + firstName + '\'' + ", lastName='" + lastName + '\'' + ", age=" + age + '}';
62+
}
63+
64+
@Override
65+
public boolean equals(Object o) {
66+
if (this == o)
67+
return true;
68+
if (o == null || getClass() != o.getClass())
69+
return false;
70+
Customer customer = (Customer) o;
71+
return Objects.equals(firstName, customer.firstName) && Objects.equals(lastName, customer.lastName) && Objects.equals(age, customer.age);
72+
}
73+
74+
@Override
75+
public int hashCode() {
76+
return Objects.hash(firstName, lastName, age);
77+
}
78+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.baeldung.geode;
2+
3+
import java.io.Serializable;
4+
5+
public class CustomerKey implements Serializable {
6+
7+
private static final long serialVersionUID = -3529253035303792458L;
8+
private long id;
9+
private String country;
10+
11+
public CustomerKey(long id) {
12+
this.id = id;
13+
this.country = "USA";
14+
}
15+
16+
public CustomerKey(long id, String country) {
17+
this.id = id;
18+
this.country = country;
19+
}
20+
21+
public long getId() {
22+
return id;
23+
}
24+
25+
public void setId(long id) {
26+
this.id = id;
27+
}
28+
29+
public String getCountry() {
30+
return country;
31+
}
32+
33+
public void setCountry(String country) {
34+
this.country = country;
35+
}
36+
37+
@Override
38+
public boolean equals(Object o) {
39+
if (this == o)
40+
return true;
41+
if (o == null || getClass() != o.getClass())
42+
return false;
43+
44+
CustomerKey that = (CustomerKey) o;
45+
46+
if (id != that.id)
47+
return false;
48+
return country != null ? country.equals(that.country) : that.country == null;
49+
}
50+
51+
@Override
52+
public int hashCode() {
53+
int result = (int) (id ^ (id >>> 32));
54+
result = 31 * result + (country != null ? country.hashCode() : 0);
55+
return result;
56+
}
57+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.baeldung.geode.functions;
2+
3+
import com.baeldung.geode.Customer;
4+
import com.baeldung.geode.CustomerKey;
5+
import org.apache.geode.cache.Region;
6+
import org.apache.geode.cache.execute.Function;
7+
import org.apache.geode.cache.execute.FunctionContext;
8+
import org.apache.geode.cache.execute.RegionFunctionContext;
9+
10+
import java.util.Map;
11+
12+
public class UpperCaseNames implements Function<Boolean> {
13+
private static final long serialVersionUID = -8946294032165677602L;
14+
15+
@Override
16+
public void execute(FunctionContext<Boolean> context) {
17+
RegionFunctionContext regionContext = (RegionFunctionContext) context;
18+
Region<CustomerKey, Customer> region = regionContext.getDataSet();
19+
20+
for (Map.Entry<CustomerKey, Customer> entry : region.entrySet()) {
21+
Customer customer = entry.getValue();
22+
customer.setFirstName(customer.getFirstName()
23+
.toUpperCase());
24+
}
25+
26+
context.getResultSender()
27+
.lastResult(true);
28+
}
29+
30+
@Override
31+
public String getId() {
32+
return getClass().getName();
33+
}
34+
}

0 commit comments

Comments
 (0)