All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.client.hotrod.impl.CacheEntryConversion Maven / Gradle / Ivy

The newest version!
package org.infinispan.client.hotrod.impl;

import java.util.function.Function;

import org.infinispan.api.common.CacheEntry;
import org.infinispan.client.hotrod.MetadataValue;
import org.infinispan.client.hotrod.impl.cache.CacheEntryImpl;
import org.infinispan.client.hotrod.impl.cache.CacheEntryMetadataImpl;

@SuppressWarnings({"unchecked", "rawtypes"})
final class CacheEntryConversion {

   private CacheEntryConversion() { }

   private static final Function READ_VALUE = entry -> entry != null
         ? ((MetadataValue) entry).getValue()
         : null;

   static  Function, V> extractValue() {
      return (Function, V>) READ_VALUE;
   }

   static  Function, CacheEntry> createCacheEntry(K key) {
      return metadata -> metadata == null
            ? null
            : new CacheEntryImpl<>(key, metadata.getValue(), new CacheEntryMetadataImpl<>(metadata));
   }
}