AccessToken (@NotNull String ruleId, boolean active) { UsageFilteringRuleStateService instance = getInstance(); Set<String> state = instance.myState; boolean modified = active ? state.add(ruleId) : state.remove(ruleId); if (!modified) { return AccessToken.EMPTY_ACCESS_TOKEN; } else { return new AccessToken() { @Override public void finish() { boolean modifiedBack = active ? state.remove(ruleId) : state.add(ruleId); assert modifiedBack; } }; } }