-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e216516
commit d370095
Showing
3 changed files
with
332 additions
and
1 deletion.
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
63 changes: 63 additions & 0 deletions
63
common/src/main/java/me/shedaniel/autoconfig/requirements/DefaultRequirements.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,63 @@ | ||
package me.shedaniel.autoconfig.requirements; | ||
|
||
import java.util.Objects; | ||
|
||
public class DefaultRequirements { | ||
private DefaultRequirements() {} | ||
|
||
/** | ||
* The condition is met when the argument is {@code true}. | ||
* | ||
* @see #isTrue(Boolean) | ||
*/ | ||
public static final String TRUE = "isTrue"; | ||
|
||
/** | ||
* The condition is met when the argument is {@code false}. | ||
* | ||
* @see #isFalse(Boolean) | ||
*/ | ||
public static final String FALSE = "isFalse"; | ||
|
||
/** | ||
* The condition is met when the first argument is equal to the second. | ||
* | ||
* @see #is(Object, Object) | ||
*/ | ||
public static final String IS = "is"; | ||
|
||
/** | ||
* The condition is met when at least one {@code arg} is equal to another. | ||
* | ||
* @see #anyMatch(Object[]) | ||
*/ | ||
public static final String ANY_MATCH = "anyMatch"; | ||
|
||
private static boolean isTrue(Boolean value) { | ||
return Boolean.TRUE.equals(value); | ||
} | ||
|
||
private static boolean isFalse(Boolean value) { | ||
return Boolean.FALSE.equals(value); | ||
} | ||
|
||
private static <T> boolean is(T value, T condition) { | ||
return Objects.equals(value, condition); | ||
} | ||
|
||
private static <T> boolean anyMatch(T ...args) { | ||
for (int i = 0; i < args.length; i++) { | ||
for (int j = 0; j < i; j++) { | ||
if (Objects.equals(args[i], args[j])) { | ||
return true; | ||
} | ||
} | ||
for (int j = i+1; j < args.length; j++) { | ||
if (Objects.equals(args[i], args[j])) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
} |