forked from gnembon/carpetmod
-
Notifications
You must be signed in to change notification settings - Fork 9
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
abfc819
commit 414c408
Showing
4 changed files
with
107 additions
and
5 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
61 changes: 61 additions & 0 deletions
61
src/main/java/carpet/helpers/UpdateSuppressionSimulator.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,61 @@ | ||
package carpet.helpers; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
|
||
import java.util.Map; | ||
|
||
public class UpdateSuppressionSimulator | ||
{ | ||
private static final Map<String, Runnable> SUPPORTED_ERRORS = ImmutableMap.of( | ||
"StackOverflowError", () -> { | ||
throw new StackOverflowError("TISCM UpdateSuppressionSimulator"); | ||
}, | ||
"OutOfMemoryError", () -> { | ||
throw new OutOfMemoryError("TISCM UpdateSuppressionSimulator"); | ||
}, | ||
"ClassCastException", () -> { | ||
throw new ClassCastException("TISCM UpdateSuppressionSimulator"); | ||
} | ||
); | ||
|
||
private static final Runnable DUMMY = () -> {}; | ||
private static Runnable nuke = DUMMY; | ||
|
||
public static boolean isActivated() | ||
{ | ||
return nuke != DUMMY; | ||
} | ||
|
||
public static void kaboom() | ||
{ | ||
nuke.run(); | ||
} | ||
|
||
public static boolean tryAcceptRule(String ruleValue) | ||
{ | ||
switch (ruleValue) | ||
{ | ||
case "true": | ||
nuke = SUPPORTED_ERRORS.values().iterator().next(); | ||
break; | ||
case "false": | ||
nuke = DUMMY; | ||
break; | ||
default: | ||
boolean[] ok = {false}; | ||
SUPPORTED_ERRORS.forEach((key, value) -> { | ||
if (key.equalsIgnoreCase(ruleValue)) | ||
{ | ||
nuke = value; | ||
ok[0] = true; | ||
} | ||
}); | ||
if (!ok[0]) | ||
{ | ||
return false; | ||
} | ||
break; | ||
} | ||
return true; | ||
} | ||
} |
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