+30
@@ -0,0 +1,30 @@
|
||||
package com.baeldung.algorithms.linkedlist;
|
||||
|
||||
public class LinkedListReversal {
|
||||
|
||||
ListNode reverseList(ListNode head) {
|
||||
ListNode previous = null;
|
||||
ListNode current = head;
|
||||
while (current != null) {
|
||||
ListNode nextElement = current.getNext();
|
||||
current.setNext(previous);
|
||||
previous = current;
|
||||
current = nextElement;
|
||||
}
|
||||
return previous;
|
||||
}
|
||||
|
||||
ListNode reverseListRecursive(ListNode head) {
|
||||
if (head == null) {
|
||||
return null;
|
||||
}
|
||||
if (head.getNext() == null) {
|
||||
return head;
|
||||
}
|
||||
ListNode node = reverseListRecursive(head.getNext());
|
||||
head.getNext().setNext(head);
|
||||
head.setNext(null);
|
||||
return node;
|
||||
}
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.baeldung.algorithms.linkedlist;
|
||||
|
||||
public class ListNode {
|
||||
|
||||
private int data;
|
||||
private ListNode next;
|
||||
|
||||
ListNode(int data) {
|
||||
this.data = data;
|
||||
this.next = null;
|
||||
}
|
||||
|
||||
public int getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public ListNode getNext() {
|
||||
return next;
|
||||
}
|
||||
|
||||
public void setData(int data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void setNext(ListNode next) {
|
||||
this.next = next;
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package com.baeldung.algorithms.linkedlist;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class LinkedListReversalUnitTest {
|
||||
@Test
|
||||
public void givenLinkedList_whenIterativeReverse_thenOutputCorrectResult() {
|
||||
ListNode head = constructLinkedList();
|
||||
ListNode node = head;
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
assertNotNull(node);
|
||||
assertEquals(i, node.getData());
|
||||
node = node.getNext();
|
||||
}
|
||||
LinkedListReversal reversal = new LinkedListReversal();
|
||||
node = reversal.reverseList(head);
|
||||
for (int i = 5; i >= 1; i--) {
|
||||
assertNotNull(node);
|
||||
assertEquals(i, node.getData());
|
||||
node = node.getNext();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenLinkedList_whenRecursiveReverse_thenOutputCorrectResult() {
|
||||
ListNode head = constructLinkedList();
|
||||
ListNode node = head;
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
assertNotNull(node);
|
||||
assertEquals(i, node.getData());
|
||||
node = node.getNext();
|
||||
}
|
||||
LinkedListReversal reversal = new LinkedListReversal();
|
||||
node = reversal.reverseListRecursive(head);
|
||||
for (int i = 5; i >= 1; i--) {
|
||||
assertNotNull(node);
|
||||
assertEquals(i, node.getData());
|
||||
node = node.getNext();
|
||||
}
|
||||
}
|
||||
|
||||
private ListNode constructLinkedList() {
|
||||
ListNode head = null;
|
||||
ListNode tail = null;
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
ListNode node = new ListNode(i);
|
||||
if (head == null) {
|
||||
head = node;
|
||||
} else {
|
||||
tail.setNext(node);
|
||||
}
|
||||
tail = node;
|
||||
}
|
||||
return head;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
### Relevant Articles:
|
||||
|
||||
- [How to Remove a Prefix From Strings in Groovy](https://www.baeldung.com/groovy-remove-string-prefix)
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.baeldung.lastmodifiedfile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.commons.io.comparator.LastModifiedFileComparator;
|
||||
import org.apache.commons.io.filefilter.FileFilterUtils;
|
||||
|
||||
public class LastModifiedFileApp {
|
||||
|
||||
public static File findUsingIOApi(String sdir) {
|
||||
File dir = new File(sdir);
|
||||
if (dir.isDirectory()) {
|
||||
Optional<File> opFile = Arrays.stream(dir.listFiles(File::isFile))
|
||||
.max((f1, f2) -> Long.compare(f1.lastModified(), f2.lastModified()));
|
||||
|
||||
if (opFile.isPresent()) {
|
||||
return opFile.get();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Path findUsingNIOApi(String sdir) throws IOException {
|
||||
Path dir = Paths.get(sdir);
|
||||
if (Files.isDirectory(dir)) {
|
||||
Optional<Path> opPath = Files.list(dir)
|
||||
.filter(p -> !Files.isDirectory(p))
|
||||
.sorted((p1, p2) -> Long.valueOf(p2.toFile().lastModified())
|
||||
.compareTo(p1.toFile().lastModified()))
|
||||
.findFirst();
|
||||
|
||||
if (opPath.isPresent()) {
|
||||
return opPath.get();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static File findUsingCommonsIO(String sdir) {
|
||||
File dir = new File(sdir);
|
||||
if (dir.isDirectory()) {
|
||||
File[] dirFiles = dir.listFiles((FileFilter) FileFilterUtils.fileFileFilter());
|
||||
if (dirFiles != null && dirFiles.length > 0) {
|
||||
Arrays.sort(dirFiles, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
|
||||
return dirFiles[0];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package com.baeldung.lastmodifiedfile;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class LastModifiedFileAppUnitTest {
|
||||
|
||||
private final static String SOURCEDIRECTORY = "src/test/resources/lastmodfiles";
|
||||
|
||||
@BeforeAll
|
||||
public static void setUpFiles() throws IOException, InterruptedException {
|
||||
File srcDir = new File(SOURCEDIRECTORY);
|
||||
if (!srcDir.exists()) {
|
||||
srcDir.mkdir();
|
||||
}
|
||||
|
||||
FileUtils.cleanDirectory(srcDir);
|
||||
|
||||
File file01 = new File(SOURCEDIRECTORY + "/file01.txt");
|
||||
file01.createNewFile();
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
File file02 = new File(SOURCEDIRECTORY + "/file02.txt");
|
||||
file02.createNewFile();
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
File file03 = new File(SOURCEDIRECTORY + "/file03.txt");
|
||||
file03.createNewFile();
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
Files.write(Paths.get(SOURCEDIRECTORY + "/file02.txt"), "Hello File02".getBytes());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDirectory_whenUsingIoApi_thenFindLastModfile() throws IOException {
|
||||
File lastModFile = LastModifiedFileApp.findUsingIOApi(SOURCEDIRECTORY);
|
||||
|
||||
assertThat(lastModFile).isNotNull();
|
||||
assertThat(lastModFile.getName()).isEqualTo("file02.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDirectory_whenUsingNioApi_thenFindLastModfile() throws IOException {
|
||||
Path lastModPath = LastModifiedFileApp.findUsingNIOApi(SOURCEDIRECTORY);
|
||||
|
||||
assertThat(lastModPath).isNotNull();
|
||||
assertThat(lastModPath.toFile().getName()).isEqualTo("file02.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDirectory_whenUsingApacheCommons_thenFindLastModfile() throws IOException {
|
||||
File lastModFile = LastModifiedFileApp.findUsingCommonsIO(SOURCEDIRECTORY);
|
||||
|
||||
assertThat(lastModFile).isNotNull();
|
||||
assertThat(lastModFile.getName()).isEqualTo("file02.txt");
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void cleanUp() throws IOException {
|
||||
File srcDir = new File(SOURCEDIRECTORY);
|
||||
FileUtils.deleteDirectory(srcDir);
|
||||
}
|
||||
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package com.baeldung.getclassobject;
|
||||
|
||||
public class Animal {
|
||||
protected int numberOfEyes;
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package com.baeldung.getclassobject;
|
||||
|
||||
public class Monkey extends Animal {
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package com.baeldung.getclassobject;
|
||||
|
||||
public abstract class SomeAbstractClass {
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package com.baeldung.getclassobject;
|
||||
|
||||
interface SomeInterface {
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.baeldung.getclassobject;
|
||||
|
||||
public class SomeUtils {
|
||||
private SomeUtils() {
|
||||
throw new RuntimeException("This Util class is not allowed to be instantiated!");
|
||||
}
|
||||
// public static utilMethods
|
||||
// ...
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.baeldung.getclassobject;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class GetClassObjectUnitTest {
|
||||
@Test
|
||||
public void givenObjectAndType_whenGettingClassObject_thenTwoMethodsHaveTheSameResult() {
|
||||
String str = "I am an object of the String class";
|
||||
Class fromStrObject = str.getClass();
|
||||
Class clazz = String.class;
|
||||
assertSame(fromStrObject, clazz);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenClassInheritance_whenGettingRuntimeTypeAndStaticType_thenGetDifferentResult() {
|
||||
Animal animal = new Monkey();
|
||||
Class runtimeType = animal.getClass();
|
||||
Class staticType = Animal.class;
|
||||
//Not equals
|
||||
assertNotEquals(staticType, runtimeType);
|
||||
|
||||
Class monkeyClass = Monkey.class;
|
||||
assertSame(runtimeType, monkeyClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenPrimitiveType_whenGettingClassObject_thenOnlyStaticTypeWorks() {
|
||||
int number = 7;
|
||||
// Class numberClass = number.getClass(); <-- compilation error
|
||||
Class intType = int.class;
|
||||
|
||||
assertNotNull(intType);
|
||||
assertEquals("int", intType.getName());
|
||||
assertTrue(intType.isPrimitive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTypeCannotInstantiate_whenGetTypeStatically_thenGetTypesSuccefully() {
|
||||
Class interfaceType = SomeInterface.class;
|
||||
Class abstractClassType = SomeAbstractClass.class;
|
||||
Class utilClassType = SomeUtils.class;
|
||||
|
||||
assertNotNull(interfaceType);
|
||||
assertTrue(interfaceType.isInterface());
|
||||
assertEquals("SomeInterface", interfaceType.getSimpleName());
|
||||
|
||||
assertNotNull(abstractClassType);
|
||||
assertEquals("SomeAbstractClass", abstractClassType.getSimpleName());
|
||||
|
||||
assertNotNull(utilClassType);
|
||||
assertEquals("SomeUtils", utilClassType.getSimpleName());
|
||||
}
|
||||
}
|
||||
@@ -9,3 +9,4 @@ This module contains articles about methods in Java
|
||||
- [Java equals() and hashCode() Contracts](https://www.baeldung.com/java-equals-hashcode-contracts)
|
||||
- [Guide to hashCode() in Java](https://www.baeldung.com/java-hashcode)
|
||||
- [The Covariant Return Type in Java](https://www.baeldung.com/java-covariant-return-type)
|
||||
- [Does a Method’s Signature Include the Return Type in Java?](https://www.baeldung.com/java-method-signature-return-type)
|
||||
|
||||
@@ -13,4 +13,5 @@ This module contains articles about networking in Java
|
||||
- [Download a File from an URL in Java](https://www.baeldung.com/java-download-file)
|
||||
- [Handling java.net.ConnectException](https://www.baeldung.com/java-net-connectexception)
|
||||
- [Getting MAC addresses in Java](https://www.baeldung.com/java-mac-address)
|
||||
- [Sending Emails with Attachments in Java](https://www.baeldung.com/java-send-emails-attachments)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-networking)
|
||||
|
||||
@@ -2,3 +2,4 @@
|
||||
|
||||
- [Reading the Value of ‘private’ Fields from a Different Class in Java](https://www.baeldung.com/java-reflection-read-private-field-value)
|
||||
- [Set Field Value With Reflection](https://www.baeldung.com/java-set-private-field-value)
|
||||
- [Checking If a Method is Static Using Reflection in Java](https://www.baeldung.com/java-check-method-is-static)
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
The files in this project were generated using gradle wrapper command.
|
||||
`gradle wrapper`
|
||||
|
||||
To test, download this project on your machine and run the following:
|
||||
`./wrapper tasks`
|
||||
|
||||
This should generate output similar to:
|
||||
```
|
||||
> Task :tasks
|
||||
|
||||
------------------------------------------------------------
|
||||
Tasks runnable from root project
|
||||
------------------------------------------------------------
|
||||
|
||||
Build Setup tasks
|
||||
-----------------
|
||||
init - Initializes a new Gradle build.
|
||||
wrapper - Generates Gradle wrapper files.
|
||||
|
||||
Help tasks
|
||||
----------
|
||||
buildEnvironment - Displays all buildscript dependencies declared in root project 'gradle-wrapper'.
|
||||
components - Displays the components produced by root project 'gradle-wrapper'. [incubating]
|
||||
dependencies - Displays all dependencies declared in root project 'gradle-wrapper'.
|
||||
dependencyInsight - Displays the insight into a specific dependency in root project 'gradle-wrapper'.
|
||||
dependentComponents - Displays the dependent components of components in root project 'gradle-wrapper'. [incubating]
|
||||
help - Displays a help message.
|
||||
model - Displays the configuration model of root project 'gradle-wrapper'. [incubating]
|
||||
outgoingVariants - Displays the outgoing variants of root project 'gradle-wrapper'.
|
||||
projects - Displays the sub-projects of root project 'gradle-wrapper'.
|
||||
properties - Displays the properties of root project 'gradle-wrapper'.
|
||||
tasks - Displays the tasks runnable from root project 'gradle-wrapper'.
|
||||
|
||||
To see all tasks and more detail, run gradlew tasks --all
|
||||
```
|
||||
@@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
+183
@@ -0,0 +1,183 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
Vendored
+103
@@ -0,0 +1,103 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -0,0 +1,13 @@
|
||||
*.class
|
||||
|
||||
#folders#
|
||||
/target
|
||||
/neoDb*
|
||||
/data
|
||||
/src/main/webapp/WEB-INF/classes
|
||||
*/META-INF/*
|
||||
|
||||
# Packaged files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
@@ -0,0 +1,12 @@
|
||||
## HttpClient 4.x
|
||||
|
||||
This module contains articles about HttpClient 4.x
|
||||
|
||||
### The Course
|
||||
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [How to Set TLS Version in Apache HttpClient](https://www.baeldung.com/TODO)
|
||||
- More articles: [[<-- prev]](../httpclient)
|
||||
@@ -0,0 +1,43 @@
|
||||
<?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>httpclient-2</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-java</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-java</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${httpclient.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>httpclient-2</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<httpclient.version>4.5.8</httpclient.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.baeldung.tlsversion;
|
||||
|
||||
import javax.net.ssl.SSLSocket;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.ssl.SSLContexts;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ClientTlsVersionExamples {
|
||||
|
||||
public static CloseableHttpClient setViaSocketFactory() {
|
||||
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
|
||||
SSLContexts.createDefault(),
|
||||
new String[] { "TLSv1.2", "TLSv1.3" },
|
||||
null,
|
||||
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
|
||||
|
||||
return HttpClients.custom().setSSLSocketFactory(sslsf).build();
|
||||
}
|
||||
|
||||
public static CloseableHttpClient setTlsVersionPerConnection() {
|
||||
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(SSLContexts.createDefault()) {
|
||||
|
||||
@Override
|
||||
protected void prepareSocket(SSLSocket socket) {
|
||||
String hostname = socket.getInetAddress().getHostName();
|
||||
if (hostname.endsWith("internal.system.com")) {
|
||||
socket.setEnabledProtocols(new String[] { "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3" });
|
||||
} else {
|
||||
socket.setEnabledProtocols(new String[] { "TLSv1.3" });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return HttpClients.custom().setSSLSocketFactory(sslsf).build();
|
||||
}
|
||||
|
||||
// To configure the TLS versions for the client, set the https.protocols system property during runtime.
|
||||
// For example: java -Dhttps.protocols=TLSv1.1,TLSv1.2,TLSv1.3 -jar webClient.jar
|
||||
public static CloseableHttpClient setViaSystemProperties() {
|
||||
return HttpClients.createSystem();
|
||||
// Alternatively:
|
||||
// return HttpClients.custom().useSystemProperties().build();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
// Alternatively:
|
||||
// CloseableHttpClient httpClient = setTlsVersionPerConnection();
|
||||
// CloseableHttpClient httpClient = setViaSystemProperties();
|
||||
try (CloseableHttpClient httpClient = setViaSocketFactory();
|
||||
CloseableHttpResponse response = httpClient.execute(new HttpGet("https://httpbin.org/"))) {
|
||||
|
||||
HttpEntity entity = response.getEntity();
|
||||
EntityUtils.consume(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,3 +18,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
- [Advanced HttpClient Configuration](https://www.baeldung.com/httpclient-advanced-config)
|
||||
- [HttpClient 4 – Do Not Follow Redirects](https://www.baeldung.com/httpclient-stop-follow-redirect)
|
||||
- [Custom User-Agent in HttpClient 4](https://www.baeldung.com/httpclient-user-agent-header)
|
||||
- More articles: [[next -->]](../httpclient-2)
|
||||
|
||||
@@ -7,4 +7,5 @@ This module contains articles about conversions among Collection types and array
|
||||
- [Array to String Conversions](https://www.baeldung.com/java-array-to-string)
|
||||
- [Mapping Lists with ModelMapper](https://www.baeldung.com/java-modelmapper-lists)
|
||||
- [Converting List to Map With a Custom Supplier](https://www.baeldung.com/list-to-map-supplier)
|
||||
- [Arrays.asList vs new ArrayList(Arrays.asList())](https://www.baeldung.com/java-arrays-aslist-vs-new-arraylist)
|
||||
- More articles: [[<-- prev]](../java-collections-conversions)
|
||||
|
||||
@@ -13,3 +13,4 @@ This module contains articles about JSON.
|
||||
- [Get a Value by Key in a JSONArray](https://www.baeldung.com/java-jsonarray-get-value-by-key)
|
||||
- [Iterating Over an Instance of org.json.JSONObject](https://www.baeldung.com/jsonobject-iteration)
|
||||
- [Escape JSON String in Java](https://www.baeldung.com/java-json-escaping)
|
||||
- [Reducing JSON Data Size](https://www.baeldung.com/json-reduce-data-size)
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<org.mapstruct.version>1.4.0.Beta1</org.mapstruct.version>
|
||||
<org.mapstruct.version>1.3.1.Final</org.mapstruct.version>
|
||||
<springframework.version>4.3.4.RELEASE</springframework.version>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
|
||||
+2
-1
@@ -5,7 +5,8 @@ import com.baeldung.mapstruct.mappingCollections.model.Company;
|
||||
import org.mapstruct.CollectionMappingStrategy;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED)
|
||||
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
|
||||
uses = EmployeeMapper.class)
|
||||
public interface CompanyMapperAdderPreferred {
|
||||
|
||||
CompanyDTO map(Company company);
|
||||
|
||||
+2
@@ -11,6 +11,8 @@ import java.util.Set;
|
||||
@Mapper
|
||||
public interface EmployeeMapper {
|
||||
|
||||
EmployeeDTO map(Employee employee);
|
||||
|
||||
List<EmployeeDTO> map(List<Employee> employees);
|
||||
|
||||
Set<EmployeeDTO> map(Set<Employee> employees);
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jooq</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>jooq-examples</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>jOOQ Examples</description>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>persistence-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jooq</groupId>
|
||||
<artifactId>jooq</artifactId>
|
||||
<version>3.13.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jooq</groupId>
|
||||
<artifactId>jooq-meta</artifactId>
|
||||
<version>3.13.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jooq</groupId>
|
||||
<artifactId>jooq-codegen</artifactId>
|
||||
<version>3.13.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.2.16</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.4.200</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user