Skip to content

Instantly share code, notes, and snippets.

View Prashant1293's full-sized avatar
:shipit:
Focusing

Prashant Sharma Prashant1293

:shipit:
Focusing
  • Publicis Sapient
  • ghaziabad
View GitHub Profile
package edu.knoldus.enumeration;
enum Rose {
RED(true), BLACK(false), WHITE(true), PINK(true), BROWN(false);
private final boolean isAvailable;
int count = 0;
Rose(boolean isAvailable) {
System.out.println("Instance " + (++count) + " for constant " + this.name() + " created.");
package edu.knoldus.enumeration;
enum BoardMaterial {WHITE, BLACK, SHEET}
enum BoardMaterial2 {BLACK}
public class BasicEnumerationDemo {
public static void main(String[] args) {
package edu.knoldus.enumeration;
enum BoardMaterial {WHITE, BLACK, SHEET}
public class BasicEnumerationConcept {
public static void main(String[] args) {
// create an instance of BoardMaterial enum and assign a value to it.
BoardMaterial material = BoardMaterial.BLACK;
System.out.println(material);
@Prashant1293
Prashant1293 / BlogControllerCorrect.java
Created February 18, 2020 15:37
To show case how to use the mono.zipWith() to combine multiple mono's.
package edu.knoldus.com.handsonspringboot.zipwithblogcontent.controller;
import edu.knoldus.com.handsonspringboot.zipwithblogcontent.repository.BlogRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
Service A implementation....
private static final ParameterizedTypeReference<
ResponseEntity<ThirdPartyResponse>> ROUTE =
new ParameterizedTypeReference<ResponseEntity<ThirdPartyResponse>>() {
};
private WebClient webClient;
//Method in service A used to invoke the service B using the webclient from spring-boot webflux.
@Prashant1293
Prashant1293 / WebClient-QueryParam-1
Created August 5, 2019 12:45
This Gist takes you through the simplest way to invoke a third party service using spring boot webflux's webclient.
Service A implementation....
private static final ParameterizedTypeReference<
ResponseEntity<ThirdPartyResponse>> ROUTE =
new ParameterizedTypeReference<ResponseEntity<ThirdPartyResponse>>() {
};
private WebClient webClient;
//Method in service A used to invoke the service B using the webclient from spring-boot webflux.
@Prashant1293
Prashant1293 / GenericsBasic.java
Last active June 23, 2019 11:43
Object references were used prior to the introduction of generics in java, but they were not type safe and lack and needed explicit type casting between the objects. In this gist we will see how the generics resolved the concerns related to object references.
/* Let suppose we need to create a class called MySummation, that provides a sum of marks obtained by a student in his annual
examination. Now marks in a subject can be int, float or double. So we need to have a method that can take these types as
parameters and perform the computation accordingly. */
class MySum<T> {
T sum; // sum is now of type T which is a parameterized type.
MySum(T totalMarks){
sum = totalMarks; // Assign sum the value in totalMarks can be a int, double, float etc.
}
@Prashant1293
Prashant1293 / ObjectReferenceGeneralization.java
Last active June 23, 2019 11:41
Object references were used prior to the introduction of generics in java, this snippet walks through the mechanism to create Object references showing their usage and areas of concern related to them.
/* Let suppose we need to create a class called MySummation, that provides a sum of marks obtained by a student in his annual
examination. Now marks in a subject can be int, float or double. So we need to have a method that can take these types as
parameters and perform the computation accordingly. */
class MySum {
Object sum; // sum is now of type object
MySum(Object totalMarks){
sum = totalMarks; // Assign sum the value in totalMarks can be a int, double, float etc.
}
@Singleton
public class ErrorHandler extends DefaultHttpErrorHandler {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
@Inject
public ErrorHandler(Config configuration, Environment environment,
OptionalSourceMapper sourceMapper, Provider<Router> routes) {
super(configuration, environment, sourceMapper, routes);
}
@Singleton
public class ErrorHandler extends DefaultHttpErrorHandler {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
@Inject
public ErrorHandler(Configuration configuration, Environment environment,
OptionalSourceMapper sourceMapper, Provider<Router> routes) {
super(configuration, environment, sourceMapper, routes);
}