📄 enumtype.java
字号:
package org.momeunit.ant.core;import org.apache.tools.ant.BuildException;/** * Abstract base class for all enumerated attribute values. Subclasses should * override abstract method {@link #getValues()} to return array of case * insensitive possible string values. This array is not exposed externally. * Method {@link #getPossibleValues()} returns copy of this array. Contains * constructor {@link #EnumType(String)} which takes string value to be * initialized with as parameter. Contains method {@link #getValue()} for * accessing string value of enumerated type. * * @author Sergio Morozov * @version 1.1.2 */public abstract class EnumType{ private int index = -1; /** * Initializes new enumerated type with specified {@link String} value. * * @param value * value new enumerated type to be initialized with. * @since 1.1.2 */ public EnumType(String value) { setValue(value); } /** * Sets value of this enumerated type. * * @param value * value to be set. * @since 1.1.2 */ public void setValue(String value) { this.index = getIndex(value); if (this.index < 0) throw new BuildException("unknown attribute value"); } /** * Returns value of this enumerated type as {@link String}. * * @return the value of this enumerated type as {@link String}. * @since 1.1.2 */ public String getValue() { return getValues()[this.index]; } /** * Returns index of value in array of possible values as returned from * {@link #getPossibleValues()}. * * @return the index of value of this enumerated type. * @since 1.1.2 */ protected int getIndex() { return this.index; } /** * Returns index of specified value in array of possible values as returned * from {@link #getPossibleValues()} or <code>-1</code> if not found. * * * @param value * string value to search for. * @return index of specified value or <code>-1</code> if not found. * @since 1.1.2 */ protected int getIndex(String value) { String[] values = getValues(); int res = -1; for (int i = values.length - 1; i >= 0; i--) if (values[i].equalsIgnoreCase(value)) res = i; return res; } /** * Returns array of possible string values of this enumerated type. * * @return the array of possible string values of this enumerated type. * @since 1.1.2 */ public String[] getPossibleValues() { String[] values = getValues(); String[] res = new String[values.length]; System.arraycopy(values, 0, res, 0, values.length); return res; } /** * Returns number of possible string values of this enumerated type. * * @return the number of possible string values of this enumerated type. * @since 1.1.2 */ public int getPossibleValuesNumber() { return getValues().length; } /** * Returns array of possible string values of this enumerated type. Subclasses * should override this method. Returned array is not exposed externally. * * @return the array of possible string values. * @since 1.1.2 */ protected abstract String[] getValues();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -