
com.github.yin.flags.Flag Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-flags Show documentation
Show all versions of java-flags Show documentation
Easy to use command-line parser, which enables you to
define cmdline flags directly the class they are used in.
package com.github.yin.flags;
/**
* Provides Flag value access and validation to client classes. Flag value is injected into static
* fields of type {@link Flag} and accessed using {@link #get()}.
*
* {@link #parse(String)} is never used by client classes, but should be implemented if a custom
* return type is desired from {@link #get()}.
*
* @author yin
*/
public interface Flag {
/**
* Validates parsed flag values. May be used to enforce compile-time constraints safely and
* also run-time if care is taken to avoid lockup in a mutually recursive chain of {@link #get()}'s.
*/
@FunctionalInterface
interface Validator {
void validate(T value);
}
/**
* Attaches a {@link Validator} function to this flag instance.
*/
Flag validator(Validator validator);
/**
* Attempts parsing a {@link String} representation of a value and is responsible for calling
* the validator function afterwards.
*/
void parse(String value);
/**
* Returns value stored in the flag, possibly a default value.
*/
T get();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy