private void removeKeyFromSecond(Object key, Integer existingSecond) { Map<Object, ScheduledEntry<K, V>> scheduledKeys = scheduledEntries.get(existingSecond); if (scheduledKeys != null) { cancelAndCleanUpIfEmpty(existingSecond, scheduledKeys, key); } }
private void removeKeyFromSecond(Object key, Integer existingSecond) { Map<Object, ScheduledEntry<K, V>> scheduledKeys = scheduledEntries.get(existingSecond); if (scheduledKeys != null) { cancelAndCleanUpIfEmpty(existingSecond, scheduledKeys, key); } }
private ScheduledEntry<K, V> cancelByCompositeKey(K key) { Set<CompositeKey> candidateKeys = getCompositeKeys(key); ScheduledEntry<K, V> result = null; for (CompositeKey compositeKey : candidateKeys) { Integer second = secondsOfKeys.remove(compositeKey); if (second == null) { continue; } Map<Object, ScheduledEntry<K, V>> entries = scheduledEntries.get(second); if (entries == null) { continue; } result = cancelAndCleanUpIfEmpty(second, entries, compositeKey); } return result; }
private ScheduledEntry<K, V> cancelByCompositeKey(K key) { Set<CompositeKey> candidateKeys = getCompositeKeys(key); ScheduledEntry<K, V> result = null; for (CompositeKey compositeKey : candidateKeys) { Integer second = secondsOfKeys.remove(compositeKey); if (second == null) { continue; } Map<Object, ScheduledEntry<K, V>> entries = scheduledEntries.get(second); if (entries == null) { continue; } result = cancelAndCleanUpIfEmpty(second, entries, compositeKey); } return result; }
private int cancelByCompositeKey(K key, ScheduledEntry<K, V> entryToRemove) { int cancelled = 0; for (CompositeKey compositeKey : getCompositeKeys(key)) { Integer second = secondsOfKeys.remove(compositeKey); if (second == null) { continue; } Map<Object, ScheduledEntry<K, V>> entries = scheduledEntries.get(second); if (entries == null) { continue; } if (cancelAndCleanUpIfEmpty(second, entries, compositeKey, entryToRemove)) { cancelled++; } } return cancelled; }
private int cancelByCompositeKey(K key, ScheduledEntry<K, V> entryToRemove) { int cancelled = 0; for (CompositeKey compositeKey : getCompositeKeys(key)) { Integer second = secondsOfKeys.remove(compositeKey); if (second == null) { continue; } Map<Object, ScheduledEntry<K, V>> entries = scheduledEntries.get(second); if (entries == null) { continue; } if (cancelAndCleanUpIfEmpty(second, entries, compositeKey, entryToRemove)) { cancelled++; } } return cancelled; }
@Override public ScheduledEntry<K, V> cancel(K key) { synchronized (mutex) { if (scheduleType.equals(ScheduleType.FOR_EACH)) { return cancelByCompositeKey(key); } Integer second = secondsOfKeys.remove(key); if (second == null) { return null; } Map<Object, ScheduledEntry<K, V>> entries = scheduledEntries.get(second); if (entries == null) { return null; } return cancelAndCleanUpIfEmpty(second, entries, key); } }
@Override public ScheduledEntry<K, V> cancel(K key) { synchronized (mutex) { if (scheduleType.equals(ScheduleType.FOR_EACH)) { return cancelByCompositeKey(key); } Integer second = secondsOfKeys.remove(key); if (second == null) { return null; } Map<Object, ScheduledEntry<K, V>> entries = scheduledEntries.get(second); if (entries == null) { return null; } return cancelAndCleanUpIfEmpty(second, entries, key); } }
@Override public int cancelIfExists(K key, V value) { synchronized (mutex) { ScheduledEntry<K, V> scheduledEntry = new ScheduledEntry<K, V>(key, value, 0, 0, 0); if (scheduleType.equals(ScheduleType.FOR_EACH)) { return cancelByCompositeKey(key, scheduledEntry); } Integer second = secondsOfKeys.remove(key); if (second == null) { return 0; } Map<Object, ScheduledEntry<K, V>> entries = scheduledEntries.get(second); if (entries == null) { return 0; } return cancelAndCleanUpIfEmpty(second, entries, key, scheduledEntry) ? 1 : 0; } }
@Override public int cancelIfExists(K key, V value) { synchronized (mutex) { ScheduledEntry<K, V> scheduledEntry = new ScheduledEntry<K, V>(key, value, 0, 0, 0); if (scheduleType.equals(ScheduleType.FOR_EACH)) { return cancelByCompositeKey(key, scheduledEntry); } Integer second = secondsOfKeys.remove(key); if (second == null) { return 0; } Map<Object, ScheduledEntry<K, V>> entries = scheduledEntries.get(second); if (entries == null) { return 0; } return cancelAndCleanUpIfEmpty(second, entries, key, scheduledEntry) ? 1 : 0; } }