/**
 * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * This file is licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License. A copy of
 * the License is located at
 *
 * http://aws.amazon.com/apache2.0/
 *
 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 *
 */

// snippet-comment:[These are tags for the AWS doc team's sample catalog. Do not remove.]
// snippet-sourcedescription:[DynamoDBAsyncGetItem.java demonstrates how to get an item by using the DynamoDbAsyncClient object]
// snippet-service:[dynamodb]
// snippet-keyword:[Java]
// snippet-keyword:[Amazon DynamoDB]
// snippet-keyword:[Code Sample]
// snippet-sourcetype:[full-example]
// snippet-sourcedate:[2019-11-19]
// snippet-sourceauthor:[AWS]

// snippet-start:[dynamodb.Java.DynamoDBAsyncGetItem.complete]
package com.example.dynamodbasync;
// snippet-start:[dynamoasyn.java2.get_item.import]
import software.amazon.awssdk.services.dynamodb.model.*;
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
import java.util.*;
import java.util.stream.Collectors;

// snippet-end:[dynamoasyn.java2.get_item.import]
public class DynamoDBAsyncGetItem {

    public static void main(String[] args)
    {

        final String USAGE = "\n" +
                "Usage:\n" +
                "    GetItem <table> <name> [projection_expression]\n\n" +
                "Where:\n" +
                "    table - the table to get an item from.\n" +
                "    name  - the item to get.\n\n" +
                "You can add an optional projection expression (a quote-delimited,\n" +
                "comma-separated list of attributes to retrieve) to limit the\n" +
                "fields returned from the table.\n\n" +
                "Example:\n" +
                "    GetItem HelloTable World\n" +
                "    GetItem SiteColors text \"default, bold\"\n";

        if (args.length < 2) {
            System.out.println(USAGE);
            System.exit(1);
        }

        // snippet-start:[dynamoasyc.java2.get_item.main]
        //Get both input arguments
        String table_name = args[0];
        String name = args[1];
        System.out.format("Retrieving item \"%s\" from \"%s\"\n", name, table_name);

        HashMap<String, AttributeValue> key_to_get =
                new HashMap<String, AttributeValue>();

        key_to_get.put("Name", AttributeValue.builder().s(name).build());

        try {

            DynamoDbAsyncClient client = DynamoDbAsyncClient.create();
            //Create a GetItemRequest instance
            GetItemRequest request =  GetItemRequest.builder()
                    .key(key_to_get)
                    .tableName(table_name)
                    .build();

            //Invoke the DynamoDbAsyncClient object's getItem
            java.util.Collection<software.amazon.awssdk.services.dynamodb.model.AttributeValue>  returned_item = client.getItem(request).join().item().values();

            //Convert Set to Map
            Map<String, AttributeValue> map = returned_item.stream().collect(Collectors.toMap(AttributeValue::s, s->s));
            Set<String> keys = map.keySet();
            for (String key : keys) {
                System.out.format("%s: %s\n",  key, map.get(key).toString());
                }


        } catch (Exception e) {
            System.err.println(e.getMessage());
            System.exit(1);
        }
        // snippet-end:[dynamoasyc.java2.get_item.main]
      }
 }
 
// snippet-end:[dynamodb.Java.DynamoDBAsyncGetItem.complete]

@@ -17,18 +17,18 @@
  2010-20
-19
+20
  Amazon.
@@ -1196,17 +1196,100 @@
 b.model.
-*
+GetItemRequest;%0Aimport software.amazon.awssdk.services.dynamodb.model.AttributeValue
 ;%0Aimport
@@ -1372,45 +1372,168 @@
 til.
-*;%0Aimport java.util.stream.Collectors
+HashMap;%0Aimport java.util.Map;%0Aimport java.util.Set;%0Aimport java.util.stream.Collectors;%0Aimport software.amazon.awssdk.services.dynamodb.model.DynamoDbException
 ;%0A%0A/
@@ -1660,20 +1660,16 @@
 %5B%5D args)
-%0A   
  %7B%0A%0A    
@@ -2550,18 +2550,17 @@
 ng table
-_n
+N
 ame = ar
@@ -2674,21 +2674,21 @@
 e, table
-_n
+N
 ame
+ 
 );%0A%0A    
@@ -2726,21 +2726,19 @@
 lue%3E key
-_to_g
+ToG
 et =%0A   
@@ -2801,21 +2801,19 @@
      key
-_to_g
+ToG
 et.put(%22
@@ -2945,24 +2945,25 @@
 t.create();%0A
+%0A
             
@@ -3033,17 +3033,16 @@
 equest =
- 
  GetItem
@@ -3091,13 +3091,11 @@
 (key
-_to_g
+ToG
 et)%0A
@@ -3134,10 +3134,9 @@
 able
-_n
+N
 ame)
@@ -3324,17 +3324,16 @@
 teValue%3E
- 
  returne
@@ -3333,18 +3333,17 @@
 returned
-_i
+I
 tem = cl
@@ -3476,18 +3476,17 @@
 returned
-_i
+I
 tem.stre
@@ -3670,17 +3670,16 @@
 : %25s%5Cn%22,
- 
  key, ma
@@ -3714,22 +3714,17 @@
         
-    %7D%0A
+%7D
 %0A%0A      
@@ -3734,16 +3734,24 @@
  catch (
+DynamoDb
 Exceptio
@@ -3907,16 +3907,12 @@
     
-  
 %7D%0A
- 
 %7D%0A
- 
 %0A// 

Update DynamoDBAsyncGetItem.java