private static Map mergeActions()

in DynamoDbEncryption/runtimes/java/src/main/java/software/amazon/cryptography/dbencryptionsdk/dynamodb/enhancedclient/DynamoDbEnhancedClientEncryption.java [255:298]


  private static Map<String, CryptoAction> mergeActions(
    List<Map<String, CryptoAction>> actionList
  ) {
    // most common case
    if (actionList.size() == 1) {
      return actionList.get(0);
    }

    // Gather set of all attributes
    HashSet<String> attributes = new HashSet<>();
    for (Map<String, CryptoAction> config : actionList) {
      attributes.addAll(config.keySet());
    }

    // for each attribute, ensure that everyone agrees on its action
    Map<String, CryptoAction> actions = new HashMap<>();
    for (String attr : attributes) {
      Optional<CryptoAction> action = Optional.empty();
      for (Map<String, CryptoAction> config : actionList) {
        CryptoAction act = config.get(attr);
        if (act != null) {
          if (action.isPresent()) {
            if (!action.get().equals(act)) {
              throw DynamoDbEncryptionException
                .builder()
                .message(
                  String.format(
                    "Attribute %s set to %s in one table and %s in another.",
                    attr,
                    action.get(),
                    act
                  )
                )
                .build();
            }
          } else {
            action = Optional.of(act);
          }
        }
      }
      actions.put(attr, action.get());
    }
    return actions;
  }