Merge branch 'master' into BAEL-6421-PrintWriter-write-vs-print

This commit is contained in:
Andrei Branza
2024-04-11 16:59:27 +03:00
254 changed files with 5757 additions and 1097 deletions
@@ -10,8 +10,4 @@
- [Check if Two Strings Are Rotations of Each Other](https://www.baeldung.com/java-string-check-strings-rotations)
- [Find the Largest Prime Under the Given Number in Java](https://www.baeldung.com/java-largest-prime-lower-threshold)
- [Count the Number of Unique Digits in an Integer using Java](https://www.baeldung.com/java-int-count-unique-digits)
- [Generate Juggler Sequence in Java](https://www.baeldung.com/java-generate-juggler-sequence)
- [Finding the Parent of a Node in a Binary Search Tree with Java](https://www.baeldung.com/java-find-parent-node-binary-search-tree)
- [Check if a Number Is a Happy Number in Java](https://www.baeldung.com/java-happy-sad-number-test)
- [Find the Largest Number Possible After Removing k Digits of a Number](https://www.baeldung.com/java-find-largest-number-remove-k-digits)
- More articles: [[<-- prev]](/algorithms-miscellaneous-6)
@@ -1,2 +0,0 @@
## Relevant Articles
- [Implement Connect 4 Game with Java](https://www.baeldung.com/java-connect-4-game)
@@ -1,3 +1,9 @@
### Relevant Articles:
- [Vigenère Cipher in Java](https://www.baeldung.com/java-vigenere-cipher)
- [Merge Overlapping Intervals in a Java Collection](https://www.baeldung.com/java-collection-merge-overlapping-intervals)
- [Generate Juggler Sequence in Java](https://www.baeldung.com/java-generate-juggler-sequence)
- [Finding the Parent of a Node in a Binary Search Tree with Java](https://www.baeldung.com/java-find-parent-node-binary-search-tree)
- [Check if a Number Is a Happy Number in Java](https://www.baeldung.com/java-happy-sad-number-test)
- [Find the Largest Number Possible After Removing k Digits of a Number](https://www.baeldung.com/java-find-largest-number-remove-k-digits)
- [Implement Connect 4 Game with Java](https://www.baeldung.com/java-connect-4-game)
- More articles: [[<-- prev]](/algorithms-miscellaneous-7)
@@ -1,6 +1,6 @@
package com.baeldung.algorithms.largestNumberRemovingK;
import java.util.*;
import java.util.Stack;
public class LargestNumberRemoveKDigits {
public static int findLargestNumberUsingArithmetic(int num, int k) {
@@ -5,7 +5,9 @@ import org.junit.jupiter.api.Test;
import java.util.NoSuchElementException;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertNull;
class BinaryTreeParentNodeFinderUnitTest {
+11
View File
@@ -40,6 +40,16 @@
<artifactId>fastexcel-reader</artifactId>
<version>${fastexcel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
<build>
@@ -64,6 +74,7 @@
<jexcel.version>1.0.9</jexcel.version>
<fastexcel.version>0.17.0</fastexcel.version>
<maven.resources.plugin.version>3.3.1</maven.resources.plugin.version>
<log4j.version>2.23.1</log4j.version>
</properties>
</project>
@@ -71,7 +71,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito-core.version}</version>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -112,7 +112,6 @@
<feign-core.version>11.2</feign-core.version>
<guice.version>5.1.0</guice.version>
<system-stubs-junit4.version>2.0.2</system-stubs-junit4.version>
<mockito-core.version>4.1.0</mockito-core.version>
<assertj-core.version>3.19.0</assertj-core.version>
<junit-jupiter.version>5.8.1</junit-jupiter.version>
</properties>
+11 -3
View File
@@ -11,9 +11,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2</relativePath>
<relativePath>../parent-boot-3</relativePath>
</parent>
<dependencies>
@@ -98,7 +98,7 @@
</property>
<property>
<name>spring.datasource.password</name>
<value></value>
<value>test</value>
<!--<value>replace-with-your-password</value> -->
</property>
</appSettings>
@@ -113,6 +113,14 @@
<!--</resource> -->
<!--</resources> -->
</configuration>
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.4.0-b180830.0359</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
@@ -1,9 +1,9 @@
package com.baeldung.springboot.azure;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
/**
* @author aiet
@@ -0,0 +1,4 @@
package com.baeldung;
public class Unrelated {
}
@@ -1,7 +1,7 @@
package com.baeldung;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Set;
@@ -14,22 +14,22 @@ public class OuterUnitTest {
@Test
public void whenGetNestHostFromOuter_thenGetNestHost() {
is(Outer.class.getNestHost().getName()).equals(NEST_HOST_NAME);
assertEquals(NEST_HOST_NAME, Outer.class.getNestHost().getName());
}
@Test
public void whenGetNestHostFromInner_thenGetNestHost() {
is(Outer.Inner.class.getNestHost().getName()).equals(NEST_HOST_NAME);
assertEquals(NEST_HOST_NAME, Outer.Inner.class.getNestHost().getName());
}
@Test
public void whenCheckNestmatesForNestedClasses_thenGetTrue() {
is(Outer.Inner.class.isNestmateOf(Outer.class)).equals(true);
assertTrue(Outer.Inner.class.isNestmateOf(Outer.class));
}
@Test
public void whenCheckNestmatesForUnrelatedClasses_thenGetFalse() {
is(Outer.Inner.class.isNestmateOf(Outer.class)).equals(false);
assertFalse(Outer.Inner.class.isNestmateOf(Unrelated.class));
}
@Test
@@ -9,9 +9,4 @@
- [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)
- [Retrieving Unix Time in Java](https://www.baeldung.com/java-retrieve-unix-time)
- [Calculate Months Between Two Dates in Java](https://www.baeldung.com/java-months-difference-two-dates)
- [Format LocalDate to ISO 8601 With T and Z](https://www.baeldung.com/java-format-localdate-iso-8601-t-z)
- [Check if Two Date Ranges Overlap](https://www.baeldung.com/java-check-two-date-ranges-overlap)
- [Difference between ZoneOffset.UTC and ZoneId.of(“UTC”)](https://www.baeldung.com/java-zoneoffset-utc-zoneid-of)
- [Check if a Given Time Lies Between Two Times Regardless of Date](https://www.baeldung.com/java-check-between-two-times)
- [[<-- Prev]](/core-java-modules/core-java-datetime-java8-1)
- [[<-- Prev]](/core-java-modules/core-java-datetime-java8-1) [[Next -->]](/core-java-modules/core-java-8-datetime-3)
@@ -0,0 +1,8 @@
### Relevant Articles:
- [Calculate Months Between Two Dates in Java](https://www.baeldung.com/java-months-difference-two-dates)
- [Format LocalDate to ISO 8601 With T and Z](https://www.baeldung.com/java-format-localdate-iso-8601-t-z)
- [Check if Two Date Ranges Overlap](https://www.baeldung.com/java-check-two-date-ranges-overlap)
- [Difference between ZoneOffset.UTC and ZoneId.of(“UTC”)](https://www.baeldung.com/java-zoneoffset-utc-zoneid-of)
- [Check if a Given Time Lies Between Two Times Regardless of Date](https://www.baeldung.com/java-check-between-two-times)
- [[<-- Prev]](/core-java-modules/core-java-8-datetime-2)
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>core-java-8-datetime-3</artifactId>
<packaging>jar</packaging>
<name>core-java-8-datetime-3</name>
<parent>
<groupId>com.baeldung.core-java-modules</groupId>
<artifactId>core-java-modules</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda-time.version}</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<joda-time.version>2.12.5</joda-time.version>
</properties>
</project>
@@ -1,11 +1,11 @@
package com.baeldung.daterangeoverlap;
import java.time.LocalDate;
import java.util.Calendar;
import org.joda.time.DateTime;
import org.joda.time.Interval;
import java.time.LocalDate;
import java.util.Calendar;
public class DateRangeOverlapChecker {
public static boolean isOverlapUsingCalendarAndDuration(Calendar start1, Calendar end1, Calendar start2, Calendar end2) {
@@ -1,20 +1,16 @@
package com.baeldung.localdatetoiso;
import org.apache.commons.lang3.time.FastDateFormat;
import org.joda.time.DateTimeZone;
import org.joda.time.format.ISODateTimeFormat;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.ISODateTimeFormat;
import org.apache.commons.lang3.time.FastDateFormat;
import java.util.TimeZone;
public class LocalDateToISO {
public String formatUsingDateTimeFormatter(LocalDate localDate) {
@@ -1,45 +1,45 @@
package com.baeldung.checkiftimebetweentwotimes;
import org.junit.Test;
import java.time.LocalTime;
import java.util.Calendar;
import java.util.Date;
import static org.junit.Assert.assertTrue;
public class CheckIfTimeBetweenTwoTimesUnitTest {
private LocalTime startTime = LocalTime.parse("09:00:00");
private LocalTime endTime = LocalTime.parse("17:00:00");
private LocalTime targetTime = LocalTime.parse("12:30:00");
@Test
public void givenLocalTime_whenUsingIsAfterIsBefore_thenTimeIsBetween() {
assertTrue(!targetTime.isBefore(startTime) && !targetTime.isAfter(endTime));
}
@Test
public void givenLocalTime_whenUsingCompareTo_thenTimeIsBetween() {
assertTrue(targetTime.compareTo(startTime) >= 0 && targetTime.compareTo(endTime) <= 0);
}
@Test
public void givenDate_whenUsingAfterBefore_thenTimeIsBetween() {
Calendar startCalendar = Calendar.getInstance();
startCalendar.set(Calendar.HOUR_OF_DAY, 9);
startCalendar.set(Calendar.MINUTE, 0);
Date startTime = startCalendar.getTime();
Calendar endCalendar = Calendar.getInstance();
endCalendar.set(Calendar.HOUR_OF_DAY, 17);
endCalendar.set(Calendar.MINUTE, 0);
Date endTime = endCalendar.getTime();
Calendar targetCalendar = Calendar.getInstance();
targetCalendar.set(Calendar.HOUR_OF_DAY, 12);
targetCalendar.set(Calendar.MINUTE, 30);
Date targetTime = targetCalendar.getTime();
assertTrue(!targetTime.before(startTime) && !targetTime.after(endTime));
}
package com.baeldung.checkiftimebetweentwotimes;
import org.junit.Test;
import java.time.LocalTime;
import java.util.Calendar;
import java.util.Date;
import static org.junit.Assert.assertTrue;
public class CheckIfTimeBetweenTwoTimesUnitTest {
private LocalTime startTime = LocalTime.parse("09:00:00");
private LocalTime endTime = LocalTime.parse("17:00:00");
private LocalTime targetTime = LocalTime.parse("12:30:00");
@Test
public void givenLocalTime_whenUsingIsAfterIsBefore_thenTimeIsBetween() {
assertTrue(!targetTime.isBefore(startTime) && !targetTime.isAfter(endTime));
}
@Test
public void givenLocalTime_whenUsingCompareTo_thenTimeIsBetween() {
assertTrue(targetTime.compareTo(startTime) >= 0 && targetTime.compareTo(endTime) <= 0);
}
@Test
public void givenDate_whenUsingAfterBefore_thenTimeIsBetween() {
Calendar startCalendar = Calendar.getInstance();
startCalendar.set(Calendar.HOUR_OF_DAY, 9);
startCalendar.set(Calendar.MINUTE, 0);
Date startTime = startCalendar.getTime();
Calendar endCalendar = Calendar.getInstance();
endCalendar.set(Calendar.HOUR_OF_DAY, 17);
endCalendar.set(Calendar.MINUTE, 0);
Date endTime = endCalendar.getTime();
Calendar targetCalendar = Calendar.getInstance();
targetCalendar.set(Calendar.HOUR_OF_DAY, 12);
targetCalendar.set(Calendar.MINUTE, 30);
Date targetTime = targetCalendar.getTime();
assertTrue(!targetTime.before(startTime) && !targetTime.after(endTime));
}
}
@@ -1,13 +1,13 @@
package com.baeldung.daterangeoverlap;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.joda.time.DateTime;
import org.junit.Test;
import java.time.LocalDate;
import java.util.Calendar;
import org.joda.time.DateTime;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class DateRangeOverlapCheckerUnitTest {
@@ -1,13 +1,14 @@
package com.baeldung.localdatetoiso;
import org.junit.Test;
import java.time.LocalDate;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import java.time.LocalDate;
public class LocalDateToISOUnitTest {
@Test
void givenLocalDate_whenUsingDateTimeFormatter_thenISOFormat(){
public void givenLocalDate_whenUsingDateTimeFormatter_thenISOFormat(){
LocalDateToISO localDateToISO = new LocalDateToISO();
LocalDate localDate = LocalDate.of(2023, 11, 6);
@@ -17,7 +18,7 @@ public class LocalDateToISOUnitTest {
}
@Test
void givenLocalDate_whenUsingSimpleDateFormat_thenISOFormat(){
public void givenLocalDate_whenUsingSimpleDateFormat_thenISOFormat(){
LocalDateToISO localDateToISO = new LocalDateToISO();
LocalDate localDate = LocalDate.of(2023, 11, 6);
@@ -27,17 +28,18 @@ public class LocalDateToISOUnitTest {
}
@Test
void givenLocalDate_whenUsingJodaTime_thenISOFormat() {
public void givenLocalDate_whenUsingJodaTime_thenISOFormat() {
LocalDateToISO localDateToISO = new LocalDateToISO();
org.joda.time.LocalDate localDate = new org.joda.time.LocalDate(2023, 11, 6);
String expected = "2023-11-06T00:00:00.000Z";
String actual = localDateToISO.formatUsingJodaTime(localDate);
assertEquals(expected, actual);
assertEquals(expected, actual);
}
@Test
void givenLocalDate_whenUsingApacheCommonsLang_thenISOFormat() {
public void givenLocalDate_whenUsingApacheCommonsLang_thenISOFormat() {
LocalDateToISO localDateToISO = new LocalDateToISO();
LocalDate localDate = LocalDate.of(2023, 11, 6);
@@ -1,25 +1,25 @@
package com.baeldung.zoneoffsetandzoneidof;
import org.junit.jupiter.api.Test;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ZoneOffSetAndZoneIdOfUnitTest {
@Test
public void givenOffsetDateTimeWithUTCZoneOffset_thenOffsetShouldBeUTC() {
OffsetDateTime dateTimeWithOffset = OffsetDateTime.now(ZoneOffset.UTC);
assertEquals(dateTimeWithOffset.getOffset(), ZoneOffset.UTC);
}
@Test
public void givenZonedDateTimeWithUTCZoneId_thenZoneShouldBeUTC() {
ZonedDateTime zonedDateTime = ZonedDateTime.now(ZoneId.of("UTC"));
assertEquals(zonedDateTime.getZone(), ZoneId.of("UTC"));
}
}
package com.baeldung.zoneoffsetandzoneidof;
import org.junit.jupiter.api.Test;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ZoneOffSetAndZoneIdOfUnitTest {
@Test
public void givenOffsetDateTimeWithUTCZoneOffset_thenOffsetShouldBeUTC() {
OffsetDateTime dateTimeWithOffset = OffsetDateTime.now(ZoneOffset.UTC);
assertEquals(dateTimeWithOffset.getOffset(), ZoneOffset.UTC);
}
@Test
public void givenZonedDateTimeWithUTCZoneId_thenZoneShouldBeUTC() {
ZonedDateTime zonedDateTime = ZonedDateTime.now(ZoneId.of("UTC"));
assertEquals(zonedDateTime.getZone(), ZoneId.of("UTC"));
}
}

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