// Path: vertx-infinispan/src/main/java/io/vertx/ext/cluster/infinispan/InfinispanAsyncMap.java
// @VertxGen
// public interface InfinispanAsyncMap<K, V> {
// 
//   /**
//    * Unwraps a generic {@link AsyncMap} to an {@link InfinispanAsyncMap}.
//    *
//    * @throws IllegalArgumentException if underlying implementation is not Infinispan
//    */
//   @SuppressWarnings("unchecked")
//   static <K, V> InfinispanAsyncMap<K, V> unwrap(AsyncMap asyncMap) {
//     if (asyncMap instanceof WrappedAsyncMap) {
//       WrappedAsyncMap wrappedAsyncMap = (WrappedAsyncMap) asyncMap;
//       AsyncMap delegate = wrappedAsyncMap.getDelegate();
//       if (delegate instanceof InfinispanAsyncMap) {
//         return (InfinispanAsyncMap<K, V>) delegate;
//       }
//     }
//     throw new IllegalArgumentException(String.valueOf(asyncMap != null ? asyncMap.getClass() : null));
//   }
// 
//   /**
//    * Get the keys of the map as a {@link ReadStream}.
//    * <p>
//    * The stream will be automatically closed if it fails or ends.
//    * Otherwise you must set a null {@link ReadStream#handler(Handler) data handler} after usage to avoid leaking resources.
//    *
//    * @return a stream of map keys
//    */
//   ReadStream<K> keyStream();
// 
//   /**
//    * Get the values of the map as a {@link ReadStream}.
//    * <p>
//    * The stream will be automatically closed if it fails or ends.
//    * Otherwise you must set a null {@link ReadStream#handler(Handler) data handler} after usage to avoid leaking resources.
//    *
//    * @return a stream of map values
//    */
//   ReadStream<V> valueStream();
// 
//   /**
//    * Get the entries of the map as a {@link ReadStream}.
//    * <p>
//    * The stream will be automatically closed if it fails or ends.
//    * Otherwise you must set a null {@link ReadStream#handler(Handler) data handler} after usage to avoid leaking resources.
//    *
//    * @return a stream of map entries
//    */
//   @GenIgnore
//   ReadStream<Map.Entry<K, V>> entryStream();
// }


import io.vertx.core.Future;
import io.vertx.core.impl.VertxInternal;
import io.vertx.core.shareddata.AsyncMap;
import io.vertx.core.streams.ReadStream;
import io.vertx.ext.cluster.infinispan.InfinispanAsyncMap;
import org.infinispan.AdvancedCache;
import org.infinispan.Cache;
import org.infinispan.context.Flag;
import org.infinispan.stream.CacheCollectors;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.*;
/*
 * Copyright 2021 Red Hat, Inc.
 *
 * Red Hat licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License 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.
 */

package io.vertx.ext.cluster.infinispan.impl;




/**
 * @author Thomas Segismont
 */
public class InfinispanAsyncMapImpl<K, V> implements AsyncMap<K, V>, InfinispanAsyncMap<K, V> {

  private final VertxInternal vertx;
  private final AdvancedCache<byte[], byte[]> cache;
  private final AdvancedCache<byte[], byte[]> ignoreReturnCache;

  public InfinispanAsyncMapImpl(VertxInternal vertx, Cache<byte[], byte[]> cache) {
    this.vertx = vertx;
    this.cache = cache.getAdvancedCache();
    ignoreReturnCache = this.cache.withFlags(Flag.IGNORE_RETURN_VALUES);
  }

  @Override
// Path: vertx-infinispan/src/main/java/io/vertx/ext/cluster/infinispan/InfinispanAsyncMap.java
// @VertxGen
// public interface InfinispanAsyncMap<K, V> {
// 
//   /**
//    * Unwraps a generic {@link AsyncMap} to an {@link InfinispanAsyncMap}.
//    *
//    * @throws IllegalArgumentException if underlying implementation is not Infinispan
//    */
//   @SuppressWarnings("unchecked")
//   static <K, V> InfinispanAsyncMap<K, V> unwrap(AsyncMap asyncMap) {
//     if (asyncMap instanceof WrappedAsyncMap) {
//       WrappedAsyncMap wrappedAsyncMap = (WrappedAsyncMap) asyncMap;
//       AsyncMap delegate = wrappedAsyncMap.getDelegate();
//       if (delegate instanceof InfinispanAsyncMap) {
//         return (InfinispanAsyncMap<K, V>) delegate;
//       }
//     }
//     throw new IllegalArgumentException(String.valueOf(asyncMap != null ? asyncMap.getClass() : null));
//   }
// 
//   /**
//    * Get the keys of the map as a {@link ReadStream}.
//    * <p>
//    * The stream will be automatically closed if it fails or ends.
//    * Otherwise you must set a null {@link ReadStream#handler(Handler) data handler} after usage to avoid leaking resources.
//    *
//    * @return a stream of map keys
//    */
//   ReadStream<K> keyStream();
// 
//   /**
//    * Get the values of the map as a {@link ReadStream}.
//    * <p>
//    * The stream will be automatically closed if it fails or ends.
//    * Otherwise you must set a null {@link ReadStream#handler(Handler) data handler} after usage to avoid leaking resources.
//    *
//    * @return a stream of map values
//    */
//   ReadStream<V> valueStream();
// 
//   /**
//    * Get the entries of the map as a {@link ReadStream}.
//    * <p>
//    * The stream will be automatically closed if it fails or ends.
//    * Otherwise you must set a null {@link ReadStream#handler(Handler) data handler} after usage to avoid leaking resources.
//    *
//    * @return a stream of map entries
//    */
//   @GenIgnore
//   ReadStream<Map.Entry<K, V>> entryStream();
// }


// Path: vertx-infinispan/src/main/java/io/vertx/ext/cluster/infinispan/impl/InfinispanAsyncMapImpl.java
import io.vertx.core.Future;
import io.vertx.core.impl.VertxInternal;
import io.vertx.core.shareddata.AsyncMap;
import io.vertx.core.streams.ReadStream;
import io.vertx.ext.cluster.infinispan.InfinispanAsyncMap;
import org.infinispan.AdvancedCache;
import org.infinispan.Cache;
import org.infinispan.context.Flag;
import org.infinispan.stream.CacheCollectors;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.*;

/*
 * Copyright 2021 Red Hat, Inc.
 *
 * Red Hat licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License 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.
 */

package io.vertx.ext.cluster.infinispan.impl;




/**
 * @author Thomas Segismont
 */
public class InfinispanAsyncMapImpl<K, V> implements AsyncMap<K, V>, InfinispanAsyncMap<K, V> {

  private final VertxInternal vertx;
  private final AdvancedCache<byte[], byte[]> cache;
  private final AdvancedCache<byte[], byte[]> ignoreReturnCache;

  public InfinispanAsyncMapImpl(VertxInternal vertx, Cache<byte[], byte[]> cache) {
    this.vertx = vertx;
    this.cache = cache.getAdvancedCache();
    ignoreReturnCache = this.cache.withFlags(Flag.IGNORE_RETURN_VALUES);
  }

  @Override
  public Future<V> get(K k) {