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

com.redis.om.spring.search.stream.actions.ArrayPopAction Maven / Gradle / Ivy

package com.redis.om.spring.search.stream.actions;

import java.lang.reflect.Field;
import java.util.Optional;
import java.util.function.Function;

import com.redis.om.spring.util.ObjectUtils;
import com.redislabs.modules.rejson.Path;

public class ArrayPopAction extends BaseAbstractAction implements Function {

  private Long index;

  public ArrayPopAction(Field field, Long index) {
    super(field);
    this.index = index;
  }

  @SuppressWarnings("unchecked")
  @Override
  public R apply(E entity) {
    Optional> maybeClass = ObjectUtils.getCollectionElementType(field);
    if (maybeClass.isPresent()) {
      return (R) json.arrPop(getKey(entity), maybeClass.get(), Path.of("." + field.getName()), index);
    } else {
      throw new RuntimeException("Cannot determine contained element type for collection " + field.getName());
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy