GenericEnums Parent

Generic Enum value-type code generation for Java 7+.

Лицензия

Лицензия

Группа

Группа

io.github.cmoine
Идентификатор

Идентификатор

generic-enums-parent
Последняя версия

Последняя версия

0.4
Дата

Дата

Тип

Тип

pom
Описание

Описание

GenericEnums Parent
Generic Enum value-type code generation for Java 7+.
Система контроля версий

Система контроля версий

https://github.com/cmoine/generic-enums

Скачать generic-enums-parent

Имя Файла Размер
generic-enums-parent-0.4.pom 6 KB
Обзор

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/io.github.cmoine/generic-enums-parent/ -->
<dependency>
    <groupId>io.github.cmoine</groupId>
    <artifactId>generic-enums-parent</artifactId>
    <version>0.4</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/io.github.cmoine/generic-enums-parent/
implementation 'io.github.cmoine:generic-enums-parent:0.4'
// https://jarcasting.com/artifacts/io.github.cmoine/generic-enums-parent/
implementation ("io.github.cmoine:generic-enums-parent:0.4")
'io.github.cmoine:generic-enums-parent:pom:0.4'
<dependency org="io.github.cmoine" name="generic-enums-parent" rev="0.4">
  <artifact name="generic-enums-parent" type="pom" />
</dependency>
@Grapes(
@Grab(group='io.github.cmoine', module='generic-enums-parent', version='0.4')
)
libraryDependencies += "io.github.cmoine" % "generic-enums-parent" % "0.4"
[io.github.cmoine/generic-enums-parent "0.4"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

  • annotations
  • processor
  • it

Generic Enums

Build Status

What is Generic Enums

This is a Java annotation processor to provide Generic Enums. It is basically an attempt to implement the JEP301

Example of generic enum which can be useful if you want to serialize typed parameters:

@GenericEnum
enum Parameters {
    BYTE(byte.class, (byte)0),
    SHORT(short.class, (short)0),
    INT(int.class, 0),
    FLOAT(float.class, 0f),
    LONG(long.class, 0L),
    DOUBLE(double.class, 0d),
    CHAR(char.class, 'a'),
    BOOLEAN(boolean.class, false),
    BOOLEAN_OBJECT(Boolean.class, false),
    STRING(String.class, "");

    private final Class<?> boxClass;
    @GenericEnumParam
    private final Object defaultValue;

    Parameters(Class<?> boxClass, @GenericEnumParam Object defaultValue) {
       this.boxClass = boxClass;
       this.defaultValue = defaultValue;
    }

    @GenericEnumParam
    public Object getDefaultValue() {
        return defaultValue;
    }
}

The annotation processor will generate a class ParametersExt by default.

Then you can use it this way:

class MyParameterSer {
    int getInt(Parameters<Integer> param) {
        // Use you deserialization mechanism...
    }
    
    void setInt(Parameters<Integer> param, int value) {
        // Use you Serialization mechanism...
    }
    
    // And so on for all supported types
}

public class Main {
    public static void main(String[] args) {
        MyParameterSer parameterSer=new MyParameterSer();
        parameterSer.setInt(ParametersExt.INT, 99);
        parameterSer.setInt(ParametersExt.BOOLEAN, 99); // ends up in a compilation error !
    }
}

You can find other sample here.

Requirements

Generic Enums requires Java 1.8 or later.

Using Generic Enums

Maven

...
<properties>
    <generic.enums.version>0.4</generic.enums.version>
</properties>
...
<dependencies>
    <dependency>
        <groupId>io.github.cmoine</groupId>
        <artifactId>generic-enums-annotations</artifactId>
        <version>${generic.enums.version}</version>
    </dependency>
</dependencies>
...
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <annotationProcessorPaths>
                    <path>
                        <groupId>io.github.cmoine</groupId>
                        <artifactId>generic-enums-annotations</artifactId>
                        <version>${generic.enums.version}</version>
                    </path>
                </annotationProcessorPaths>
            </configuration>
        </plugin>
    </plugins>
</build>
...

Gradle

dependencies {
    compileOnly "io.github.cmoine:generic-enums-annotations:0.4"
    annotationProcessor "io.github.cmoine:generic-enums-processor:0.4"
}

Licensing

MIT License

Copyright (c) 2021 Christophe Moine

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Версии библиотеки

Версия
0.4
0.3
0.2