Skip to content

Instantly share code, notes, and snippets.

@euch
Created December 19, 2014 13:09
Show Gist options
  • Select an option

  • Save euch/61cb14c92ec9a12430e5 to your computer and use it in GitHub Desktop.

Select an option

Save euch/61cb14c92ec9a12430e5 to your computer and use it in GitHub Desktop.
List pendingVisits = new LinkedList<>();
Long pendingVisitsRefreshTime = 0L;
public List getPendingVisits() throws QmaticClientException {
Long currentTime = new Date().getTime();
if (!this.pendingVisits.isEmpty() && (currentTime - pendingVisitsRefreshTime <= 10000))
return this.pendingVisits;
this.pendingVisits.clear();
List<VisitInfo> pendingVisitsForCurrentWS = new ArrayList<>();
List<VisitInfo> pendingVisitsForOthersWS = new ArrayList<>();
try {
List<Queue> activeQueues = this.qmaticClient.getCurrentStats(this.getCurrentWorkstationInfo().getBranchId());
for (Queue activeQueue : activeQueues) {
List<VisitInfo> queuePendingVisits = activeQueue.getPendingVisits();
if (queuePendingVisits != null) {
for (VisitInfo pendingVisit : queuePendingVisits)
if (this.getCurrentWorkstationInfo().getWorkstationId().equals(pendingVisit.getDesignatedWorkstationId()))
pendingVisitsForCurrentWS.add(pendingVisit);
else
pendingVisitsForOthersWS.add(pendingVisit);
}
}
} catch (NullPointerException ignored) {
}
Collections.sort(pendingVisitsForCurrentWS, new VisitInfoEnqueuedTimeComparator()); // sort by waiting time
Collections.sort(pendingVisitsForOthersWS, new VisitInfoEnqueuedTimeComparator()); // sort by waiting time
if (8 <= pendingVisitsForCurrentWS.size() + pendingVisitsForCurrentWS.size())
this.pendingVisits = ListUtils.union(pendingVisitsForCurrentWS, pendingVisitsForOthersWS).subList(0, 8);
else
this.pendingVisits = ListUtils.union(pendingVisitsForCurrentWS, pendingVisitsForOthersWS);
pendingVisitsRefreshTime = currentTime;
return this.pendingVisits;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment