001/* 002 * Configurate 003 * Copyright (C) zml and Configurate contributors 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.spongepowered.configurate.objectmapping.meta; 018 019import org.checkerframework.checker.regex.qual.Regex; 020 021import java.lang.annotation.Documented; 022import java.lang.annotation.ElementType; 023import java.lang.annotation.Retention; 024import java.lang.annotation.RetentionPolicy; 025import java.lang.annotation.Target; 026 027/** 028 * Constrains a field value to ensure it matches the provided expression. 029 * 030 * <p>This constraint will always pass with an empty field. See {@link Required} 031 * to enforce a non-null value.</p> 032 * 033 * @since 4.0.0 034 */ 035@Documented 036@Retention(RetentionPolicy.RUNTIME) 037@Target(ElementType.FIELD) 038public @interface Matches { 039 040 /** 041 * Pattern to test string value against. 042 * 043 * @return pattern to test against 044 * @since 4.0.0 045 */ 046 @Regex String value(); 047 048 /** 049 * Message to throw in an exception when a match fails. 050 * 051 * <p>This message will be formatted as a MessageFormat with two 052 * parameters:</p> 053 * <ol start="0"> 054 * <li>the input string</li> 055 * <li>the pattern being matched</li> 056 * </ol> 057 * 058 * @return message format. 059 * @since 4.0.0 060 */ 061 String failureMessage() default ""; 062 063}