インタフェース BiCatalog<E extends BiCatalog<E,T>,T>
-
- すべてのスーパーインタフェース:
BiCatalogSupport<E,T>
,CodeSupport
,TagSupport<T>
public interface BiCatalog<E extends BiCatalog<E,T>,T> extends BiCatalogSupport<E,T>
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. TheBiCatalog
interface will then manage values of any type as tags, and the second generic type should be the type of value you want to manage in the Enum element.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.
The value managed as a tag can be any value as long as it conforms to the type specified in the generics. However, since Java does not currently allow primitive types to be specified in generics, only object types can be managed as tags. This specification may be improved in a later version of Java.
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 BiCatalog<EnumClass, String> { ELEMENT_1(0, "test1"), ELEMENT_2(1, "test2"); private int code; private String tag; EnumClass(int code) { this.code = code; } @Override public int getCode() { return this.code; } @Override public String getTag() { return this.tag; } }
public class TestBiCatalog { public static void main(String[] args) { BiCatalog.hasCode(EnumClass.class, 1); // Returns true BiCatalog.getEnum(EnumClass.class, 1); // Returns EnumClass#ELEMENT_2 BiCatalog.contains(EnumClass.class, "test1"); // Returns true BiCatalog.getEnumByTag(EnumClass.class, "test1"); // Returns EnumClass#ELEMENT_1 } }
- 導入されたバージョン:
- 1.0.0
-
-
メソッドの概要
staticメソッド 修飾子とタイプ メソッド 説明 static <E extends BiCatalog<E,T>,T>
booleancontains(Class<? extends BiCatalog<E,T>> clazz, T tag)
Checks if the target Enum class has an Enum element linked to the tag value passed as an argument.static <E extends BiCatalog<E,T>,T>
EgetEnum(Class<? extends BiCatalog<E,T>> clazz, int code)
Returns the Enum element linked to the code value given as an argument from the target Enum class.static <E extends BiCatalog<E,T>,T>
EgetEnumByTag(Class<? extends BiCatalog<E,T>> clazz, T tag)
Returns the Enum element linked to the tag value given as an argument from the target Enum class.static <E extends BiCatalog<E,T>,T>
Map<Integer,E>getMap(Class<? extends BiCatalog<E,T>> clazz)
Returns theMap
representation of this catalog class.static <E extends BiCatalog<E,T>,T>
List<E>getOrderedList(Class<? extends BiCatalog<E,T>> clazz)
Returns theList
representation of this catalog class.static <E extends BiCatalog<E,T>,T>
booleanhasCode(Class<? extends BiCatalog<E,T>> 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 BiCatalog<E,T>,T>
Stream<? extends BiCatalog<E,T>>stream(Class<? extends BiCatalog<E,T>> clazz)
Returns theStream
representation of the target Enum class.-
インタフェースから継承されたメソッド org.thinkit.api.catalog.BiCatalogSupport
equalsByCode, equalsByTag, toEnum
-
インタフェースから継承されたメソッド org.thinkit.api.catalog.CodeSupport
getCode
-
インタフェースから継承されたメソッド org.thinkit.api.catalog.TagSupport
getTag
-
-
-
-
メソッドの詳細
-
getOrderedList
static <E extends BiCatalog<E,T>,T> List<E> getOrderedList(Class<? extends BiCatalog<E,T>> 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 classT
- The type of tag value- パラメータ:
clazz
- The Enum class to be sorted- 戻り値:
- The sorted Enum elements based on the code value
-
getEnum
static <E extends BiCatalog<E,T>,T> E getEnum(Class<? extends BiCatalog<E,T>> 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 classT
- The type of tag value- パラメータ:
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
-
getEnumByTag
static <E extends BiCatalog<E,T>,T> E getEnumByTag(Class<? extends BiCatalog<E,T>> clazz, T tag)
Returns the Enum element linked to the tag value given as an argument from the target Enum class. If the target Enum class does not have an Enum element linked to the tag value given as an argument,null
is returned.- 型パラメータ:
E
- The type of Enum classT
- The type of tag value- パラメータ:
clazz
- The target Enum classtag
- The tag value linked to the Enum element- 戻り値:
- The Enum element linked to the tag value, or
null
if the target Enum class does not have an Enum element linked to the tag value
-
getMap
static <E extends BiCatalog<E,T>,T> Map<Integer,E> getMap(Class<? extends BiCatalog<E,T>> 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.BiCatalog<E, T>>)
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 classT
- The type of tag value- パラメータ:
clazz
- The target Enum class- 戻り値:
- The
Map
representation of this catalog class
-
hasCode
static <E extends BiCatalog<E,T>,T> boolean hasCode(Class<? extends BiCatalog<E,T>> 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 classT
- The type of tag value- パラメータ:
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
-
contains
static <E extends BiCatalog<E,T>,T> boolean contains(Class<? extends BiCatalog<E,T>> clazz, T tag)
Checks if the target Enum class has an Enum element linked to the tag value passed as an argument.- 型パラメータ:
E
- The type of Enum classT
- The type of tag value- パラメータ:
clazz
- The target Enum classtag
- The tag value- 戻り値:
true
if the target Enum class has an Enum element linked to the tag value passed as an argument, otherwisefalse
-
stream
static <E extends BiCatalog<E,T>,T> Stream<? extends BiCatalog<E,T>> stream(Class<? extends BiCatalog<E,T>> clazz)
Returns theStream
representation of the target Enum class.- 型パラメータ:
E
- The type of Enum classT
- The type of tag value- パラメータ:
clazz
- The target Enum class- 戻り値:
- The
Stream
representation of the target Enum class
-
-