-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mrsaraira/enum-containers
2.0.0 + support enum constant containers
- Loading branch information
Showing
11 changed files
with
459 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
328 changes: 251 additions & 77 deletions
328
src/main/java/io/github/mrsaraira/constants/Constants.java
Large diffs are not rendered by default.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
src/main/java/io/github/mrsaraira/constants/EnumConstantContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.github.mrsaraira.constants; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Enumeration constant container that stores a {@link Constant}. | ||
* The constants can be operated using utility class {@link Constants} or custom logic. | ||
* <p> | ||
* {@inheritDoc} | ||
* | ||
* @param <L> relation constant key value type | ||
* @param <E> (self reference) of Enum which implements this {@link EnumConstantContainer} | ||
* @author Takhsin Saraira | ||
*/ | ||
public interface EnumConstantContainer<L, E extends Enum<E> & EnumConstantContainer<L, E>> extends ConstantContainer<L> { | ||
|
||
/** | ||
* Get enumeration constant. | ||
* | ||
* @return enumeration constant | ||
*/ | ||
Constant<L> getConstant(); | ||
|
||
@Override | ||
default Collection<Constant<L>> getAllKeys() { | ||
return Arrays.stream(values()).map(EnumConstantContainer::getConstant).collect(Collectors.toUnmodifiableSet()); | ||
} | ||
|
||
@Override | ||
default Set<L> getAllValues() { | ||
return getAllKeys().stream() | ||
.map(Constant::getValue) | ||
.collect(Collectors.toUnmodifiableSet()); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private E[] values() { | ||
return Constants.Inner.getEnumValues((Class<E>) getClass()); | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/io/github/mrsaraira/constants/EnumRelationConstantContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.github.mrsaraira.constants; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Enumeration relation constant container that stores a {@link RelationConstant}. | ||
* The relation constants can be operated using utility class {@link Constants} or custom logic. | ||
* <p> | ||
* {@inheritDoc} | ||
* | ||
* @param <L> relation constant key value type | ||
* @param <R>relation constant relation values type | ||
* @param <E> (self reference) of Enum which implements this {@link EnumRelationConstantContainer} | ||
* @author Takhsin Saraira | ||
*/ | ||
public interface EnumRelationConstantContainer<L, R, E extends Enum<E> & EnumRelationConstantContainer<L, R, E>> extends EnumConstantContainer<L, E>, RelationConstantContainer<L, R> { | ||
|
||
/** | ||
* Get enumeration relation constant. | ||
* | ||
* @return enum relation constant | ||
*/ | ||
RelationConstant<L, R> getConstant(); | ||
|
||
/** | ||
* Returns relation values of the enumeration relation constant. | ||
* | ||
* @return collection of relation values of the constant. | ||
*/ | ||
default Collection<R> getRelationValues() { | ||
return Constants.getValues(getConstant().getRelations()); | ||
} | ||
|
||
@Override | ||
default Collection<RelationConstant<L, R>> getAllRelations() { | ||
return Arrays.stream(values()).map(EnumRelationConstantContainer::getConstant).collect(Collectors.toUnmodifiableSet()); | ||
} | ||
|
||
@Override | ||
default List<Collection<R>> getAllRelationsValues() { | ||
return getAllRelations().stream() | ||
.map(RelationConstant::getRelations) | ||
.map(Constants::getValues) | ||
.collect(Collectors.toUnmodifiableList()); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private E[] values() { | ||
return Constants.Inner.getEnumValues((Class<E>) getClass()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.