Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
+ update method name
  • Loading branch information
mrsaraira committed Oct 16, 2023
1 parent c00b27b commit eec51e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/main/java/io/github/mrsaraira/constants/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static <T, C extends ConstantContainer<T>> boolean anyValue(T value, @Non
* @return true - if any constant has a relation constant value equal to value parameter
*/
@SafeVarargs
public static <R, C extends RelationConstant<?, R>> boolean anyRelation(R value, @NonNull C... constants) {
public static <R, C extends RelationConstant<?, R>> boolean anyRelationValue(R value, @NonNull C... constants) {
return Stream.of(constants).anyMatch(constant -> getRelationValues(constant).contains(value));
}

Expand All @@ -185,7 +185,7 @@ public static <R, C extends RelationConstant<?, R>> boolean anyRelation(R value,
* @return true - if any container has a constant value equal to value parameter
*/
@SafeVarargs
public static <R, C extends RelationConstantContainer<?, R>> boolean anyRelation(R value, @NonNull C... containers) {
public static <R, C extends RelationConstantContainer<?, R>> boolean anyRelationValue(R value, @NonNull C... containers) {
return Stream.of(containers)
.map(container -> container.getAllRelationsValues())
.flatMap(Collection::stream)
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/io/github/mrsaraira/constants/DemoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ protected List<RelationConstant<String, Integer>> initialConstants() {
assertEquals("One", oneRelation.getKey().getValue());
assertEquals(1, oneRelation.getRelations().size());
assertEquals(1, oneRelation.getRelations().iterator().next().getValue());
assertTrue(Constants.anyRelation(1, oneRelation)); // same as above check
assertTrue(Constants.anyRelationValue(1, oneRelation)); // same as above statement

/*
We can get container instance anytime using Constants.getInstance(containerClass).
Unfortunately, Constants.getInstance(clazz) does not support anonymous classes, but it's not bad because you cannot
use the class anywhere beside this method, also you have container instance already ☺ -> (var anonymousContainer)
Unfortunately, Constants.getInstance(clazz) does not support anonymous classes, but it's bad because you cannot
use the anonymous class anywhere beside this method, also you have container instance already ☺ -> (var anonymousContainer)
*/
assertThrows(IllegalStateException.class, () -> Constants.getInstance(anonymousContainer.getClass()));

Expand Down Expand Up @@ -84,12 +84,12 @@ use the class anywhere beside this method, also you have container instance alre
assertTrue(relationValues.get(relationValues.size() - 1).containsAll(List.of(4, 5)));

// Check if value exist in the containers relation values
assertTrue(Constants.anyRelation(3, innerClassContainer));
assertTrue(Constants.anyRelationValue(3, innerClassContainer));
// Check if value exist in the relations of some key
var optionalTwoRelation = innerClassContainer.getRelation("Two");
assertTrue(optionalTwoRelation.isPresent());
assertEquals("Two", optionalTwoRelation.get().getValue());
assertTrue(Constants.anyRelation(2, optionalTwoRelation.get()));
assertTrue(Constants.anyRelationValue(2, optionalTwoRelation.get()));

// Check if any value in the container
assertTrue(Constants.anyValue("Three", Constants.getInstance(DemoConstantContainer.class))); // constant container
Expand All @@ -99,12 +99,12 @@ use the class anywhere beside this method, also you have container instance alre
assertTrue(Constants.anyValue("One", DemoRelationContainerWithStaticFinalFields.ONE, DemoRelationContainerWithStaticFinalFields.TWO, DemoRelationContainerWithStaticFinalFields.THREE));

// Check any relation by static references of the constants
assertTrue(Constants.anyRelation(1, DemoRelationContainerWithStaticFinalFields.ONE, DemoRelationContainerWithStaticFinalFields.TWO, DemoRelationContainerWithStaticFinalFields.THREE));
assertTrue(Constants.anyRelationValue(1, DemoRelationContainerWithStaticFinalFields.ONE, DemoRelationContainerWithStaticFinalFields.TWO, DemoRelationContainerWithStaticFinalFields.THREE));
// Check any value by container local refs
var containerWithFields = Constants.getInstance(DemoContainerWithStaticFields.class);
assertTrue(Constants.anyValue("One", DemoContainerWithStaticFields.ONE, DemoContainerWithStaticFields.TWO, DemoContainerWithStaticFields.THREE));

// Get optional constant by value
// Get optional constant value by value
var one = Constants.getKeyValue("One", DemoRelationContainerWithStaticFinalFields.class);
assertTrue(one.isPresent());
assertEquals(one.get(), DemoRelationContainerWithStaticFinalFields.ONE.getValue());
Expand Down

0 comments on commit eec51e0

Please sign in to comment.