diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000000..40f5c88746
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2017 Eugen Paraschiv
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
index d94a786bc2..271aea0767 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,14 @@
The "REST with Spring" Classes
==============================
+
After 5 months of work, here's the Master Class of REST With Spring:
**[>> THE REST WITH SPRING MASTER CLASS](http://www.baeldung.com/rest-with-spring-course?utm_source=github&utm_medium=social&utm_content=tutorials&utm_campaign=rws#master-class)**
+And here's the Master Class of Learn Spring Security:
+**[>> LEARN SPRING SECURITY MASTER CLASS](http://www.baeldung.com/learn-spring-security-course?utm_source=github&utm_medium=social&utm_content=tutorials&utm_campaign=lss#master-class)**
+
+
Spring Tutorials
================
diff --git a/apache-poi/src/main/java/com/baeldung/poi/powerpoint/PowerPointHelper.java b/apache-poi/src/main/java/com/baeldung/poi/powerpoint/PowerPointHelper.java
new file mode 100644
index 0000000000..e2af4f8808
--- /dev/null
+++ b/apache-poi/src/main/java/com/baeldung/poi/powerpoint/PowerPointHelper.java
@@ -0,0 +1,224 @@
+package com.baeldung.poi.powerpoint;
+
+import org.apache.poi.sl.usermodel.AutoNumberingScheme;
+import org.apache.poi.sl.usermodel.PictureData;
+import org.apache.poi.sl.usermodel.TableCell;
+import org.apache.poi.sl.usermodel.TextParagraph;
+import org.apache.poi.util.IOUtils;
+import org.apache.poi.xslf.usermodel.*;
+
+import java.awt.*;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Helper class for the PowerPoint presentation creation
+ */
+public class PowerPointHelper {
+
+ /**
+ * Read an existing presentation
+ *
+ * @param fileLocation
+ * File location of the presentation
+ * @return instance of {@link XMLSlideShow}
+ * @throws IOException
+ */
+ public XMLSlideShow readingExistingSlideShow(String fileLocation) throws IOException {
+ return new XMLSlideShow(new FileInputStream(fileLocation));
+ }
+
+ /**
+ * Create a sample presentation
+ *
+ * @param fileLocation
+ * File location of the presentation
+ * @throws IOException
+ */
+ public void createPresentation(String fileLocation) throws IOException {
+ // Create presentation
+ XMLSlideShow ppt = new XMLSlideShow();
+
+ XSLFSlideMaster defaultMaster = ppt.getSlideMasters().get(0);
+
+ // Retriving the slide layout
+ XSLFSlideLayout layout = defaultMaster.getLayout(SlideLayout.TITLE_ONLY);
+
+ // Creating the 1st slide
+ XSLFSlide slide1 = ppt.createSlide(layout);
+ XSLFTextShape title = slide1.getPlaceholder(0);
+ // Clearing text to remove the predefined one in the template
+ title.clearText();
+ XSLFTextParagraph p = title.addNewTextParagraph();
+
+ XSLFTextRun r1 = p.addNewTextRun();
+ r1.setText("Baeldung");
+ r1.setFontColor(new Color(78, 147, 89));
+ r1.setFontSize(48.);
+
+ // Add Image
+ ClassLoader classLoader = getClass().getClassLoader();
+ byte[] pictureData = IOUtils.toByteArray(new FileInputStream(classLoader.getResource("logo-leaf.png").getFile()));
+
+ XSLFPictureData pd = ppt.addPicture(pictureData, PictureData.PictureType.PNG);
+ XSLFPictureShape picture = slide1.createPicture(pd);
+ picture.setAnchor(new Rectangle(320, 230, 100, 92));
+
+ // Creating 2nd slide
+ layout = defaultMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
+ XSLFSlide slide2 = ppt.createSlide(layout);
+
+ // setting the tile
+ title = slide2.getPlaceholder(0);
+ title.clearText();
+ XSLFTextRun r = title.addNewTextParagraph().addNewTextRun();
+ r.setText("Baeldung");
+
+ // Adding the link
+ XSLFHyperlink link = r.createHyperlink();
+ link.setAddress("http://www.baeldung.com");
+
+ // setting the content
+ XSLFTextShape content = slide2.getPlaceholder(1);
+ content.clearText(); // unset any existing text
+ content.addNewTextParagraph().addNewTextRun().setText("First paragraph");
+ content.addNewTextParagraph().addNewTextRun().setText("Second paragraph");
+ content.addNewTextParagraph().addNewTextRun().setText("Third paragraph");
+
+ // Creating 3rd slide - List
+ layout = defaultMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
+ XSLFSlide slide3 = ppt.createSlide(layout);
+ title = slide3.getPlaceholder(0);
+ title.clearText();
+ r = title.addNewTextParagraph().addNewTextRun();
+ r.setText("Lists");
+
+ content = slide3.getPlaceholder(1);
+ content.clearText();
+ XSLFTextParagraph p1 = content.addNewTextParagraph();
+ p1.setIndentLevel(0);
+ p1.setBullet(true);
+ r1 = p1.addNewTextRun();
+ r1.setText("Bullet");
+
+ // the next three paragraphs form an auto-numbered list
+ XSLFTextParagraph p2 = content.addNewTextParagraph();
+ p2.setBulletAutoNumber(AutoNumberingScheme.alphaLcParenRight, 1);
+ p2.setIndentLevel(1);
+ XSLFTextRun r2 = p2.addNewTextRun();
+ r2.setText("Numbered List Item - 1");
+
+ // Creating 4th slide
+ XSLFSlide slide4 = ppt.createSlide();
+ createTable(slide4);
+
+ // Save presentation
+ FileOutputStream out = new FileOutputStream(fileLocation);
+ ppt.write(out);
+ out.close();
+
+ // Closing presentation
+ ppt.close();
+ }
+
+ /**
+ * Delete a slide from the presentation
+ *
+ * @param ppt
+ * The presentation
+ * @param slideNumber
+ * The number of the slide to be deleted (0-based)
+ */
+ public void deleteSlide(XMLSlideShow ppt, int slideNumber) {
+ ppt.removeSlide(slideNumber);
+ }
+
+ /**
+ * Re-order the slides inside a presentation
+ *
+ * @param ppt
+ * The presentation
+ * @param slideNumber
+ * The number of the slide to move
+ * @param newSlideNumber
+ * The new position of the slide (0-base)
+ */
+ public void reorderSlide(XMLSlideShow ppt, int slideNumber, int newSlideNumber) {
+ List slides = ppt.getSlides();
+
+ XSLFSlide secondSlide = slides.get(slideNumber);
+ ppt.setSlideOrder(secondSlide, newSlideNumber);
+ }
+
+ /**
+ * Retrieve the placeholder inside a slide
+ *
+ * @param slide
+ * The slide
+ * @return List of placeholder inside a slide
+ */
+ public List retrieveTemplatePlaceholders(XSLFSlide slide) {
+ List placeholders = new ArrayList<>();
+
+ for (XSLFShape shape : slide.getShapes()) {
+ if (shape instanceof XSLFAutoShape) {
+ placeholders.add(shape);
+ }
+ }
+ return placeholders;
+ }
+
+ /**
+ * Create a table
+ *
+ * @param slide
+ * Slide
+ */
+ private void createTable(XSLFSlide slide) {
+
+ XSLFTable tbl = slide.createTable();
+ tbl.setAnchor(new Rectangle(50, 50, 450, 300));
+
+ int numColumns = 3;
+ int numRows = 5;
+
+ // header
+ XSLFTableRow headerRow = tbl.addRow();
+ headerRow.setHeight(50);
+ for (int i = 0; i < numColumns; i++) {
+ XSLFTableCell th = headerRow.addCell();
+ XSLFTextParagraph p = th.addNewTextParagraph();
+ p.setTextAlign(TextParagraph.TextAlign.CENTER);
+ XSLFTextRun r = p.addNewTextRun();
+ r.setText("Header " + (i + 1));
+ r.setBold(true);
+ r.setFontColor(Color.white);
+ th.setFillColor(new Color(79, 129, 189));
+ th.setBorderWidth(TableCell.BorderEdge.bottom, 2.0);
+ th.setBorderColor(TableCell.BorderEdge.bottom, Color.white);
+ // all columns are equally sized
+ tbl.setColumnWidth(i, 150);
+ }
+
+ // data
+ for (int rownum = 0; rownum < numRows; rownum++) {
+ XSLFTableRow tr = tbl.addRow();
+ tr.setHeight(50);
+ for (int i = 0; i < numColumns; i++) {
+ XSLFTableCell cell = tr.addCell();
+ XSLFTextParagraph p = cell.addNewTextParagraph();
+ XSLFTextRun r = p.addNewTextRun();
+
+ r.setText("Cell " + (i * rownum + 1));
+ if (rownum % 2 == 0) {
+ cell.setFillColor(new Color(208, 216, 232));
+ } else {
+ cell.setFillColor(new Color(233, 247, 244));
+ }
+ }
+ }
+ }
+}
diff --git a/apache-poi/src/test/java/com/baeldung/poi/powerpoint/PowerPointIntegrationTest.java b/apache-poi/src/test/java/com/baeldung/poi/powerpoint/PowerPointIntegrationTest.java
new file mode 100644
index 0000000000..5319208e85
--- /dev/null
+++ b/apache-poi/src/test/java/com/baeldung/poi/powerpoint/PowerPointIntegrationTest.java
@@ -0,0 +1,77 @@
+package com.baeldung.poi.powerpoint;
+
+import org.apache.poi.xslf.usermodel.XMLSlideShow;
+import org.apache.poi.xslf.usermodel.XSLFShape;
+import org.apache.poi.xslf.usermodel.XSLFSlide;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.List;
+
+public class PowerPointIntegrationTest {
+
+ private PowerPointHelper pph;
+ private String fileLocation;
+ private static final String FILE_NAME = "presentation.pptx";
+
+ @Before
+ public void setUp() throws Exception {
+ File currDir = new File(".");
+ String path = currDir.getAbsolutePath();
+ fileLocation = path.substring(0, path.length() - 1) + FILE_NAME;
+
+ pph = new PowerPointHelper();
+ pph.createPresentation(fileLocation);
+ }
+
+ @Test
+ public void whenReadingAPresentation_thenOK() throws Exception {
+ XMLSlideShow xmlSlideShow = pph.readingExistingSlideShow(fileLocation);
+
+ Assert.assertNotNull(xmlSlideShow);
+ Assert.assertEquals(4, xmlSlideShow.getSlides().size());
+ }
+
+ @Test
+ public void whenRetrievingThePlaceholdersForEachSlide_thenOK() throws Exception {
+ XMLSlideShow xmlSlideShow = pph.readingExistingSlideShow(fileLocation);
+
+ List onlyTitleSlidePlaceholders = pph.retrieveTemplatePlaceholders(xmlSlideShow.getSlides().get(0));
+ List titleAndBodySlidePlaceholders = pph.retrieveTemplatePlaceholders(xmlSlideShow.getSlides().get(1));
+ List emptySlidePlaceholdes = pph.retrieveTemplatePlaceholders(xmlSlideShow.getSlides().get(3));
+
+ Assert.assertEquals(1, onlyTitleSlidePlaceholders.size());
+ Assert.assertEquals(2, titleAndBodySlidePlaceholders.size());
+ Assert.assertEquals(0, emptySlidePlaceholdes.size());
+
+ }
+
+ @Test
+ public void whenSortingSlides_thenOK() throws Exception {
+ XMLSlideShow xmlSlideShow = pph.readingExistingSlideShow(fileLocation);
+ XSLFSlide slide4 = xmlSlideShow.getSlides().get(3);
+ pph.reorderSlide(xmlSlideShow, 3, 1);
+
+ Assert.assertEquals(slide4, xmlSlideShow.getSlides().get(1));
+ }
+
+ @Test
+ public void givenPresentation_whenDeletingASlide_thenOK() throws Exception {
+ XMLSlideShow xmlSlideShow = pph.readingExistingSlideShow(fileLocation);
+ pph.deleteSlide(xmlSlideShow, 3);
+
+ Assert.assertEquals(3, xmlSlideShow.getSlides().size());
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ File testFile = new File(fileLocation);
+ if (testFile.exists()) {
+ testFile.delete();
+ }
+ pph = null;
+ }
+}
diff --git a/bootique/dependency-reduced-pom.xml b/bootique/dependency-reduced-pom.xml
index ed18f4e42a..ab09cfb7b1 100644
--- a/bootique/dependency-reduced-pom.xml
+++ b/bootique/dependency-reduced-pom.xml
@@ -28,8 +28,14 @@
junit
junit
- 3.8.1
+ 4.12
test
+
+
+ hamcrest-core
+ org.hamcrest
+
+
diff --git a/cas/cas-secured-app/pom.xml b/cas/cas-secured-app/pom.xml
index 543354e8b3..d52597412e 100644
--- a/cas/cas-secured-app/pom.xml
+++ b/cas/cas-secured-app/pom.xml
@@ -14,7 +14,7 @@
org.springframework.boot
spring-boot-starter-parent
- 2.0.0.BUILD-SNAPSHOT
+ 2.0.0.M7
@@ -87,14 +87,6 @@
-
- spring-snapshots
- Spring Snapshots
- https://repo.spring.io/snapshot
-
- true
-
-
spring-milestones
Spring Milestones
@@ -106,14 +98,6 @@
-
- spring-snapshots
- Spring Snapshots
- https://repo.spring.io/snapshot
-
- true
-
-
spring-milestones
Spring Milestones
diff --git a/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/controllers/AuthController.java b/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/controllers/AuthController.java
index 703e6abf7a..7faccbb125 100644
--- a/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/controllers/AuthController.java
+++ b/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/controllers/AuthController.java
@@ -1,6 +1,7 @@
package com.baeldung.cassecuredapp.controllers;
-import org.apache.log4j.Logger;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.LogManager;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.CookieClearingLogoutHandler;
@@ -15,7 +16,7 @@ import javax.servlet.http.HttpServletResponse;
@Controller
public class AuthController {
- private Logger logger = Logger.getLogger(AuthController.class);
+ private Logger logger = LogManager.getLogger(AuthController.class);
@GetMapping("/logout")
public String logout(
diff --git a/core-java-8/pom.xml b/core-java-8/pom.xml
index f5506f095e..17d330b3b8 100644
--- a/core-java-8/pom.xml
+++ b/core-java-8/pom.xml
@@ -1,258 +1,276 @@
-
- 4.0.0
- com.baeldung
- core-java-8
- 0.1.0-SNAPSHOT
- jar
-
- core-java-8
-
-
-
- com.baeldung
- parent-modules
- 1.0.0-SNAPSHOT
-
-
-
-
-
-
- com.google.guava
- guava
- ${guava.version}
-
-
-
- org.apache.commons
- commons-collections4
- ${commons-collections4.version}
-
-
-
- commons-io
- commons-io
- ${commons-io.version}
-
-
-
- org.apache.commons
- commons-lang3
- ${commons-lang3.version}
-
-
-
- org.apache.commons
- commons-math3
- ${commons-math3.version}
-
-
-
- log4j
- log4j
- 1.2.17
-
-
-
- commons-codec
- commons-codec
- ${commons-codec.version}
-
-
-
- org.projectlombok
- lombok
- ${lombok.version}
- provided
-
-
-
-
-
- org.assertj
- assertj-core
- ${assertj.version}
- test
-
-
-
- com.jayway.awaitility
- awaitility
- ${avaitility.version}
- test
-
-
-
-
-
- core-java-8
-
-
- src/main/resources
- true
-
-
-
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- copy-dependencies
- prepare-package
-
- copy-dependencies
-
-
- ${project.build.directory}/libs
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
-
-
-
- true
- libs/
- org.baeldung.executable.ExecutableMavenJar
-
-
-
-
-
- org.apache.maven.plugins
- maven-assembly-plugin
-
-
- package
-
- single
-
-
- ${project.basedir}
-
-
- org.baeldung.executable.ExecutableMavenJar
-
-
-
- jar-with-dependencies
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-shade-plugin
-
-
-
- shade
-
-
- true
-
-
- org.baeldung.executable.ExecutableMavenJar
-
-
-
-
-
-
-
- com.jolira
- onejar-maven-plugin
-
-
-
- org.baeldung.executable.ExecutableMavenJar
- true
- ${project.build.finalName}-onejar.${project.packaging}
-
-
- one-jar
-
-
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
- repackage
-
-
- spring-boot
- org.baeldung.executable.ExecutableMavenJar
-
-
-
-
-
-
-
-
-
-
- integration
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
- integration-test
-
- test
-
-
-
- **/*ManualTest.java
-
-
- **/*IntegrationTest.java
-
-
-
-
-
-
- json
-
-
-
-
-
-
-
-
-
-
-
- 21.0
- 3.5
- 3.6.1
- 2.5
- 4.1
- 4.01
- 1.10
- 1.16.12
-
-
- 3.6.1
- 1.7.0
-
-
+
+ 4.0.0
+ com.baeldung
+ core-java-8
+ 0.1.0-SNAPSHOT
+ jar
+
+ core-java-8
+
+
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+
+
+
+
+
+
+ com.google.guava
+ guava
+ ${guava.version}
+
+
+
+ org.apache.commons
+ commons-collections4
+ ${commons-collections4.version}
+
+
+
+ commons-io
+ commons-io
+ ${commons-io.version}
+
+
+
+ org.apache.commons
+ commons-lang3
+ ${commons-lang3.version}
+
+
+
+ org.apache.commons
+ commons-math3
+ ${commons-math3.version}
+
+
+
+ log4j
+ log4j
+ 1.2.17
+
+
+
+ commons-codec
+ commons-codec
+ ${commons-codec.version}
+
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+ provided
+
+
+
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
+
+
+ com.jayway.awaitility
+ awaitility
+ ${avaitility.version}
+ test
+
+
+
+ org.openjdk.jmh
+ jmh-core
+ 1.19
+
+
+
+ org.openjdk.jmh
+ jmh-generator-annprocess
+ 1.19
+
+
+
+ org.openjdk.jmh
+ jmh-generator-bytecode
+ 1.19
+
+
+
+
+
+ core-java-8
+
+
+ src/main/resources
+ true
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+
+
+ copy-dependencies
+ prepare-package
+
+ copy-dependencies
+
+
+ ${project.build.directory}/libs
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+
+ true
+ libs/
+ org.baeldung.executable.ExecutableMavenJar
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+ package
+
+ single
+
+
+ ${project.basedir}
+
+
+ org.baeldung.executable.ExecutableMavenJar
+
+
+
+ jar-with-dependencies
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+
+
+
+ shade
+
+
+ true
+
+
+ org.baeldung.executable.ExecutableMavenJar
+
+
+
+
+
+
+
+ com.jolira
+ onejar-maven-plugin
+
+
+
+ org.baeldung.executable.ExecutableMavenJar
+ true
+ ${project.build.finalName}-onejar.${project.packaging}
+
+
+ one-jar
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ repackage
+
+
+ spring-boot
+ org.baeldung.executable.ExecutableMavenJar
+
+
+
+
+
+
+
+
+
+
+ integration
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ integration-test
+
+ test
+
+
+
+ **/*ManualTest.java
+
+
+ **/*IntegrationTest.java
+
+
+
+
+
+
+ json
+
+
+
+
+
+
+
+
+
+
+
+ 21.0
+ 3.5
+ 3.6.1
+ 2.5
+ 4.1
+ 4.01
+ 1.10
+ 1.16.12
+
+
+ 3.6.1
+ 1.7.0
+
+
\ No newline at end of file
diff --git a/core-java-8/src/test/java/com/baeldung/counter/CounterStatistics.java b/core-java-8/src/test/java/com/baeldung/counter/CounterStatistics.java
new file mode 100644
index 0000000000..2a42a166fa
--- /dev/null
+++ b/core-java-8/src/test/java/com/baeldung/counter/CounterStatistics.java
@@ -0,0 +1,45 @@
+package com.baeldung.counter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Mode;
+
+import com.baeldung.counter.CounterUtil.MutableInteger;
+
+@Fork(value = 1, warmups = 3)
+@BenchmarkMode(Mode.All)
+public class CounterStatistics {
+
+ private static final Map counterMap = new HashMap<>();
+ private static final Map counterWithMutableIntMap = new HashMap<>();
+ private static final Map counterWithIntArrayMap = new HashMap<>();
+ private static final Map counterWithLongWrapperMap = new HashMap<>();
+
+ @Benchmark
+ public void wrapperAsCounter() {
+ CounterUtil.counterWithWrapperObject(counterMap);
+ }
+
+ @Benchmark
+ public void lambdaExpressionWithWrapper() {
+ CounterUtil.counterWithLambdaAndWrapper(counterWithLongWrapperMap);
+ }
+
+ @Benchmark
+ public void mutableIntegerAsCounter() {
+ CounterUtil.counterWithMutableInteger(counterWithMutableIntMap);
+ }
+
+ @Benchmark
+ public void primitiveArrayAsCounter() {
+ CounterUtil.counterWithPrimitiveArray(counterWithIntArrayMap);
+ }
+
+ public static void main(String[] args) throws Exception {
+ org.openjdk.jmh.Main.main(args);
+ }
+}
diff --git a/core-java-8/src/test/java/com/baeldung/counter/CounterTest.java b/core-java-8/src/test/java/com/baeldung/counter/CounterTest.java
new file mode 100644
index 0000000000..657b510452
--- /dev/null
+++ b/core-java-8/src/test/java/com/baeldung/counter/CounterTest.java
@@ -0,0 +1,53 @@
+package com.baeldung.counter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+import com.baeldung.counter.CounterUtil.MutableInteger;
+
+public class CounterTest {
+
+ @Test
+ public void whenMapWithWrapperAsCounter_runsSuccessfully() {
+ Map counterMap = new HashMap<>();
+ CounterUtil.counterWithWrapperObject(counterMap);
+
+ assertEquals(3, counterMap.get("China")
+ .intValue());
+ assertEquals(2, counterMap.get("India")
+ .intValue());
+ }
+
+ @Test
+ public void whenMapWithLambdaAndWrapperCounter_runsSuccessfully() {
+ Map counterMap = new HashMap<>();
+ CounterUtil.counterWithLambdaAndWrapper(counterMap);
+
+ assertEquals(3l, counterMap.get("China")
+ .longValue());
+ assertEquals(2l, counterMap.get("India")
+ .longValue());
+ }
+
+ @Test
+ public void whenMapWithMutableIntegerCounter_runsSuccessfully() {
+ Map counterMap = new HashMap<>();
+ CounterUtil.counterWithMutableInteger(counterMap);
+ assertEquals(3, counterMap.get("China")
+ .getCount());
+ assertEquals(2, counterMap.get("India")
+ .getCount());
+ }
+
+ @Test
+ public void whenMapWithPrimitiveArray_runsSuccessfully() {
+ Map counterMap = new HashMap<>();
+ CounterUtil.counterWithPrimitiveArray(counterMap);
+ assertEquals(3, counterMap.get("China")[0]);
+ assertEquals(2, counterMap.get("India")[0]);
+ }
+}
diff --git a/core-java-8/src/test/java/com/baeldung/counter/CounterUtil.java b/core-java-8/src/test/java/com/baeldung/counter/CounterUtil.java
new file mode 100644
index 0000000000..647fbfb0cc
--- /dev/null
+++ b/core-java-8/src/test/java/com/baeldung/counter/CounterUtil.java
@@ -0,0 +1,61 @@
+package com.baeldung.counter;
+
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class CounterUtil {
+
+ private final static String[] COUNTRY_NAMES = { "China", "Australia", "India", "USA", "USSR", "UK", "China", "France", "Poland", "Austria", "India", "USA", "Egypt", "China" };
+
+ public static void counterWithWrapperObject(Map counterMap) {
+ for (String country : COUNTRY_NAMES) {
+ counterMap.compute(country, (k, v) -> v == null ? 1 : v + 1);
+ }
+ }
+
+ public static void counterWithLambdaAndWrapper(Map counterMap) {
+ counterMap.putAll(Stream.of(COUNTRY_NAMES)
+ .parallel()
+ .collect(Collectors.groupingBy(k -> k, Collectors.counting())));
+ }
+
+ public static class MutableInteger {
+ int count;
+
+ public MutableInteger(int count) {
+ this.count = count;
+ }
+
+ public void increment() {
+ this.count++;
+ }
+
+ public int getCount() {
+ return this.count;
+ }
+ }
+
+ public static void counterWithMutableInteger(Map counterMap) {
+ for (String country : COUNTRY_NAMES) {
+ MutableInteger oldValue = counterMap.get(country);
+ if (oldValue != null) {
+ oldValue.increment();
+ } else {
+ counterMap.put(country, new MutableInteger(1));
+ }
+ }
+ }
+
+ public static void counterWithPrimitiveArray(Map counterMap) {
+ for (String country : COUNTRY_NAMES) {
+ int[] oldCounter = counterMap.get(country);
+ if (oldCounter != null) {
+ oldCounter[0] += 1;
+ } else {
+ counterMap.put(country, new int[] { 1 });
+ }
+ }
+ }
+
+}
diff --git a/core-java-9/compile-httpclient.bat b/core-java-9/compile-httpclient.bat
new file mode 100644
index 0000000000..9d845784cf
--- /dev/null
+++ b/core-java-9/compile-httpclient.bat
@@ -0,0 +1,3 @@
+javac --module-path mods -d mods/com.baeldung.httpclient^
+ src/modules/com.baeldung.httpclient/module-info.java^
+ src/modules/com.baeldung.httpclient/com/baeldung/httpclient/HttpClientExample.java
\ No newline at end of file
diff --git a/core-java-9/run-httpclient.bat b/core-java-9/run-httpclient.bat
new file mode 100644
index 0000000000..60b1eb7f68
--- /dev/null
+++ b/core-java-9/run-httpclient.bat
@@ -0,0 +1 @@
+java --module-path mods -m com.baeldung.httpclient/com.baeldung.httpclient.HttpClientExample
\ No newline at end of file
diff --git a/core-java-9/src/modules/com.baeldung.httpclient/com/baeldung/httpclient/HttpClientExample.java b/core-java-9/src/modules/com.baeldung.httpclient/com/baeldung/httpclient/HttpClientExample.java
new file mode 100644
index 0000000000..de08c2164e
--- /dev/null
+++ b/core-java-9/src/modules/com.baeldung.httpclient/com/baeldung/httpclient/HttpClientExample.java
@@ -0,0 +1,84 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.baeldung.httpclient;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
+import jdk.incubator.http.HttpClient;
+import jdk.incubator.http.HttpRequest;
+import jdk.incubator.http.HttpRequest.BodyProcessor;
+import jdk.incubator.http.HttpResponse;
+import jdk.incubator.http.HttpResponse.BodyHandler;
+
+/**
+ *
+ * @author pkaria
+ */
+public class HttpClientExample {
+
+ public static void main(String[] args) throws Exception {
+ httpGetRequest();
+ httpPostRequest();
+ asynchronousRequest();
+ asynchronousMultipleRequests();
+ }
+
+ public static void httpGetRequest() throws URISyntaxException, IOException, InterruptedException {
+ HttpClient client = HttpClient.newHttpClient();
+ URI httpURI = new URI("http://jsonplaceholder.typicode.com/posts/1");
+ HttpRequest request = HttpRequest.newBuilder(httpURI).GET()
+ .headers("Accept-Enconding", "gzip, deflate").build();
+ HttpResponse response = client.send(request, HttpResponse.BodyHandler.asString());
+ String responseBody = response.body();
+ int responseStatusCode = response.statusCode();
+ System.out.println(responseBody);
+ }
+
+ public static void httpPostRequest() throws URISyntaxException, IOException, InterruptedException {
+ HttpClient client = HttpClient
+ .newBuilder()
+ .build();
+ HttpRequest request = HttpRequest
+ .newBuilder(new URI("http://jsonplaceholder.typicode.com/posts"))
+ .POST(BodyProcessor.fromString("Sample Post Request"))
+ .build();
+ HttpResponse response
+ = client.send(request, HttpResponse.BodyHandler.asString());
+ String responseBody = response.body();
+ System.out.println(responseBody);
+ }
+
+ public static void asynchronousRequest() throws URISyntaxException {
+ HttpClient client = HttpClient.newHttpClient();
+ URI httpURI = new URI("http://jsonplaceholder.typicode.com/posts/1");
+ HttpRequest request = HttpRequest.newBuilder(httpURI).GET().build();
+ CompletableFuture> futureResponse = client.sendAsync(request,
+ HttpResponse.BodyHandler.asString());
+ }
+
+ public static void asynchronousMultipleRequests() throws URISyntaxException {
+ List targets = Arrays.asList(new URI("http://jsonplaceholder.typicode.com/posts/1"), new URI("http://jsonplaceholder.typicode.com/posts/2"));
+ HttpClient client = HttpClient.newHttpClient();
+ List> futures = targets
+ .stream()
+ .map(target -> client
+ .sendAsync(
+ HttpRequest.newBuilder(target)
+ .GET()
+ .build(),
+ BodyHandler.asFile(Paths.get("base", target.getPath())))
+ .thenApply(response -> response.body())
+ .thenApply(path -> path.toFile()))
+ .collect(Collectors.toList());
+ }
+}
diff --git a/core-java-9/src/modules/com.baeldung.httpclient/module-info.java b/core-java-9/src/modules/com.baeldung.httpclient/module-info.java
new file mode 100644
index 0000000000..205c9ea725
--- /dev/null
+++ b/core-java-9/src/modules/com.baeldung.httpclient/module-info.java
@@ -0,0 +1,3 @@
+module com.baeldung.httpclient {
+ requires jdk.incubator.httpclient;
+}
diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/NewThread.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/NewThread.java
index d742d3a55f..4d87978070 100644
--- a/core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/NewThread.java
+++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/NewThread.java
@@ -3,7 +3,6 @@ package com.baeldung.concurrent.daemon;
public class NewThread extends Thread {
public void run() {
-
long startTime = System.currentTimeMillis();
while (true) {
for (int i = 0; i < 10; i++) {
diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Data.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Data.java
new file mode 100644
index 0000000000..9b850c4153
--- /dev/null
+++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Data.java
@@ -0,0 +1,33 @@
+package com.baeldung.concurrent.waitandnotify;
+
+public class Data {
+ private String packet;
+
+ // True if receiver should wait
+ // False if sender should wait
+ private boolean transfer = true;
+
+ public synchronized String receive() {
+ while (transfer) {
+ try {
+ wait();
+ } catch (InterruptedException e) {}
+ }
+ transfer = true;
+
+ notifyAll();
+ return packet;
+ }
+
+ public synchronized void send(String packet) {
+ while (!transfer) {
+ try {
+ wait();
+ } catch (InterruptedException e) {}
+ }
+ transfer = false;
+
+ this.packet = packet;
+ notifyAll();
+ }
+}
\ No newline at end of file
diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/NetworkDriver.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/NetworkDriver.java
new file mode 100644
index 0000000000..d4fd1574c6
--- /dev/null
+++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/NetworkDriver.java
@@ -0,0 +1,12 @@
+package com.baeldung.concurrent.waitandnotify;
+
+public class NetworkDriver {
+ public static void main(String[] args) {
+ Data data = new Data();
+ Thread sender = new Thread(new Sender(data));
+ Thread receiver = new Thread(new Receiver(data));
+
+ sender.start();
+ receiver.start();
+ }
+}
\ No newline at end of file
diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Receiver.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Receiver.java
new file mode 100644
index 0000000000..63f48b8031
--- /dev/null
+++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Receiver.java
@@ -0,0 +1,25 @@
+package com.baeldung.concurrent.waitandnotify;
+
+import java.util.concurrent.ThreadLocalRandom;
+
+public class Receiver implements Runnable {
+ private Data load;
+
+ public Receiver(Data load) {
+ this.load = load;
+ }
+
+ public void run() {
+ for(String receivedMessage = load.receive();
+ !"End".equals(receivedMessage) ;
+ receivedMessage = load.receive()) {
+
+ System.out.println(receivedMessage);
+
+ //Thread.sleep() to mimic heavy server-side processing
+ try {
+ Thread.sleep(ThreadLocalRandom.current().nextInt(1000, 5000));
+ } catch (InterruptedException e) {}
+ }
+ }
+}
\ No newline at end of file
diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Sender.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Sender.java
new file mode 100644
index 0000000000..b7d782c3f5
--- /dev/null
+++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Sender.java
@@ -0,0 +1,30 @@
+package com.baeldung.concurrent.waitandnotify;
+
+import java.util.concurrent.ThreadLocalRandom;
+
+public class Sender implements Runnable {
+ private Data data;
+
+ public Sender(Data data) {
+ this.data = data;
+ }
+
+ public void run() {
+ String packets[] = {
+ "First packet",
+ "Second packet",
+ "Third packet",
+ "Fourth packet",
+ "End"
+ };
+
+ for (String packet : packets) {
+ data.send(packet);
+
+ //Thread.sleep() to mimic heavy server-side processing
+ try {
+ Thread.sleep(ThreadLocalRandom.current().nextInt(1000, 5000));
+ } catch (InterruptedException e) {}
+ }
+ }
+}
\ No newline at end of file
diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/executorservice/WaitingForThreadsToFinishTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/executorservice/WaitingForThreadsToFinishTest.java
index 17b71aa35b..7e2bf590fd 100644
--- a/core-java-concurrency/src/test/java/com/baeldung/concurrent/executorservice/WaitingForThreadsToFinishTest.java
+++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/executorservice/WaitingForThreadsToFinishTest.java
@@ -9,7 +9,6 @@ import java.util.List;
import java.util.concurrent.*;
import static junit.framework.TestCase.assertTrue;
-import static org.junit.Assert.fail;
public class WaitingForThreadsToFinishTest {
@@ -40,16 +39,13 @@ public class WaitingForThreadsToFinishTest {
CountDownLatch latch = new CountDownLatch(2);
for (int i = 0; i < 2; i++) {
- WORKER_THREAD_POOL.submit(new Runnable() {
- @Override
- public void run() {
- try {
- Thread.sleep(1000);
- latch.countDown();
- } catch (InterruptedException e) {
- e.printStackTrace();
- Thread.currentThread().interrupt();
- }
+ WORKER_THREAD_POOL.submit(() -> {
+ try {
+ Thread.sleep(1000);
+ latch.countDown();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ Thread.currentThread().interrupt();
}
});
}
@@ -83,13 +79,9 @@ public class WaitingForThreadsToFinishTest {
awaitTerminationAfterShutdown(WORKER_THREAD_POOL);
try {
- WORKER_THREAD_POOL.submit(new Callable() {
- @Override
- public String call() throws Exception {
- fail("This thread should have been rejected !");
- Thread.sleep(1000000);
- return null;
- }
+ WORKER_THREAD_POOL.submit((Callable) () -> {
+ Thread.sleep(1000000);
+ return null;
});
} catch (RejectedExecutionException ex) {
//
diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/stopping/StopThreadTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/stopping/StopThreadTest.java
index 8c1bdbf787..70854f013f 100644
--- a/core-java-concurrency/src/test/java/com/baeldung/concurrent/stopping/StopThreadTest.java
+++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/stopping/StopThreadTest.java
@@ -1,7 +1,11 @@
package com.baeldung.concurrent.stopping;
+import com.jayway.awaitility.Awaitility;
import org.junit.Test;
+import java.util.concurrent.TimeUnit;
+
+import static com.jayway.awaitility.Awaitility.await;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -22,11 +26,10 @@ public class StopThreadTest {
// Stop it and make sure the flags have been reversed
controlSubThread.stop();
- Thread.sleep(interval);
- assertTrue(controlSubThread.isStopped());
+ await()
+ .until(() -> assertTrue(controlSubThread.isStopped()));
}
-
@Test
public void whenInterruptedThreadIsStopped() throws InterruptedException {
@@ -44,7 +47,8 @@ public class StopThreadTest {
controlSubThread.interrupt();
// Wait less than the time we would normally sleep, and make sure we exited.
- Thread.sleep(interval/10);
- assertTrue(controlSubThread.isStopped());
+ Awaitility.await()
+ .atMost(interval/ 10, TimeUnit.MILLISECONDS)
+ .until(controlSubThread::isStopped);
}
}
diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/waitandnotify/NetworkIntegrationTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/waitandnotify/NetworkIntegrationTest.java
new file mode 100644
index 0000000000..49f4313e9d
--- /dev/null
+++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/waitandnotify/NetworkIntegrationTest.java
@@ -0,0 +1,65 @@
+package com.baeldung.concurrent.waitandnotify;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class NetworkIntegrationTest {
+
+ private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+ private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
+ private String expected;
+
+ @Before
+ public void setUpStreams() {
+ System.setOut(new PrintStream(outContent));
+ System.setErr(new PrintStream(errContent));
+ }
+
+ @Before
+ public void setUpExpectedOutput() {
+ StringWriter expectedStringWriter = new StringWriter();
+
+ PrintWriter printWriter = new PrintWriter(expectedStringWriter);
+ printWriter.println("First packet");
+ printWriter.println("Second packet");
+ printWriter.println("Third packet");
+ printWriter.println("Fourth packet");
+ printWriter.close();
+
+ expected = expectedStringWriter.toString();
+ }
+
+ @After
+ public void cleanUpStreams() {
+ System.setOut(null);
+ System.setErr(null);
+ }
+
+ @Test
+ public void givenSenderAndReceiver_whenSendingPackets_thenNetworkSynchronized() {
+ Data data = new Data();
+ Thread sender = new Thread(new Sender(data));
+ Thread receiver = new Thread(new Receiver(data));
+
+ sender.start();
+ receiver.start();
+
+ //wait for sender and receiver to finish before we test against expected
+ try {
+ sender.join();
+ receiver.join();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ assertEquals(expected, outContent.toString());
+ }
+}
diff --git a/core-java-sun/.gitignore b/core-java-sun/.gitignore
new file mode 100644
index 0000000000..3de4cc647e
--- /dev/null
+++ b/core-java-sun/.gitignore
@@ -0,0 +1,26 @@
+*.class
+
+0.*
+
+#folders#
+/target
+/neoDb*
+/data
+/src/main/webapp/WEB-INF/classes
+*/META-INF/*
+.resourceCache
+
+# Packaged files #
+*.jar
+*.war
+*.ear
+
+# Files generated by integration tests
+*.txt
+backup-pom.xml
+/bin/
+/temp
+
+#IntelliJ specific
+.idea/
+*.iml
\ No newline at end of file
diff --git a/core-java-sun/README.md b/core-java-sun/README.md
new file mode 100644
index 0000000000..9cf8b26f1b
--- /dev/null
+++ b/core-java-sun/README.md
@@ -0,0 +1,6 @@
+=========
+
+## Core Java Cookbooks and Examples
+
+### Relevant Articles:
+- [Creating a Java Compiler Plugin](http://www.baeldung.com/java-build-compiler-plugin)
diff --git a/core-java-sun/pom.xml b/core-java-sun/pom.xml
new file mode 100644
index 0000000000..3997f47d19
--- /dev/null
+++ b/core-java-sun/pom.xml
@@ -0,0 +1,489 @@
+
+ 4.0.0
+ com.baeldung
+ core-java-sun
+ 0.1.0-SNAPSHOT
+ jar
+
+ core-java-sun
+
+
+
+
+
+ net.sourceforge.collections
+ collections-generic
+ ${collections-generic.version}
+
+
+ com.google.guava
+ guava
+ ${guava.version}
+
+
+
+ org.apache.commons
+ commons-collections4
+ ${commons-collections4.version}
+
+
+
+ commons-io
+ commons-io
+ ${commons-io.version}
+
+
+
+ org.apache.commons
+ commons-lang3
+ ${commons-lang3.version}
+
+
+
+ org.apache.commons
+ commons-math3
+ ${commons-math3.version}
+
+
+
+ org.decimal4j
+ decimal4j
+ ${decimal4j.version}
+
+
+
+ org.bouncycastle
+ bcprov-jdk15on
+ ${bouncycastle.version}
+
+
+
+ org.unix4j
+ unix4j-command
+ ${unix4j.version}
+
+
+
+ com.googlecode.grep4j
+ grep4j
+ ${grep4j.version}
+
+
+
+
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ ${jackson.version}
+
+
+
+
+ log4j
+ log4j
+ 1.2.17
+
+
+ org.slf4j
+ slf4j-api
+ ${org.slf4j.version}
+
+
+ ch.qos.logback
+ logback-classic
+ ${logback.version}
+
+
+
+ org.slf4j
+ jcl-over-slf4j
+ ${org.slf4j.version}
+
+
+
+ org.slf4j
+ log4j-over-slf4j
+ ${org.slf4j.version}
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+ provided
+
+
+
+
+
+ org.hamcrest
+ hamcrest-all
+ 1.3
+ test
+
+
+
+ junit
+ junit
+ ${junit.version}
+ test
+
+
+
+ org.hamcrest
+ hamcrest-core
+ ${org.hamcrest.version}
+ test
+
+
+ org.hamcrest
+ hamcrest-library
+ ${org.hamcrest.version}
+ test
+
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
+
+
+ org.mockito
+ mockito-core
+ ${mockito.version}
+ test
+
+
+ com.jayway.awaitility
+ awaitility
+ ${avaitility.version}
+ test
+
+
+
+ commons-codec
+ commons-codec
+ ${commons-codec.version}
+
+
+
+ org.javamoney
+ moneta
+ 1.1
+
+
+
+ org.owasp.esapi
+ esapi
+ 2.1.0.1
+
+
+
+ com.sun.messaging.mq
+ fscontext
+ ${fscontext.version}
+
+
+ com.codepoetics
+ protonpack
+ ${protonpack.version}
+
+
+ one.util
+ streamex
+ ${streamex.version}
+
+
+ io.vavr
+ vavr
+ ${vavr.version}
+
+
+ org.openjdk.jmh
+ jmh-core
+ 1.19
+
+
+ org.openjdk.jmh
+ jmh-generator-annprocess
+ 1.19
+
+
+ org.springframework
+ spring-web
+ 4.3.4.RELEASE
+
+
+ com.sun
+ tools
+ 1.8.0
+ system
+ ${java.home}/../lib/tools.jar
+
+
+
+
+ core-java
+
+
+ src/main/resources
+ true
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+
+ 1.8
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ **/*LiveTest.java
+ **/*IntegrationTest.java
+ **/*LongRunningUnitTest.java
+ **/*ManualTest.java
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+
+
+ copy-dependencies
+ prepare-package
+
+ copy-dependencies
+
+
+ ${project.build.directory}/libs
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+
+ true
+ libs/
+ org.baeldung.executable.ExecutableMavenJar
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+ package
+
+ single
+
+
+ ${project.basedir}
+
+
+ org.baeldung.executable.ExecutableMavenJar
+
+
+
+ jar-with-dependencies
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+
+
+
+ shade
+
+
+ true
+
+
+ org.baeldung.executable.ExecutableMavenJar
+
+
+
+
+
+
+
+
+ com.jolira
+ onejar-maven-plugin
+
+
+
+ org.baeldung.executable.ExecutableMavenJar
+ true
+ ${project.build.finalName}-onejar.${project.packaging}
+
+
+ one-jar
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ repackage
+
+
+ spring-boot
+ org.baeldung.executable.ExecutableMavenJar
+
+
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.6.0
+
+ java
+ com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed
+
+ -Xmx300m
+ -XX:+UseParallelGC
+ -classpath
+
+ com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed
+
+
+
+
+
+
+
+
+
+
+
+ integration
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ integration-test
+
+ test
+
+
+
+ **/*ManualTest.java
+
+
+ **/*IntegrationTest.java
+
+
+
+
+
+
+ json
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+
+
+
+ run-benchmarks
+
+ none
+
+ exec
+
+
+ test
+ java
+
+ -classpath
+
+ org.openjdk.jmh.Main
+ .*
+
+
+
+
+
+
+
+
+
+
+
+
+ 2.8.5
+
+
+ 1.7.21
+ 1.1.7
+
+
+ 23.0
+ 3.5
+ 1.55
+ 1.10
+ 3.6.1
+ 1.0.3
+ 2.5
+ 4.1
+ 4.01
+ 0.4
+ 1.8.7
+ 1.16.12
+ 4.6-b01
+ 1.13
+ 0.6.5
+ 0.9.0
+
+
+ 1.3
+ 4.12
+ 2.8.9
+ 3.6.1
+ 1.7.0
+
+
+ 3.6.0
+ 2.19.1
+
+
\ No newline at end of file
diff --git a/spring-jpa/.gitignore b/core-java-sun/src/main/java/com/baeldung/.gitignore
similarity index 100%
rename from spring-jpa/.gitignore
rename to core-java-sun/src/main/java/com/baeldung/.gitignore
diff --git a/core-java-sun/src/main/java/com/baeldung/README.md b/core-java-sun/src/main/java/com/baeldung/README.md
new file mode 100644
index 0000000000..51809b2882
--- /dev/null
+++ b/core-java-sun/src/main/java/com/baeldung/README.md
@@ -0,0 +1,2 @@
+### Relevant Articles:
+- [SHA-256 Hashing in Java](http://www.baeldung.com/sha-256-hashing-java)
diff --git a/core-java/src/main/java/com/baeldung/javac/Positive.java b/core-java-sun/src/main/java/com/baeldung/javac/Positive.java
similarity index 100%
rename from core-java/src/main/java/com/baeldung/javac/Positive.java
rename to core-java-sun/src/main/java/com/baeldung/javac/Positive.java
diff --git a/core-java/src/main/java/com/baeldung/javac/SampleJavacPlugin.java b/core-java-sun/src/main/java/com/baeldung/javac/SampleJavacPlugin.java
similarity index 100%
rename from core-java/src/main/java/com/baeldung/javac/SampleJavacPlugin.java
rename to core-java-sun/src/main/java/com/baeldung/javac/SampleJavacPlugin.java
diff --git a/core-java-sun/src/main/resources/log4j.properties b/core-java-sun/src/main/resources/log4j.properties
new file mode 100644
index 0000000000..621cf01735
--- /dev/null
+++ b/core-java-sun/src/main/resources/log4j.properties
@@ -0,0 +1,6 @@
+log4j.rootLogger=DEBUG, A1
+
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
\ No newline at end of file
diff --git a/spring-jpa/src/main/resources/logback.xml b/core-java-sun/src/main/resources/logback.xml
similarity index 100%
rename from spring-jpa/src/main/resources/logback.xml
rename to core-java-sun/src/main/resources/logback.xml
diff --git a/core-java/src/test/java/com/baeldung/javac/SampleJavacPluginIntegrationTest.java b/core-java-sun/src/test/java/com/baeldung/javac/SampleJavacPluginIntegrationTest.java
similarity index 100%
rename from core-java/src/test/java/com/baeldung/javac/SampleJavacPluginIntegrationTest.java
rename to core-java-sun/src/test/java/com/baeldung/javac/SampleJavacPluginIntegrationTest.java
diff --git a/core-java/src/test/java/com/baeldung/javac/SimpleClassFile.java b/core-java-sun/src/test/java/com/baeldung/javac/SimpleClassFile.java
similarity index 100%
rename from core-java/src/test/java/com/baeldung/javac/SimpleClassFile.java
rename to core-java-sun/src/test/java/com/baeldung/javac/SimpleClassFile.java
diff --git a/core-java/src/test/java/com/baeldung/javac/SimpleFileManager.java b/core-java-sun/src/test/java/com/baeldung/javac/SimpleFileManager.java
similarity index 100%
rename from core-java/src/test/java/com/baeldung/javac/SimpleFileManager.java
rename to core-java-sun/src/test/java/com/baeldung/javac/SimpleFileManager.java
diff --git a/core-java/src/test/java/com/baeldung/javac/SimpleSourceFile.java b/core-java-sun/src/test/java/com/baeldung/javac/SimpleSourceFile.java
similarity index 100%
rename from core-java/src/test/java/com/baeldung/javac/SimpleSourceFile.java
rename to core-java-sun/src/test/java/com/baeldung/javac/SimpleSourceFile.java
diff --git a/core-java/src/test/java/com/baeldung/javac/TestCompiler.java b/core-java-sun/src/test/java/com/baeldung/javac/TestCompiler.java
similarity index 100%
rename from core-java/src/test/java/com/baeldung/javac/TestCompiler.java
rename to core-java-sun/src/test/java/com/baeldung/javac/TestCompiler.java
diff --git a/core-java/src/test/java/com/baeldung/javac/TestRunner.java b/core-java-sun/src/test/java/com/baeldung/javac/TestRunner.java
similarity index 100%
rename from core-java/src/test/java/com/baeldung/javac/TestRunner.java
rename to core-java-sun/src/test/java/com/baeldung/javac/TestRunner.java
diff --git a/spring-jpa/src/test/resources/.gitignore b/core-java-sun/src/test/resources/.gitignore
similarity index 100%
rename from spring-jpa/src/test/resources/.gitignore
rename to core-java-sun/src/test/resources/.gitignore
diff --git a/core-java/README.md b/core-java/README.md
index 4573d5f7e2..8287a21d1e 100644
--- a/core-java/README.md
+++ b/core-java/README.md
@@ -119,4 +119,6 @@
- [Initializing Arrays in Java](http://www.baeldung.com/java-initialize-array)
- [Guide to Java String Pool](http://www.baeldung.com/java-string-pool)
- [Copy a File with Java](http://www.baeldung.com/java-copy-file)
+- [Introduction to Creational Design Patterns](http://www.baeldung.com/creational-design-patterns)
+- [Quick Example - Comparator vs Comparable in Java](http://www.baeldung.com/java-comparator-comparable)
diff --git a/core-java/customers.xml b/core-java/customers.xml
new file mode 100644
index 0000000000..b52dc27633
--- /dev/null
+++ b/core-java/customers.xml
@@ -0,0 +1,95 @@
+
+
+
+ SELECT * FROM customers
+ 1008
+
+ true
+ 1000
+ 0
+ 2
+
+
+
+ 0
+ 0
+ 0
+ true
+ ResultSet.TYPE_SCROLL_INSENSITIVE
+ false
+ customers
+ jdbc:h2:mem:testdb
+
+ com.sun.rowset.providers.RIOptimisticProvider
+ Oracle Corporation
+ 1.0
+ 2
+ 1
+
+
+
+ 2
+
+ 1
+ false
+ true
+ false
+ 0
+ true
+ true
+ 11
+ ID
+ ID
+ PUBLIC
+ 10
+ 0
+ CUSTOMERS
+ TESTDB
+ 4
+ INTEGER
+
+
+ 2
+ false
+ true
+ false
+ 0
+ true
+ true
+ 50
+ NAME
+ NAME
+ PUBLIC
+ 50
+ 0
+ CUSTOMERS
+ TESTDB
+ 12
+ VARCHAR
+
+
+
+
+ 1
+ Customer1
+
+
+ 2
+ Customer2
+
+
+ 3
+ Customer3
+
+
+ 4
+ Customer4
+
+
+ 5
+ Customer5
+
+
+
diff --git a/core-java/pom.xml b/core-java/pom.xml
index 77000b8741..068a772c43 100644
--- a/core-java/pom.xml
+++ b/core-java/pom.xml
@@ -1,491 +1,496 @@
- 4.0.0
- com.baeldung
- core-java
- 0.1.0-SNAPSHOT
- jar
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
+ com.baeldung
+ core-java
+ 0.1.0-SNAPSHOT
+ jar
- core-java
+ core-java
-
+
-
-
- net.sourceforge.collections
- collections-generic
- ${collections-generic.version}
-
-
- com.google.guava
- guava
- ${guava.version}
-
-
-
- org.apache.commons
- commons-collections4
- ${commons-collections4.version}
-
-
-
- commons-io
- commons-io
- ${commons-io.version}
-
-
-
- org.apache.commons
- commons-lang3
- ${commons-lang3.version}
-
-
-
- org.apache.commons
- commons-math3
- ${commons-math3.version}
-
-
-
- org.decimal4j
- decimal4j
- ${decimal4j.version}
-
-
-
- org.bouncycastle
- bcprov-jdk15on
- ${bouncycastle.version}
-
-
-
- org.unix4j
- unix4j-command
- ${unix4j.version}
-
-
-
- com.googlecode.grep4j
- grep4j
- ${grep4j.version}
-
-
-
-
-
-
- com.fasterxml.jackson.core
- jackson-databind
- ${jackson.version}
-
-
-
-
- log4j
- log4j
- 1.2.17
-
-
- org.slf4j
- slf4j-api
- ${org.slf4j.version}
-
-
- ch.qos.logback
- logback-classic
- ${logback.version}
-
-
-
- org.slf4j
- jcl-over-slf4j
- ${org.slf4j.version}
-
-
-
- org.slf4j
- log4j-over-slf4j
- ${org.slf4j.version}
-
-
- org.projectlombok
- lombok
- ${lombok.version}
- provided
-
-
-
-
-
- org.hamcrest
- hamcrest-all
- 1.3
- test
-
-
-
- junit
- junit
- ${junit.version}
- test
-
-
-
- org.hamcrest
- hamcrest-core
- ${org.hamcrest.version}
- test
-
-
- org.hamcrest
- hamcrest-library
- ${org.hamcrest.version}
- test
-
-
-
- org.assertj
- assertj-core
- ${assertj.version}
- test
-
-
-
- org.mockito
- mockito-core
- ${mockito.version}
- test
-
-
- com.jayway.awaitility
- awaitility
- ${avaitility.version}
- test
-
-
-
- commons-codec
- commons-codec
- ${commons-codec.version}
-
-
-
- org.javamoney
- moneta
- 1.1
-
-
-
- org.owasp.esapi
- esapi
- 2.1.0.1
-
-
-
- com.sun.messaging.mq
- fscontext
- ${fscontext.version}
-
-
- com.codepoetics
- protonpack
- ${protonpack.version}
-
-
- one.util
- streamex
- ${streamex.version}
-
-
- io.vavr
- vavr
- ${vavr.version}
-
-
- org.openjdk.jmh
- jmh-core
- 1.19
-
-
- org.openjdk.jmh
- jmh-generator-annprocess
- 1.19
-
+
- org.springframework
- spring-web
- 4.3.4.RELEASE
+ net.sourceforge.collections
+ collections-generic
+ ${collections-generic.version}
+
+
+ com.google.guava
+ guava
+ ${guava.version}
-
- com.sun
- tools
- 1.8.0
- system
- ${java.home}/../lib/tools.jar
-
-
-
- core-java
-
-
- src/main/resources
- true
-
-
+
+ org.apache.commons
+ commons-collections4
+ ${commons-collections4.version}
+
-
+
+ commons-io
+ commons-io
+ ${commons-io.version}
+
-
- org.apache.maven.plugins
- maven-compiler-plugin
- ${maven-compiler-plugin.version}
-
-
- 1.8
-
-
+
+ org.apache.commons
+ commons-lang3
+ ${commons-lang3.version}
+
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
- **/*LiveTest.java
- **/*IntegrationTest.java
- **/*LongRunningUnitTest.java
- **/*ManualTest.java
-
+
+ org.apache.commons
+ commons-math3
+ ${commons-math3.version}
+
-
-
+
+ org.decimal4j
+ decimal4j
+ ${decimal4j.version}
+
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- copy-dependencies
- prepare-package
-
- copy-dependencies
-
-
- ${project.build.directory}/libs
-
-
-
-
+
+ org.bouncycastle
+ bcprov-jdk15on
+ ${bouncycastle.version}
+
-
- org.apache.maven.plugins
- maven-jar-plugin
-
-
-
- true
- libs/
- org.baeldung.executable.ExecutableMavenJar
-
-
-
-
+
+ org.unix4j
+ unix4j-command
+ ${unix4j.version}
+
-
- org.apache.maven.plugins
- maven-assembly-plugin
-
-
- package
-
- single
-
-
- ${project.basedir}
-
-
- org.baeldung.executable.ExecutableMavenJar
-
-
-
- jar-with-dependencies
-
-
-
-
-
+
+ com.googlecode.grep4j
+ grep4j
+ ${grep4j.version}
+
+
-
- org.apache.maven.plugins
- maven-shade-plugin
-
-
-
- shade
-
-
- true
-
-
- org.baeldung.executable.ExecutableMavenJar
-
-
-
-
-
-
+
-
- com.jolira
- onejar-maven-plugin
-
-
-
- org.baeldung.executable.ExecutableMavenJar
- true
- ${project.build.finalName}-onejar.${project.packaging}
-
-
- one-jar
-
-
-
-
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ ${jackson.version}
+
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
- repackage
-
-
- spring-boot
- org.baeldung.executable.ExecutableMavenJar
-
-
-
-
+
+
+ log4j
+ log4j
+ 1.2.17
+
+
+ org.slf4j
+ slf4j-api
+ ${org.slf4j.version}
+
+
+ ch.qos.logback
+ logback-classic
+ ${logback.version}
+
+
+
+ org.slf4j
+ jcl-over-slf4j
+ ${org.slf4j.version}
+
+
+
+ org.slf4j
+ log4j-over-slf4j
+ ${org.slf4j.version}
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+ provided
+
-
- org.codehaus.mojo
- exec-maven-plugin
- 1.6.0
-
- java
- com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed
-
- -Xmx300m
- -XX:+UseParallelGC
- -classpath
-
- com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed
-
-
-
+
+
+
+ org.hamcrest
+ hamcrest-all
+ 1.3
+ test
+
+
+
+ junit
+ junit
+ ${junit.version}
+ test
+
+
+
+ org.hamcrest
+ hamcrest-core
+ ${org.hamcrest.version}
+ test
+
+
+ org.hamcrest
+ hamcrest-library
+ ${org.hamcrest.version}
+ test
+
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
+
+
+ org.mockito
+ mockito-core
+ ${mockito.version}
+ test
+
+
+ com.jayway.awaitility
+ awaitility
+ ${avaitility.version}
+ test
+
+
+
+ commons-codec
+ commons-codec
+ ${commons-codec.version}
+
+
+
+ org.javamoney
+ moneta
+ 1.1
+
+
+
+ org.owasp.esapi
+ esapi
+ 2.1.0.1
+
+
+ com.h2database
+ h2
+ 1.4.196
+ runtime
+
+
+ com.sun.messaging.mq
+ fscontext
+ ${fscontext.version}
+
+
+ com.codepoetics
+ protonpack
+ ${protonpack.version}
+
+
+ one.util
+ streamex
+ ${streamex.version}
+
+
+ io.vavr
+ vavr
+ ${vavr.version}
+
+
+ org.openjdk.jmh
+ jmh-core
+ 1.19
+
+
+ org.openjdk.jmh
+ jmh-generator-annprocess
+ 1.19
+
+
+ org.springframework
+ spring-web
+ 4.3.4.RELEASE
+
+
+
+ org.springframework.boot
+ spring-boot-starter
+ 1.5.8.RELEASE
+
+
+
+
+
+ core-java
+
+
+ src/main/resources
+ true
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+
+ 1.8
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ **/*LiveTest.java
+ **/*IntegrationTest.java
+ **/*LongRunningUnitTest.java
+ **/*ManualTest.java
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+
+
+ copy-dependencies
+ prepare-package
+
+ copy-dependencies
+
+
+ ${project.build.directory}/libs
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+
+ true
+ libs/
+ org.baeldung.executable.ExecutableMavenJar
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+ package
+
+ single
+
+
+ ${project.basedir}
+
+
+ org.baeldung.executable.ExecutableMavenJar
+
+
+
+ jar-with-dependencies
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+
+
+
+ shade
+
+
+ true
+
+
+ org.baeldung.executable.ExecutableMavenJar
+
+
+
+
+
+
+
+
+ com.jolira
+ onejar-maven-plugin
+
+
+
+ org.baeldung.executable.ExecutableMavenJar
+ true
+ ${project.build.finalName}-onejar.${project.packaging}
+
+
+ one-jar
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ repackage
+
+
+ spring-boot
+ org.baeldung.executable.ExecutableMavenJar
+
+
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.6.0
+
+ java
+ com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed
+
+ -Xmx300m
+ -XX:+UseParallelGC
+ -classpath
+
+ com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed
+
+
+
-
+
-
+
-
-
- integration
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
- integration-test
-
- test
-
-
-
- **/*ManualTest.java
-
-
- **/*IntegrationTest.java
-
-
-
-
-
-
- json
-
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
+
+
+ integration
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ integration-test
+
+ test
+
+
+
+ **/*ManualTest.java
+
+
+ **/*IntegrationTest.java
+
+
+
+
+
+
+ json
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
-
-
- run-benchmarks
-
- none
-
- exec
-
-
- test
- java
-
- -classpath
-
- org.openjdk.jmh.Main
- .*
-
-
-
-
-
-
-
-
-
+
+
+ run-benchmarks
+
+ none
+
+ exec
+
+
+ test
+ java
+
+ -classpath
+
+ org.openjdk.jmh.Main
+ .*
+
+
+
+
+
+
+
+
+
-
-
- 2.8.5
+
+
+ 2.8.5
-
- 1.7.21
- 1.1.7
+
+ 1.7.21
+ 1.1.7
-
- 23.0
- 3.5
- 1.55
- 1.10
- 3.6.1
- 1.0.3
- 2.5
- 4.1
- 4.01
- 0.4
- 1.8.7
- 1.16.12
- 4.6-b01
- 1.13
- 0.6.5
- 0.9.0
-
-
- 1.3
- 4.12
- 2.8.9
- 3.6.1
- 1.7.0
+
+ 22.0
+ 3.5
+ 1.55
+ 1.10
+ 3.6.1
+ 1.0.3
+ 2.5
+ 4.1
+ 4.01
+ 0.4
+ 1.8.7
+ 1.16.12
+ 4.6-b01
+ 1.13
+ 0.6.5
+ 0.9.0
-
- 3.6.0
- 2.19.1
-
-
\ No newline at end of file
+
+ 1.3
+ 4.12
+ 2.8.9
+ 3.6.1
+ 1.7.0
+
+
+ 3.6.0
+ 2.19.1
+
+
diff --git a/core-java/src/main/java/com/baeldung/array/ArrayBenchmarkRunner.java b/core-java/src/main/java/com/baeldung/array/ArrayBenchmarkRunner.java
new file mode 100644
index 0000000000..977587a06a
--- /dev/null
+++ b/core-java/src/main/java/com/baeldung/array/ArrayBenchmarkRunner.java
@@ -0,0 +1,21 @@
+package com.baeldung.array;
+
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+public class ArrayBenchmarkRunner {
+
+ public static void main(String[] args) throws Exception {
+
+ Options options = new OptionsBuilder()
+ .include(SearchArrayTest.class.getSimpleName()).threads(1)
+ .forks(1).shouldFailOnError(true).shouldDoGC(true)
+ .jvmArgs("-server").build();
+
+ new Runner(options).run();
+
+
+ }
+
+}
diff --git a/core-java/src/main/java/com/baeldung/array/ArrayInverter.java b/core-java/src/main/java/com/baeldung/array/ArrayInverter.java
new file mode 100644
index 0000000000..7f7fcbb5a8
--- /dev/null
+++ b/core-java/src/main/java/com/baeldung/array/ArrayInverter.java
@@ -0,0 +1,41 @@
+package com.baeldung.array;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.IntStream;
+
+import org.apache.commons.lang3.ArrayUtils;
+
+import com.google.common.collect.Lists;
+
+public class ArrayInverter {
+
+ public void invertUsingFor(Object[] array) {
+ for (int i = 0; i < array.length / 2; i++) {
+ Object temp = array[i];
+ array[i] = array[array.length - 1 - i];
+ array[array.length - 1 - i] = temp;
+ }
+ }
+
+ public void invertUsingCollectionsReverse(Object[] array) {
+ List