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

cdc.issues.Param Maven / Gradle / Ivy

package cdc.issues;

import java.util.regex.Pattern;

import cdc.util.lang.Checks;

/**
 * Definition of an effective parameter.
 * 

* It is a (name, value) pair, where name can not be {@code null}. * * @author Damien Carbonne */ public interface Param extends NameValue, Comparable { /** * @param name The name. * @param value The value. * @return A new Param instance from {@code name} and {@code value}. * @throws IllegalArgumentException When {@code name} is not valid. */ public static Param of(String name, String value) { return new ParamImpl(name, value); } /** * Returns true if a string is a valid name: *

    *
  • It cannot be null *
  • It cannot be empty *
  • It cannot contain any space or control character *
* * @param name The name. * @return {@code true} if {@code label} is a valid label. */ public static boolean isValidName(String name) { return name != null && ParamImpl.VALID_NAME_PATTERN.matcher(name).matches(); } /** * @return A new {@link Builder} of {@link Param}. * @deprecated Use {@link Param#of(String, String)}. */ @Deprecated(since = "2014-03-30", forRemoval = true) public static Builder builder() { return new Builder(); } /** * Builder of {@link Param}. * * @deprecated Use {@link Param#of(String, String)}. */ @Deprecated(since = "2014-03-30", forRemoval = true) public static final class Builder { private String name; private String value; private Builder() { } public Builder name(String name) { this.name = name; return this; } public Builder value(String value) { this.value = value; return this; } public Param build() { return Param.of(name, value); } } } record ParamImpl(String name, String value) implements Param { /** Accept anything except spaces */ static final Pattern VALID_NAME_PATTERN = Pattern.compile("^\\w[\\w\\-/ ]*$"); ParamImpl { Checks.isTrue(Meta.isValidName(name), "name"); } @Override public int compareTo(Param other) { return name.compareTo(other.getName()); } @Override public String getName() { return name; } @Override public String getValue() { return value; } @Override public String toString() { return "[" + name + "=" + value + "]"; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy