Merge branch 'master' into BAEL-6421-PrintWriter-write-vs-print
This commit is contained in:
commit
9b0e10496a
@ -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 {
|
||||
|
@ -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,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)
|
||||
|
8
core-java-modules/core-java-8-datetime-3/README.md
Normal file
8
core-java-modules/core-java-8-datetime-3/README.md
Normal file
@ -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)
|
55
core-java-modules/core-java-8-datetime-3/pom.xml
Normal file
55
core-java-modules/core-java-8-datetime-3/pom.xml
Normal file
@ -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"));
|
||||
}
|
||||
}
|
@ -9,7 +9,6 @@
|
||||
- [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)
|
||||
- [Time Complexity of Java Collections Sort in Java](https://www.baeldung.com/java-time-complexity-collections-sort)
|
||||
- [Check if List Contains at Least One Enum](https://www.baeldung.com/java-list-check-enum-presence)
|
||||
- [Comparison of for Loops and Iterators](https://www.baeldung.com/java-for-loops-vs-iterators)
|
||||
|
@ -55,8 +55,8 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>9</source>
|
||||
<target>9</target>
|
||||
<source>16</source>
|
||||
<target>16</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
7
core-java-modules/core-java-collections-6/README.md
Normal file
7
core-java-modules/core-java-collections-6/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
=========
|
||||
|
||||
## Core Java Collections Cookbooks and Examples
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- More articles: [[<-- prev]](/core-java-modules/core-java-collections-5)
|
71
core-java-modules/core-java-collections-6/pom.xml
Normal file
71
core-java-modules/core-java-collections-6/pom.xml
Normal file
@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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-collections-6</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>core-java-collections-6</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.junit.platform</groupId>
|
||||
<artifactId>junit-platform-runner</artifactId>
|
||||
<version>${junit-platform.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.roaringbitmap</groupId>
|
||||
<artifactId>RoaringBitmap</artifactId>
|
||||
<version>${roaringbitmap.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>9</source>
|
||||
<target>9</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<junit.version>5.9.2</junit.version>
|
||||
<roaringbitmap.version>0.9.38</roaringbitmap.version>
|
||||
<jmh.version>1.36</jmh.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -0,0 +1,64 @@
|
||||
package com.baeldung.iteratorvsforeach;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
class IteratorVsForeachUnitTest {
|
||||
|
||||
private static Stream<Arguments> listProvider() {
|
||||
return Stream.of(Arguments.of(List.of("String1", "String2", "unwanted"), List.of("String1", "String2")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEmptyCollection_whenUsingForEach_thenNoElementsAreIterated() {
|
||||
List<String> names = Collections.emptyList();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
names.forEach(stringBuilder::append);
|
||||
assertEquals("", stringBuilder.toString());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("listProvider")
|
||||
public void givenCollectionWithElements_whenRemovingElementDuringForEachIteration_thenElementIsRemoved(List<String> input, List<String> expected) {
|
||||
List<String> mutableList = new ArrayList<>(input);
|
||||
// Separate collection for items to be removed
|
||||
List<String> toRemove = new ArrayList<>();
|
||||
|
||||
// Using forEach to identify items to remove
|
||||
input.forEach(item -> {
|
||||
if (item.equals("unwanted")) {
|
||||
toRemove.add(item);
|
||||
}
|
||||
});
|
||||
|
||||
// Removing the identified items from the original list
|
||||
mutableList.removeAll(toRemove);
|
||||
assertIterableEquals(expected, mutableList);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("listProvider")
|
||||
public void givenCollectionWithElements_whenRemovingElementDuringIteratorIteration_thenElementIsRemoved(List<String> input, List<String> expected) {
|
||||
List<String> mutableList = new ArrayList<>(input);
|
||||
Iterator<String> it = mutableList.iterator();
|
||||
while (it.hasNext()) {
|
||||
String item = it.next();
|
||||
if (item.equals("unwanted")) {
|
||||
it.remove(); // Safely remove item
|
||||
}
|
||||
}
|
||||
assertIterableEquals(expected, mutableList);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.baeldung.listiteration;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
|
||||
|
||||
public class ListIterationUnitTest {
|
||||
|
||||
List<String> programmingLanguages = new ArrayList<>(List.of("Java", "Python", "C++"));
|
||||
List<Integer> numbers = new ArrayList<>(List.of(1, 2, 3));
|
||||
|
||||
@Test
|
||||
public void givenStringList_whenAddElementWithListIterator_thenModifiedList() {
|
||||
ListIterator<String> listIterator = programmingLanguages.listIterator();
|
||||
while (listIterator.hasNext()) {
|
||||
String language = listIterator.next();
|
||||
if (language.equals("Python")) {
|
||||
listIterator.add("JavaScript");
|
||||
}
|
||||
}
|
||||
|
||||
assertIterableEquals(Arrays.asList("Java", "Python", "JavaScript", "C++"), programmingLanguages);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNumericalList_whenMultiplyElementWithListIterator_thenModifiedList() {
|
||||
ListIterator<Integer> listIterator = numbers.listIterator();
|
||||
while (listIterator.hasNext()) {
|
||||
int num = listIterator.next();
|
||||
if (num == 2) {
|
||||
listIterator.add(num * 10);
|
||||
}
|
||||
}
|
||||
assertIterableEquals(Arrays.asList(1, 2, 20, 3), numbers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringList_whenAddElementWithEnhancedForLoopAndCopy_thenModifiedList() {
|
||||
List<String> copyOfWords = new ArrayList<>(programmingLanguages);
|
||||
for (String word : copyOfWords) {
|
||||
programmingLanguages.add(word.toUpperCase()); // Modified: Convert to uppercase
|
||||
}
|
||||
assertIterableEquals(Arrays.asList("Java", "Python", "C++", "JAVA", "PYTHON", "C++"), programmingLanguages);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNumericalList_whenMultiplyElementWithEnhancedForLoopAndCopy_thenModifiedList() {
|
||||
List<Integer> copyOfNumbers = new ArrayList<>(numbers);
|
||||
for (int num : copyOfNumbers) {
|
||||
numbers.add(num * 2);
|
||||
}
|
||||
assertIterableEquals(Arrays.asList(1, 2, 3, 2, 4, 6), numbers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringList_whenConvertToUpperCaseWithJava8Stream_thenModifiedList() {
|
||||
programmingLanguages = programmingLanguages.stream().map(String::toUpperCase).collect(Collectors.toList());
|
||||
assertIterableEquals(Arrays.asList("JAVA", "PYTHON", "C++"), programmingLanguages);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNumericalList_whenMultiplyByThreeWithJava8Stream_thenModifiedList() {
|
||||
numbers = numbers.stream().map(num -> num * 3).collect(Collectors.toList());
|
||||
assertIterableEquals(Arrays.asList(3, 6, 9), numbers);
|
||||
}
|
||||
|
||||
}
|
@ -5,3 +5,4 @@ This module contains articles about conversions among Collection types in Java.
|
||||
### Relevant Articles:
|
||||
- [Converting HashMap Values to an ArrayList in Java](https://www.baeldung.com/java-hashmap-arraylist)
|
||||
- [Joining a List<String> in Java With Commas and “and”](https://www.baeldung.com/java-string-concatenation-natural-language)
|
||||
- [HashSet toArray() Method in Java](https://www.baeldung.com/java-hashset-toarray)
|
||||
|
@ -1,59 +0,0 @@
|
||||
package com.baeldung.java.listInitialization;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import lombok.extern.java.Log;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@Log
|
||||
public class ListInitializationUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenAnonymousInnerClass_thenInitialiseList() {
|
||||
List<String> cities = new ArrayList() {
|
||||
{
|
||||
add("New York");
|
||||
add("Rio");
|
||||
add("Tokyo");
|
||||
}
|
||||
};
|
||||
|
||||
Assert.assertTrue(cities.contains("New York"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArraysAsList_thenInitialiseList() {
|
||||
List<String> list = Arrays.asList("foo", "bar");
|
||||
|
||||
Assert.assertTrue(list.contains("foo"));
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void givenArraysAsList_whenAdd_thenUnsupportedException() {
|
||||
List<String> list = Arrays.asList("foo", "bar");
|
||||
|
||||
list.add("baz");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArraysAsList_whenCreated_thenShareReference() {
|
||||
String[] array = { "foo", "bar" };
|
||||
List<String> list = Arrays.asList(array);
|
||||
array[0] = "baz";
|
||||
Assert.assertEquals("baz", list.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStream_thenInitializeList() {
|
||||
List<String> list = Stream.of("foo", "bar")
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Assert.assertTrue(list.contains("foo"));
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package com.baeldung.java.listinitialization;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import lombok.extern.java.Log;
|
||||
|
||||
@Log
|
||||
public class ListInitializationUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenAnonymousInnerClass_thenInitialiseList() {
|
||||
List<String> cities = new ArrayList() {
|
||||
{
|
||||
add("New York");
|
||||
add("Rio");
|
||||
add("Tokyo");
|
||||
}
|
||||
};
|
||||
|
||||
assertTrue(cities.contains("New York"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArraysAsList_thenInitialiseList() {
|
||||
List<String> list = Arrays.asList("foo", "bar");
|
||||
|
||||
assertTrue(list.contains("foo"));
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void givenArraysAsList_whenAdd_thenUnsupportedException() {
|
||||
List<String> list = Arrays.asList("foo", "bar");
|
||||
|
||||
list.add("baz");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArraysAsList_whenUsingArrayListConstructor_thenWeCanAddOrRemove() {
|
||||
List<String> list = new ArrayList<>(Arrays.asList("foo", "bar"));
|
||||
|
||||
list.add("baz");
|
||||
assertEquals(List.of("foo", "bar","baz"), list);
|
||||
|
||||
list.remove("baz");
|
||||
assertEquals(List.of("foo", "bar"), list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArraysAsList_whenCreated_thenShareReference() {
|
||||
String[] array = { "foo", "bar" };
|
||||
List<String> list = Arrays.asList(array);
|
||||
array[0] = "baz";
|
||||
assertEquals("baz", list.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenIntNumbers_whenRequiredLong_thenCastAutomatically() {
|
||||
int intNum = 42;
|
||||
long longNum = intNum;
|
||||
|
||||
assertEquals(42L, longNum);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArrayAsList_whenRequiredLongList_thenGetExpectedResult() {
|
||||
List<Long> listOfLongFixedSize = Arrays.asList(1L, 2L, 3L);
|
||||
List<Long> listOfLong = new ArrayList<>(Arrays.asList(1L, 2L, 3L));
|
||||
|
||||
List<Long> expected = List.of(1L, 2L, 3L);
|
||||
|
||||
assertEquals(expected, listOfLongFixedSize);
|
||||
assertEquals(expected, listOfLong);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStream_thenInitializeList() {
|
||||
List<String> list = Stream.of("foo", "bar")
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertTrue(list.contains("foo"));
|
||||
}
|
||||
}
|
@ -12,3 +12,4 @@ This module contains articles about core Java input/output(IO) APIs.
|
||||
- [Read Input Character-by-Character in Java](https://www.baeldung.com/java-read-input-character)
|
||||
- [Difference Between flush() and close() in Java FileWriter](https://www.baeldung.com/java-filewriter-flush-vs-close)
|
||||
- [Get a Path to a Resource in a Java JAR File](https://www.baeldung.com/java-get-path-resource-jar)
|
||||
- [Java InputStream vs. InputStreamReader](https://www.baeldung.com/java-inputstream-vs-inputstreamreader)
|
||||
|
@ -13,4 +13,3 @@ This module contains articles about core Java input/output(IO) APIs.
|
||||
- [Difference Between FileReader and BufferedReader in Java](https://www.baeldung.com/java-filereader-vs-bufferedreader)
|
||||
- [Read Multiple Inputs on the Same Line in Java](https://www.baeldung.com/java-read-multiple-inputs-same-line)
|
||||
- [Write Console Output to Text File in Java](https://www.baeldung.com/java-write-console-output-file)
|
||||
- [Java InputStream vs. InputStreamReader](https://www.baeldung.com/java-inputstream-vs-inputstreamreader)
|
||||
|
@ -260,7 +260,6 @@
|
||||
<!-- util -->
|
||||
<unix4j.version>0.4</unix4j.version>
|
||||
<grep4j.version>1.8.7</grep4j.version>
|
||||
<mockito.version>4.6.1</mockito.version>
|
||||
<!-- maven plugins -->
|
||||
<javamoney.moneta.version>1.1</javamoney.moneta.version>
|
||||
<maven-javadoc-plugin.version>3.6.2</maven-javadoc-plugin.version>
|
||||
|
@ -7,15 +7,11 @@
|
||||
- [Evaluating a Math Expression in Java](https://www.baeldung.com/java-evaluate-math-expression-string)
|
||||
- [Swap Two Variables in Java](https://www.baeldung.com/java-swap-two-variables)
|
||||
- [Java Program to Find the Roots of a Quadratic Equation](https://www.baeldung.com/roots-quadratic-equation)
|
||||
- [Create a BMI Calculator in Java](https://www.baeldung.com/java-body-mass-index-calculator)
|
||||
- [Java Program to Calculate the Standard Deviation](https://www.baeldung.com/java-calculate-standard-deviation)
|
||||
- [Java Program to Print Pascal’s Triangle](https://www.baeldung.com/java-pascal-triangle)
|
||||
- [Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency)
|
||||
- [Clamp Function in Java](https://www.baeldung.com/java-clamp-function)
|
||||
- [Creating a Magic Square in Java](https://www.baeldung.com/java-magic-square)
|
||||
- [Check if a Point Is Between Two Points Drawn on a Straight Line in Java](https://www.baeldung.com/java-check-point-straight-line)
|
||||
- [Validate if a String Is a Valid Geo Coordinate](https://www.baeldung.com/java-geo-coordinates-validation)
|
||||
- [Rotate a Vertex Around a Certain Point in Java](https://www.baeldung.com/java-rotate-vertex-around-point)
|
||||
- [Calculating the Power of Any Number in Java Without Using Math pow() Method](https://www.baeldung.com/java-calculating-the-power-without-math-pow)
|
||||
- [Solving Rod Cutting Problem in Java](https://www.baeldung.com/java-rod-cutting-problem)
|
||||
- More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math-2)
|
||||
|
@ -2,3 +2,7 @@
|
||||
|
||||
### Relevant articles:
|
||||
- [Calculate Percentiles in Java](https://www.baeldung.com/java-compute-percentiles)
|
||||
- [Solving Rod Cutting Problem in Java](https://www.baeldung.com/java-rod-cutting-problem)
|
||||
- [Rotate a Vertex Around a Certain Point in Java](https://www.baeldung.com/java-rotate-vertex-around-point)
|
||||
- [Create a BMI Calculator in Java](https://www.baeldung.com/java-body-mass-index-calculator)
|
||||
- [Check if a Point Is Between Two Points Drawn on a Straight Line in Java](https://www.baeldung.com/java-check-point-straight-line)
|
||||
|
@ -12,4 +12,8 @@
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.baeldung.passclassasparameter;
|
||||
|
||||
public class Example {
|
||||
public static void processClass(Class<?> clazz) {
|
||||
System.out.println("Processing class: " + clazz.getName());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
processClass(String.class);
|
||||
processClass(Integer.class);
|
||||
processClass(Double.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.baeldung.passclassasparameter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GenericExample {
|
||||
public static <T> void printListElements(Class<T> clazz, List<T> list) {
|
||||
System.out.println("Elements of " + clazz.getSimpleName() + " list:");
|
||||
for (T element : list) {
|
||||
System.out.println(element);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<String> stringList = new ArrayList<>();
|
||||
stringList.add("Java");
|
||||
stringList.add("is");
|
||||
stringList.add("awesome");
|
||||
|
||||
printListElements(String.class, stringList);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.baeldung.passclassasparameter;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ReflectionExample {
|
||||
public static void processClass(Class<?> clazz, String methodName) throws Exception {
|
||||
Method method = clazz.getMethod(methodName);
|
||||
Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||
method.invoke(instance);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
processClass(ReflectionTarget.class, "sayHello");
|
||||
}
|
||||
}
|
||||
|
||||
class ReflectionTarget {
|
||||
public void sayHello() {
|
||||
System.out.println("Hello, Reflection!");
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package com.baeldung.symmetricsubstringlength;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class SymmetricSubstringMaxLengthUnitTest {
|
||||
String input = "<><??>>";
|
||||
int expected = 4;
|
||||
|
||||
@Test
|
||||
public void givenString_whenUsingSymmetricSubstringExpansion_thenFindLongestSymmetricSubstring() {
|
||||
int start = 0;
|
||||
int mid = 0;
|
||||
int last_gt = 0;
|
||||
int end = 0;
|
||||
int best = 0;
|
||||
|
||||
while (start < input.length()) {
|
||||
int current = Math.min(mid - start, end - mid);
|
||||
if (best < current) {
|
||||
best = current;
|
||||
}
|
||||
|
||||
if (end - mid == current && end < input.length()) {
|
||||
if (input.charAt(end) == '?') {
|
||||
end++;
|
||||
} else if (input.charAt(end) == '>') {
|
||||
end++;
|
||||
last_gt = end;
|
||||
} else {
|
||||
end++;
|
||||
mid = end;
|
||||
start = Math.max(start, last_gt);
|
||||
}
|
||||
} else if (mid < input.length() && input.charAt(mid) == '?') {
|
||||
mid++;
|
||||
} else if (start < mid) {
|
||||
start++;
|
||||
} else {
|
||||
start = Math.max(start, last_gt);
|
||||
mid++;
|
||||
end = Math.max(mid, end);
|
||||
}
|
||||
}
|
||||
int result = 2 * best;
|
||||
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_whenUsingBruteForce_thenFindLongestSymmetricSubstring() {
|
||||
int max = 0;
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
for (int j = i + 1; j <= input.length(); j++) {
|
||||
String t = input.substring(i, j);
|
||||
if (t.length() % 2 == 0) {
|
||||
int k = 0, l = t.length() - 1;
|
||||
boolean isSym = true;
|
||||
while (k < l && isSym) {
|
||||
if (!(t.charAt(k) == '<' || t.charAt(k) == '?') && (t.charAt(l) == '>' || t.charAt(l) == '?')) {
|
||||
isSym = false;
|
||||
}
|
||||
k++;
|
||||
l--;
|
||||
}
|
||||
if (isSym) {
|
||||
max = Math.max(max, t.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(expected, max);
|
||||
}
|
||||
|
||||
}
|
@ -89,6 +89,7 @@
|
||||
<module>core-java-collections-3</module>
|
||||
<module>core-java-collections-4</module>
|
||||
<module>core-java-collections-5</module>
|
||||
<module>core-java-collections-6</module>
|
||||
<module>core-java-collections-conversions</module>
|
||||
<module>core-java-collections-set-2</module>
|
||||
<module>core-java-collections-list</module>
|
||||
|
@ -20,7 +20,7 @@
|
||||
<!-- Boot version compatible with spqr-boot-starter -->
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>2.6.4</version>
|
||||
<version>2.6.15</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
@ -34,4 +34,9 @@
|
||||
<module>graphql-spqr-boot-starter</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<!-- Can't update to the recent mockito version, without updating the spring boot version-->
|
||||
<mockito.version>4.4.0</mockito.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -12,6 +12,13 @@
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>maven</id>
|
||||
<url>https://maven.openimaj.org/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.imagej</groupId>
|
||||
|
@ -0,0 +1,5 @@
|
||||
package com.baeldung.gson.polymorphic;
|
||||
|
||||
public interface Shape {
|
||||
double getArea();
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.baeldung.gson.polymorphic;
|
||||
|
||||
import com.google.gson.*;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class ShapeTypeAdapter implements JsonSerializer<Shape>, JsonDeserializer<Shape> {
|
||||
@Override
|
||||
public JsonElement serialize(Shape shape, Type type, JsonSerializationContext context) {
|
||||
JsonElement elem = new Gson().toJsonTree(shape);
|
||||
elem.getAsJsonObject().addProperty("type", shape.getClass().getName());
|
||||
return elem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Shape deserialize(JsonElement json, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
||||
JsonObject jsonObject = json.getAsJsonObject();
|
||||
String typeName = jsonObject.get("type").getAsString();
|
||||
|
||||
try {
|
||||
Class<? extends Shape> cls = (Class<? extends Shape>) Class.forName(typeName);
|
||||
return new Gson().fromJson(json, cls);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new JsonParseException(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
package com.baeldung.gson.polymorphic;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TypeAdapterUnitTest {
|
||||
@Test
|
||||
void testSerialize() {
|
||||
List<Shape> shapes = Arrays.asList(
|
||||
new Circle(4d),
|
||||
new Square(5d)
|
||||
);
|
||||
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
builder.registerTypeHierarchyAdapter(Shape.class, new ShapeTypeAdapter());
|
||||
Gson gson = builder.create();
|
||||
|
||||
String json = gson.toJson(shapes);
|
||||
|
||||
assertEquals("[" +
|
||||
"{" +
|
||||
"\"radius\":4.0," +
|
||||
"\"area\":50.26548245743669," +
|
||||
"\"type\":\"com.baeldung.gson.polymorphic.TypeAdapterUnitTest$Circle\"" +
|
||||
"},{" +
|
||||
"\"side\":5.0," +
|
||||
"\"area\":25.0," +
|
||||
"\"type\":\"com.baeldung.gson.polymorphic.TypeAdapterUnitTest$Square\"" +
|
||||
"}]", json);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testDeserializeWrapper() {
|
||||
List<Shape> shapes = Arrays.asList(
|
||||
new Circle(4d),
|
||||
new Square(5d)
|
||||
);
|
||||
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
builder.registerTypeHierarchyAdapter(Shape.class, new ShapeTypeAdapter());
|
||||
Gson gson = builder.create();
|
||||
|
||||
String json = gson.toJson(shapes);
|
||||
|
||||
Type collectionType = new TypeToken<List<Shape>>(){}.getType();
|
||||
List<Shape> result = gson.fromJson(json, collectionType);
|
||||
|
||||
assertEquals(shapes, result);
|
||||
}
|
||||
|
||||
private static class Square implements Shape {
|
||||
private final double side;
|
||||
private final double area;
|
||||
|
||||
public Square(double side) {
|
||||
this.side = side;
|
||||
this.area = side * side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getArea() {
|
||||
return area;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Square square = (Square) o;
|
||||
return Double.compare(square.side, side) == 0 && Double.compare(square.area, area) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(side, area);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Circle implements Shape {
|
||||
private final double radius;
|
||||
|
||||
private final double area;
|
||||
|
||||
public Circle(double radius) {
|
||||
this.radius = radius;
|
||||
this.area = Math.PI * radius * radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getArea() {
|
||||
return area;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Circle circle = (Circle) o;
|
||||
return Double.compare(circle.radius, radius) == 0 && Double.compare(circle.area, area) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(radius, area);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package com.baeldung.gson.polymorphic;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TypeFieldUnitTest {
|
||||
@Test
|
||||
void testSerialize() {
|
||||
List<Shape> shapes = Arrays.asList(
|
||||
new Circle(4d),
|
||||
new Square(5d)
|
||||
);
|
||||
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(shapes);
|
||||
|
||||
assertEquals("[" +
|
||||
"{" +
|
||||
"\"type\":\"circle\"," +
|
||||
"\"radius\":4.0," +
|
||||
"\"area\":50.26548245743669" +
|
||||
"},{" +
|
||||
"\"type\":\"square\"," +
|
||||
"\"side\":5.0," +
|
||||
"\"area\":25.0" +
|
||||
"}]", json);
|
||||
}
|
||||
|
||||
private static class Square implements Shape {
|
||||
private final String type = "square";
|
||||
private final double side;
|
||||
private final double area;
|
||||
|
||||
public Square(double side) {
|
||||
this.side = side;
|
||||
this.area = side * side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getArea() {
|
||||
return area;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Circle implements Shape {
|
||||
private final String type = "circle";
|
||||
private final double radius;
|
||||
|
||||
private final double area;
|
||||
|
||||
public Circle(double radius) {
|
||||
this.radius = radius;
|
||||
this.area = Math.PI * radius * radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getArea() {
|
||||
return area;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,148 @@
|
||||
package com.baeldung.gson.polymorphic;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class WrapperUnitTest {
|
||||
@Test
|
||||
void testSerializeWrapper() {
|
||||
List<Wrapper> shapes = Arrays.asList(
|
||||
new Wrapper(new Circle(4d)),
|
||||
new Wrapper(new Square(5d))
|
||||
);
|
||||
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(shapes);
|
||||
|
||||
assertEquals("[" +
|
||||
"{" +
|
||||
"\"circle\":{" +
|
||||
"\"radius\":4.0," +
|
||||
"\"area\":50.26548245743669" +
|
||||
"}" +
|
||||
"},{" +
|
||||
"\"square\":{" +
|
||||
"\"side\":5.0," +
|
||||
"\"area\":25.0" +
|
||||
"}" +
|
||||
"}]", json);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeserializeWrapper() {
|
||||
List<Wrapper> shapes = Arrays.asList(
|
||||
new Wrapper(new Circle(4d)),
|
||||
new Wrapper(new Square(5d))
|
||||
);
|
||||
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(shapes);
|
||||
|
||||
Type collectionType = new TypeToken<List<Wrapper>>(){}.getType();
|
||||
List<Wrapper> result = gson.fromJson(json, collectionType);
|
||||
|
||||
assertEquals(shapes, result);
|
||||
}
|
||||
|
||||
private static class Square implements Shape {
|
||||
private final double side;
|
||||
private final double area;
|
||||
|
||||
public Square(double side) {
|
||||
this.side = side;
|
||||
this.area = side * side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getArea() {
|
||||
return area;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Square square = (Square) o;
|
||||
return Double.compare(square.side, side) == 0 && Double.compare(square.area, area) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(side, area);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Circle implements Shape {
|
||||
private final double radius;
|
||||
|
||||
private final double area;
|
||||
|
||||
public Circle(double radius) {
|
||||
this.radius = radius;
|
||||
this.area = Math.PI * radius * radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getArea() {
|
||||
return area;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Circle circle = (Circle) o;
|
||||
return Double.compare(circle.radius, radius) == 0 && Double.compare(circle.area, area) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(radius, area);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Wrapper {
|
||||
private final Circle circle;
|
||||
private final Square square;
|
||||
|
||||
public Wrapper(Circle circle) {
|
||||
this.circle = circle;
|
||||
this.square = null;
|
||||
}
|
||||
|
||||
public Wrapper(Square square) {
|
||||
this.square = square;
|
||||
this.circle = null;
|
||||
}
|
||||
|
||||
public Circle getCircle() {
|
||||
return circle;
|
||||
}
|
||||
|
||||
public Square getSquare() {
|
||||
return square;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Wrapper wrapper = (Wrapper) o;
|
||||
return Objects.equals(circle, wrapper.circle) && Objects.equals(square, wrapper.square);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(circle, square);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -44,15 +44,27 @@
|
||||
<version>${mockftpserver.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.tukaani</groupId>
|
||||
<artifactId>xz</artifactId>
|
||||
<version>${xz.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.luben</groupId>
|
||||
<artifactId>zstd-jni</artifactId>
|
||||
<version>${zstd-jni.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<commons-compress.version>1.23.0</commons-compress.version>
|
||||
<commons-compress.version>1.26.1</commons-compress.version>
|
||||
<ant.version>1.10.13</ant.version>
|
||||
<commons-vfs2.version>2.9.0</commons-vfs2.version>
|
||||
<apache-commons-text.version>1.10.0</apache-commons-text.version>
|
||||
<commons-net.version>3.6</commons-net.version>
|
||||
<mockftpserver.version>2.7.1</mockftpserver.version>
|
||||
<xz.version>1.9</xz.version>
|
||||
<zstd-jni.version>1.5.5-11</zstd-jni.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -0,0 +1,119 @@
|
||||
package com.baeldung.commons.compress;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.zip.Deflater;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import org.apache.commons.compress.archivers.ArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.ArchiveException;
|
||||
import org.apache.commons.compress.archivers.ArchiveInputStream;
|
||||
import org.apache.commons.compress.archivers.ArchiveOutputStream;
|
||||
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
|
||||
import org.apache.commons.compress.archivers.examples.Archiver;
|
||||
import org.apache.commons.compress.archivers.examples.Expander;
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
|
||||
import org.apache.commons.compress.compressors.CompressorException;
|
||||
import org.apache.commons.compress.compressors.CompressorInputStream;
|
||||
import org.apache.commons.compress.compressors.CompressorOutputStream;
|
||||
import org.apache.commons.compress.compressors.CompressorStreamFactory;
|
||||
import org.apache.commons.compress.utils.FileNameUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
public class CompressUtils {
|
||||
|
||||
private CompressUtils() {
|
||||
}
|
||||
|
||||
public static void archive(Path directory, Path destination) throws IOException, ArchiveException {
|
||||
String format = FileNameUtils.getExtension(destination);
|
||||
new Archiver().create(format, destination, directory);
|
||||
}
|
||||
|
||||
public static void archiveAndCompress(String directory, Path destination) throws IOException, ArchiveException, CompressorException {
|
||||
archiveAndCompress(Paths.get(directory), destination);
|
||||
}
|
||||
|
||||
public static void archiveAndCompress(Path directory, Path destination) throws IOException, ArchiveException, CompressorException {
|
||||
String compressionFormat = FileNameUtils.getExtension(destination);
|
||||
String archiveFormat = FilenameUtils.getExtension(destination.getFileName()
|
||||
.toString()
|
||||
.replace("." + compressionFormat, ""));
|
||||
|
||||
try (OutputStream archive = Files.newOutputStream(destination);
|
||||
BufferedOutputStream archiveBuffer = new BufferedOutputStream(archive);
|
||||
CompressorOutputStream compressor = new CompressorStreamFactory().createCompressorOutputStream(compressionFormat, archiveBuffer);
|
||||
ArchiveOutputStream<?> archiver = new ArchiveStreamFactory().createArchiveOutputStream(archiveFormat, compressor)) {
|
||||
new Archiver().create(archiver, directory);
|
||||
}
|
||||
}
|
||||
|
||||
public static void decompress(Path file, Path destination) throws IOException, ArchiveException, CompressorException {
|
||||
decompress(Files.newInputStream(file), destination);
|
||||
}
|
||||
|
||||
public static void decompress(InputStream file, Path destination) throws IOException, ArchiveException, CompressorException {
|
||||
try (InputStream in = file;
|
||||
BufferedInputStream inputBuffer = new BufferedInputStream(in);
|
||||
OutputStream out = Files.newOutputStream(destination);
|
||||
CompressorInputStream decompressor = new CompressorStreamFactory().createCompressorInputStream(inputBuffer)) {
|
||||
IOUtils.copy(decompressor, out);
|
||||
}
|
||||
}
|
||||
|
||||
public static void extract(Path archive, Path destination) throws IOException, ArchiveException, CompressorException {
|
||||
new Expander().expand(archive, destination);
|
||||
}
|
||||
|
||||
public static void compressFile(Path file, Path destination) throws IOException, CompressorException {
|
||||
String format = FileNameUtils.getExtension(destination);
|
||||
|
||||
try (OutputStream out = Files.newOutputStream(destination);
|
||||
BufferedOutputStream buffer = new BufferedOutputStream(out);
|
||||
CompressorOutputStream compressor = new CompressorStreamFactory().createCompressorOutputStream(format, buffer)) {
|
||||
IOUtils.copy(Files.newInputStream(file), compressor);
|
||||
}
|
||||
}
|
||||
|
||||
public static void zip(Path file, Path destination) throws IOException {
|
||||
try (InputStream input = Files.newInputStream(file);
|
||||
OutputStream output = Files.newOutputStream(destination);
|
||||
ZipArchiveOutputStream archive = new ZipArchiveOutputStream(output)) {
|
||||
archive.setLevel(Deflater.BEST_COMPRESSION);
|
||||
archive.setMethod(ZipEntry.DEFLATED);
|
||||
|
||||
archive.putArchiveEntry(new ZipArchiveEntry(file.getFileName()
|
||||
.toString()));
|
||||
IOUtils.copy(input, archive);
|
||||
archive.closeArchiveEntry();
|
||||
}
|
||||
}
|
||||
|
||||
public static void extractOne(Path archivePath, String fileName, Path destinationDirectory) throws IOException, ArchiveException {
|
||||
try (InputStream input = Files.newInputStream(archivePath);
|
||||
BufferedInputStream buffer = new BufferedInputStream(input);
|
||||
ArchiveInputStream<?> archive = new ArchiveStreamFactory().createArchiveInputStream(buffer)) {
|
||||
|
||||
ArchiveEntry entry;
|
||||
while ((entry = archive.getNextEntry()) != null) {
|
||||
if (entry.getName()
|
||||
.equals(fileName)) {
|
||||
Path outFile = destinationDirectory.resolve(fileName);
|
||||
Files.createDirectories(outFile.getParent());
|
||||
try (OutputStream os = Files.newOutputStream(outFile)) {
|
||||
IOUtils.copy(archive, os);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package com.baeldung.commons.convertunicode;
|
||||
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
|
||||
public class UnicodeConverterUtil {
|
||||
|
||||
public static String decodeWithApacheCommons(String input) {
|
||||
@ -15,7 +15,7 @@ public class UnicodeConverterUtil {
|
||||
Pattern pattern = Pattern.compile("\\\\u[0-9a-fA-F]{4}");
|
||||
Matcher matcher = pattern.matcher(input);
|
||||
|
||||
StringBuilder decodedString = new StringBuilder();
|
||||
StringBuffer decodedString = new StringBuffer();
|
||||
|
||||
while (matcher.find()) {
|
||||
String unicodeSequence = matcher.group();
|
||||
|
@ -0,0 +1,135 @@
|
||||
package com.baeldung.commons.compress;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.apache.commons.compress.archivers.ArchiveException;
|
||||
import org.apache.commons.compress.compressors.CompressorException;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class CompressUtilsUnitTest {
|
||||
|
||||
static Path TMP;
|
||||
static String ZIP_FILE = "new.txt.zip";
|
||||
static String COMPRESSED_FILE = "new.txt.gz";
|
||||
static String DECOMPRESSED_FILE = "decompressed-file.txt";
|
||||
static String DECOMPRESSED_ARCHIVE = "decompressed-archive.tar";
|
||||
static String COMPRESSED_ARCHIVE = "archive.tar.gz";
|
||||
static String MODIFIED_ARCHIVE = "modified-archive.tar";
|
||||
static String EXTRACTED_DIR = "extracted";
|
||||
|
||||
@BeforeAll
|
||||
static void setup() throws IOException {
|
||||
TMP = Files.createTempDirectory("compress-test")
|
||||
.toAbsolutePath();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void destroy() throws IOException {
|
||||
FileUtils.deleteDirectory(TMP.toFile());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void givenFile_whenCompressing_thenCompressed() throws IOException, CompressorException, URISyntaxException {
|
||||
Path destination = TMP.resolve(COMPRESSED_FILE);
|
||||
|
||||
CompressUtils.compressFile(TestResources.testFile(), destination);
|
||||
|
||||
assertTrue(Files.isRegularFile(destination));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void givenFile_whenZipping_thenZipFileCreated() throws IOException, URISyntaxException {
|
||||
Path destination = TMP.resolve(ZIP_FILE);
|
||||
|
||||
CompressUtils.zip(TestResources.testFile(), destination);
|
||||
|
||||
assertTrue(Files.isRegularFile(destination));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void givenCompressedArchive_whenDecompressing_thenArchiveAvailable() throws IOException, ArchiveException, CompressorException {
|
||||
Path destination = TMP.resolve(DECOMPRESSED_ARCHIVE);
|
||||
|
||||
CompressUtils.decompress(TestResources.compressedArchive(), destination);
|
||||
|
||||
assertTrue(Files.isRegularFile(destination));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void givenCompressedFile_whenDecompressing_thenFileAvailable() throws IOException, ArchiveException, CompressorException {
|
||||
Path destination = TMP.resolve(DECOMPRESSED_FILE);
|
||||
|
||||
CompressUtils.decompress(TMP.resolve(COMPRESSED_FILE), destination);
|
||||
|
||||
assertTrue(Files.isRegularFile(destination));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void givenDecompressedArchive_whenUnarchiving_thenFilesAvailable() throws IOException, ArchiveException, CompressorException {
|
||||
Path destination = TMP.resolve(EXTRACTED_DIR);
|
||||
|
||||
CompressUtils.extract(TMP.resolve(DECOMPRESSED_ARCHIVE), destination);
|
||||
|
||||
assertTrue(Files.isDirectory(destination));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void givenDirectory_whenArchivingAndCompressing_thenCompressedArchiveAvailable() throws IOException, ArchiveException, CompressorException {
|
||||
Path destination = TMP.resolve(COMPRESSED_ARCHIVE);
|
||||
|
||||
CompressUtils.archiveAndCompress(TMP.resolve(EXTRACTED_DIR), destination);
|
||||
|
||||
assertTrue(Files.isRegularFile(destination));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void givenExistingArchive_whenAddingSingleEntry_thenArchiveModified() throws IOException, ArchiveException, CompressorException, URISyntaxException {
|
||||
Path archive = TMP.resolve(DECOMPRESSED_ARCHIVE);
|
||||
Path newArchive = TMP.resolve(MODIFIED_ARCHIVE);
|
||||
Path tmpDir = TMP.resolve(newArchive + "-tmpd");
|
||||
|
||||
Path newEntry = TestResources.testFile();
|
||||
|
||||
CompressUtils.extract(archive, tmpDir);
|
||||
assertTrue(Files.isDirectory(tmpDir));
|
||||
|
||||
Files.copy(newEntry, tmpDir.resolve(newEntry.getFileName()));
|
||||
CompressUtils.archive(tmpDir, newArchive);
|
||||
assertTrue(Files.isRegularFile(newArchive));
|
||||
|
||||
FileUtils.deleteDirectory(tmpDir.toFile());
|
||||
Files.delete(archive);
|
||||
Files.move(newArchive, archive);
|
||||
assertTrue(Files.isRegularFile(archive));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void givenExistingArchive_whenExtractingSingleEntry_thenFileExtracted() throws IOException, ArchiveException {
|
||||
Path archive = TMP.resolve(DECOMPRESSED_ARCHIVE);
|
||||
String targetFile = "sub/other.txt";
|
||||
|
||||
CompressUtils.extractOne(archive, targetFile, TMP);
|
||||
|
||||
assertTrue(Files.isRegularFile(TMP.resolve(targetFile)));
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.baeldung.commons.compress;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public interface TestResources {
|
||||
|
||||
String DIR = "/compress/";
|
||||
|
||||
static InputStream compressedArchive() {
|
||||
return TestResources.class.getResourceAsStream(DIR + CompressUtilsUnitTest.COMPRESSED_ARCHIVE);
|
||||
}
|
||||
|
||||
static Path testFile() throws URISyntaxException {
|
||||
URL resource = TestResources.class.getResource(DIR + "new.txt");
|
||||
if (resource == null) {
|
||||
throw new IllegalArgumentException("file not found!");
|
||||
} else {
|
||||
return Paths.get(resource.toURI());
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
@ -0,0 +1,2 @@
|
||||
lorem ipsum
|
||||
dolor sit amet
|
@ -85,7 +85,7 @@
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
<version>${mockito.version}</version>
|
||||
<version>${mockito-inline.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -120,6 +120,7 @@
|
||||
<reactive.stream.version>1.0.3</reactive.stream.version>
|
||||
<reactor.version>3.6.0</reactor.version>
|
||||
<jmockit.version>1.49</jmockit.version>
|
||||
<mockito-inline.version>5.2.0</mockito-inline.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -36,7 +36,7 @@
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.ws</groupId>
|
||||
<artifactId>jaxws-ri</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>${jaxws.version}</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@ -46,7 +46,7 @@
|
||||
<plugin>
|
||||
<groupId>com.sun.xml.ws</groupId>
|
||||
<artifactId>jaxws-maven-plugin</artifactId>
|
||||
<version>4.0.1</version>
|
||||
<version>${jaxws.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@ -73,4 +73,8 @@
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<jaxws.version>4.0.2</jaxws.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -44,7 +44,7 @@
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>${mockito-core.version}</version>
|
||||
<version>${mockito.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -83,7 +83,6 @@
|
||||
<activemq.version>5.14.1</activemq.version>
|
||||
<spring-boot-test.version>1.5.10.RELEASE</spring-boot-test.version>
|
||||
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
|
||||
<mockito-core.version>4.6.1</mockito-core.version>
|
||||
<activemq-junit.version>5.16.5</activemq-junit.version>
|
||||
<testcontainers.version>1.17.3</testcontainers.version>
|
||||
<junit-jupiter.version>5.10.1</junit-jupiter.version>
|
||||
|
@ -14,6 +14,13 @@
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>wso2-https</id>
|
||||
<url>https://maven.wso2.org/nexus/content/groups/wso2-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@ -40,7 +47,7 @@
|
||||
|
||||
<properties>
|
||||
<microservice.mainClass>com.baeldung.msf4j.msf4jintro.Application</microservice.mainClass>
|
||||
<msf4j.version>2.6.3</msf4j.version>
|
||||
<msf4j.version>2.8.11</msf4j.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -16,9 +16,13 @@
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
<version>${mockito.version}</version>
|
||||
<version>${mockito-inline.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<mockito-inline.version>5.2.0</mockito-inline.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
6
persistence-modules/hibernate-annotations-2/README.md
Normal file
6
persistence-modules/hibernate-annotations-2/README.md
Normal file
@ -0,0 +1,6 @@
|
||||
## Hibernate Annotations
|
||||
|
||||
This module contains articles about Annotations used in Hibernate.
|
||||
|
||||
### Relevant Articles:
|
||||
- [@Subselect Annotation in Hibernate](https://www.baeldung.com/hibernate-subselect)
|
109
persistence-modules/hibernate-annotations-2/pom.xml
Normal file
109
persistence-modules/hibernate-annotations-2/pom.xml
Normal file
@ -0,0 +1,109 @@
|
||||
<?xml version="1.0"?>
|
||||
<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>hibernate-annotations-2</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<name>hibernate-annotations-2</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Hibernate annotations module, part 2</description>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>persistence-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spring -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${org.springframework.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-jpa</artifactId>
|
||||
<version>${org.springframework.data.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate.orm</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>${hibernate-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hsqldb</groupId>
|
||||
<artifactId>hsqldb</artifactId>
|
||||
<version>${hsqldb.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>${h2.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate.orm</groupId>
|
||||
<artifactId>hibernate-testing</artifactId>
|
||||
<version>${hibernate-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate.orm</groupId>
|
||||
<artifactId>hibernate-spatial</artifactId>
|
||||
<version>${hibernate-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat</groupId>
|
||||
<artifactId>tomcat-dbcp</artifactId>
|
||||
<version>${tomcat-dbcp.version}</version>
|
||||
</dependency>
|
||||
<!-- validation -->
|
||||
<!-- utils -->
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<!-- test scoped -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${org.springframework.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.hypersistence</groupId>
|
||||
<artifactId>hypersistence-utils-hibernate-60</artifactId>
|
||||
<version>${hypersistance-utils-hibernate-60.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.liquibase</groupId>
|
||||
<artifactId>liquibase-core</artifactId>
|
||||
<version>${liquibase-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<!-- Spring -->
|
||||
<org.springframework.version>6.0.6</org.springframework.version>
|
||||
<org.springframework.data.version>3.0.3</org.springframework.data.version>
|
||||
<hibernate-core.version>6.4.2.Final</hibernate-core.version>
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
<tomcat-dbcp.version>9.0.0.M26</tomcat-dbcp.version>
|
||||
<hypersistance-utils-hibernate-60.version>3.3.1</hypersistance-utils-hibernate-60.version>
|
||||
<lombok.version>1.18.30</lombok.version>
|
||||
<liquibase-core.version>4.24.0</liquibase-core.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -0,0 +1,50 @@
|
||||
package com.baeldung.hibernate;
|
||||
|
||||
import com.baeldung.hibernate.subselect.RuntimeConfiguration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
public class HibernateAnnotationUtil {
|
||||
|
||||
private static final SessionFactory SESSION_FACTORY = buildSessionFactory();
|
||||
|
||||
/**
|
||||
* Utility class
|
||||
*/
|
||||
private HibernateAnnotationUtil() {
|
||||
}
|
||||
|
||||
public static SessionFactory getSessionFactory() {
|
||||
return SESSION_FACTORY;
|
||||
}
|
||||
|
||||
private static SessionFactory buildSessionFactory() {
|
||||
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.applySettings(dbSettings())
|
||||
.build();
|
||||
|
||||
Metadata metadata = new MetadataSources(serviceRegistry)
|
||||
.addAnnotatedClass(RuntimeConfiguration.class)
|
||||
.buildMetadata();
|
||||
|
||||
return metadata.buildSessionFactory();
|
||||
}
|
||||
|
||||
private static Map<String, Object> dbSettings() {
|
||||
Map<String, Object> dbSettings = new HashMap<>();
|
||||
dbSettings.put(Environment.URL, "jdbc:h2:mem:spring_hibernate_one_to_many");
|
||||
dbSettings.put(Environment.USER, "sa");
|
||||
dbSettings.put(Environment.PASS, "");
|
||||
dbSettings.put(Environment.DRIVER, "org.h2.Driver");
|
||||
dbSettings.put(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread");
|
||||
dbSettings.put(Environment.SHOW_SQL, "true");
|
||||
dbSettings.put(Environment.HBM2DDL_AUTO, "create");
|
||||
return dbSettings;
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package com.baeldung.hibernate;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.Properties;
|
||||
import javax.sql.DataSource;
|
||||
import org.apache.tomcat.dbcp.dbcp2.BasicDataSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
|
||||
import org.springframework.orm.hibernate5.HibernateTransactionManager;
|
||||
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
@PropertySource({ "classpath:persistence-h2.properties" })
|
||||
public class PersistenceConfig {
|
||||
|
||||
@Autowired
|
||||
private Environment env;
|
||||
|
||||
@Bean
|
||||
public LocalSessionFactoryBean sessionFactory() {
|
||||
final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
|
||||
sessionFactory.setDataSource(dataSource());
|
||||
sessionFactory.setPackagesToScan(new String[] { "com.baeldung.hibernate" });
|
||||
sessionFactory.setHibernateProperties(hibernateProperties());
|
||||
return sessionFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
final BasicDataSource dataSource = new BasicDataSource();
|
||||
dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName")));
|
||||
dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url")));
|
||||
dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user")));
|
||||
dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass")));
|
||||
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager hibernateTransactionManager() {
|
||||
final HibernateTransactionManager transactionManager = new HibernateTransactionManager();
|
||||
transactionManager.setSessionFactory(sessionFactory().getObject());
|
||||
return transactionManager;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
|
||||
return new PersistenceExceptionTranslationPostProcessor();
|
||||
}
|
||||
|
||||
private final Properties hibernateProperties() {
|
||||
final Properties hibernateProperties = new Properties();
|
||||
hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
|
||||
hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
|
||||
hibernateProperties.setProperty("hibernate.show_sql", "false");
|
||||
return hibernateProperties;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
# jdbc.X
|
||||
jdbc.driverClassName=org.h2.Driver
|
||||
jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
|
||||
jdbc.eventGeneratedId=sa
|
||||
jdbc.user=sa
|
||||
jdbc.pass=
|
||||
|
||||
# hibernate.X
|
||||
hibernate.dialect=org.hibernate.dialect.H2Dialect
|
||||
hibernate.show_sql=false
|
||||
hibernate.hbm2ddl.auto=create-drop
|
||||
hibernate.cache.use_second_level_cache=true
|
||||
hibernate.cache.use_query_cache=true
|
||||
hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
import com.baeldung.hibernate.PersistenceConfig;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
public class SpringContextTest {
|
||||
|
||||
@Test
|
||||
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.baeldung.hibernate.subselect;
|
||||
|
||||
import com.baeldung.hibernate.oneToMany.config.HibernateAnnotationUtil;
|
||||
import com.baeldung.hibernate.HibernateAnnotationUtil;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
import liquibase.Contexts;
|
||||
import liquibase.LabelExpression;
|
@ -4,7 +4,6 @@ import com.baeldung.hibernate.oneToMany.model.Cart;
|
||||
import com.baeldung.hibernate.oneToMany.model.CartOIO;
|
||||
import com.baeldung.hibernate.oneToMany.model.Item;
|
||||
import com.baeldung.hibernate.oneToMany.model.ItemOIO;
|
||||
import com.baeldung.hibernate.subselect.RuntimeConfiguration;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
@ -39,7 +38,6 @@ public class HibernateAnnotationUtil {
|
||||
.addAnnotatedClass(CartOIO.class)
|
||||
.addAnnotatedClass(Item.class)
|
||||
.addAnnotatedClass(ItemOIO.class)
|
||||
.addAnnotatedClass(RuntimeConfiguration.class)
|
||||
.buildMetadata();
|
||||
|
||||
return metadata.buildSessionFactory();
|
||||
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is generated by jOOQ.
|
||||
*/
|
||||
package com.baeldung.jooq.jointables;
|
||||
|
||||
|
||||
import com.baeldung.jooq.jointables.public_.Public;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.jooq.Constants;
|
||||
import org.jooq.Schema;
|
||||
import org.jooq.impl.CatalogImpl;
|
||||
|
||||
|
||||
/**
|
||||
* This class is generated by jOOQ.
|
||||
*/
|
||||
@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
|
||||
public class DefaultCatalog extends CatalogImpl {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* The reference instance of <code>DEFAULT_CATALOG</code>
|
||||
*/
|
||||
public static final DefaultCatalog DEFAULT_CATALOG = new DefaultCatalog();
|
||||
|
||||
/**
|
||||
* The schema <code>public</code>.
|
||||
*/
|
||||
public final Public PUBLIC = Public.PUBLIC;
|
||||
|
||||
/**
|
||||
* No further instances allowed
|
||||
*/
|
||||
private DefaultCatalog() {
|
||||
super("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<Schema> getSchemas() {
|
||||
return Arrays.asList(
|
||||
Public.PUBLIC
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A reference to the 3.19 minor release of the code generator. If this
|
||||
* doesn't compile, it's because the runtime library uses an older minor
|
||||
* release, namely: 3.19. You can turn off the generation of this reference
|
||||
* by specifying /configuration/generator/generate/jooqVersionReference
|
||||
*/
|
||||
private static final String REQUIRE_RUNTIME_JOOQ_VERSION = Constants.VERSION_3_19;
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package com.baeldung.jooq.jointables;
|
||||
|
||||
import static org.jooq.impl.DSL.field;
|
||||
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Result;
|
||||
import org.jooq.SelectJoinStep;
|
||||
|
||||
import com.baeldung.jooq.jointables.public_.Tables;
|
||||
|
||||
public class JoinTables {
|
||||
|
||||
public static Result<Record> usingJoinMethod(DSLContext context) {
|
||||
SelectJoinStep<Record> query = context.select()
|
||||
.from(Tables.BOOK)
|
||||
.join(Tables.BOOKAUTHOR)
|
||||
.on(field(Tables.BOOK.AUTHOR_ID).eq(field(Tables.BOOKAUTHOR.ID)));
|
||||
return query.fetch();
|
||||
}
|
||||
|
||||
public static Result<Record> usingMultipleJoinMethod(DSLContext context) {
|
||||
SelectJoinStep<Record> query = context.select()
|
||||
.from(Tables.BOOK)
|
||||
.join(Tables.BOOKAUTHOR)
|
||||
.on(field(Tables.BOOK.AUTHOR_ID).eq(field(Tables.BOOKAUTHOR.ID)))
|
||||
.join(Tables.STORE)
|
||||
.on(field(Tables.BOOK.STORE_ID).eq(field(Tables.STORE.ID)));
|
||||
return query.fetch();
|
||||
}
|
||||
|
||||
public static Result<Record> usingLeftOuterJoinMethod(DSLContext context) {
|
||||
SelectJoinStep<Record> query = context.select()
|
||||
.from(Tables.BOOK)
|
||||
.leftOuterJoin(Tables.BOOKAUTHOR)
|
||||
.on(field(Tables.BOOK.AUTHOR_ID).eq(field(Tables.BOOKAUTHOR.ID)));
|
||||
return query.fetch();
|
||||
}
|
||||
|
||||
public static Result<Record> usingRightOuterJoinMethod(DSLContext context) {
|
||||
SelectJoinStep<Record> query = context.select()
|
||||
.from(Tables.BOOK)
|
||||
.rightOuterJoin(Tables.BOOKAUTHOR)
|
||||
.on(field(Tables.BOOK.AUTHOR_ID).eq(field(Tables.BOOKAUTHOR.ID)));
|
||||
return query.fetch();
|
||||
}
|
||||
|
||||
public static Result<Record> usingFullOuterJoinMethod(DSLContext context) {
|
||||
SelectJoinStep<Record> query = context.select()
|
||||
.from(Tables.BOOK)
|
||||
.fullOuterJoin(Tables.BOOKAUTHOR)
|
||||
.on(field(Tables.BOOK.AUTHOR_ID).eq(field(Tables.BOOKAUTHOR.ID)));
|
||||
return query.fetch();
|
||||
}
|
||||
|
||||
public static Result<Record> usingNaturalJoinMethod(DSLContext context) {
|
||||
SelectJoinStep<Record> query = context.select()
|
||||
.from(Tables.BOOK)
|
||||
.naturalJoin(Tables.BOOKAUTHOR);
|
||||
return query.fetch();
|
||||
}
|
||||
|
||||
public static Result<Record> usingCrossJoinMethod(DSLContext context) {
|
||||
SelectJoinStep<Record> query = context.select()
|
||||
.from(Tables.STORE)
|
||||
.crossJoin(Tables.BOOK);
|
||||
return query.fetch();
|
||||
}
|
||||
|
||||
public static void printResult(Result<Record> result) {
|
||||
for (Record record : result) {
|
||||
System.out.println(record);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is generated by jOOQ.
|
||||
*/
|
||||
package com.baeldung.jooq.jointables.public_;
|
||||
|
||||
|
||||
import com.baeldung.jooq.jointables.public_.tables.Book;
|
||||
import com.baeldung.jooq.jointables.public_.tables.Bookauthor;
|
||||
import com.baeldung.jooq.jointables.public_.tables.Store;
|
||||
import com.baeldung.jooq.jointables.public_.tables.records.BookRecord;
|
||||
import com.baeldung.jooq.jointables.public_.tables.records.BookauthorRecord;
|
||||
import com.baeldung.jooq.jointables.public_.tables.records.StoreRecord;
|
||||
|
||||
import org.jooq.TableField;
|
||||
import org.jooq.UniqueKey;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.jooq.impl.Internal;
|
||||
|
||||
|
||||
/**
|
||||
* A class modelling foreign key relationships and constraints of tables in
|
||||
* public.
|
||||
*/
|
||||
@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
|
||||
public class Keys {
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// UNIQUE and PRIMARY KEY definitions
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public static final UniqueKey<BookRecord> BOOK_PKEY = Internal.createUniqueKey(Book.BOOK, DSL.name("Book_pkey"), new TableField[] { Book.BOOK.ID }, true);
|
||||
public static final UniqueKey<BookauthorRecord> AUTHOR_PKEY = Internal.createUniqueKey(Bookauthor.BOOKAUTHOR, DSL.name("Author_pkey"), new TableField[] { Bookauthor.BOOKAUTHOR.ID }, true);
|
||||
public static final UniqueKey<StoreRecord> STORE_PKEY = Internal.createUniqueKey(Store.STORE, DSL.name("Store_pkey"), new TableField[] { Store.STORE.ID }, true);
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* This file is generated by jOOQ.
|
||||
*/
|
||||
package com.baeldung.jooq.jointables.public_;
|
||||
|
||||
|
||||
import com.baeldung.jooq.jointables.DefaultCatalog;
|
||||
import com.baeldung.jooq.jointables.public_.tables.Book;
|
||||
import com.baeldung.jooq.jointables.public_.tables.Bookauthor;
|
||||
import com.baeldung.jooq.jointables.public_.tables.Store;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.jooq.Catalog;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.impl.SchemaImpl;
|
||||
|
||||
|
||||
/**
|
||||
* This class is generated by jOOQ.
|
||||
*/
|
||||
@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
|
||||
public class Public extends SchemaImpl {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* The reference instance of <code>public</code>
|
||||
*/
|
||||
public static final Public PUBLIC = new Public();
|
||||
|
||||
/**
|
||||
* The table <code>public.Book</code>.
|
||||
*/
|
||||
public final Book BOOK = Book.BOOK;
|
||||
|
||||
/**
|
||||
* The table <code>public.BookAuthor</code>.
|
||||
*/
|
||||
public final Bookauthor BOOKAUTHOR = Bookauthor.BOOKAUTHOR;
|
||||
|
||||
/**
|
||||
* The table <code>public.Store</code>.
|
||||
*/
|
||||
public final Store STORE = Store.STORE;
|
||||
|
||||
/**
|
||||
* No further instances allowed
|
||||
*/
|
||||
private Public() {
|
||||
super("public", null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Catalog getCatalog() {
|
||||
return DefaultCatalog.DEFAULT_CATALOG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<Table<?>> getTables() {
|
||||
return Arrays.asList(
|
||||
Book.BOOK,
|
||||
Bookauthor.BOOKAUTHOR,
|
||||
Store.STORE
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is generated by jOOQ.
|
||||
*/
|
||||
package com.baeldung.jooq.jointables.public_;
|
||||
|
||||
|
||||
import com.baeldung.jooq.jointables.public_.tables.Book;
|
||||
import com.baeldung.jooq.jointables.public_.tables.Bookauthor;
|
||||
import com.baeldung.jooq.jointables.public_.tables.Store;
|
||||
|
||||
|
||||
/**
|
||||
* Convenience access to all tables in public.
|
||||
*/
|
||||
@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
|
||||
public class Tables {
|
||||
|
||||
/**
|
||||
* The table <code>public.Book</code>.
|
||||
*/
|
||||
public static final Book BOOK = Book.BOOK;
|
||||
|
||||
/**
|
||||
* The table <code>public.BookAuthor</code>.
|
||||
*/
|
||||
public static final Bookauthor BOOKAUTHOR = Bookauthor.BOOKAUTHOR;
|
||||
|
||||
/**
|
||||
* The table <code>public.Store</code>.
|
||||
*/
|
||||
public static final Store STORE = Store.STORE;
|
||||
}
|
@ -0,0 +1,238 @@
|
||||
/*
|
||||
* This file is generated by jOOQ.
|
||||
*/
|
||||
package com.baeldung.jooq.jointables.public_.tables;
|
||||
|
||||
|
||||
import com.baeldung.jooq.jointables.public_.Keys;
|
||||
import com.baeldung.jooq.jointables.public_.Public;
|
||||
import com.baeldung.jooq.jointables.public_.tables.records.BookRecord;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.Name;
|
||||
import org.jooq.PlainSQL;
|
||||
import org.jooq.QueryPart;
|
||||
import org.jooq.SQL;
|
||||
import org.jooq.Schema;
|
||||
import org.jooq.Select;
|
||||
import org.jooq.Stringly;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableField;
|
||||
import org.jooq.TableOptions;
|
||||
import org.jooq.UniqueKey;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.jooq.impl.SQLDataType;
|
||||
import org.jooq.impl.TableImpl;
|
||||
|
||||
|
||||
/**
|
||||
* This class is generated by jOOQ.
|
||||
*/
|
||||
@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
|
||||
public class Book extends TableImpl<BookRecord> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* The reference instance of <code>public.Book</code>
|
||||
*/
|
||||
public static final Book BOOK = new Book();
|
||||
|
||||
/**
|
||||
* The class holding records for this type
|
||||
*/
|
||||
@Override
|
||||
public Class<BookRecord> getRecordType() {
|
||||
return BookRecord.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* The column <code>public.Book.id</code>.
|
||||
*/
|
||||
public final TableField<BookRecord, Integer> ID = createField(DSL.name("id"), SQLDataType.INTEGER.nullable(false), this, "");
|
||||
|
||||
/**
|
||||
* The column <code>public.Book.author_id</code>.
|
||||
*/
|
||||
public final TableField<BookRecord, Integer> AUTHOR_ID = createField(DSL.name("author_id"), SQLDataType.INTEGER, this, "");
|
||||
|
||||
/**
|
||||
* The column <code>public.Book.title</code>.
|
||||
*/
|
||||
public final TableField<BookRecord, String> TITLE = createField(DSL.name("title"), SQLDataType.VARCHAR, this, "");
|
||||
|
||||
/**
|
||||
* The column <code>public.Book.description</code>.
|
||||
*/
|
||||
public final TableField<BookRecord, String> DESCRIPTION = createField(DSL.name("description"), SQLDataType.VARCHAR, this, "");
|
||||
|
||||
/**
|
||||
* The column <code>public.Book.store_id</code>.
|
||||
*/
|
||||
public final TableField<BookRecord, Integer> STORE_ID = createField(DSL.name("store_id"), SQLDataType.INTEGER, this, "");
|
||||
|
||||
private Book(Name alias, Table<BookRecord> aliased) {
|
||||
this(alias, aliased, (Field<?>[]) null, null);
|
||||
}
|
||||
|
||||
private Book(Name alias, Table<BookRecord> aliased, Field<?>[] parameters, Condition where) {
|
||||
super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table(), where);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an aliased <code>public.Book</code> table reference
|
||||
*/
|
||||
public Book(String alias) {
|
||||
this(DSL.name(alias), BOOK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an aliased <code>public.Book</code> table reference
|
||||
*/
|
||||
public Book(Name alias) {
|
||||
this(alias, BOOK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a <code>public.Book</code> table reference
|
||||
*/
|
||||
public Book() {
|
||||
this(DSL.name("Book"), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Schema getSchema() {
|
||||
return aliased() ? null : Public.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UniqueKey<BookRecord> getPrimaryKey() {
|
||||
return Keys.BOOK_PKEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Book as(String alias) {
|
||||
return new Book(DSL.name(alias), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Book as(Name alias) {
|
||||
return new Book(alias, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Book as(Table<?> alias) {
|
||||
return new Book(alias.getQualifiedName(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename this table
|
||||
*/
|
||||
@Override
|
||||
public Book rename(String name) {
|
||||
return new Book(DSL.name(name), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename this table
|
||||
*/
|
||||
@Override
|
||||
public Book rename(Name name) {
|
||||
return new Book(name, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename this table
|
||||
*/
|
||||
@Override
|
||||
public Book rename(Table<?> name) {
|
||||
return new Book(name.getQualifiedName(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
public Book where(Condition condition) {
|
||||
return new Book(getQualifiedName(), aliased() ? this : null, null, condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
public Book where(Collection<? extends Condition> conditions) {
|
||||
return where(DSL.and(conditions));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
public Book where(Condition... conditions) {
|
||||
return where(DSL.and(conditions));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
public Book where(Field<Boolean> condition) {
|
||||
return where(DSL.condition(condition));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
@PlainSQL
|
||||
public Book where(SQL condition) {
|
||||
return where(DSL.condition(condition));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
@PlainSQL
|
||||
public Book where(@Stringly.SQL String condition) {
|
||||
return where(DSL.condition(condition));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
@PlainSQL
|
||||
public Book where(@Stringly.SQL String condition, Object... binds) {
|
||||
return where(DSL.condition(condition, binds));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
@PlainSQL
|
||||
public Book where(@Stringly.SQL String condition, QueryPart... parts) {
|
||||
return where(DSL.condition(condition, parts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
public Book whereExists(Select<?> select) {
|
||||
return where(DSL.exists(select));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
public Book whereNotExists(Select<?> select) {
|
||||
return where(DSL.notExists(select));
|
||||
}
|
||||
}
|
@ -0,0 +1,228 @@
|
||||
/*
|
||||
* This file is generated by jOOQ.
|
||||
*/
|
||||
package com.baeldung.jooq.jointables.public_.tables;
|
||||
|
||||
|
||||
import com.baeldung.jooq.jointables.public_.Keys;
|
||||
import com.baeldung.jooq.jointables.public_.Public;
|
||||
import com.baeldung.jooq.jointables.public_.tables.records.BookauthorRecord;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.Name;
|
||||
import org.jooq.PlainSQL;
|
||||
import org.jooq.QueryPart;
|
||||
import org.jooq.SQL;
|
||||
import org.jooq.Schema;
|
||||
import org.jooq.Select;
|
||||
import org.jooq.Stringly;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableField;
|
||||
import org.jooq.TableOptions;
|
||||
import org.jooq.UniqueKey;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.jooq.impl.SQLDataType;
|
||||
import org.jooq.impl.TableImpl;
|
||||
|
||||
|
||||
/**
|
||||
* This class is generated by jOOQ.
|
||||
*/
|
||||
@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
|
||||
public class Bookauthor extends TableImpl<BookauthorRecord> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* The reference instance of <code>public.BookAuthor</code>
|
||||
*/
|
||||
public static final Bookauthor BOOKAUTHOR = new Bookauthor();
|
||||
|
||||
/**
|
||||
* The class holding records for this type
|
||||
*/
|
||||
@Override
|
||||
public Class<BookauthorRecord> getRecordType() {
|
||||
return BookauthorRecord.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* The column <code>public.BookAuthor.id</code>.
|
||||
*/
|
||||
public final TableField<BookauthorRecord, Integer> ID = createField(DSL.name("id"), SQLDataType.INTEGER.nullable(false), this, "");
|
||||
|
||||
/**
|
||||
* The column <code>public.BookAuthor.name</code>.
|
||||
*/
|
||||
public final TableField<BookauthorRecord, String> NAME = createField(DSL.name("name"), SQLDataType.VARCHAR.nullable(false), this, "");
|
||||
|
||||
/**
|
||||
* The column <code>public.BookAuthor.country</code>.
|
||||
*/
|
||||
public final TableField<BookauthorRecord, String> COUNTRY = createField(DSL.name("country"), SQLDataType.VARCHAR, this, "");
|
||||
|
||||
private Bookauthor(Name alias, Table<BookauthorRecord> aliased) {
|
||||
this(alias, aliased, (Field<?>[]) null, null);
|
||||
}
|
||||
|
||||
private Bookauthor(Name alias, Table<BookauthorRecord> aliased, Field<?>[] parameters, Condition where) {
|
||||
super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table(), where);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an aliased <code>public.BookAuthor</code> table reference
|
||||
*/
|
||||
public Bookauthor(String alias) {
|
||||
this(DSL.name(alias), BOOKAUTHOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an aliased <code>public.BookAuthor</code> table reference
|
||||
*/
|
||||
public Bookauthor(Name alias) {
|
||||
this(alias, BOOKAUTHOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a <code>public.BookAuthor</code> table reference
|
||||
*/
|
||||
public Bookauthor() {
|
||||
this(DSL.name("BookAuthor"), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Schema getSchema() {
|
||||
return aliased() ? null : Public.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UniqueKey<BookauthorRecord> getPrimaryKey() {
|
||||
return Keys.AUTHOR_PKEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bookauthor as(String alias) {
|
||||
return new Bookauthor(DSL.name(alias), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bookauthor as(Name alias) {
|
||||
return new Bookauthor(alias, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bookauthor as(Table<?> alias) {
|
||||
return new Bookauthor(alias.getQualifiedName(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename this table
|
||||
*/
|
||||
@Override
|
||||
public Bookauthor rename(String name) {
|
||||
return new Bookauthor(DSL.name(name), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename this table
|
||||
*/
|
||||
@Override
|
||||
public Bookauthor rename(Name name) {
|
||||
return new Bookauthor(name, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename this table
|
||||
*/
|
||||
@Override
|
||||
public Bookauthor rename(Table<?> name) {
|
||||
return new Bookauthor(name.getQualifiedName(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
public Bookauthor where(Condition condition) {
|
||||
return new Bookauthor(getQualifiedName(), aliased() ? this : null, null, condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
public Bookauthor where(Collection<? extends Condition> conditions) {
|
||||
return where(DSL.and(conditions));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
public Bookauthor where(Condition... conditions) {
|
||||
return where(DSL.and(conditions));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
public Bookauthor where(Field<Boolean> condition) {
|
||||
return where(DSL.condition(condition));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
@PlainSQL
|
||||
public Bookauthor where(SQL condition) {
|
||||
return where(DSL.condition(condition));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
@PlainSQL
|
||||
public Bookauthor where(@Stringly.SQL String condition) {
|
||||
return where(DSL.condition(condition));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
@PlainSQL
|
||||
public Bookauthor where(@Stringly.SQL String condition, Object... binds) {
|
||||
return where(DSL.condition(condition, binds));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
@PlainSQL
|
||||
public Bookauthor where(@Stringly.SQL String condition, QueryPart... parts) {
|
||||
return where(DSL.condition(condition, parts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
public Bookauthor whereExists(Select<?> select) {
|
||||
return where(DSL.exists(select));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
public Bookauthor whereNotExists(Select<?> select) {
|
||||
return where(DSL.notExists(select));
|
||||
}
|
||||
}
|
@ -0,0 +1,223 @@
|
||||
/*
|
||||
* This file is generated by jOOQ.
|
||||
*/
|
||||
package com.baeldung.jooq.jointables.public_.tables;
|
||||
|
||||
|
||||
import com.baeldung.jooq.jointables.public_.Keys;
|
||||
import com.baeldung.jooq.jointables.public_.Public;
|
||||
import com.baeldung.jooq.jointables.public_.tables.records.StoreRecord;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.Name;
|
||||
import org.jooq.PlainSQL;
|
||||
import org.jooq.QueryPart;
|
||||
import org.jooq.SQL;
|
||||
import org.jooq.Schema;
|
||||
import org.jooq.Select;
|
||||
import org.jooq.Stringly;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableField;
|
||||
import org.jooq.TableOptions;
|
||||
import org.jooq.UniqueKey;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.jooq.impl.SQLDataType;
|
||||
import org.jooq.impl.TableImpl;
|
||||
|
||||
|
||||
/**
|
||||
* This class is generated by jOOQ.
|
||||
*/
|
||||
@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
|
||||
public class Store extends TableImpl<StoreRecord> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* The reference instance of <code>public.Store</code>
|
||||
*/
|
||||
public static final Store STORE = new Store();
|
||||
|
||||
/**
|
||||
* The class holding records for this type
|
||||
*/
|
||||
@Override
|
||||
public Class<StoreRecord> getRecordType() {
|
||||
return StoreRecord.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* The column <code>public.Store.id</code>.
|
||||
*/
|
||||
public final TableField<StoreRecord, Integer> ID = createField(DSL.name("id"), SQLDataType.INTEGER.nullable(false), this, "");
|
||||
|
||||
/**
|
||||
* The column <code>public.Store.name</code>.
|
||||
*/
|
||||
public final TableField<StoreRecord, String> NAME = createField(DSL.name("name"), SQLDataType.VARCHAR.nullable(false), this, "");
|
||||
|
||||
private Store(Name alias, Table<StoreRecord> aliased) {
|
||||
this(alias, aliased, (Field<?>[]) null, null);
|
||||
}
|
||||
|
||||
private Store(Name alias, Table<StoreRecord> aliased, Field<?>[] parameters, Condition where) {
|
||||
super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table(), where);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an aliased <code>public.Store</code> table reference
|
||||
*/
|
||||
public Store(String alias) {
|
||||
this(DSL.name(alias), STORE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an aliased <code>public.Store</code> table reference
|
||||
*/
|
||||
public Store(Name alias) {
|
||||
this(alias, STORE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a <code>public.Store</code> table reference
|
||||
*/
|
||||
public Store() {
|
||||
this(DSL.name("Store"), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Schema getSchema() {
|
||||
return aliased() ? null : Public.PUBLIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UniqueKey<StoreRecord> getPrimaryKey() {
|
||||
return Keys.STORE_PKEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Store as(String alias) {
|
||||
return new Store(DSL.name(alias), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Store as(Name alias) {
|
||||
return new Store(alias, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Store as(Table<?> alias) {
|
||||
return new Store(alias.getQualifiedName(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename this table
|
||||
*/
|
||||
@Override
|
||||
public Store rename(String name) {
|
||||
return new Store(DSL.name(name), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename this table
|
||||
*/
|
||||
@Override
|
||||
public Store rename(Name name) {
|
||||
return new Store(name, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename this table
|
||||
*/
|
||||
@Override
|
||||
public Store rename(Table<?> name) {
|
||||
return new Store(name.getQualifiedName(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
public Store where(Condition condition) {
|
||||
return new Store(getQualifiedName(), aliased() ? this : null, null, condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
public Store where(Collection<? extends Condition> conditions) {
|
||||
return where(DSL.and(conditions));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
public Store where(Condition... conditions) {
|
||||
return where(DSL.and(conditions));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
public Store where(Field<Boolean> condition) {
|
||||
return where(DSL.condition(condition));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
@PlainSQL
|
||||
public Store where(SQL condition) {
|
||||
return where(DSL.condition(condition));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
@PlainSQL
|
||||
public Store where(@Stringly.SQL String condition) {
|
||||
return where(DSL.condition(condition));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
@PlainSQL
|
||||
public Store where(@Stringly.SQL String condition, Object... binds) {
|
||||
return where(DSL.condition(condition, binds));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
@PlainSQL
|
||||
public Store where(@Stringly.SQL String condition, QueryPart... parts) {
|
||||
return where(DSL.condition(condition, parts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
public Store whereExists(Select<?> select) {
|
||||
return where(DSL.exists(select));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline derived table from this table
|
||||
*/
|
||||
@Override
|
||||
public Store whereNotExists(Select<?> select) {
|
||||
return where(DSL.notExists(select));
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* This file is generated by jOOQ.
|
||||
*/
|
||||
package com.baeldung.jooq.jointables.public_.tables.records;
|
||||
|
||||
|
||||
import com.baeldung.jooq.jointables.public_.tables.Book;
|
||||
|
||||
import org.jooq.Record1;
|
||||
import org.jooq.impl.UpdatableRecordImpl;
|
||||
|
||||
|
||||
/**
|
||||
* This class is generated by jOOQ.
|
||||
*/
|
||||
@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
|
||||
public class BookRecord extends UpdatableRecordImpl<BookRecord> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Setter for <code>public.Book.id</code>.
|
||||
*/
|
||||
public void setId(Integer value) {
|
||||
set(0, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>public.Book.id</code>.
|
||||
*/
|
||||
public Integer getId() {
|
||||
return (Integer) get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>public.Book.author_id</code>.
|
||||
*/
|
||||
public void setAuthorId(Integer value) {
|
||||
set(1, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>public.Book.author_id</code>.
|
||||
*/
|
||||
public Integer getAuthorId() {
|
||||
return (Integer) get(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>public.Book.title</code>.
|
||||
*/
|
||||
public void setTitle(String value) {
|
||||
set(2, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>public.Book.title</code>.
|
||||
*/
|
||||
public String getTitle() {
|
||||
return (String) get(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>public.Book.description</code>.
|
||||
*/
|
||||
public void setDescription(String value) {
|
||||
set(3, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>public.Book.description</code>.
|
||||
*/
|
||||
public String getDescription() {
|
||||
return (String) get(3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>public.Book.store_id</code>.
|
||||
*/
|
||||
public void setStoreId(Integer value) {
|
||||
set(4, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>public.Book.store_id</code>.
|
||||
*/
|
||||
public Integer getStoreId() {
|
||||
return (Integer) get(4);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Primary key information
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public Record1<Integer> key() {
|
||||
return (Record1) super.key();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Constructors
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create a detached BookRecord
|
||||
*/
|
||||
public BookRecord() {
|
||||
super(Book.BOOK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a detached, initialised BookRecord
|
||||
*/
|
||||
public BookRecord(Integer id, Integer authorId, String title, String description, Integer storeId) {
|
||||
super(Book.BOOK);
|
||||
|
||||
setId(id);
|
||||
setAuthorId(authorId);
|
||||
setTitle(title);
|
||||
setDescription(description);
|
||||
setStoreId(storeId);
|
||||
resetChangedOnNotNull();
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* This file is generated by jOOQ.
|
||||
*/
|
||||
package com.baeldung.jooq.jointables.public_.tables.records;
|
||||
|
||||
|
||||
import com.baeldung.jooq.jointables.public_.tables.Bookauthor;
|
||||
|
||||
import org.jooq.Record1;
|
||||
import org.jooq.impl.UpdatableRecordImpl;
|
||||
|
||||
|
||||
/**
|
||||
* This class is generated by jOOQ.
|
||||
*/
|
||||
@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
|
||||
public class BookauthorRecord extends UpdatableRecordImpl<BookauthorRecord> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Setter for <code>public.BookAuthor.id</code>.
|
||||
*/
|
||||
public void setId(Integer value) {
|
||||
set(0, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>public.BookAuthor.id</code>.
|
||||
*/
|
||||
public Integer getId() {
|
||||
return (Integer) get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>public.BookAuthor.name</code>.
|
||||
*/
|
||||
public void setName(String value) {
|
||||
set(1, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>public.BookAuthor.name</code>.
|
||||
*/
|
||||
public String getName() {
|
||||
return (String) get(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>public.BookAuthor.country</code>.
|
||||
*/
|
||||
public void setCountry(String value) {
|
||||
set(2, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>public.BookAuthor.country</code>.
|
||||
*/
|
||||
public String getCountry() {
|
||||
return (String) get(2);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Primary key information
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public Record1<Integer> key() {
|
||||
return (Record1) super.key();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Constructors
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create a detached BookauthorRecord
|
||||
*/
|
||||
public BookauthorRecord() {
|
||||
super(Bookauthor.BOOKAUTHOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a detached, initialised BookauthorRecord
|
||||
*/
|
||||
public BookauthorRecord(Integer id, String name, String country) {
|
||||
super(Bookauthor.BOOKAUTHOR);
|
||||
|
||||
setId(id);
|
||||
setName(name);
|
||||
setCountry(country);
|
||||
resetChangedOnNotNull();
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is generated by jOOQ.
|
||||
*/
|
||||
package com.baeldung.jooq.jointables.public_.tables.records;
|
||||
|
||||
|
||||
import com.baeldung.jooq.jointables.public_.tables.Store;
|
||||
|
||||
import org.jooq.Record1;
|
||||
import org.jooq.impl.UpdatableRecordImpl;
|
||||
|
||||
|
||||
/**
|
||||
* This class is generated by jOOQ.
|
||||
*/
|
||||
@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
|
||||
public class StoreRecord extends UpdatableRecordImpl<StoreRecord> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Setter for <code>public.Store.id</code>.
|
||||
*/
|
||||
public void setId(Integer value) {
|
||||
set(0, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>public.Store.id</code>.
|
||||
*/
|
||||
public Integer getId() {
|
||||
return (Integer) get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>public.Store.name</code>.
|
||||
*/
|
||||
public void setName(String value) {
|
||||
set(1, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>public.Store.name</code>.
|
||||
*/
|
||||
public String getName() {
|
||||
return (String) get(1);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Primary key information
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public Record1<Integer> key() {
|
||||
return (Record1) super.key();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Constructors
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create a detached StoreRecord
|
||||
*/
|
||||
public StoreRecord() {
|
||||
super(Store.STORE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a detached, initialised StoreRecord
|
||||
*/
|
||||
public StoreRecord(Integer id, String name) {
|
||||
super(Store.STORE);
|
||||
|
||||
setId(id);
|
||||
setName(name);
|
||||
resetChangedOnNotNull();
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user