Skip to content

Commit

Permalink
Changing the get last id to a simpler and more efficient mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
itaiag committed Jan 18, 2018
1 parent a97ebfb commit f2bc46d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ private int getLastId() {
if (isCachedEmpty()) {
return 0;
}
final List<ExecutionMetadata> result = new ArrayList<ExecutionMetadata>();
result.addAll(executionsCache.values());
Collections.sort(result);
return result.get(0).getId();
return Collections.max(executionsCache.values()).getId();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package il.co.topq.report.business.execution;

import static il.co.topq.difido.DateTimeConverter.fromDateString;
import static il.co.topq.difido.DateTimeConverter.fromTimeString;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -199,40 +195,19 @@ public int compareTo(ExecutionMetadata o) {
if (null == o) {
return 1;
}
if (!(o instanceof ExecutionMetadata)) {
throw new IllegalArgumentException("Can't compare " + this.getClass().getSimpleName() + " to " + o.getClass().getSimpleName());
}
if (this == o) {
return 0;
}
if (null == getDate() || null == getTime() || null == o.getTime() || null == o.getDate()) {
throw new IllegalArgumentException("Can't compare when some fields are null. Trying to compare '"
+ this.toString() + "' with '" + o.toString() + "'");
}
if (getDate().isEmpty() || getTime().isEmpty() || o.getTime().isEmpty() || o.getDate().isEmpty()) {
throw new IllegalArgumentException("Can't compare when some fields are empty. Trying to compare '"
+ this.toString() + "' with '" + o.toString() + "'");
if (this.getId() == o.getId()) {
return 0;
}
try {
final Date thisDate = fromDateString(getDate()).toDateObject();
final Date otherDate = fromDateString(o.getDate()).toDateObject();
if (thisDate.before(otherDate)) {
return 1;
} else if (thisDate.after(otherDate)) {
return -1;
} else {
final Date thisTime = fromTimeString(getTime()).toDateObject();
final Date otherTime = fromTimeString(o.getTime()).toDateObject();
if (thisTime.before(otherTime)) {
return 1;
} if (thisTime.after(otherTime)) {
return -1;
} else {
return 0;
}
}
} catch (Throwable t) {
throw new IllegalArgumentException(
"Exception accured while trying to parse date or time when comparing. Trying to compare '"
+ this.toString() + "' with '" + o.toString() + "'",
t);
if (this.getId() > o.getId()) {
return 1;
} else {
return -1;
}
}

Expand Down

0 comments on commit f2bc46d

Please sign in to comment.