Skip to content

The Catalog API provides an interface to give a common behavior to an Enum, such as searching for a specific Enum element based on the field value set in the Enum, or checking if a specific value is defined in the field of the Enum.

License

Notifications You must be signed in to change notification settings

myConsciousness/catalog-api

Repository files navigation

Build Latest Version License
Java CI with Gradle

1. Catalog API

Table of Contents

1.1. What is it?

Make easier to maintain and use constants!

This is a Java-based API designed to make the constants group more maintainable and extensible.
It manages regularized constants as a single catalog and provides a convenient utility interface to manipulate the catalog.

1.2. Benefits

  • It assumes the use of Enum
  • Necessary processes for constant operation are integrated in the interface
  • Useful common behaviors can be used anywhere
  • No need to use public static final constant classes anymore
  • Easy to maintain and use constants!

1.3. How To Use

1.3.1. Add the dependencies

Note:
Replace version you want to use. Check the latest Packages.
Please contact me for a token to download the package.

Maven

<dependency>
  <groupId>org.thinkit.api.catalog</groupId>
  <artifactId>catalog-api</artifactId>
  <version>v1.0.3</version>
</dependency>

<servers>
  <server>
    <id>github</id>
    <username>myConsciousness</username>
    <password>xxxxxxxxxxxxxxxxxx</password>
  </server>
</servers>

Gradle

repositories {
    maven {
        name = "GitHubPackages"
        url = uri("https://maven.pkg.github.com/myConsciousness/catalog-api")
        credentials {
          username = "myConsciousness"
          password = "xxxxxxxxxxxxxxxxxx"
        }
    }
}

dependencies {
    implementation 'org.thinkit.api.catalog:catalog-api:v1.0.3'
}

1.3.2. Select interface you want to use

The Catalog API currently provides the following interfaces.
Choose the interface you want to use depending on your needs.

Interface Overview
Catalog<E extends Catalog> This is the basic catalog interface.
Elements of the concrete catalog class that implement this interface have a code value.
You can use the common behavior defined in the Catalog interface.
BiCatalog<E extends BiCatalog<E, T>, T> Each element of a concrete catalog class that implements this interface can have a code value plus a value of any data type.
The arbitrary data type is defined at the time of implementation of the concrete catalog class.
You can use the common behavior of the interface.

1.3.3. Import and implement Enum with Catalog / BiCatalog interface

Catalog<E extends Catalog>

import org.thinkit.api.catalog.Catalog;

/**
 * Because the catalog applies the mechanism of recursive generics,
 * specify own type to the generics when implement the Catalog interface.
 */
public enum TestCatalog implements Catalog<TestCatalog> {

    /**
     * Catalog constants need unique code value as an parameter
     */
    TEST(0);

    /**
     * Required code value
     */
    private int code;

    /**
     * Simple constructor
     */
    TestCatalog(int code) {
        this.codecode;
    }

    @Override
    public int getCode() {
        return this.code;
    }
}

BiCatalog<E extends BiCatalog<E, T>, T>

import org.thinkit.api.catalog.BiCatalog;

/**
 * Because the catalog applies the mechanism of recursive generics,
 * specify own type to the generics when implement the BiCatalog interface.
 */
public enum TestBiCatalog implements BiCatalog<TestBiCatalog, String> {

    /**
     * BiCatalog constants need unique code value and any tag value as parameters
     */
    TEST(0, "test");

    /**
     * Required code value
     */
    private int code;

    /**
     * Required tag value.
     * The data type of the tag is the data type specified to generics when implement BiCatalog interface.
     */
    private String tag;

    /**
     * Simple constructor
     */
    TestCatalog(int code, String tag) {
        this.codecode;
        this.tagtag;
    }

    @Override
    public int getCode() {
        return this.code;
    }

    @Override
    public String getTag() {
        return this.tag;
    }
}

1.4. License

Copyright 2020 Kato Shinya.

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.

1.5. More Information

Catalog API was designed and implemented by Kato Shinya, who works as a freelance developer.

Regardless of the means or content of communication, I would love to hear from you if you have any questions or concerns. I do not check my email box very often so a response may be delayed, anyway thank you for your interest!

About

The Catalog API provides an interface to give a common behavior to an Enum, such as searching for a specific Enum element based on the field value set in the Enum, or checking if a specific value is defined in the field of the Enum.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Languages