当前位置: 首页>>代码示例>>Java>>正文


Java InMemRestaurantRepository类代码示例

本文整理汇总了Java中com.packtpub.mmj.mcrsrvc.persistence.InMemRestaurantRepository的典型用法代码示例。如果您正苦于以下问题:Java InMemRestaurantRepository类的具体用法?Java InMemRestaurantRepository怎么用?Java InMemRestaurantRepository使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


InMemRestaurantRepository类属于com.packtpub.mmj.mcrsrvc.persistence包,在下文中一共展示了InMemRestaurantRepository类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.packtpub.mmj.mcrsrvc.persistence.InMemRestaurantRepository; //导入依赖的package包/类
/**
 * main method of the Application
 *
 * @param args
 */
public static void main(String[] args) {
    try {
        // Initialize the RestaurantService
        RestaurantService restaurantService = new RestaurantService(new InMemRestaurantRepository());

        // Data Creation for Restaurants
        Table table1 = new Table("Table 1", BigInteger.ONE, 6);
        Table table2 = new Table("Table 2", BigInteger.valueOf(2), 4);
        Table table3 = new Table("Table 3", BigInteger.valueOf(3), 2);
        List<Table> tableList = new ArrayList();
        tableList.add(table1);
        tableList.add(table2);
        tableList.add(table3);
        Restaurant restaurant1 = new Restaurant("Big-O Restaurant", "1", tableList);

        // Adding the created restaurant using Service
        restaurantService.add(restaurant1);

        // Note: To raise an exception give Same restaurant name to one of the below restaurant
        Restaurant restaurant2 = new Restaurant("Pizza Shops", "2", null);
        restaurantService.add(restaurant2);

        Restaurant restaurant3 = new Restaurant("La Pasta", "3", null);
        restaurantService.add(restaurant3);

        // Retrieving all restaurants using Service
        Collection<Restaurant> restaurants = restaurantService.getAll();

        // Print the retrieved restaurants on console
        System.out.println("Restaurants List:");
        restaurants.stream().forEach((restaurant) -> {
            System.out.println(String.format("Restaurant: %s", restaurant));
        });
    } catch (Exception ex) {
        System.out.println(String.format("Exception: %s", ex.getMessage()));
        // Exception Handling Code
    }
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Microservices-with-Java-9-Second-Edition,代码行数:44,代码来源:RestaurantApp.java

示例2: main

import com.packtpub.mmj.mcrsrvc.persistence.InMemRestaurantRepository; //导入依赖的package包/类
/**
 * main method of the Application
 *
 * @param args
 */
public static void main(String[] args) {
    try {
        // Initialize the RestaurantService
        RestaurantService restaurantService = new RestaurantService(new InMemRestaurantRepository());

        // Data Creation for Restaurants
        Table table1 = new Table("Table 1", BigInteger.ONE, 6);
        Table table2 = new Table("Table 2", BigInteger.valueOf(2), 4);
        Table table3 = new Table("Table 3", BigInteger.valueOf(3), 2);
        List<Table> tableList = new ArrayList();
        tableList.add(table1);
        tableList.add(table2);
        tableList.add(table3);
        Restaurant restaurant1 = new Restaurant("Big-O Restaurant", "1", tableList);

        // Adding the created restaurant using Service
        restaurantService.add(restaurant1);

        // Note: To raise an exception give Same restaurant name to one of the below restaurant
        Restaurant restaurant2 = new Restaurant("Pizza Shops", "2", null);
        restaurantService.add(restaurant2);

        Restaurant restaurant3 = new Restaurant("La Pasta", "3", null);
        restaurantService.add(restaurant3);

        // Retrieving all restaurants using Service
        Collection<Restaurant> restaurants = restaurantService.getAll();

        // Print the retrieved restaurants on console
        System.out.println("Restaurants List:");
        restaurants.stream().forEach((restaurant) -> {
            System.out.println("Restaurant: " + restaurant);
        });
    } catch (Exception ex) {
        System.out.println("Exception: " + ex.getMessage());
        // Exception Handling Code
    }
}
 
开发者ID:PacktPublishing,项目名称:Microservices-Building-Scalable-Software,代码行数:44,代码来源:RestaurantApp.java


注:本文中的com.packtpub.mmj.mcrsrvc.persistence.InMemRestaurantRepository类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。