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

net.forthecrown.grenadier.annotations.tree.ArgumentValue Maven / Gradle / Ivy

There is a newer version: 1.3.3
Show newest version
package net.forthecrown.grenadier.annotations.tree;

import java.util.List;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.jetbrains.annotations.ApiStatus.Internal;

@Internal
@Getter
@RequiredArgsConstructor
public class ArgumentValue {
  final T value;

  @Setter
  List mappedValues;

  public Object findValue(Class hint) {
    if (hint.isInstance(value)) {
      return value;
    }

    if (mappedValues == null || mappedValues.isEmpty()) {
      return null;
    }

    for (var o: mappedValues) {
      if (hint.isInstance(o)) {
        return o;
      }
    }

    return null;
  }
}