Passing result here is the same thing as passing null
. You have to return this DBObject
someway. For example, you can return something like Map.Entry<Integer, DBObject>
. This could not be supposed to be a good solution, maybe you should create some class like BlahBlahResult
, containing both int
result and DBObject
.
If you really-really want to pass it as a parameter, you may pass something like AtomicReference<DBObject>
and set it inside the method:
public static int getEarliestValue(Map<DBObject, DBCursor> cursorMap, AtomicReference<DBObject> result) {
int mergeCount = 1;
if (!cursorMap.isEmpty()) {
long ealiest = Long.MAX_VALUE;
for (DBObject o : cursorMap.keySet()) {
// do stuff to init tmp
...
if (tmp < ealiest) {
result.set(o);
ealiest = tmp;
}
// other stuff .....
}
return mergeCount;
}
...
...
AtomicReference<DBObject> resultReference = new AtomicReference<>(null);
int mergeCount = MongoTickReaderUtil.getEarliestValue(cursorList, resultReference);
DBObject result = resultReference.get();