インタフェース Catalog<E extends Catalog<E>>
-
- すべてのスーパーインタフェース:
CatalogSupport<E>
,CodeSupport
public interface Catalog<E extends Catalog<E>> extends CatalogSupport<E>
The interface that extends the functionality of Enum, a built-in feature of Java, and consolidates general-purpose functions used in many situations. This interface can be implements in existing Enum classes to easily add useful functionality. When implementing this interface, please specify the type of the class that implements this interface in the generic.This interface manages the code value used to identify each element of an Enum. The code value is an arbitrary numeric value that can be specified for each element of the Enum class that implements this interface; the code value for each element of the Enum does not need to be in the order of the elements, and can be specified in any way that the implementor of this interface chooses. However, since this code value is used to identify each element of the Enum, it is important that the specified value does not overlap with any other element in the Enum class.
This interface provides generic functions based on the code values specified in the Enum class that implements this interface. For example, there is a
hasCode(Class, int)
to determine whether the code value given as an argument is defined in the target Enum class, and there is agetEnum(Class, int)
that returns the Enum element associated with the number given as an argument from the target Enum class. Other generic methods are also provided, but all of them require the target Enum class to implement this interface.The basic implementation and usage examples of this interface are briefly described below.
public enum EnumClass implements Catalog<EnumClass> { ELEMENT_1(0), ELEMENT_2(1); private int code; EnumClass(int code) { this.code = code; } @Override public int getCode() { return this.code; } }
public class TestCatalog { public static void main(String[] args) { Catalog.hasCode(EnumClass.class, 1); // Returns true Catalog.getEnum(EnumClass.class, 1); // Returns EnumClass#ELEMENT_2 } }
- 導入されたバージョン:
- 1.0.0
-
-
メソッドの概要
staticメソッド 修飾子とタイプ メソッド 説明 static <E extends Catalog<E>>
EgetEnum(Class<? extends Catalog<E>> clazz, int code)
Returns the Enum element linked to the code value given as an argument from the target Enum class.static <E extends Catalog<E>>
Map<Integer,E>getMap(Class<? extends Catalog<E>> clazz)
Returns theMap
representation of this catalog class.static <E extends Catalog<E>>
List<E>getOrderedList(Class<? extends Catalog<E>> clazz)
Returns theList
representation of this catalog class.static <E extends Catalog<E>>
booleanhasCode(Class<? extends Catalog<E>> clazz, int code)
Checks if the target Enum class has an Enum element linked to the code value passed as an argument.static <E extends Catalog<E>>
Stream<? extends Catalog<E>>stream(Class<? extends Catalog<E>> clazz)
Returns theStream
representation of the target Enum class.-
インタフェースから継承されたメソッド org.thinkit.api.catalog.CatalogSupport
equalsByCode, toEnum
-
インタフェースから継承されたメソッド org.thinkit.api.catalog.CodeSupport
getCode
-
-
-
-
メソッドの詳細
-
getOrderedList
static <E extends Catalog<E>> List<E> getOrderedList(Class<? extends Catalog<E>> clazz)
Returns theList
representation of this catalog class.The
List
representation of this catalog class is sorted each element based on the code value specified for each element of the Enum class that implements theCatalog
interface. This sorting process is based on theStream.sorted()
algorithm.- 型パラメータ:
E
- The type of Enum class- パラメータ:
clazz
- The Enum class to be sorted- 戻り値:
- The sorted Enum elements based on the code value
-
getEnum
static <E extends Catalog<E>> E getEnum(Class<? extends Catalog<E>> clazz, int code)
Returns the Enum element linked to the code value given as an argument from the target Enum class. If the target Enum class does not have an Enum element linked to the code value given as an argument,null
is returned.- 型パラメータ:
E
- The type of Enum class- パラメータ:
clazz
- The target Enum classcode
- The code value linked to the Enum element- 戻り値:
- The Enum element linked to the code value, or
null
if the target Enum class does not have an Enum element linked to the code value
-
getMap
static <E extends Catalog<E>> Map<Integer,E> getMap(Class<? extends Catalog<E>> clazz)
Returns theMap
representation of this catalog class.The structure of the map returned by this
getMap(java.lang.Class<? extends org.thinkit.api.catalog.Catalog<E>>)
has the code value specified in the Enum element of the Enum class that implements thisCatalog
interface as the key and the Enum element linked to the code value as the value.- 型パラメータ:
E
- The type of Enum class- パラメータ:
clazz
- The target Enum class- 戻り値:
- The
Map
representation of this catalog class
-
hasCode
static <E extends Catalog<E>> boolean hasCode(Class<? extends Catalog<E>> clazz, int code)
Checks if the target Enum class has an Enum element linked to the code value passed as an argument.- 型パラメータ:
E
- The type of Enum class- パラメータ:
clazz
- The target Enum classcode
- The code value- 戻り値:
true
if the target Enum class has an Enum element linked to the code value passed as an argument, otherwisefalse
-
-