-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unknown value for cedar partial evaluation (#259)
Signed-off-by: Mohamed Amine Ouali <[email protected]>
- Loading branch information
1 parent
1c09e46
commit 22f569b
Showing
5 changed files
with
146 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
85 changes: 85 additions & 0 deletions
85
CedarJava/src/main/java/com/cedarpolicy/value/Unknown.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,85 @@ | ||
/* | ||
* Copyright Cedar Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.cedarpolicy.value; | ||
|
||
import java.util.Objects; | ||
|
||
import com.cedarpolicy.Experimental; | ||
import com.cedarpolicy.ExperimentalFeature; | ||
|
||
|
||
/** | ||
* Represents a Cedar unknown extension value. | ||
* This class can only be used with partial evaluation. | ||
*/ | ||
@Experimental(ExperimentalFeature.PARTIAL_EVALUATION) | ||
public class Unknown extends Value { | ||
|
||
|
||
/** | ||
* arg as a string. | ||
*/ | ||
private final String arg; | ||
|
||
/** | ||
* Construct Unknown. | ||
* | ||
* @param arg for the unknown extension | ||
*/ | ||
public Unknown(String arg) throws NullPointerException, IllegalArgumentException { | ||
this.arg = arg; | ||
} | ||
|
||
/** | ||
* Convert Decimal to Cedar expr that can be used in a Cedar policy. | ||
*/ | ||
@Override | ||
public String toCedarExpr() { | ||
return "Unknown(\"" + arg + "\")"; | ||
} | ||
|
||
/** | ||
* Equals. | ||
*/ | ||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Unknown unknown = (Unknown) o; | ||
return arg.equals(unknown.arg); | ||
} | ||
|
||
/** | ||
* Hash. | ||
*/ | ||
@Override | ||
public int hashCode() { | ||
return Objects.hash(arg); | ||
} | ||
|
||
/** | ||
* As a string. | ||
*/ | ||
@Override | ||
public String toString() { | ||
return arg; | ||
} | ||
} |
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