-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactoring Expression Visitor so all expression types have visit methods. * Added BooleanExpression class
- Loading branch information
Showing
8 changed files
with
73 additions
and
52 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
41 changes: 41 additions & 0 deletions
41
...rc/main/java/com/yahoo/elide/core/security/permissions/expressions/BooleanExpression.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,41 @@ | ||
/* | ||
* Copyright 2022, Yahoo Inc. | ||
* Licensed under the Apache License, Version 2.0 | ||
* See LICENSE file in project root for terms. | ||
*/ | ||
|
||
package com.yahoo.elide.core.security.permissions.expressions; | ||
|
||
import static org.fusesource.jansi.Ansi.ansi; | ||
|
||
import com.yahoo.elide.core.security.permissions.ExpressionResult; | ||
import org.fusesource.jansi.Ansi; | ||
|
||
/** | ||
* Expression that returns always true (PASS) or false (FAILURE). | ||
*/ | ||
public class BooleanExpression implements Expression { | ||
private boolean value; | ||
public BooleanExpression(boolean value) { | ||
this.value = value; | ||
} | ||
@Override | ||
public ExpressionResult evaluate(EvaluationMode mode) { | ||
if (value == true) { | ||
return ExpressionResult.PASS; | ||
} | ||
return ExpressionResult.FAIL; | ||
} | ||
|
||
@Override | ||
public <T> T accept(ExpressionVisitor<T> visitor) { | ||
return visitor.visitBooleanExpression(this); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
Ansi.Color color = value ? Ansi.Color.GREEN : Ansi.Color.RED; | ||
String label = value ? "SUCCESS" : "FAILURE"; | ||
return ansi().fg(color).a(label).reset().toString(); | ||
} | ||
} |
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
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