Skip to content

Commit

Permalink
add more equals methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed Jun 15, 2024
1 parent a0f3d74 commit d279c8d
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 19 deletions.
41 changes: 26 additions & 15 deletions src/main/java/org/biscuitsec/biscuit/datalog/Check.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,6 @@ public List<Rule> queries() {
return queries;
}

@Override
public int hashCode() {
return Objects.hash(queries);
}

@Override
public boolean equals(Object o) {
return super.equals(o);
}

@Override
public String toString() {
return super.toString();
}

public Schema.CheckV2 serialize() {
Schema.CheckV2.Builder b = Schema.CheckV2.newBuilder();

Expand Down Expand Up @@ -95,4 +80,30 @@ static public Either<Error.FormatError, Check> deserializeV2(Schema.CheckV2 chec

return Right(new Check(kind, queries));
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Check check = (Check) o;

if (kind != check.kind) return false;
return Objects.equals(queries, check.queries);
}

@Override
public int hashCode() {
int result = kind != null ? kind.hashCode() : 0;
result = 31 * result + (queries != null ? queries.hashCode() : 0);
return result;
}

@Override
public String toString() {
return "Check{" +
"kind=" + kind +
", queries=" + queries +
'}';
}
}
32 changes: 32 additions & 0 deletions src/main/java/org/biscuitsec/biscuit/datalog/Rule.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,36 @@ static public Either<Error.FormatError, Rule> deserializeV2(Schema.RuleV2 rule)
return Right(new Rule(res.get(), body, expressions, scopes));
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Rule rule = (Rule) o;

if (!Objects.equals(head, rule.head)) return false;
if (!Objects.equals(body, rule.body)) return false;
if (!Objects.equals(expressions, rule.expressions)) return false;
return Objects.equals(scopes, rule.scopes);
}

@Override
public int hashCode() {
int result = head != null ? head.hashCode() : 0;
result = 31 * result + (body != null ? body.hashCode() : 0);
result = 31 * result + (expressions != null ? expressions.hashCode() : 0);
result = 31 * result + (scopes != null ? scopes.hashCode() : 0);
return result;
}

@Override
public String toString() {
return "Rule{" +
"head=" + head +
", body=" + body +
", expressions=" + expressions +
", scopes=" + scopes +
'}';
}
}
18 changes: 18 additions & 0 deletions src/main/java/org/biscuitsec/biscuit/datalog/Scope.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,22 @@ public String toString() {
", publicKey=" + publicKey +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Scope scope = (Scope) o;

if (publicKey != scope.publicKey) return false;
return kind == scope.kind;
}

@Override
public int hashCode() {
int result = kind != null ? kind.hashCode() : 0;
result = 31 * result + (int) (publicKey ^ (publicKey >>> 32));
return result;
}
}
28 changes: 28 additions & 0 deletions src/main/java/org/biscuitsec/biscuit/datalog/SymbolTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,32 @@ public List<String> getAllSymbols() {
allSymbols.addAll(symbols);
return allSymbols;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

SymbolTable that = (SymbolTable) o;

if (!dateTimeFormatter.equals(that.dateTimeFormatter)) return false;
if (!symbols.equals(that.symbols)) return false;
return publicKeys.equals(that.publicKeys);
}

@Override
public int hashCode() {
int result = dateTimeFormatter.hashCode();
result = 31 * result + symbols.hashCode();
result = 31 * result + publicKeys.hashCode();
return result;
}

@Override
public String toString() {
return "SymbolTable{" +
"symbols=" + symbols +
", publicKeys=" + publicKeys +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import io.vavr.control.Either;
import io.vavr.control.Option;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Map;
import java.util.*;

import static io.vavr.API.Left;
import static io.vavr.API.Right;
Expand Down Expand Up @@ -78,4 +75,26 @@ static public Either<Error.FormatError, Expression> deserializeV2(Schema.Express

return Right(new Expression(ops));
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Expression that = (Expression) o;

return Objects.equals(ops, that.ops);
}

@Override
public int hashCode() {
return ops != null ? ops.hashCode() : 0;
}

@Override
public String toString() {
return "Expression{" +
"ops=" + ops +
'}';
}
}
15 changes: 15 additions & 0 deletions src/main/java/org/biscuitsec/biscuit/token/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,20 @@ public int hashCode() {
result = 31 * result + (int) (version ^ (version >>> 32));
return result;
}

@Override
public String toString() {
return "Block{" +
"symbols=" + symbols +
", context='" + context + '\'' +
", facts=" + facts +
", rules=" + rules +
", checks=" + checks +
", scopes=" + scopes +
", publicKeys=" + publicKeys +
", externalKey=" + externalKey +
", version=" + version +
'}';
}
}

0 comments on commit d279c8d

Please sign in to comment.