*
* @param tuple
*/
public boolean add(SlopeOneTuple tuple) {
String compositeKey = StringUtilities.generateUniqueID(tuple.getFirstItem(), tuple.getSecondItem()).toString();
SlopeOneTuple find = manager.find(SlopeOneTuple.class, compositeKey);
EntityTransaction txn = manager.getTransaction();
txn.begin();
if(find!=null) {
find.setCardinality(find.getCardinality() + tuple.getCardinality());
if(find.getSecondItem().compareTo(tuple.getFirstItem())==0) {
//there has been a reversal, so set the deviation accordingly
find.setDeviation(0 - find.getDeviation() - tuple.getDeviation());
}
else {
find.setDeviation(find.getDeviation() + tuple.getDeviation());
}
}
else {
manager.persist(find);
}