public boolean remove(Data dataKey, Object testValue) { checkIfLoaded(); Record record = records.get(dataKey); Object oldValue = null; boolean removed = false; if (record == null) { if (mapContainer.getStore() != null) { oldValue = mapContainer.getStore().load(mapService.toObject(dataKey)); } if (oldValue == null) return false; } else { oldValue = record.getValue(); } if (mapService.compare(name, testValue, oldValue)) { mapService.interceptRemove(name, oldValue); removeIndex(dataKey); mapStoreDelete(record, dataKey); // reduce size updateSizeEstimator(-calculateRecordSize(record)); deleteRecord(dataKey); cancelAssociatedSchedulers(dataKey); removed = true; } return removed; }
public boolean containsValue(Object value) { checkIfLoaded(); for (Record record : records.values()) { if (mapService.compare(name, value, record.getValue())) return true; } return false; }
public boolean replace(Data dataKey, Object testValue, Object newValue) { checkIfLoaded(); Record record = records.get(dataKey); if (record == null) return false; if (mapService.compare(name, record.getValue(), testValue)) { newValue = mapService.interceptPut(name, record.getValue(), newValue); newValue = writeMapStore(dataKey, newValue, record); updateSizeEstimator(-calculateRecordSize(record)); setRecordValue(record, newValue); updateSizeEstimator(calculateRecordSize(record)); } else { return false; } saveIndex(record); return true; }
public boolean merge(Data dataKey, EntryView mergingEntry, MapMergePolicy mergePolicy) { checkIfLoaded(); Record record = records.get(dataKey); Object newValue = null; if (record == null) { newValue = mergingEntry.getValue(); newValue = writeMapStore(dataKey, newValue, null); record = mapService.createRecord(name, dataKey, newValue, DEFAULT_TTL); records.put(dataKey, record); updateSizeEstimator(calculateRecordSize(record)); } else { Object oldValue = record.getValue(); EntryView existingEntry = mapService.createSimpleEntryView( mapService.toObject(record.getKey()), mapService.toObject(record.getValue()), record); newValue = mergePolicy.merge(name, mergingEntry, existingEntry); if (newValue == null) { // existing entry will be removed removeIndex(dataKey); mapStoreDelete(record, dataKey); // reduce size. updateSizeEstimator(-calculateRecordSize(record)); // remove from map & invalidate. deleteRecord(dataKey); return true; } // same with the existing entry so no need to mapstore etc operations. if (mapService.compare(name, newValue, oldValue)) { return true; } newValue = writeMapStore(dataKey, newValue, record); updateSizeEstimator(-calculateRecordSize(record)); recordFactory.setValue(record, newValue); updateSizeEstimator(calculateRecordSize(record)); } saveIndex(record); return newValue != null; }