This is a simple description of the method. . . + * Superman! + *
+ * @param incomingDamage the amount of incoming damage + * @return the amount of health hero has after attack + * @see HERO-402 + * @since 1.0 + */ + public int successfullyAttacked(int incomingDamage, String damageType) { + // do things + return 0; + } + + public String getHeroName() { + return heroName; + } + + public void setHeroName(String heroName) { + this.heroName = heroName; + } + + public String getUniquePower() { + return uniquePower; + } + + public void setUniquePower(String uniquePower) { + this.uniquePower = uniquePower; + } + + public int getHealth() { + return health; + } + + public void setHealth(int health) { + this.health = health; + } + + public int getDefense() { + return defense; + } + + public void setDefense(int defense) { + this.defense = defense; + } + +} diff --git a/core-java/src/main/java/com/baeldung/regexp/datepattern/DateMatcher.java b/core-java/src/main/java/com/baeldung/regexp/datepattern/DateMatcher.java new file mode 100644 index 0000000000..3e85bf13bb --- /dev/null +++ b/core-java/src/main/java/com/baeldung/regexp/datepattern/DateMatcher.java @@ -0,0 +1,7 @@ +package com.baeldung.regexp.datepattern; + +public interface DateMatcher { + + boolean matches(String date); + +} diff --git a/core-java/src/main/java/com/baeldung/regexp/datepattern/FormattedDateMatcher.java b/core-java/src/main/java/com/baeldung/regexp/datepattern/FormattedDateMatcher.java new file mode 100644 index 0000000000..1d3a609b55 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/regexp/datepattern/FormattedDateMatcher.java @@ -0,0 +1,14 @@ +package com.baeldung.regexp.datepattern; + +import java.util.regex.Pattern; + +class FormattedDateMatcher implements DateMatcher { + + private static final Pattern DATE_PATTERN = Pattern.compile( + "^\\d{4}-\\d{2}-\\d{2}$"); + + @Override + public boolean matches(String date) { + return DATE_PATTERN.matcher(date).matches(); + } +} diff --git a/core-java/src/main/java/com/baeldung/regexp/datepattern/RangedDateMatcher.java b/core-java/src/main/java/com/baeldung/regexp/datepattern/RangedDateMatcher.java new file mode 100644 index 0000000000..af4e183fef --- /dev/null +++ b/core-java/src/main/java/com/baeldung/regexp/datepattern/RangedDateMatcher.java @@ -0,0 +1,14 @@ +package com.baeldung.regexp.datepattern; + +import java.util.regex.Pattern; + +class RangedDateMatcher implements DateMatcher { + + private static final Pattern DATE_PATTERN = Pattern.compile( + "^((19|2[0-9])[0-9]{2})-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$"); + + @Override + public boolean matches(String date) { + return DATE_PATTERN.matcher(date).matches(); + } +} diff --git a/core-java/src/main/java/com/baeldung/regexp/datepattern/gregorian/February29thMatcher.java b/core-java/src/main/java/com/baeldung/regexp/datepattern/gregorian/February29thMatcher.java new file mode 100644 index 0000000000..b0243ae48f --- /dev/null +++ b/core-java/src/main/java/com/baeldung/regexp/datepattern/gregorian/February29thMatcher.java @@ -0,0 +1,16 @@ +package com.baeldung.regexp.datepattern.gregorian; + +import com.baeldung.regexp.datepattern.DateMatcher; + +import java.util.regex.Pattern; + +public class February29thMatcher implements DateMatcher { + + private static final Pattern DATE_PATTERN = Pattern.compile( + "^((2000|2400|2800|(19|2[0-9](0[48]|[2468][048]|[13579][26])))-02-29)$"); + + @Override + public boolean matches(String date) { + return DATE_PATTERN.matcher(date).matches(); + } +} diff --git a/core-java/src/main/java/com/baeldung/regexp/datepattern/gregorian/FebruaryGeneralMatcher.java b/core-java/src/main/java/com/baeldung/regexp/datepattern/gregorian/FebruaryGeneralMatcher.java new file mode 100644 index 0000000000..f294348928 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/regexp/datepattern/gregorian/FebruaryGeneralMatcher.java @@ -0,0 +1,16 @@ +package com.baeldung.regexp.datepattern.gregorian; + +import com.baeldung.regexp.datepattern.DateMatcher; + +import java.util.regex.Pattern; + +public class FebruaryGeneralMatcher implements DateMatcher { + + private static final Pattern DATE_PATTERN = Pattern.compile( + "^(((19|2[0-9])[0-9]{2})-02-(0[1-9]|1[0-9]|2[0-8]))$"); + + @Override + public boolean matches(String date) { + return DATE_PATTERN.matcher(date).matches(); + } +} diff --git a/core-java/src/main/java/com/baeldung/regexp/datepattern/gregorian/GregorianDateMatcher.java b/core-java/src/main/java/com/baeldung/regexp/datepattern/gregorian/GregorianDateMatcher.java new file mode 100644 index 0000000000..fc8abdb201 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/regexp/datepattern/gregorian/GregorianDateMatcher.java @@ -0,0 +1,19 @@ +package com.baeldung.regexp.datepattern.gregorian; + +import com.baeldung.regexp.datepattern.DateMatcher; + +import java.util.regex.Pattern; + +class GregorianDateMatcher implements DateMatcher { + + private static final Pattern DATE_PATTERN = Pattern.compile( + "^((2000|2400|2800|(19|2[0-9](0[48]|[2468][048]|[13579][26])))-02-29)$" + + "|^(((19|2[0-9])[0-9]{2})-02-(0[1-9]|1[0-9]|2[0-8]))$" + + "|^(((19|2[0-9])[0-9]{2})-(0[13578]|10|12)-(0[1-9]|[12][0-9]|3[01]))$" + + "|^(((19|2[0-9])[0-9]{2})-(0[469]|11)-(0[1-9]|[12][0-9]|30))$"); + + @Override + public boolean matches(String date) { + return DATE_PATTERN.matcher(date).matches(); + } +} diff --git a/core-java/src/main/java/com/baeldung/regexp/datepattern/gregorian/MonthsOf30DaysMatcher.java b/core-java/src/main/java/com/baeldung/regexp/datepattern/gregorian/MonthsOf30DaysMatcher.java new file mode 100644 index 0000000000..be202081e8 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/regexp/datepattern/gregorian/MonthsOf30DaysMatcher.java @@ -0,0 +1,17 @@ +package com.baeldung.regexp.datepattern.gregorian; + +import com.baeldung.regexp.datepattern.DateMatcher; + +import java.util.regex.Pattern; + +public class MonthsOf30DaysMatcher implements DateMatcher { + + private static final Pattern DATE_PATTERN = Pattern.compile( + "^(((19|2[0-9])[0-9]{2})-(0[469]|11)-(0[1-9]|[12][0-9]|30))$"); + + @Override + public boolean matches(String date) { + return DATE_PATTERN.matcher(date).matches(); + } + +} diff --git a/core-java/src/main/java/com/baeldung/regexp/datepattern/gregorian/MonthsOf31DaysMatcher.java b/core-java/src/main/java/com/baeldung/regexp/datepattern/gregorian/MonthsOf31DaysMatcher.java new file mode 100644 index 0000000000..7f0943991b --- /dev/null +++ b/core-java/src/main/java/com/baeldung/regexp/datepattern/gregorian/MonthsOf31DaysMatcher.java @@ -0,0 +1,17 @@ +package com.baeldung.regexp.datepattern.gregorian; + +import com.baeldung.regexp.datepattern.DateMatcher; + +import java.util.regex.Pattern; + +public class MonthsOf31DaysMatcher implements DateMatcher { + + private static final Pattern DATE_PATTERN = Pattern.compile( + "^(((19|2[0-9])[0-9]{2})-(0[13578]|10|12)-(0[1-9]|[12][0-9]|3[01]))$"); + + @Override + public boolean matches(String date) { + return DATE_PATTERN.matcher(date).matches(); + } + +} diff --git a/core-java/src/main/java/com/baeldung/socket/EchoMultiServer.java b/core-java/src/main/java/com/baeldung/socket/EchoMultiServer.java index a9f055f8f4..d2f9f0459c 100644 --- a/core-java/src/main/java/com/baeldung/socket/EchoMultiServer.java +++ b/core-java/src/main/java/com/baeldung/socket/EchoMultiServer.java @@ -16,7 +16,7 @@ public class EchoMultiServer { try { serverSocket = new ServerSocket(port); while (true) - new EchoClientHandler(serverSocket.accept()).run(); + new EchoClientHandler(serverSocket.accept()).start(); } catch (IOException e) { e.printStackTrace(); diff --git a/core-java/src/main/java/com/baeldung/staticclass/Pizza.java b/core-java/src/main/java/com/baeldung/staticclass/Pizza.java new file mode 100644 index 0000000000..ee6283cee1 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/staticclass/Pizza.java @@ -0,0 +1,33 @@ +package com.baeldung.staticclass; + +public class Pizza { + + private static String cookedCount; + private boolean isThinCrust; + + // Accessible globally + public static class PizzaSalesCounter { + + private static String orderedCount; + public static String deliveredCount; + + PizzaSalesCounter() { + System.out.println("Static field of enclosing class is " + + Pizza.cookedCount); + System.out.println("Non-static field of enclosing class is " + + new Pizza().isThinCrust); + } + } + + Pizza() { + System.out.println("Non private static field of static class is " + + PizzaSalesCounter.deliveredCount); + System.out.println("Private static field of static class is " + + PizzaSalesCounter.orderedCount); + } + + public static void main(String[] a) { + // Create instance of the static class without an instance of enclosing class + new Pizza.PizzaSalesCounter(); + } +} diff --git a/core-java/src/main/java/com/baeldung/threadlocalrandom/ThreadLocalRandomBenchMarkRunner.java b/core-java/src/main/java/com/baeldung/threadlocalrandom/ThreadLocalRandomBenchMarkRunner.java new file mode 100644 index 0000000000..e9c8056ff5 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/threadlocalrandom/ThreadLocalRandomBenchMarkRunner.java @@ -0,0 +1,22 @@ +package com.baeldung.threadlocalrandom; + +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +public class ThreadLocalRandomBenchMarkRunner { + + public static void main(String[] args) throws Exception { + + Options options = new OptionsBuilder().include(ThreadLocalRandomBenchMarker.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/threadlocalrandom/ThreadLocalRandomBenchMarker.java b/core-java/src/main/java/com/baeldung/threadlocalrandom/ThreadLocalRandomBenchMarker.java new file mode 100644 index 0000000000..8a0e2d2826 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/threadlocalrandom/ThreadLocalRandomBenchMarker.java @@ -0,0 +1,64 @@ +package com.baeldung.threadlocalrandom; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.TimeUnit; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Level; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Warmup; + +@BenchmarkMode(Mode.AverageTime) +@Warmup(iterations = 1) +@OutputTimeUnit(TimeUnit.MICROSECONDS) +@State(Scope.Benchmark) +public class ThreadLocalRandomBenchMarker { + + ListClasses number | +Lines number | +
---|---|
$CLASSES_NUMBER$ | +$LINES_NUMBER$ | +
+ Person's information: +
+ + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-security/oauth2client/src/test/java/com/example/springoath2/Springoath2ApplicationTests.java b/spring-cloud/spring-cloud-security/oauth2client/src/test/java/com/example/springoath2/Springoath2ApplicationTests.java new file mode 100644 index 0000000000..5fa51a61c3 --- /dev/null +++ b/spring-cloud/spring-cloud-security/oauth2client/src/test/java/com/example/springoath2/Springoath2ApplicationTests.java @@ -0,0 +1,16 @@ +package com.example.springoath2; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class Springoath2ApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/spring-cloud/spring-cloud-security/personresource/pom.xml b/spring-cloud/spring-cloud-security/personresource/pom.xml new file mode 100644 index 0000000000..ca1ff82515 --- /dev/null +++ b/spring-cloud/spring-cloud-security/personresource/pom.xml @@ -0,0 +1,70 @@ + +This page was rendered by the ExampleOne Servlet!
" + - "" + - "" - ); - } + + private static final long serialVersionUID = 1L; + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + out.println("" + "" + "" + "This page was rendered by the ExampleOne Servlet!
" + + "" + ""); + } } \ No newline at end of file diff --git a/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java b/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java index 49fefcffde..7269f917b4 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java +++ b/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java @@ -7,18 +7,14 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -@WebServlet( - name = "ExampleThree", - description = "JSP Servlet With Annotations", - urlPatterns = {"/ExampleThree"} -) +@WebServlet(name = "ExampleThree", description = "JSP Servlet With Annotations", urlPatterns = { "/ExampleThree" }) public class ExampleThree extends HttpServlet { - private static final long serialVersionUID = 1L; - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - String message = request.getParameter("message"); - request.setAttribute("text", message); - request.getRequestDispatcher("/jsp/ExampleThree.jsp").forward(request, response); - } + private static final long serialVersionUID = 1L; + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String message = request.getParameter("message"); + request.setAttribute("text", message); + request.getRequestDispatcher("/jsp/ExampleThree.jsp").forward(request, response); + } } diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ErrorController.java b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ErrorController.java index 96556bd5b1..6ae1023374 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ErrorController.java +++ b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ErrorController.java @@ -9,7 +9,7 @@ import org.springframework.web.servlet.ModelAndView; @Controller public class ErrorController { - + @RequestMapping(value = "500Error", method = RequestMethod.GET) public void throwRuntimeException() { throw new NullPointerException("Throwing a null pointer exception"); @@ -34,19 +34,18 @@ public class ErrorController { errorMsg = "Http Error Code : 404. Resource not found"; break; } - // Handle other 4xx error codes. + // Handle other 4xx error codes. case 500: { errorMsg = "Http Error Code : 500. Internal Server Error"; break; } - // Handle other 5xx error codes. + // Handle other 5xx error codes. } errorPage.addObject("errorMsg", errorMsg); return errorPage; } private int getErrorCode(HttpServletRequest httpRequest) { - return (Integer) httpRequest - .getAttribute("javax.servlet.error.status_code"); + return (Integer) httpRequest.getAttribute("javax.servlet.error.status_code"); } } diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GeoIPTestController.java b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GeoIPTestController.java index 16de4e56f5..eeaddcf8e0 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GeoIPTestController.java +++ b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GeoIPTestController.java @@ -14,15 +14,15 @@ import com.baeldung.spring.service.RawDBDemoGeoIPLocationService; @Controller public class GeoIPTestController { private RawDBDemoGeoIPLocationService locationService; + public GeoIPTestController() throws IOException { - locationService - = new RawDBDemoGeoIPLocationService(); + locationService = new RawDBDemoGeoIPLocationService(); } - @RequestMapping(value="/GeoIPTest", method = RequestMethod.POST) + + @RequestMapping(value = "/GeoIPTest", method = RequestMethod.POST) @ResponseBody - public GeoIP getLocation( - @RequestParam(value="ipAddress", required=true) String ipAddress) throws Exception { - + public GeoIP getLocation(@RequestParam(value = "ipAddress", required = true) String ipAddress) throws Exception { + return locationService.getLocation(ipAddress); } } diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java index ef8d1214df..fc46c07e06 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java +++ b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java @@ -12,7 +12,6 @@ import org.springframework.web.context.support.ServletContextResource; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletResponse; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/form/GeoIP.java b/spring-mvc-xml/src/main/java/com/baeldung/spring/form/GeoIP.java index 19f56867a1..4373303107 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/spring/form/GeoIP.java +++ b/spring-mvc-xml/src/main/java/com/baeldung/spring/form/GeoIP.java @@ -5,15 +5,15 @@ public class GeoIP { private String city; private String latitude; private String longitude; - + public GeoIP() { - + } - + public GeoIP(String ipAddress) { this.ipAddress = ipAddress; } - + public GeoIP(String ipAddress, String city, String latitude, String longitude) { this.ipAddress = ipAddress; this.city = city; @@ -52,5 +52,5 @@ public class GeoIP { public void setLongitude(String longitude) { this.longitude = longitude; } - + } diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java b/spring-mvc-xml/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java index af3ce8cfb3..04443466c9 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java +++ b/spring-mvc-xml/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java @@ -9,18 +9,18 @@ import com.maxmind.geoip2.DatabaseReader; import com.maxmind.geoip2.exception.GeoIp2Exception; import com.maxmind.geoip2.model.CityResponse; -public class RawDBDemoGeoIPLocationService{ +public class RawDBDemoGeoIPLocationService { private DatabaseReader dbReader; - + public RawDBDemoGeoIPLocationService() throws IOException { File database = new File("your-path-to-db-file"); dbReader = new DatabaseReader.Builder(database).build(); } - + public GeoIP getLocation(String ip) throws IOException, GeoIp2Exception { InetAddress ipAddress = InetAddress.getByName(ip); CityResponse response = dbReader.city(ipAddress); - + String cityName = response.getCity().getName(); String latitude = response.getLocation().getLatitude().toString(); String longitude = response.getLocation().getLongitude().toString(); diff --git a/spring-mvc-xml/src/main/resources/contentManagementWebMvcConfig.xml b/spring-mvc-xml/src/main/resources/contentManagementWebMvcConfig.xml index 41422d8954..75d5c1ecd6 100644 --- a/spring-mvc-xml/src/main/resources/contentManagementWebMvcConfig.xml +++ b/spring-mvc-xml/src/main/resources/contentManagementWebMvcConfig.xml @@ -4,11 +4,11 @@ xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans-4.2.xsd + http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://www.springframework.org/schema/context - http://www.springframework.org/schema/context/spring-context-4.2.xsd + http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/mvc - http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd"> + http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd">