In the following code the returned matchEntry is recycled, how can I fix that so that the returned matchEntry is not recycled.
I want the last matched entry in the loop to be returned
The object.clone() method does not seem to be available, and object.getClass().newInstance() doesn't seem to work.
public ViewEntry getStdTime(DateTime input,String key){
ViewEntryCollection checkColl = v.getAllEntriesByKey(key, true);
ViewEntry checkEntry;
ViewEntry checkTmpEntry = null;
ViewEntry matchEntry = null;
checkEntry = checkColl.getFirstEntry();
while (checkEntry != null) {
String xStartDate = checkEntry.getColumnValues().get(2);
DateTime dtx = session.createDateTime(xStartDate);
if (dtx.toJavaDate().compareTo(input.toJavaDate()) <= 0) {
matchEntry = checkEntry;
}
checkTmpEntry = checkColl.getNextEntry(checkEntry);
checkEntry.recycle();
checkEntry = checkTmpEntry;
}
return matchEntry;
}
Return the entry as soon as you find it:
public ViewEntry getStdTime(DateTime input,String key){
ViewEntryCollection checkColl = v.getAllEntriesByKey(key, true);
ViewEntry checkEntry;
ViewEntry checkTmpEntry = null;
checkEntry = checkColl.getFirstEntry();
while (checkEntry != null) {
String xStartDate = checkEntry.getColumnValues().get(2);
DateTime dtx = session.createDateTime(xStartDate);
if (dtx.toJavaDate().compareTo(input.toJavaDate()) <= 0) {
return checkEntry;
}
checkTmpEntry = checkColl.getNextEntry(checkEntry);
checkEntry.recycle();
checkEntry = checkTmpEntry;
}
return null;
}
Alternatively you can change your method to return the universal id of the document (using checkEntry.getUniversalID()
) and then use that to get the document and the needed fields.