com.univocity.parsers.annotations.EnumOptions Maven / Gradle / Ivy
Show all versions of univocity-parsers Show documentation
/*******************************************************************************
* Copyright 2015 Univocity Software Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package com.univocity.parsers.annotations;
import com.univocity.parsers.common.processor.*;
import com.univocity.parsers.conversions.*;
import java.lang.annotation.*;
/**
* The {@code EnumSelector} annotation is meant to be used in conjunction with enumeration attributes.
*
* Values parsed from the input will be matched against one or more properties of the enumeration type.
* By default, values read from the input will be matched against:
*
* - {@link Enum#name()} - the name of the elements in the enumeration type
* - {@link Enum#ordinal()} - the ordinal of the elements in the enumeration type
* - {@link Enum#toString()} - the {@code String} representation of the elements in the enumeration type
*
*
* You can also define a {@link #customElement()} of your enumeration type (an attribute or method), as long as it
* uniquely identifies each value of your enumeration type.
*
* Use the {@link #selectors()} option to choose which properties to match the parsed input against, and in what order. You will only need to
* explicitly add a {@link EnumSelector#CUSTOM_FIELD} or {@link EnumSelector#CUSTOM_METHOD} to the list of {@link #selectors()} if your {@link #customElement()} name
* could point to both an attribute and a method in your enumeration.
*
* This will assign an {@link EnumConversion} to this field.
*
* Commonly used for java beans processed using {@link BeanProcessor} and/or {@link BeanWriterProcessor}
*
* @see BeanProcessor
* @see BeanWriterProcessor
*
* @author Univocity Software Pty Ltd - [email protected]
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE})
public @interface EnumOptions {
/**
*
A list of properties of the enumeration type that will be matched against the parsed input to identify which enum element should be assigned to the annotated field.
* By default, values read from the input will be matched against:
*
* - {@link Enum#name()} - the name of the elements in the enumeration type
* - {@link Enum#ordinal()} - the ordinal of the elements in the enumeration type
* - {@link Enum#toString()} - the {@code String} representation of the elements in the enumeration type
*
* @return the sequence of properties of the enumeration type to match against the parsed input.
*/
EnumSelector[] selectors() default {EnumSelector.NAME, EnumSelector.ORDINAL, EnumSelector.STRING};
/**
*
* Defines the name of a custom element (attribute or method) of the annotated enumeration. This will be used to match the parsed input and identify an individual value of the enumeration.
* The attribute value, or object returned from the method, should uniquely identify a value of the enumeration;
*
* You will only need to explicitly add a {@link EnumSelector#CUSTOM_FIELD} or {@link EnumSelector#CUSTOM_METHOD} to the list of {@link #selectors()}
* if your {@link #customElement()} name could point to both an attribute and a method in your enumeration.
*
* @return the name of a custom element (attribute or method) of the enumeration which will match the parsed input and identify an enumeration's value.
*/
String customElement() default "";
}