Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Mario Angelo Casari 2023-11-22 09:40:19 +01:00
commit b38867d054
186 changed files with 2542 additions and 245 deletions

View File

@ -28,7 +28,7 @@
</modules>
<properties>
<commons-codec.version>1.11</commons-codec.version>
<commons-codec.version>1.16.0</commons-codec.version>
<commons-math3.version>3.6.1</commons-math3.version>
<cobertura.plugin.version>2.7</cobertura.plugin.version>
<tradukisto.version>1.0.1</tradukisto.version>

View File

@ -58,11 +58,16 @@
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>${wiremock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
</dependencies>
<build>
@ -77,11 +82,12 @@
<properties>
<mockserver.version>5.6.1</mockserver.version>
<wiremock.version>2.5.1</wiremock.version>
<wiremock.version>3.3.1</wiremock.version>
<!-- http client & core 5 -->
<httpcore5.version>5.2</httpcore5.version>
<httpclient5.version>5.2</httpclient5.version>
<httpclient5-fluent.version>5.2</httpclient5-fluent.version>
<httpclient.version>4.5.14</httpclient.version>
</properties>
</project>

View File

@ -8,7 +8,7 @@ import static org.mockserver.model.HttpResponse.response;
import java.io.IOException;
import java.net.ServerSocket;
import org.apache.http.HttpStatus;
import org.apache.hc.core5.http.HttpStatus;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.mockserver.client.MockServerClient;

View File

@ -38,8 +38,6 @@ import org.junit.jupiter.api.Test;
class HttpAsyncClientLiveTest extends GetRequestMockServer {
private static final String HOST = "http://www.google.com";
private static final String HOST_WITH_SSL = "https://mms.nw.ru/";
private static final String HOST_WITH_PROXY = "http://httpbin.org/";
private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://browserspy.dk/password-ok.php";// "http://localhost:8080/spring-security-rest-basic-auth/api/foos/1";
@ -136,7 +134,7 @@ class HttpAsyncClientLiveTest extends GetRequestMockServer {
client.start();
final SimpleHttpRequest request = new SimpleHttpRequest("GET",HOST_WITH_SSL);
final SimpleHttpRequest request = new SimpleHttpRequest("GET", HOST_WITH_SSL);
final Future<SimpleHttpResponse> future = client.execute(request, null);
final HttpResponse response = future.get();
@ -201,7 +199,7 @@ class HttpAsyncClientLiveTest extends GetRequestMockServer {
@Override
public void run() {
try {
final Future<SimpleHttpResponse> future = client.execute(SimpleHttpRequest.copy(request), context, null);
final Future<SimpleHttpResponse> future = client.execute(SimpleRequestBuilder.copy(request).build(), context, null);
final HttpResponse response = future.get();
assertThat(response.getCode(), equalTo(200));
} catch (final Exception ex) {

View File

@ -1,10 +1,10 @@
package com.baeldung.httpclient;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import java.io.IOException;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.HttpEntity;
public final class ResponseUtil {
private ResponseUtil() {
}

View File

@ -103,7 +103,7 @@ class HttpClientAdvancedConfigurationIntegrationTest {
void givenServerThatIsBehindProxy_whenClientIsConfiguredToSendRequestViaProxy_shouldReturn200() throws IOException {
//given
proxyMock.stubFor(get(urlMatching(".*"))
.willReturn(aResponse().proxiedFrom("http://localhost:8089/")));
.willReturn(aResponse().proxiedFrom("http://localhost:8089")));
serviceMock.stubFor(get(urlEqualTo("/private"))
.willReturn(aResponse().withStatus(200)));
@ -129,7 +129,7 @@ class HttpClientAdvancedConfigurationIntegrationTest {
public void givenServerThatIsBehindAuthorizationProxy_whenClientSendRequest_shouldAuthorizeProperly() throws IOException {
//given
proxyMock.stubFor(get(urlMatching("/private"))
.willReturn(aResponse().proxiedFrom("http://localhost:8089/")));
.willReturn(aResponse().proxiedFrom("http://localhost:8089")));
serviceMock.stubFor(get(urlEqualTo("/private"))
.willReturn(aResponse().withStatus(200)));

View File

@ -158,7 +158,7 @@
<version>${mockserver.version}</version>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>${wiremock.version}</version>
<scope>test</scope>
@ -234,10 +234,10 @@
<properties>
<!-- util -->
<commons-codec.version>1.10</commons-codec.version>
<commons-codec.version>1.16.0</commons-codec.version>
<httpasyncclient.version>4.1.5</httpasyncclient.version>
<!-- testing -->
<wiremock.version>2.5.1</wiremock.version>
<wiremock.version>3.3.1</wiremock.version>
<httpcore.version>4.4.16</httpcore.version>
<httpclient.version>4.5.14</httpclient.version>
<mockserver.version>5.11.2</mockserver.version>

View File

@ -102,7 +102,7 @@ class HttpClientAdvancedConfigurationIntegrationTest {
void givenServerThatIsBehindProxy_whenClientIsConfiguredToSendRequestViaProxy_shouldReturn200() throws IOException {
//given
proxyMock.stubFor(get(urlMatching(".*"))
.willReturn(aResponse().proxiedFrom("http://localhost:8089/")));
.willReturn(aResponse().proxiedFrom("http://localhost:8089")));
serviceMock.stubFor(get(urlEqualTo("/private"))
.willReturn(aResponse().withStatus(200)));
@ -128,7 +128,7 @@ class HttpClientAdvancedConfigurationIntegrationTest {
void givenServerThatIsBehindAuthorizationProxy_whenClientSendRequest_shouldAuthorizeProperly() throws IOException {
//given
proxyMock.stubFor(get(urlMatching("/private"))
.willReturn(aResponse().proxiedFrom("http://localhost:8089/")));
.willReturn(aResponse().proxiedFrom("http://localhost:8089")));
serviceMock.stubFor(get(urlEqualTo("/private"))
.willReturn(aResponse().withStatus(200)));

View File

@ -14,3 +14,4 @@ You can build the project from the command line using: *mvn clean install*, or i
- [Get Partition Count for a Topic in Kafka](https://www.baeldung.com/java-kafka-partition-count-topic)
- [bootstrap-server in Kafka Configuration](https://www.baeldung.com/java-kafka-bootstrap-server)
- [Introduction to Apache Kafka](https://www.baeldung.com/apache-kafka)
- [Ensuring Message Ordering in Kafka: Strategies and Configurations](https://www.baeldung.com/kafka-message-ordering)

View File

@ -191,7 +191,7 @@
<bval.version>2.0.6</bval.version>
<javax.validation.validation-api.version>2.0.1.Final</javax.validation.validation-api.version>
<meecrowave-junit.version>1.2.15</meecrowave-junit.version>
<okhttp.version>3.10.0</okhttp.version>
<okhttp.version>4.12.0</okhttp.version>
<meecrowave-jpa.version>1.2.15</meecrowave-jpa.version>
<meecrowave-core.version>1.2.15</meecrowave-core.version>
<meecrowave-maven-plugin.version>1.2.15</meecrowave-maven-plugin.version>

View File

@ -75,7 +75,7 @@
<properties>
<gson.version>2.10.1</gson.version>
<dynamodblocal.version>1.21.1</dynamodblocal.version>
<commons-codec-version>1.10.L001</commons-codec-version>
<commons-codec-version>1.16.0</commons-codec-version>
<jets3t-version>0.9.4.0006L</jets3t-version>
<maven-plugins-version>3.1.1</maven-plugins-version>
</properties>

View File

@ -0,0 +1,47 @@
package com.baeldung.deserializationfilters;
import java.io.ObjectInputFilter;
import java.util.function.BinaryOperator;
import com.baeldung.deserializationfilters.service.DeserializationService;
import com.baeldung.deserializationfilters.service.LimitedArrayService;
import com.baeldung.deserializationfilters.service.LowDepthService;
import com.baeldung.deserializationfilters.service.SmallObjectService;
import com.baeldung.deserializationfilters.utils.FilterUtils;
public class ContextSpecificDeserializationFilterFactory implements BinaryOperator<ObjectInputFilter> {
@Override
public ObjectInputFilter apply(ObjectInputFilter current, ObjectInputFilter next) {
if (current == null) {
Class<?> caller = findInStack(DeserializationService.class);
if (caller == null) {
current = FilterUtils.fallbackFilter();
} else if (caller.equals(SmallObjectService.class)) {
current = FilterUtils.safeSizeFilter(190);
} else if (caller.equals(LowDepthService.class)) {
current = FilterUtils.safeDepthFilter(2);
} else if (caller.equals(LimitedArrayService.class)) {
current = FilterUtils.safeArrayFilter(3);
}
}
return ObjectInputFilter.merge(current, next);
}
private static Class<?> findInStack(Class<?> superType) {
for (StackTraceElement element : Thread.currentThread()
.getStackTrace()) {
try {
Class<?> subType = Class.forName(element.getClassName());
if (superType.isAssignableFrom(subType)) {
return subType;
}
} catch (ClassNotFoundException e) {
return null;
}
}
return null;
}
}

View File

@ -0,0 +1,7 @@
package com.baeldung.deserializationfilters.pojo;
import java.io.Serializable;
public interface ContextSpecific extends Serializable {
}

View File

@ -0,0 +1,19 @@
package com.baeldung.deserializationfilters.pojo;
public class NestedSample implements ContextSpecific {
private static final long serialVersionUID = 1L;
private Sample optional;
public NestedSample(Sample optional) {
this.optional = optional;
}
public Sample getOptional() {
return optional;
}
public void setOptional(Sample optional) {
this.optional = optional;
}
}

View File

@ -0,0 +1,61 @@
package com.baeldung.deserializationfilters.pojo;
public class Sample implements ContextSpecific, Comparable<Sample> {
private static final long serialVersionUID = 1L;
private int[] array;
private String name;
private NestedSample nested;
public Sample(String name) {
this.name = name;
}
public Sample(int[] array) {
this.array = array;
}
public Sample(NestedSample nested) {
this.nested = nested;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int[] getArray() {
return array;
}
public void setArray(int[] array) {
this.array = array;
}
public NestedSample getNested() {
return nested;
}
public void setNested(NestedSample nested) {
this.nested = nested;
}
@Override
public String toString() {
return name;
}
@Override
public int compareTo(Sample o) {
if (name == null)
return -1;
if (o == null || o.getName() == null)
return 1;
return getName().compareTo(o.getName());
}
}

View File

@ -0,0 +1,25 @@
package com.baeldung.deserializationfilters.pojo;
public class SampleExploit extends Sample {
private static final long serialVersionUID = 1L;
public SampleExploit() {
super("exploit");
}
public static void maliciousCode() {
System.out.println("exploit executed");
}
@Override
public String toString() {
maliciousCode();
return "exploit";
}
@Override
public int compareTo(Sample o) {
maliciousCode();
return super.compareTo(o);
}
}

View File

@ -0,0 +1,11 @@
package com.baeldung.deserializationfilters.service;
import java.io.InputStream;
import java.util.Set;
import com.baeldung.deserializationfilters.pojo.ContextSpecific;
public interface DeserializationService {
Set<ContextSpecific> process(InputStream... inputStreams);
}

View File

@ -0,0 +1,15 @@
package com.baeldung.deserializationfilters.service;
import java.io.InputStream;
import java.util.Set;
import com.baeldung.deserializationfilters.pojo.ContextSpecific;
import com.baeldung.deserializationfilters.utils.DeserializationUtils;
public class LimitedArrayService implements DeserializationService {
@Override
public Set<ContextSpecific> process(InputStream... inputStreams) {
return DeserializationUtils.deserializeIntoSet(inputStreams);
}
}

View File

@ -0,0 +1,20 @@
package com.baeldung.deserializationfilters.service;
import java.io.InputStream;
import java.io.ObjectInputFilter;
import java.util.Set;
import com.baeldung.deserializationfilters.pojo.ContextSpecific;
import com.baeldung.deserializationfilters.utils.DeserializationUtils;
public class LowDepthService implements DeserializationService {
public Set<ContextSpecific> process(ObjectInputFilter filter, InputStream... inputStreams) {
return DeserializationUtils.deserializeIntoSet(filter, inputStreams);
}
@Override
public Set<ContextSpecific> process(InputStream... inputStreams) {
return process(null, inputStreams);
}
}

View File

@ -0,0 +1,15 @@
package com.baeldung.deserializationfilters.service;
import java.io.InputStream;
import java.util.Set;
import com.baeldung.deserializationfilters.pojo.ContextSpecific;
import com.baeldung.deserializationfilters.utils.DeserializationUtils;
public class SmallObjectService implements DeserializationService {
@Override
public Set<ContextSpecific> process(InputStream... inputStreams) {
return DeserializationUtils.deserializeIntoSet(inputStreams);
}
}

View File

@ -0,0 +1,50 @@
package com.baeldung.deserializationfilters.utils;
import java.io.InputStream;
import java.io.InvalidClassException;
import java.io.ObjectInputFilter;
import java.io.ObjectInputStream;
import java.util.Set;
import java.util.TreeSet;
import com.baeldung.deserializationfilters.pojo.ContextSpecific;
public class DeserializationUtils {
private DeserializationUtils() {
}
public static Object deserialize(InputStream inStream) {
return deserialize(inStream, null);
}
public static Object deserialize(InputStream inStream, ObjectInputFilter filter) {
try (ObjectInputStream in = new ObjectInputStream(inStream)) {
if (filter != null) {
in.setObjectInputFilter(filter);
}
return in.readObject();
} catch (InvalidClassException e) {
return null;
} catch (Throwable e) {
e.printStackTrace();
return null;
}
}
public static Set<ContextSpecific> deserializeIntoSet(InputStream... inputStreams) {
return deserializeIntoSet(null, inputStreams);
}
public static Set<ContextSpecific> deserializeIntoSet(ObjectInputFilter filter, InputStream... inputStreams) {
Set<ContextSpecific> set = new TreeSet<>();
for (InputStream inputStream : inputStreams) {
Object object = deserialize(inputStream, filter);
if (object != null) {
set.add((ContextSpecific) object);
}
}
return set;
}
}

View File

@ -0,0 +1,32 @@
package com.baeldung.deserializationfilters.utils;
import java.io.ObjectInputFilter;
public class FilterUtils {
private static final String DEFAULT_PACKAGE_PATTERN = "java.base/*;!*";
private static final String POJO_PACKAGE = "com.baeldung.deserializationfilters.pojo";
private FilterUtils() {
}
private static ObjectInputFilter baseFilter(String parameter, int max) {
return ObjectInputFilter.Config.createFilter(String.format("%s=%d;%s.**;%s", parameter, max, POJO_PACKAGE, DEFAULT_PACKAGE_PATTERN));
}
public static ObjectInputFilter fallbackFilter() {
return ObjectInputFilter.Config.createFilter(String.format("%s", DEFAULT_PACKAGE_PATTERN));
}
public static ObjectInputFilter safeSizeFilter(int max) {
return baseFilter("maxbytes", max);
}
public static ObjectInputFilter safeArrayFilter(int max) {
return baseFilter("maxarray", max);
}
public static ObjectInputFilter safeDepthFilter(int max) {
return baseFilter("maxdepth", max);
}
}

View File

@ -0,0 +1,17 @@
package com.baeldung.deserializationfilters.utils;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
public class SerializationUtils {
private SerializationUtils() {
}
public static void serialize(Object object, OutputStream outStream) throws IOException {
try (ObjectOutputStream objStream = new ObjectOutputStream(outStream)) {
objStream.writeObject(object);
}
}
}

View File

@ -0,0 +1,119 @@
package com.baeldung.deserializationfilters;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputFilter;
import java.util.Set;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import com.baeldung.deserializationfilters.pojo.ContextSpecific;
import com.baeldung.deserializationfilters.pojo.NestedSample;
import com.baeldung.deserializationfilters.pojo.Sample;
import com.baeldung.deserializationfilters.pojo.SampleExploit;
import com.baeldung.deserializationfilters.service.LimitedArrayService;
import com.baeldung.deserializationfilters.service.LowDepthService;
import com.baeldung.deserializationfilters.service.SmallObjectService;
import com.baeldung.deserializationfilters.utils.DeserializationUtils;
import com.baeldung.deserializationfilters.utils.FilterUtils;
import com.baeldung.deserializationfilters.utils.SerializationUtils;
public class ContextSpecificDeserializationFilterIntegrationTest {
private static ByteArrayOutputStream serialSampleA = new ByteArrayOutputStream();
private static ByteArrayOutputStream serialBigSampleA = new ByteArrayOutputStream();
private static ByteArrayOutputStream serialSampleB = new ByteArrayOutputStream();
private static ByteArrayOutputStream serialBigSampleB = new ByteArrayOutputStream();
private static ByteArrayOutputStream serialSampleC = new ByteArrayOutputStream();
private static ByteArrayOutputStream serialBigSampleC = new ByteArrayOutputStream();
private static ByteArrayInputStream bytes(ByteArrayOutputStream stream) {
return new ByteArrayInputStream(stream.toByteArray());
}
@BeforeAll
static void setup() throws IOException {
ObjectInputFilter.Config.setSerialFilterFactory(new ContextSpecificDeserializationFilterFactory());
SerializationUtils.serialize(new Sample("simple"), serialSampleA);
SerializationUtils.serialize(new SampleExploit(), serialBigSampleA);
SerializationUtils.serialize(new Sample(new int[] { 1, 2, 3 }), serialSampleB);
SerializationUtils.serialize(new Sample(new int[] { 1, 2, 3, 4, 5, 6 }), serialBigSampleB);
SerializationUtils.serialize(new Sample(new NestedSample(null)), serialSampleC);
SerializationUtils.serialize(new Sample(new NestedSample(new Sample("deep"))), serialBigSampleC);
}
@Test
void whenSmallObjectContext_thenCorrectFilterApplied() {
Set<ContextSpecific> result = new SmallObjectService().process( //
bytes(serialSampleA), //
bytes(serialBigSampleA));
assertEquals(1, result.size());
assertEquals("simple", ((Sample) result.iterator()
.next()).getName());
}
@Test
void whenLimitedArrayContext_thenCorrectFilterApplied() {
Set<ContextSpecific> result = new LimitedArrayService().process( //
bytes(serialSampleB), //
bytes(serialBigSampleB));
assertEquals(1, result.size());
}
@Test
void whenLowDepthContext_thenCorrectFilterApplied() {
Set<ContextSpecific> result = new LowDepthService().process( //
bytes(serialSampleC), //
bytes(serialBigSampleC));
assertEquals(1, result.size());
}
@Test
void givenExtraFilter_whenCombinedContext_thenMergedFiltersApplied() {
Set<ContextSpecific> result = new LowDepthService().process( //
FilterUtils.safeSizeFilter(190), //
bytes(serialSampleA), //
bytes(serialBigSampleA), //
bytes(serialSampleC), //
bytes(serialBigSampleC));
assertEquals(1, result.size());
assertEquals("simple", ((Sample) result.iterator()
.next()).getName());
}
@Test
void givenFallbackContext_whenUsingBaseClasses_thenRestrictiveFilterApplied() throws IOException {
String a = new String("a");
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
SerializationUtils.serialize(a, outStream);
String deserializedA = (String) DeserializationUtils.deserialize(bytes(outStream));
assertEquals(a, deserializedA);
}
@Test
void givenFallbackContext_whenUsingAppClasses_thenRejected() throws IOException {
Sample a = new Sample("a");
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
SerializationUtils.serialize(a, outStream);
Sample deserializedA = (Sample) DeserializationUtils.deserialize(bytes(outStream));
assertNull(deserializedA);
}
}

View File

@ -18,19 +18,19 @@ public class VehicleUnitTest {
}
@Test
public void givenCar_whenUsingReflectionAPI_thenSuperClassIsSealed() {
public void givenCar_whenUsingReflectionAPI_thenSuperClassIsSealed() throws ClassNotFoundException {
Assertions.assertThat(car.getClass().isSealed()).isEqualTo(false);
Assertions.assertThat(car.getClass().getSuperclass().isSealed()).isEqualTo(true);
Assertions.assertThat(car.getClass().getSuperclass().getPermittedSubclasses())
.contains(ClassDesc.of(car.getClass().getCanonicalName()));
.contains(Class.forName(car.getClass().getCanonicalName()));
}
@Test
public void givenTruck_whenUsingReflectionAPI_thenSuperClassIsSealed() {
public void givenTruck_whenUsingReflectionAPI_thenSuperClassIsSealed() throws ClassNotFoundException {
Assertions.assertThat(truck.getClass().isSealed()).isEqualTo(false);
Assertions.assertThat(truck.getClass().getSuperclass().isSealed()).isEqualTo(true);
Assertions.assertThat(truck.getClass().getSuperclass().getPermittedSubclasses())
.contains(ClassDesc.of(truck.getClass().getCanonicalName()));
.contains(Class.forName(truck.getClass().getCanonicalName()));
}
@Test

View File

@ -18,19 +18,19 @@ public class VehicleUnitTest {
}
@Test
public void givenCar_whenUsingReflectionAPI_thenInterfaceIsSealed() {
public void givenCar_whenUsingReflectionAPI_thenInterfaceIsSealed() throws ClassNotFoundException {
Assertions.assertThat(car.getClass().isSealed()).isEqualTo(false);
Assertions.assertThat(car.getClass().getInterfaces()[0].isSealed()).isEqualTo(true);
Assertions.assertThat(car.getClass().getInterfaces()[0].permittedSubclasses())
.contains(ClassDesc.of(car.getClass().getCanonicalName()));
Assertions.assertThat(car.getClass().getInterfaces()[0].getPermittedSubclasses())
.contains(Class.forName(car.getClass().getCanonicalName()));
}
@Test
public void givenTruck_whenUsingReflectionAPI_thenInterfaceIsSealed() {
public void givenTruck_whenUsingReflectionAPI_thenInterfaceIsSealed() throws ClassNotFoundException {
Assertions.assertThat(truck.getClass().isSealed()).isEqualTo(false);
Assertions.assertThat(truck.getClass().getInterfaces()[0].isSealed()).isEqualTo(true);
Assertions.assertThat(truck.getClass().getInterfaces()[0].permittedSubclasses())
.contains(ClassDesc.of(truck.getClass().getCanonicalName()));
Assertions.assertThat(truck.getClass().getInterfaces()[0].getPermittedSubclasses())
.contains(Class.forName(truck.getClass().getCanonicalName()));
}
@Test

View File

@ -7,4 +7,5 @@
- [Difference Between Instant and LocalDateTime](https://www.baeldung.com/java-instant-vs-localdatetime)
- [Add Minutes to a Time String in Java](https://www.baeldung.com/java-string-time-add-mins)
- [Round the Date in Java](https://www.baeldung.com/java-round-the-date)
- [Representing Furthest Possible Date in Java](https://www.baeldung.com/java-date-represent-max)
- [[<-- Prev]](/core-java-modules/core-java-datetime-java8-1)

View File

@ -34,7 +34,6 @@
<properties>
<commons-lang.version>2.2</commons-lang.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
</properties>
</project>

View File

@ -9,4 +9,5 @@
- [Skipping the First Iteration in Java](https://www.baeldung.com/java-skip-first-iteration)
- [Remove Elements From a Queue Using Loop](https://www.baeldung.com/java-remove-elements-queue)
- [Intro to Vector Class in Java](https://www.baeldung.com/java-vector-guide)
- [HashSet toArray() Method in Java](https://www.baeldung.com/java-hashset-toarray)
- More articles: [[<-- prev]](/core-java-modules/core-java-collections-4)

View File

@ -0,0 +1,60 @@
package com.baeldung.collectionssortcomplexity;
import org.openjdk.jmh.annotations.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Fork(value = 1, warmups = 1)
@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 5, time = 1)
public class CollectionsSortTimeComplexityJMH {
public static void main(String[] args) throws Exception {
org.openjdk.jmh.Main.main(args);
}
@Benchmark
public void measureCollectionsSortBestCase(BestCaseBenchmarkState state) {
List<Integer> sortedList = new ArrayList<>(state.sortedList);
Collections.sort(sortedList);
}
@Benchmark
public void measureCollectionsSortAverageWorstCase(AverageWorstCaseBenchmarkState state) {
List<Integer> unsortedList = new ArrayList<>(state.unsortedList);
Collections.sort(unsortedList);
}
@State(Scope.Benchmark)
public static class BestCaseBenchmarkState {
List<Integer> sortedList;
@Setup(Level.Trial)
public void setUp() {
sortedList = new ArrayList<>();
for (int i = 1; i <= 1000000; i++) {
sortedList.add(i);
}
}
}
@State(Scope.Benchmark)
public static class AverageWorstCaseBenchmarkState {
List<Integer> unsortedList;
@Setup(Level.Trial)
public void setUp() {
unsortedList = new ArrayList<>();
for (int i = 1000000; i > 0; i--) {
unsortedList.add(i);
}
}
}
}

View File

@ -0,0 +1,33 @@
package com.baeldung.collectionssortcomplexity;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class CollectionsSortTimeComplexityMain {
// O(n log n) Time Complexity Example
public static void worstAndAverageCasesTimeComplexity() {
Integer[] sortedArray = {20, 21, 22, 23, 24, 25, 26, 17, 28, 29, 30, 31, 18, 19, 32, 33, 34, 27, 35};
List<Integer> list = Arrays.asList(sortedArray);
Collections.shuffle(list);
long startTime = System.nanoTime();
Collections.sort(list);
long endTime = System.nanoTime();
System.out.println("Execution Time for O(n log n): " + (endTime - startTime) + " nanoseconds");
}
// O(n) Time Complexity Example
public static void bestCaseTimeComplexity() {
Integer[] sortedArray = {19, 22, 19, 22, 24, 25, 17, 11, 22, 23, 28, 23, 0, 1, 12, 9, 13, 27, 15};
List<Integer> list = Arrays.asList(sortedArray);
long startTime = System.nanoTime();
Collections.sort(list);
long endTime = System.nanoTime();
System.out.println("Execution Time for O(n): " + (endTime - startTime) + " nanoseconds");
}
public static void main(String[] args) {
worstAndAverageCasesTimeComplexity();
bestCaseTimeComplexity();
}
}

View File

@ -66,7 +66,6 @@
<properties>
<jmh.version>1.21</jmh.version>
<commons-lang.version>2.2</commons-lang.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<gson.version>2.10.1</gson.version>
<jackson.version>2.15.2</jackson.version>
<org.json.version>20230618</org.json.version>

View File

@ -33,6 +33,11 @@
<artifactId>commons-csv</artifactId>
<version>${csv.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.1.2-jre</version>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,70 @@
package com.baeldung.map;
import java.util.HashMap;
import java.util.Map;
public class BenchmarkMapMethods {
public static void main(String[] args) {
BenchmarkMapMethods bmm = new BenchmarkMapMethods();
Map<String, Long> map = new HashMap<>();
map.put("Guava", bmm.benchMarkGuavaMap());
map.put("ContainsKey", bmm.benchContainsKeyMap());
map.put("MergeMethod", bmm.benchMarkMergeMethod());
map.put("ComputeMethod", bmm.benchMarComputeMethod());
map.put("GetOrDefault", bmm.benchMarkGetOrDefaultMethod());
}
private long benchMarkGuavaMap() {
long startTime = System.nanoTime();
IncrementMapValueWays im = new IncrementMapValueWays();
im.charFrequencyUsingAtomicMap(getString());
long endTime = System.nanoTime();
return endTime - startTime;
}
private long benchContainsKeyMap() {
long startTime = System.nanoTime();
IncrementMapValueWays im = new IncrementMapValueWays();
im.charFrequencyUsingContainsKey(getString());
long endTime = System.nanoTime();
return endTime - startTime;
}
private long benchMarComputeMethod() {
long startTime = System.nanoTime();
IncrementMapValueWays im = new IncrementMapValueWays();
im.charFrequencyUsingCompute(getString());
long endTime = System.nanoTime();
return endTime - startTime;
}
private long benchMarkMergeMethod() {
long startTime = System.nanoTime();
IncrementMapValueWays im = new IncrementMapValueWays();
im.charFrequencyUsingMerge(getString());
long endTime = System.nanoTime();
return endTime - startTime;
}
private long benchMarkGetOrDefaultMethod() {
long startTime = System.nanoTime();
IncrementMapValueWays im = new IncrementMapValueWays();
im.charFrequencyUsingGetOrDefault(getString());
long endTime = System.nanoTime();
return endTime - startTime;
}
private String getString() {
return
"Once upon a time in a quaint village nestled between rolling hills and whispering forests, there lived a solitary storyteller named Elias. Elias was known for spinning tales that transported listeners to magical realms and awakened forgotten dreams.\n"
+ "\n"
+ "His favorite spot was beneath an ancient oak tree, its sprawling branches offering shade to those who sought refuge from the bustle of daily life. Villagers of all ages would gather around Elias, their faces illuminated by the warmth of his stories.\n"
+ "\n" + "One evening, as dusk painted the sky in hues of orange and purple, a curious young girl named Lily approached Elias. Her eyes sparkled with wonder as she asked for a tale unlike any other.\n" + "\n"
+ "Elias smiled, sensing her thirst for adventure, and began a story about a forgotten kingdom veiled by mist, guarded by mystical creatures and enchanted by ancient spells. With each word, the air grew thick with anticipation, and the listeners were transported into a world where magic danced on the edges of reality.\n"
+ "\n" + "As Elias weaved the story, Lily's imagination took flight. She envisioned herself as a brave warrior, wielding a shimmering sword against dark forces, her heart fueled by courage and kindness.\n" + "\n"
+ "The night wore on, but the spell of the tale held everyone captive. The villagers laughed, gasped, and held their breaths, journeying alongside the characters through trials and triumphs.\n" + "\n"
+ "As the final words lingered in the air, a sense of enchantment settled upon the listeners. They thanked Elias for the gift of his storytelling, each carrying a piece of the magical kingdom within their hearts.\n" + "\n"
+ "Lily, inspired by the story, vowed to cherish the spirit of adventure and kindness in her own life. With a newfound spark in her eyes, she bid Elias goodnight, already dreaming of the countless adventures awaiting her.\n" + "\n"
+ "Under the star-studded sky, Elias remained beneath the ancient oak, his heart aglow with the joy of sharing tales that ignited imagination and inspired dreams. And as the night embraced the village, whispers of the enchanted kingdom lingered in the breeze, promising endless possibilities to those who dared to believe.";
}
}

View File

@ -0,0 +1,80 @@
package com.baeldung.map;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import com.google.common.util.concurrent.AtomicLongMap;
public class IncrementMapValueWays {
public Map<Character, Integer> charFrequencyUsingContainsKey(String sentence) {
Map<Character, Integer> charMap = new HashMap<>();
for (int c = 0; c < sentence.length(); c++) {
int count = 0;
if (charMap.containsKey(sentence.charAt(c))) {
count = charMap.get(sentence.charAt(c));
}
charMap.put(sentence.charAt(c), count + 1);
}
return charMap;
}
public Map<Character, Integer> charFrequencyUsingGetOrDefault(String sentence) {
Map<Character, Integer> charMap = new HashMap<>();
for (int c = 0; c < sentence.length(); c++) {
charMap.put(sentence.charAt(c), charMap.getOrDefault(sentence.charAt(c), 0) + 1);
}
return charMap;
}
public Map<Character, Integer> charFrequencyUsingMerge(String sentence) {
Map<Character, Integer> charMap = new HashMap<>();
for (int c = 0; c < sentence.length(); c++) {
charMap.merge(sentence.charAt(c), 1, Integer::sum);
}
return charMap;
}
public Map<Character, Integer> charFrequencyUsingCompute(String sentence) {
Map<Character, Integer> charMap = new HashMap<>();
for (int c = 0; c < sentence.length(); c++) {
charMap.compute(sentence.charAt(c), (key, value) -> (value == null) ? 1 : value + 1);
}
return charMap;
}
public Map<Character, Long> charFrequencyUsingAtomicMap(String sentence) {
AtomicLongMap<Character> map = AtomicLongMap.create();
for (int c = 0; c < sentence.length(); c++) {
map.getAndIncrement(sentence.charAt(c));
}
return map.asMap();
}
public Map<Character, Integer> charFrequencyWithConcurrentMap(String sentence, Map<Character, Integer> charMap) {
for (int c = 0; c < sentence.length(); c++) {
charMap.compute(sentence.charAt(c), (key, value) -> (value == null) ? 1 : value + 1);
}
return charMap;
}
public Map<Character, AtomicInteger> charFrequencyWithGetAndIncrement(String sentence) {
Map<Character, AtomicInteger> charMap = new HashMap<>();
for (int c = 0; c < sentence.length(); c++) {
charMap.putIfAbsent(sentence.charAt(c), new AtomicInteger(0));
charMap.get(sentence.charAt(c))
.incrementAndGet();
}
return charMap;
}
public Map<Character, AtomicInteger> charFrequencyWithGetAndIncrementComputeIfAbsent(String sentence) {
Map<Character, AtomicInteger> charMap = new HashMap<>();
for (int c = 0; c < sentence.length(); c++) {
charMap.computeIfAbsent(sentence.charAt(c), k -> new AtomicInteger(0))
.incrementAndGet();
}
return charMap;
}
}

View File

@ -0,0 +1,103 @@
package com.baeldung.map;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.Assert;
import org.junit.Test;
public class IncrementMapValueUnitTest {
@Test
public void givenString_whenUsingContainsKey_thenReturnFreqMap() {
String string = "the quick brown fox jumps over the lazy dog";
IncrementMapValueWays ic = new IncrementMapValueWays();
Map<Character, Integer> actualMap = ic.charFrequencyUsingContainsKey(string);
Map<Character, Integer> expectedMap = getExpectedMap();
Assert.assertEquals(expectedMap, actualMap);
}
@Test
public void givenString_whenUsingGetOrDefault_thenReturnFreqMap() {
String string = "the quick brown fox jumps over the lazy dog";
IncrementMapValueWays ic = new IncrementMapValueWays();
Map<Character, Integer> actualMap = ic.charFrequencyUsingGetOrDefault(string);
Map<Character, Integer> expectedMap = getExpectedMap();
Assert.assertEquals(expectedMap, actualMap);
}
@Test
public void givenString_whenUsingMapMerge_thenReturnFreqMap() {
String string = "the quick brown fox jumps over the lazy dog";
IncrementMapValueWays ic = new IncrementMapValueWays();
Map<Character, Integer> actualMap = ic.charFrequencyUsingMerge(string);
Map<Character, Integer> expectedMap = getExpectedMap();
Assert.assertEquals(expectedMap, actualMap);
}
@Test
public void givenString_whenUsingMapCompute_thenReturnFreqMap() {
String string = "the quick brown fox jumps over the lazy dog";
IncrementMapValueWays ic = new IncrementMapValueWays();
Map<Character, Integer> actualMap = ic.charFrequencyUsingCompute(string);
Map<Character, Integer> expectedMap = getExpectedMap();
Assert.assertEquals(expectedMap, actualMap);
}
@Test
public void givenString_whenUsingGuava_thenReturnFreqMap() {
String string = "the quick brown fox jumps over the lazy dog";
IncrementMapValueWays ic = new IncrementMapValueWays();
Map<Character, Long> actualMap = ic.charFrequencyUsingAtomicMap(string);
Map<Character, Integer> expectedMap = getExpectedMap();
Assert.assertEquals(expectedMap.keySet(), actualMap.keySet());
}
@Test
public void givenString_whenUsingIncrementAndGet_thenReturnFreqMap() {
String string = "the quick brown fox jumps over the lazy dog";
IncrementMapValueWays ic = new IncrementMapValueWays();
Map<Character, AtomicInteger> actualMap = ic.charFrequencyWithGetAndIncrement(string);
Assert.assertEquals(getExpectedMap().keySet(), actualMap.keySet());
}
@Test
public void givenString_whenUsingIncrementAndGetAndComputeIfAbsent_thenReturnFreqMap() {
String string = "the quick brown fox jumps over the lazy dog";
IncrementMapValueWays ic = new IncrementMapValueWays();
Map<Character, AtomicInteger> actualMap = ic.charFrequencyWithGetAndIncrementComputeIfAbsent(string);
Assert.assertEquals(getExpectedMap().keySet(), actualMap.keySet());
}
@Test
public void givenString_whenUsingConcurrentMapCompute_thenReturnFreqMap() throws InterruptedException {
Map<Character, Integer> charMap = new ConcurrentHashMap<>();
Thread thread1 = new Thread(() -> {
IncrementMapValueWays ic = new IncrementMapValueWays();
ic.charFrequencyWithConcurrentMap("the quick brown", charMap);
});
Thread thread2 = new Thread(() -> {
IncrementMapValueWays ic = new IncrementMapValueWays();
ic.charFrequencyWithConcurrentMap(" fox jumps over the lazy dog", charMap);
});
thread1.start();
thread2.start();
thread1.join();
thread2.join();
Map<Character, Integer> expectedMap = getExpectedMap();
Assert.assertEquals(expectedMap, charMap);
}
private Map<Character, Integer> getExpectedMap() {
return Stream.of(
new Object[][] { { ' ', 8 }, { 'a', 1 }, { 'b', 1 }, { 'c', 1 }, { 'd', 1 }, { 'e', 3 }, { 'f', 1 }, { 'g', 1 }, { 'h', 2 }, { 'i', 1 }, { 'j', 1 }, { 'k', 1 }, { 'l', 1 }, { 'm', 1 }, { 'n', 1 }, { 'o', 4 }, { 'p', 1 }, { 'q', 1 }, { 'r', 2 },
{ 's', 1 }, { 't', 2 }, { 'u', 2 }, { 'v', 1 }, { 'w', 1 }, { 'x', 1 }, { 'y', 1 }, { 'z', 1 } })
.collect(Collectors.toMap(data -> (Character) data[0], data -> (Integer) data[1]));
}
}

View File

@ -85,12 +85,12 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<jcabi-aspects.version>0.22.6</jcabi-aspects.version>
<aspectjrt.version>1.9.5</aspectjrt.version>
<aspectjrt.version>1.9.20.1</aspectjrt.version>
<cactoos.version>0.43</cactoos.version>
<ea-async.version>1.2.3</ea-async.version>
<jcabi-maven-plugin.version>0.14.1</jcabi-maven-plugin.version>
<aspectjtools.version>1.9.1</aspectjtools.version>
<aspectjweaver.version>1.9.1</aspectjweaver.version>
<aspectjtools.version>1.9.20.1</aspectjtools.version>
<aspectjweaver.version>1.9.20.1</aspectjweaver.version>
</properties>
</project>

View File

@ -12,4 +12,5 @@ This module contains articles about basic Java concurrency.
- [CompletableFuture allOf().join() vs. CompletableFuture.join()](https://www.baeldung.com/java-completablefuture-allof-join)
- [Retry Logic with CompletableFuture](https://www.baeldung.com/java-completablefuture-retry-logic)
- [Convert From List of CompletableFuture to CompletableFuture List](https://www.baeldung.com/java-completablefuture-list-convert)
- [Synchronize a Static Variable Among Different Threads](https://www.baeldung.com/java-synchronize-static-variable-different-threads)
- [[<-- Prev]](../core-java-concurrency-basic-2)

View File

@ -7,3 +7,4 @@
- [ASCII Art in Java](http://www.baeldung.com/ascii-art-in-java)
- [System.console() vs. System.out](https://www.baeldung.com/java-system-console-vs-system-out)
- [How to Log to the Console in Color](https://www.baeldung.com/java-log-console-in-color)
- [Create Table Using ASCII in a Console in Java](https://www.baeldung.com/java-console-ascii-make-table)

View File

@ -28,7 +28,6 @@
<properties>
<joda-time.version>2.12.5</joda-time.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
</properties>
</project>

View File

@ -1,32 +1,31 @@
package com.baeldung.timestamptolong;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
public class TimestampToLong {
public void usingSimpleDateFormat() throws ParseException {
public long usingSimpleDateFormat(String timestampString) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String currentDateString = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
long actualTimestamp = sdf.parse(currentDateString).getTime();
Date date = sdf.parse(timestampString);
String currentDateString = sdf.format(date);
return sdf.parse(currentDateString).getTime();
}
public void usingInstantClass() {
Instant instant = Instant.now();
long actualTimestamp = instant.toEpochMilli();
public long usingInstantClass(String timestampString) {
Instant instant = LocalDateTime.parse(timestampString, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
.atZone(ZoneId.systemDefault())
.toInstant();
return instant.toEpochMilli();
}
public void usingTimestamp() {
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
long actualTimestamp = timestamp.getTime();
public long usingJava8DateTime(String timestampString) {
LocalDateTime localDateTime = LocalDateTime.parse(timestampString.replace(" ", "T"));
return localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
}
public void usingJava8DateTime() {
LocalDateTime localDateTime = LocalDateTime.now();
long actualTimestamp = localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
}
}
}

View File

@ -0,0 +1,42 @@
package com.baeldung.timestamptolocaldatetime;
import org.joda.time.DateTimeZone;
import org.junit.Test;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import static org.junit.Assert.assertEquals;
public class TimeToLocalDateTimeUnitTest {
private static final long timestampInMillis = 1700010123000L;
private static final String expectedTimestampString = "2023-11-15 01:02:03";
@Test
public void givenTimestamp_whenConvertingToLocalDateTime_thenConvertSuccessfully() {
Instant instant = Instant.ofEpochMilli(timestampInMillis);
LocalDateTime localDateTime =
LocalDateTime.ofInstant(instant, ZoneId.of("UTC"));
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateTime = localDateTime.format(formatter);
assertEquals(expectedTimestampString, formattedDateTime);
}
@Test
public void givenJodaTime_whenGettingTimestamp_thenConvertToLong() {
DateTime dateTime = new DateTime(timestampInMillis, DateTimeZone.UTC);
org.joda.time.LocalDateTime localDateTime = dateTime.toLocalDateTime();
org.joda.time.format.DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
String actualTimestamp = formatter.print(localDateTime);
assertEquals(expectedTimestampString, actualTimestamp);
}
}

View File

@ -2,51 +2,42 @@ package com.baeldung.timestamptolong;
import org.junit.Test;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
public class TimestampToLongUnitTest {
private static final long TOLERANCE = 1000;
private static final String timestampString = "2023-11-15 01:02:03";
@Test
public void givenSimpleDateFormat_whenFormattingDate_thenTConvertToLong() throws ParseException {
public void givenSimpleDateFormat_whenFormattingDate_thenConvertToLong() throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = sdf.parse(timestampString);
String currentDateString = sdf.format(new Date());
String currentDateString = sdf.format(date);
long actualTimestamp = sdf.parse(currentDateString).getTime();
assertTrue(Math.abs(System.currentTimeMillis() - actualTimestamp) < TOLERANCE);
assertEquals(1700010123000L, actualTimestamp);
}
@Test
public void givenInstantClass_whenGettingTimestamp_thenTConvertToLong() {
Instant instant = Instant.now();
public void givenInstantClass_whenGettingTimestamp_thenConvertToLong() {
Instant instant = LocalDateTime.parse(timestampString, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
.atZone(ZoneId.systemDefault())
.toInstant();
long actualTimestamp = instant.toEpochMilli();
assertTrue(Math.abs(System.currentTimeMillis() - actualTimestamp) < TOLERANCE);
assertEquals(1700010123000L, actualTimestamp);
}
@Test
public void givenTimestamp_whenCreatingTimestamp_thenTConvertToLong() {
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
long actualTimestamp = timestamp.getTime();
assertTrue(Math.abs(System.currentTimeMillis() - actualTimestamp) < TOLERANCE);
}
@Test
public void givenJava8DateTime_whenGettingTimestamp_thenTConvertToLong() {
LocalDateTime localDateTime = LocalDateTime.now();
public void givenJava8DateTime_whenGettingTimestamp_thenConvertToLong() {
LocalDateTime localDateTime = LocalDateTime.parse(timestampString.replace(" ", "T"));
long actualTimestamp = localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
assertTrue(Math.abs(System.currentTimeMillis() - actualTimestamp) < TOLERANCE);
assertEquals(1700010123000L, actualTimestamp);
}
}

View File

@ -51,7 +51,6 @@
<properties>
<mockito-inline.version>3.8.0</mockito-inline.version>
<assertj.version>3.22.0</assertj.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<vavr.version>0.10.4</vavr.version>
</properties>

View File

@ -35,7 +35,6 @@
<properties>
<mockito-inline.version>3.8.0</mockito-inline.version>
<assertj.version>3.22.0</assertj.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<vavr.version>0.10.4</vavr.version>
</properties>

View File

@ -1,2 +1,3 @@
## Relevant Articles
- [Convert Hex to RGB Using Java](https://www.baeldung.com/java-convert-hex-to-rgb)
- [Convert a Hex String to an Integer in Java](https://www.baeldung.com/java-convert-hex-string-to-integer)

View File

@ -32,7 +32,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>${wiremock.version}</version>
<scope>test</scope>
@ -58,7 +58,7 @@
<maven.compiler.target.version>11</maven.compiler.target.version>
<assertj.version>3.22.0</assertj.version>
<mockserver.version>5.11.2</mockserver.version>
<wiremock.version>2.27.2</wiremock.version>
<wiremock.version>3.3.1</wiremock.version>
</properties>
</project>

View File

@ -31,9 +31,8 @@
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.tomakehurst/wiremock -->
<dependency>
<groupId>com.github.tomakehurst</groupId>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>${wiremock.version}</version>
<scope>test</scope>
@ -63,7 +62,7 @@
<properties>
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
<wiremock.version>2.26.3</wiremock.version>
<wiremock.version>3.3.1</wiremock.version>
</properties>
</project>

View File

@ -12,4 +12,5 @@ This module contains articles about core Java input/output(IO) conversions.
- [How to Convert InputStream to Base64 String](https://www.baeldung.com/java-inputstream-to-base64-string)
- [Convert an OutputStream to an InputStream](https://www.baeldung.com/java-convert-outputstream-to-inputstream)
- [Java PrintStream to String](https://www.baeldung.com/java-printstream-to-string)
- [Convert File to Byte Array in Java](https://www.baeldung.com/java-convert-file-byte-array)
- More articles: [[<-- prev]](/core-java-modules/core-java-io-conversions)

View File

@ -12,6 +12,10 @@ public class WriteCsvFileExample {
}
public String escapeSpecialCharacters(String data) {
if (data == null) {
throw new IllegalArgumentException("Input data cannot be null");
}
String escapedData = data.replaceAll("\\R", " ");
if (data.contains(",") || data.contains("\"") || data.contains("'")) {
data = data.replace("\"", "\"\"");

View File

@ -24,7 +24,6 @@
</build>
<properties>
<commons-lang3.version>3.12.0</commons-lang3.version>
<reflections.version>0.10.2</reflections.version>
</properties>

View File

@ -35,7 +35,7 @@
<properties>
<commons-lang.version>2.6</commons-lang.version>
<assertj-core.version>3.10.0</assertj-core.version>
<equalsverifier.version>3.0.3</equalsverifier.version>
<equalsverifier.version>3.15.3</equalsverifier.version>
</properties>
</project>

View File

@ -0,0 +1,75 @@
package com.baeldung.enums.classcheck;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
enum Device {
Keyboard, Monitor, Mouse, Printer
}
enum Weekday {
Monday, Tuesday, Wednesday, Thursday, Friday,
Saturday {
@Override
boolean isWeekend() {
return true;
}
},
Sunday {
@Override
boolean isWeekend() {
return true;
}
};
boolean isWeekend() {
return false;
}
}
public class CheckClassIsEnumUnitTest {
@Test
void whenUsingInstanceOf_thenGetExpectedResult() {
Object obj = Device.Keyboard;
assertTrue(obj instanceof Enum);
}
@Test
void whenUsingisInstance_thenGetExpectedResult() {
Object obj = Device.Keyboard;
assertTrue(Enum.class.isInstance(obj));
}
@Test
void whenUsingEnumClassisAssignableFrom_thenGetExpectedResult() {
Object obj = Device.Keyboard;
assertTrue(Enum.class.isAssignableFrom(obj.getClass()));
}
@Test
void whenUsingGetClassIsEnum_thenGetExpectedResult() {
assertTrue(Device.class.isEnum());
Object obj = Device.Keyboard;
assertTrue(obj.getClass().isEnum());
}
@Test
void whenEnum_thenGetExpectedResult() {
Object monday = Weekday.Monday;
assertTrue(monday instanceof Enum);
assertTrue(Enum.class.isInstance(monday));
assertTrue(Enum.class.isAssignableFrom(monday.getClass()));
assertTrue(monday.getClass().isEnum());
Object sunday = Weekday.Sunday;
assertTrue(sunday instanceof Enum);
assertTrue(Enum.class.isInstance(sunday));
assertTrue(Enum.class.isAssignableFrom(sunday.getClass()));
assertFalse(sunday.getClass().isEnum()); // <-- isEnum() check failed when Enum values with body
}
}

View File

@ -56,7 +56,7 @@
<async-http-client.version>2.4.5</async-http-client.version>
<jakarta.bind.version>2.3.3</jakarta.bind.version>
<greenmail.version>2.0.0-alpha-3</greenmail.version>
<commons-codec.version>1.15</commons-codec.version>
<commons-codec.version>1.16.0</commons-codec.version>
</properties>
</project>

View File

@ -7,4 +7,5 @@
- [Java Double vs. BigDecimal](https://www.baeldung.com/java-double-vs-bigdecimal)
- [Finding the Square Root of a BigInteger in Java](https://www.baeldung.com/java-find-square-root-biginteger)
- [Truncate a Double to Two Decimal Places in Java](https://www.baeldung.com/java-double-round-two-decimal-places)
- [Comparing the Values of Two Generic Numbers in Java](https://www.baeldung.com/java-generic-numbers-comparison-methods)
- More articles: [[<-- prev]](../core-java-numbers-5)

View File

@ -42,7 +42,6 @@
</build>
<properties>
<commons-codec>1.15</commons-codec>
<guava.version>32.1.2-jre</guava.version>
<commons-codec>1.16.0</commons-codec>
</properties>
</project>

View File

@ -75,7 +75,6 @@
<properties>
<collections-generic.version>4.01</collections-generic.version>
<asspectj.version>1.8.9</asspectj.version>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
<unix4j.version>0.4</unix4j.version>

View File

@ -52,7 +52,6 @@
<source.version>1.8</source.version>
<target.version>1.8</target.version>
<reflections.version>0.10.2</reflections.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
</properties>
</project>

View File

@ -21,7 +21,7 @@
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<artifactId>bcprov-jdk18on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
@ -33,8 +33,8 @@
</dependencies>
<properties>
<bouncycastle.version>1.60</bouncycastle.version>
<commons-codec.version>1.11</commons-codec.version>
<bouncycastle.version>1.76</bouncycastle.version>
<commons-codec.version>1.16.0</commons-codec.version>
<jaxb-api.version>2.3.1</jaxb-api.version>
</properties>

View File

@ -21,7 +21,7 @@
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<artifactId>bcprov-jdk18on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
@ -43,8 +43,8 @@
</dependencies>
<properties>
<bouncycastle.version>1.70</bouncycastle.version>
<commons-codec.version>1.15</commons-codec.version>
<bouncycastle.version>1.76</bouncycastle.version>
<commons-codec.version>1.16.0</commons-codec.version>
<jaxb-api.version>2.3.1</jaxb-api.version>
<spring-security-crypto.version>6.0.3</spring-security-crypto.version>
</properties>

View File

@ -16,7 +16,7 @@
<dependencies>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<artifactId>bcpkix-jdk18on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
<dependency>
@ -27,7 +27,7 @@
</dependencies>
<properties>
<bouncycastle.version>1.70</bouncycastle.version>
<bouncycastle.version>1.76</bouncycastle.version>
<cryptacular.version>1.2.6</cryptacular.version>
</properties>

View File

@ -0,0 +1,49 @@
package com.baeldung.keystorealias;
import static org.assertj.core.api.Assertions.assertThat;
import java.security.KeyStore;
import java.security.cert.X509Certificate;
import org.junit.jupiter.api.Test;
public class KeystoreCertificateNameAliasUnitTest {
private static final String KEYSTORE_FILE = "my-keystore.jks";
private static final String KEYSTORE_PWD = "storepw@1";
private static final String KEYSTORE_ALIAS = "baeldung";
private KeyStore readKeyStore() throws Exception {
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(getClass().getResourceAsStream(KEYSTORE_FILE), KEYSTORE_PWD.toCharArray());
return keystore;
}
@Test
void whenCheckingAliasAndName_thenMatchIsFound() throws Exception {
KeyStore keystore = readKeyStore();
assertThat(keystore.containsAlias(KEYSTORE_ALIAS)).isTrue();
X509Certificate x509Certificate = (X509Certificate) keystore.getCertificate(KEYSTORE_ALIAS);
String ownerName = x509Certificate.getSubjectX500Principal().getName();
assertThat(ownerName.contains("my-cn.localhost")).isTrue();
}
@Test
void whenCheckingAliasAndName_thenNameIsNotFound() throws Exception {
KeyStore keystore = readKeyStore();
assertThat(keystore.containsAlias(KEYSTORE_ALIAS)).isTrue();
X509Certificate x509Certificate = (X509Certificate) keystore.getCertificate(KEYSTORE_ALIAS);
String ownerName = x509Certificate.getSubjectX500Principal().getName();
assertThat(ownerName.contains("commonName1")).isFalse();
}
@Test
void whenCheckingAliasAndName_thenAliasIsNotFound() throws Exception {
KeyStore keystore = readKeyStore();
assertThat(keystore.containsAlias("alias1")).isFalse();
}
}

View File

@ -7,3 +7,4 @@
- [Taking Every N-th Element from Finite and Infinite Streams in Java](https://www.baeldung.com/java-nth-element-finite-infinite-streams)
- [Modifying Objects Within Stream While Iterating](https://www.baeldung.com/java-stream-modify-objects-during-iteration)
- [Convert a Stream into a Map or Multimap in Java](https://www.baeldung.com/java-convert-stream-map-multimap)
- [How to Avoid NoSuchElementException in Stream API](https://www.baeldung.com/java-streams-api-avoid-nosuchelementexception)

View File

@ -77,7 +77,6 @@
<maven.compiler.source>12</maven.compiler.source>
<maven.compiler.target>12</maven.compiler.target>
<vavr.version>0.10.2</vavr.version>
<guava.version>32.1.2-jre</guava.version>
</properties>
</project>

View File

@ -21,7 +21,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${apache-commons-lang3.version}</version>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>com.vdurmont</groupId>
@ -61,7 +61,6 @@
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<validator.version>1.7</validator.version>
<apache-commons-lang3.version>3.12.0</apache-commons-lang3.version>
<emoji-java.version>5.1.1</emoji-java.version>
<apache-commons-text.version>1.10.0</apache-commons-text.version>
</properties>

View File

@ -1,12 +1,12 @@
package com.baeldung.bytebuffertostring;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Test;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ByteArrayToStringUnitTest {
private static Charset charset = StandardCharsets.UTF_8;
@ -37,8 +37,17 @@ public class ByteArrayToStringUnitTest {
// Allocate a ByteBuffer
ByteBuffer byteBuffer = ByteBuffer.wrap(content.getBytes());
String newContent = charset.decode(byteBuffer)
.toString();
.toString();
assertEquals(content, newContent);
}
@Test
public void convertStringToByteBuffer_thenOk() {
byte[] expectedBytes = content.getBytes(Charset.forName(charset.toString()));
ByteBuffer byteBuffer = ByteBuffer.wrap(expectedBytes);
// Test the conversion from string to ByteBuffer
assertEquals(expectedBytes, byteBuffer.array());
}
}

View File

@ -87,7 +87,7 @@
<properties>
<hibernate-validator.version>8.0.1.Final</hibernate-validator.version>
<expressly.version>5.0.0</expressly.version>
<commons-codec.version>1.14</commons-codec.version>
<commons-codec.version>1.16.0</commons-codec.version>
<spring-core.version>5.3.0</spring-core.version>
</properties>

View File

@ -22,7 +22,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${apache-commons-lang3.version}</version>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
@ -70,7 +70,6 @@
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<spring-core.version>5.3.9</spring-core.version>
<apache-commons-lang3.version>3.12.0</apache-commons-lang3.version>
<maven-artifact.version>3.6.3</maven-artifact.version>
<gradle-core.version>6.1.1</gradle-core.version>
<jackson-core.version>2.11.1</jackson-core.version>

View File

@ -27,12 +27,12 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${apache-commons-lang3.version}</version>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${apache-commons-text.version}</version>
<version>${commons-text.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
@ -60,8 +60,7 @@
<maven.compiler.target>11</maven.compiler.target>
<opencsv.version>5.8</opencsv.version>
<spring-core.version>5.3.13</spring-core.version>
<apache-commons-lang3.version>3.12.0</apache-commons-lang3.version>
<apache-commons-text.version>1.10.0</apache-commons-text.version>
<commons-text.version>1.10.0</commons-text.version>
</properties>
</project>

View File

@ -11,4 +11,3 @@
- [Check if a String Has All Unique Characters in Java](https://www.baeldung.com/java-check-string-all-unique-chars)
- [Performance Comparison Between Different Java String Concatenation Methods](https://www.baeldung.com/java-string-concatenation-methods)
- [Replacing Single Quote with \ in Java String](https://www.baeldung.com/java-replacing-single-quote-string)
- [Check if a String Contains a Number Value in Java](https://www.baeldung.com/java-string-number-presence)

View File

@ -3,3 +3,5 @@
- [How to Center Text Output in Java](https://www.baeldung.com/java-center-text-output)
- [Capitalize the First Letter of Each Word in a String](https://www.baeldung.com/java-string-initial-capital-letter-every-word)
- [Check if a String Contains Only Unicode Letters](https://www.baeldung.com/java-string-all-unicode-characters)
- [Create a Mutable String in Java](https://www.baeldung.com/java-mutable-string)
- [Check if a String Contains a Number Value in Java](https://www.baeldung.com/java-string-number-presence)

View File

@ -0,0 +1,25 @@
package com.baeldung.isemptyvsisblank;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class StringIsEmptyVsIsBlankUnitTest {
@Test
public void givenString_whenCallIsEmpty_thenReturnCorrectValues() {
assertFalse("Example text".isEmpty());
assertTrue("".isEmpty());
assertFalse(" ".isEmpty());
assertFalse("\t\n\r\f".isEmpty());
}
@Test
public void givenString_whenCallStringIsBlank_thenReturnCorrectValues() {
assertFalse("Example text".isBlank());
assertTrue("".isBlank());
assertTrue(" ".isBlank());
assertTrue("\t\n\r\f ".isBlank());
}
}

View File

@ -5,4 +5,6 @@ This module contains articles about the sun package
### Relevant Articles:
- [Creating a Java Compiler Plugin](http://www.baeldung.com/java-build-compiler-plugin)
- [Guide to sun.misc.Unsafe](http://www.baeldung.com/java-unsafe)
- [Guide to sun.misc.Unsafe](http://www.baeldung.com/java-unsafe)
- [Why Is sun.misc.Unsafe.park Actually Unsafe?](https://www.baeldung.com/java-sun-misc-unsafe-park-reason)
- [Sharing Memory Between JVMs](https://www.baeldung.com/java-sharing-memory-between-jvms)

View File

@ -33,7 +33,7 @@
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${asspectj.version}</version>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
@ -74,7 +74,7 @@
<properties>
<commons-math3.version>3.6.1</commons-math3.version>
<joda.version>2.10</joda.version>
<asspectj.version>1.8.9</asspectj.version>
<aspectj.version>1.9.20.1</aspectj.version>
<jmockit.version>1.44</jmockit.version>
<mockito-inline.version>4.1.0</mockito-inline.version>
</properties>

View File

@ -198,7 +198,8 @@
<module>core-java-records</module>
<module>core-java-9-jigsaw</module>
<!--<module>core-java-20</module>--> <!--JAVA-25373-->
<!--<module>core-java-conditionals</module>--> <!--JAVA-25373-->
<!--<module>core-java-21</module>--> <!--JAVA-25373-->
<!--<module>core-java-conditionals</module>--> <!--JAVA-20931-->
<module>core-java-collections-set</module>
<module>core-java-date-operations-1</module>
<module>core-java-datetime-conversion</module>

View File

@ -59,7 +59,7 @@
<properties>
<cdi-api.version>2.0.SP1</cdi-api.version>
<weld-se-core.version>3.1.6.Final</weld-se-core.version>
<aspectjweaver.version>1.9.19</aspectjweaver.version>
<aspectjweaver.version>1.9.20.1</aspectjweaver.version>
</properties>
</project>

View File

@ -27,7 +27,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<guava.version>32.1.2-jre</guava.version>
<guava.version>32.1.3-jre</guava.version>
</properties>
</project>

View File

@ -49,7 +49,7 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<guava.version>32.1.2-jre</guava.version>
<guava.version>32.1.3-jre</guava.version>
</properties>
</project>

1
gradle-modules/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
!gradle-wrapper.jar

View File

@ -1,5 +1,7 @@
### Relevant Articles:
This module is using gradle-8.3.
- [Run a Java main Method Using Gradle](https://www.baeldung.com/gradle-run-java-main)
- [Finding Unused Gradle Dependencies](https://www.baeldung.com/gradle-finding-unused-dependencies)
- [Intro to Gradle Lint Plugin](https://www.baeldung.com/java-gradle-lint-intro)

View File

@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -1,41 +0,0 @@
//This default Shipkit configuration file was created automatically and is intended to be checked-in.
//Default configuration is sufficient for local testing and trying out Shipkit.
//To leverage Shipkit fully, please fix the TODO items, refer to our Getting Started Guide for help:
//
// https://github.com/mockito/shipkit/blob/master/docs/getting-started.md
//
shipkit {
//TODO is the repository correct?
gitHub.repository = "unspecified-user/unspecified-repo"
//TODO generate and use your own read-only GitHub personal access token
gitHub.readOnlyAuthToken = "76826c9ec886612f504d12fd4268b16721c4f85d"
//TODO generate GitHub write token, and ensure your Travis CI has this env variable exported
gitHub.writeAuthToken = System.getenv("GH_WRITE_TOKEN")
}
allprojects {
plugins.withId("com.jfrog.bintray") {
//Bintray configuration is handled by JFrog Bintray Gradle Plugin
//For reference see the official documentation: https://github.com/bintray/gradle-bintray-plugin
bintray {
//TODO sign up for free open source account with https://bintray.com, then look up your API key on your profile page in Bintray
key = '7ea297848ca948adb7d3ee92a83292112d7ae989'
//TODO don't check in the key, remove above line and use env variable exported on CI:
//key = System.getenv("BINTRAY_API_KEY")
pkg {
//TODO configure Bintray settings per your project (https://github.com/bintray/gradle-bintray-plugin)
repo = 'bootstrap'
user = 'shipkit-bootstrap-bot'
userOrg = 'shipkit-bootstrap'
name = 'maven'
licenses = ['MIT']
labels = ['continuous delivery', 'release automation', 'shipkit']
}
}
}
}

Binary file not shown.

View File

@ -1,6 +1,7 @@
#Thu Oct 12 16:43:02 BDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-bin.zip

View File

@ -99,7 +99,7 @@
<version>${commons-codec.version}</version>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>${wiremock.version}</version>
<scope>test</scope>
@ -205,9 +205,9 @@
<properties>
<java.version>17</java.version>
<!-- util -->
<commons-codec.version>1.10</commons-codec.version>
<commons-codec.version>1.16.0</commons-codec.version>
<!-- testing -->
<wiremock.version>2.5.1</wiremock.version>
<wiremock.version>3.3.1</wiremock.version>
<!-- http client & core 5 -->
<httpcore5.version>5.2</httpcore5.version>
<httpclient5.version>5.2</httpclient5.version>

View File

@ -65,7 +65,7 @@
<properties>
<exchange-rate-api.version>1.0.0-SNAPSHOT</exchange-rate-api.version>
<okhttp.version>3.10.0</okhttp.version>
<okhttp.version>4.12.0</okhttp.version>
<javax.json.bind-api.version>1.0</javax.json.bind-api.version>
<yasson.version>1.0.1</yasson.version>
<javax.json.version>1.1.2</javax.json.version>

View File

@ -9,26 +9,24 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-3</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.boot.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.databind.version}</version>
</dependency>
</dependencies>
@ -42,9 +40,16 @@
<!--<version>${hibernate-validator.ap.version}</version> </path> </annotationProcessorPaths> </configuration> -->
<!--</plugin> </plugins> </build> -->
<properties>
<spring.boot.version>3.0.4</spring.boot.version>
<jackson.databind.version>2.14.0</jackson.databind.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,4 +1,4 @@
package com.baeldung.javaxval;
package com.baeldung.javaxval.afterdeserialization;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

View File

@ -8,20 +8,19 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-3</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.boot.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
@ -38,7 +37,6 @@
<properties>
<hibernate-validator.ap.version>8.0.1.Final</hibernate-validator.ap.version>
<spring.boot.version>3.0.4</spring.boot.version>
</properties>
</project>

View File

@ -38,7 +38,6 @@
<properties>
<gson.version>2.10.1</gson.version>
<guava.version>32.1.2-jre</guava.version>
</properties>
</project>

View File

@ -219,10 +219,10 @@
<airline.version>2.7.2</airline.version>
<cache2k.version>1.2.3.Final</cache2k.version>
<jcabi-aspects.version>0.22.6</jcabi-aspects.version>
<aspectjrt.version>1.9.2</aspectjrt.version>
<aspectjrt.version>1.9.20.1</aspectjrt.version>
<jcabi-maven-plugin.version>0.14.1</jcabi-maven-plugin.version>
<aspectjtools.version>1.9.2</aspectjtools.version>
<aspectjweaver.version>1.9.2</aspectjweaver.version>
<aspectjtools.version>1.9.20.1</aspectjtools.version>
<aspectjweaver.version>1.9.20.1</aspectjweaver.version>
<takes.version>1.19</takes.version>
<httpcore.version>4.4.13</httpcore.version>
<httpclient.version>4.5.12</httpclient.version>

View File

@ -74,7 +74,7 @@ public class OpenCsvIntegrationTest {
assertThat(contents.split(NEW_LINE))
.containsExactly(
"'colA','colB','colC'",
"'COLA','COLB','COLC'",
"'Test1','sample','data'",
"'Test2','ipso','facto'"
);

View File

@ -109,7 +109,7 @@
</build>
<properties>
<okhttp.version>4.9.1</okhttp.version>
<okhttp.version>4.12.0</okhttp.version>
<gson.version>2.10.1</gson.version>
<mockwebserver.version>4.9.1</mockwebserver.version>
<jetty.httpclient.version>1.0.3</jetty.httpclient.version>

View File

@ -105,7 +105,7 @@
<properties>
<gson.version>2.10.1</gson.version>
<httpclient.version>4.5.3</httpclient.version>
<com.squareup.okhttp3.version>4.9.1</com.squareup.okhttp3.version>
<com.squareup.okhttp3.version>4.12.0</com.squareup.okhttp3.version>
<googleclient.version>1.23.0</googleclient.version>
<async.http.client.version>2.2.0</async.http.client.version>
<retrofit.version>2.3.0</retrofit.version>

View File

@ -122,7 +122,7 @@
<tink.version>1.2.2</tink.version>
<cryptacular.version>1.2.2</cryptacular.version>
<jasypt.version>1.9.2</jasypt.version>
<bouncycastle.version>1.58</bouncycastle.version>
<bouncycastle.version>1.68</bouncycastle.version>
<jsch.version>0.1.55</jsch.version>
<apache-mina.version>2.5.1</apache-mina.version>
<spring-security-oauth2.version>2.4.0.RELEASE</spring-security-oauth2.version>

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