package com.lanyuanxiaoyao.service.command.provider;

import java.util.List;
import java.util.Optional;
import org.springframework.shell.standard.ValueProviderSupport;

/**
 * @author ZhangJiacheng
 * @date 2022-05-30
 */
public abstract class BaseValueProvider extends ValueProviderSupport {
    protected Optional<String> getField(List<String> words, String fieldName) {
        boolean hasField = words.stream().anyMatch(word -> word.contains(fieldName));
        if (hasField) {
            int index = words.indexOf(fieldName) + 1;
            if (index < words.size()) {
                return Optional.of(words.get(index));
            }
        }
        return Optional.empty();
    }
}
