This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Sample productDetailsJson = "{'productId' : '1', 'name': 'Xbox360', 'price': '18000', 'currency': 'INR'}"; | |
public Map<String, Object> buildProductMap(String productDetailsJson) throws IOException { | |
ObjectMapper mapper = new ObjectMapper(); | |
Map<String, Object> productMap = mapper.readValue(productDetailsJson, new TypeReference<Map<String, String>>(){}); | |
return productMap; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Sample productDetailsJson = "{'productId' : '1', 'name': 'Xbox360', 'price': '18000', 'currency': 'INR'}"; | |
public Product buildConcreteProduct(String productDetailsJson) { | |
ObjectMapper mapper = new ObjectMapper(); | |
Product product = mapper.readValue(productDetailsJson, Product.class); | |
return product; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Future<String> buildOrderDetail(String orderId) { | |
CompletableFuture<String> products = supplyAsync(() -> getProductList(orderId)); | |
CompletableFuture<String> addressDetails = supplyAsync(() -> getAddress(orderId)); | |
CompletableFuture<Void> combinedFuture = CompletableFuture.allOf(products, addressDetails); | |
return combinedFuture.get(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.microservices.example; | |
import com.google.common.cache.Cache; | |
import com.google.common.cache.CacheBuilder; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RequestParam; | |
import org.springframework.web.bind.annotation.RestController; | |
import org.springframework.web.context.request.async.DeferredResult; | |
import java.util.concurrent.TimeUnit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final String URL = "http://bookmarkservice.herokuapp.com/bookmarks"; | |
try { | |
String recordListAsString = ClientBuilder.newClient().target(URL).request().accept(MediaType.APPLICATION_JSON).get(String.class); | |
Gson gson = new Gson(); | |
Type type = new TypeToken<List<Bookmark>>() { }.getType(); | |
List<Bookmark> list = gson.fromJson(recordListAsString, type); | |
return list; | |
} catch (Exception ce) { | |
return null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IAnalyzer { | |
public void collectSample(); | |
public String analyzeSample(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IRover { | |
public void run(); | |
public String currentLocation(); | |
public void turnRight(); | |
public void turnLeft(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MarsRoverTest { | |
@Test | |
public void canProvideCurrentLocationAsString() { | |
//Given | |
// a set of coordinates and plateau | |
//When | |
// we initialize the | |
// rover with coordinates and plateau |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BeverageMaker { | |
public Beverage prepareBeverage(IBeverageStrategy beverageStrategy) { | |
//Delegates to strategy | |
return beverageStrategy.prepare(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BeverageMaker { | |
public Beverage prepareBeverage(String beverageName) { | |
Beverage preparedBeverage = null; | |
if("Coffee".equals(beverageName)) { | |
//Uses builder pattern | |
preparedBeverage = new Beverage("Coffee").addCoffeePowderTbsp(2).addMilkCups(2).addSugarTbsp(1).prepare(); | |
} else if ("Tea".equals(beverageName)) { | |
preparedBeverage = new Beverage("Tea").addTeaPowderTbsp(2).addMilkCups(2).addSugarTbsp(1).prepare(); | |
} else if ("Black Tea".equals(beverageName)) { |
NewerOlder