55
66package org .eclipse .biscuit .datalog ;
77
8- import io .vavr .Tuple2 ;
9- import io .vavr .control .Option ;
108import java .io .Serializable ;
119import java .util .HashSet ;
1210import java .util .Iterator ;
1311import java .util .List ;
1412import java .util .Map ;
1513import java .util .NoSuchElementException ;
14+ import java .util .Optional ;
1615import java .util .Set ;
1716import java .util .function .Supplier ;
1817import java .util .stream .Stream ;
1918
20- public final class Combinator implements Serializable , Iterator <Tuple2 <Origin , Map <Long , Term >>> {
19+ public final class Combinator implements Serializable , Iterator <Pair <Origin , Map <Long , Term >>> {
2120 private MatchedVariables variables ;
22- private final Supplier <Stream <Tuple2 <Origin , Fact >>> allFacts ;
21+ private final Supplier <Stream <Pair <Origin , Fact >>> allFacts ;
2322 private final List <Predicate > predicates ;
24- private final Iterator <Tuple2 <Origin , Fact >> currentFacts ;
23+ private final Iterator <Pair <Origin , Fact >> currentFacts ;
2524 private Combinator currentIt ;
2625 private final SymbolTable symbolTable ;
2726
2827 private Origin currentOrigin ;
2928
30- private Option < Tuple2 <Origin , Map <Long , Term >>> nextElement ;
29+ private Optional < Pair <Origin , Map <Long , Term >>> nextElement ;
3130
3231 @ Override
3332 public boolean hasNext () {
34- if (this .nextElement != null && this .nextElement .isDefined ()) {
33+ if (this .nextElement != null && this .nextElement .isPresent ()) {
3534 return true ;
3635 }
3736 this .nextElement = getNext ();
38- return this .nextElement .isDefined ();
37+ return this .nextElement .isPresent ();
3938 }
4039
4140 @ Override
42- public Tuple2 <Origin , Map <Long , Term >> next () {
43- if (this .nextElement == null || !this .nextElement .isDefined ()) {
41+ public Pair <Origin , Map <Long , Term >> next () {
42+ if (this .nextElement == null || !this .nextElement .isPresent ()) {
4443 this .nextElement = getNext ();
4544 }
46- if (this .nextElement == null || !this .nextElement .isDefined ()) {
45+ if (this .nextElement == null || !this .nextElement .isPresent ()) {
4746 throw new NoSuchElementException ();
4847 } else {
49- Tuple2 <Origin , Map <Long , Term >> t = this .nextElement .get ();
50- this .nextElement = Option . none ();
48+ Pair <Origin , Map <Long , Term >> t = this .nextElement .get ();
49+ this .nextElement = Optional . empty ();
5150 return t ;
5251 }
5352 }
5453
55- public Option < Tuple2 <Origin , Map <Long , Term >>> getNext () {
54+ public Optional < Pair <Origin , Map <Long , Term >>> getNext () {
5655 if (this .predicates .isEmpty ()) {
57- final Option <Map <Long , Term >> vOpt = this .variables .complete ();
56+ final Optional <Map <Long , Term >> vOpt = this .variables .complete ();
5857 if (vOpt .isEmpty ()) {
59- return Option . none ();
58+ return Optional . empty ();
6059 } else {
6160 Map <Long , Term > variables = vOpt .get ();
6261 // if there were no predicates,
@@ -67,7 +66,7 @@ public Option<Tuple2<Origin, Map<Long, Term>>> getNext() {
6766 set .add ((long ) 0 );
6867
6968 this .variables = new MatchedVariables (set );
70- return Option . some (new Tuple2 <>(new Origin (), variables ));
69+ return Optional . of (new Pair <>(new Origin (), variables ));
7170 }
7271 }
7372
@@ -78,7 +77,7 @@ public Option<Tuple2<Origin, Map<Long, Term>>> getNext() {
7877 while (true ) {
7978 // we iterate over the facts that match the current predicate
8079 if (this .currentFacts .hasNext ()) {
81- final Tuple2 <Origin , Fact > t = this .currentFacts .next ();
80+ final Pair <Origin , Fact > t = this .currentFacts .next ();
8281 Origin currentOrigin = t ._1 .clone ();
8382 Fact fact = t ._2 ;
8483
@@ -111,11 +110,11 @@ public Option<Tuple2<Origin, Map<Long, Term>>> getNext() {
111110
112111 // there are no more predicates to check
113112 if (this .predicates .size () == 1 ) {
114- final Option <Map <Long , Term >> vOpt = vars .complete ();
113+ final Optional <Map <Long , Term >> vOpt = vars .complete ();
115114 if (vOpt .isEmpty ()) {
116115 continue ;
117116 } else {
118- return Option . some (new Tuple2 <>(currentOrigin , vOpt .get ()));
117+ return Optional . of (new Pair <>(currentOrigin , vOpt .get ()));
119118 }
120119 } else {
121120 this .currentOrigin = currentOrigin ;
@@ -132,20 +131,20 @@ public Option<Tuple2<Origin, Map<Long, Term>>> getNext() {
132131 break ;
133132
134133 } else {
135- return Option . none ();
134+ return Optional . empty ();
136135 }
137136 }
138137 }
139138
140139 if (this .currentIt == null ) {
141- return Option . none ();
140+ return Optional . empty ();
142141 }
143142
144- Option < Tuple2 <Origin , Map <Long , Term >>> opt = this .currentIt .getNext ();
143+ Optional < Pair <Origin , Map <Long , Term >>> opt = this .currentIt .getNext ();
145144
146- if (opt .isDefined ()) {
147- Tuple2 <Origin , Map <Long , Term >> t = opt .get ();
148- return Option . some (new Tuple2 <>(t ._1 .union (currentOrigin ), t ._2 ));
145+ if (opt .isPresent ()) {
146+ Pair <Origin , Map <Long , Term >> t = opt .get ();
147+ return Optional . of (new Pair <>(t ._1 .union (currentOrigin ), t ._2 ));
149148 } else {
150149 currentOrigin = null ;
151150 currentIt = null ;
@@ -156,7 +155,7 @@ public Option<Tuple2<Origin, Map<Long, Term>>> getNext() {
156155 public Combinator (
157156 final MatchedVariables variables ,
158157 final List <Predicate > predicates ,
159- Supplier <Stream <Tuple2 <Origin , Fact >>> allFacts ,
158+ Supplier <Stream <Pair <Origin , Fact >>> allFacts ,
160159 final SymbolTable symbolTable ) {
161160 this .variables = variables ;
162161 this .allFacts = allFacts ;
0 commit comments