Skip to content

Commit

Permalink
fixed equals methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lc0197 committed Jun 15, 2020
1 parent b1acfcb commit 376d2c9
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,30 @@ protected Predicate unfoldLTE(TimePoint arg){
return disjGt;
}

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

MaxTimePoint that = (MaxTimePoint) o;

if(args.size()!=that.args.size()){
return false;
}

for(TimePoint arg: args){
boolean foundEq = false;
for(TimePoint arg2: that.args){
if(arg.equals(arg2)){
foundEq = true;
break;
}
}
if(!foundEq){
return false;
}
}
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,31 @@ protected Predicate unfoldLTE(TimePoint arg){
return disjLte;
}

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

MinTimePoint that = (MinTimePoint) o;

if(args.size()!=that.args.size()){
return false;
}

for(TimePoint arg: args){
boolean foundEq = false;
for(TimePoint arg2: that.args){
if(arg.equals(arg2)){
foundEq = true;
break;
}
}
if(!foundEq){
return false;
}
}
return true;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public boolean containsSelectorType(TimeSelector.TimeField type){
return timePoint.containsSelectorType(type);
}

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

PlusTimePoint that = (PlusTimePoint) o;

return timePoint.equals(that.timePoint) && constant.equals(that.constant);

}


}
10 changes: 10 additions & 0 deletions src/main/java/org/s1ck/gdl/model/comparables/time/TimeLiteral.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ public boolean containsSelectorType(TimeSelector.TimeField type){
return false;
}

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

TimeLiteral that = (TimeLiteral) o;

return evaluate()==that.evaluate();
}


/**
* Utility method to handle input strings like 1970-01-01. They are not recognized by LocalDateTime.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.s1ck.gdl.model.comparables.time.util;

import org.s1ck.gdl.model.comparables.time.MinTimePoint;
import org.s1ck.gdl.model.comparables.time.TimePoint;

/**
* Represents a constant duration via a fixed number of milliseconds
* Not really a timestamp, but needed for certain related computations (e.g. deltas)
Expand Down Expand Up @@ -48,4 +51,13 @@ public long getMillis(){
return millis;
}

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

TimeConstant that = (TimeConstant) o;
return getMillis()==that.getMillis();
}

}
18 changes: 9 additions & 9 deletions src/test/java/org/s1ck/gdl/GDLLoaderTemporalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void simpleTimestampFunctionsTest(){
public void periodLiteralTest(){
GDLLoader loader = getLoaderFromGDLString("MATCH (a)-->(b) " +
"WHERE a.tx.overlaps(Interval(1970-01-01,1970-01-02))");
assertEquals(loader.getPredicates().get().toString(),
assertEquals(loader.getPredicates().get(),
new And(
new And(
new Comparison(
Expand All @@ -68,7 +68,7 @@ public void periodLiteralTest(){
new TimeLiteral("1970-01-01")
)
)
).toString()
)
);
}

Expand All @@ -89,7 +89,7 @@ public void afterTest(){
new TimeSelector("a", "tx_to"))

);
assertEquals(result.toString(), expected.toString());
assertEquals(result, expected);
}

@Test
Expand All @@ -109,7 +109,7 @@ public void fromToTest(){
new TimeSelector("a", "tx_to")
)
);
assertEquals(result.toString(), expected.toString());
assertEquals(result, expected);
}

@Test
Expand All @@ -129,7 +129,7 @@ public void betweenTest(){
new TimeSelector("b", TimeSelector.TimeField.TX_FROM)
)
).switchSides();
assertEquals(result.toString(), expected.toString());
assertEquals(result, expected);
}

@Test
Expand All @@ -153,7 +153,7 @@ public void precedesTest(){
Comparator.LTE,
new TimeSelector("b", TimeSelector.TimeField.VAL_FROM)
).switchSides();
assertEquals(result.toString(), expected.toString());
assertEquals(result, expected);
}

@Test
Expand All @@ -166,7 +166,7 @@ public void succeedsTest(){
Comparator.GTE,
new TimeSelector("b", TimeSelector.TimeField.TX_TO)
).switchSides();
assertEquals(result.toString(), expected.toString());
assertEquals(result, expected);

// timestamp as caller
loader = getLoaderFromGDLString("MATCH (a)-->(b) " +
Expand All @@ -177,7 +177,7 @@ public void succeedsTest(){
Comparator.GTE,
new TimeSelector("b", TimeSelector.TimeField.VAL_TO)
).switchSides();
assertEquals(result.toString(), expected.toString());
assertEquals(result, expected);
}

@Test
Expand All @@ -197,7 +197,7 @@ public void asOfTest(){
new TimeLiteral("1970-01-01")
)
).switchSides();
assertEquals(result.toString(), expected.toString());
assertEquals(result, expected);
}


Expand Down

0 comments on commit 376d2c9

Please sign in to comment.