Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,11 @@ public final void purge() {
* @return whether the operation was successful or not
*/
public final boolean add(final ResourceOperation type, final T key) {
Set<T> set;
switch (type) {
case CREATE:
set = toBeCreated;
break;

case UPDATE:
set = toBeUpdated;
break;

case DELETE:
default:
set = toBeDeleted;
break;
}
Set<T> set = switch (type) {
case CREATE -> toBeCreated;
case UPDATE -> toBeUpdated;
default -> toBeDeleted;
};

return set.add(key);
}
Expand All @@ -114,21 +104,11 @@ public final boolean add(final ResourceOperation type, final T key) {
* @return whether the operation was successful or not
*/
public boolean addAll(final ResourceOperation type, final Collection<T> keys) {
Set<T> set;
switch (type) {
case CREATE:
set = toBeCreated;
break;

case UPDATE:
set = toBeUpdated;
break;

case DELETE:
default:
set = toBeDeleted;
break;
}
Set<T> set = switch (type) {
case CREATE -> toBeCreated;
case UPDATE -> toBeUpdated;
default -> toBeDeleted;
};

return set.addAll(keys);
}
Expand All @@ -141,25 +121,12 @@ public boolean addAll(final ResourceOperation type, final Collection<T> keys) {
* @return whether the operation was successful or not
*/
public final boolean remove(final ResourceOperation type, final T key) {
boolean result = false;

switch (type) {
case CREATE:
result = toBeCreated.remove(key);
break;

case UPDATE:
result = toBeUpdated.remove(key);
break;

case DELETE:
result = toBeDeleted.remove(key);
break;

default:
}

return result;
return switch (type) {
case CREATE -> toBeCreated.remove(key);
case UPDATE -> toBeUpdated.remove(key);
case DELETE -> toBeDeleted.remove(key);
default -> false;
};
}

/**
Expand All @@ -170,21 +137,11 @@ public final boolean remove(final ResourceOperation type, final T key) {
* @return whether the operation was successful or not
*/
public boolean removeAll(final ResourceOperation type, final Set<T> keys) {
Set<T> set;
switch (type) {
case CREATE:
set = toBeCreated;
break;

case UPDATE:
set = toBeUpdated;
break;

case DELETE:
default:
set = toBeDeleted;
break;
}
Set<T> set = switch (type) {
case CREATE -> toBeCreated;
case UPDATE -> toBeUpdated;
default -> toBeDeleted;
};

return set.removeAll(keys);
}
Expand All @@ -198,8 +155,8 @@ public boolean removeAll(final ResourceOperation type, final Set<T> keys) {
*/
public boolean removeAll(final Collection<T> keys) {
return toBeCreated.removeAll(keys)
|| toBeUpdated.removeAll(keys)
|| toBeDeleted.removeAll(keys);
| toBeUpdated.removeAll(keys)
| toBeDeleted.removeAll(keys);
}

/**
Expand All @@ -211,8 +168,8 @@ public boolean removeAll(final Collection<T> keys) {
*/
public boolean removeIf(final Predicate<? super T> filter) {
return toBeCreated.removeIf(filter)
|| toBeUpdated.removeIf(filter)
|| toBeDeleted.removeIf(filter);
| toBeUpdated.removeIf(filter)
| toBeDeleted.removeIf(filter);
}

/**
Expand All @@ -225,30 +182,17 @@ public boolean removeIf(final Predicate<? super T> filter) {
*/
public boolean retainAll(final Collection<T> keys) {
return toBeCreated.retainAll(keys)
|| toBeUpdated.retainAll(keys)
|| toBeDeleted.retainAll(keys);
| toBeUpdated.retainAll(keys)
| toBeDeleted.retainAll(keys);
}

public boolean contains(final ResourceOperation type, final T key) {
boolean result = false;

switch (type) {
case CREATE:
result = toBeCreated.contains(key);
break;

case UPDATE:
result = toBeUpdated.contains(key);
break;

case DELETE:
result = toBeDeleted.contains(key);
break;

default:
}

return result;
return switch (type) {
case CREATE -> toBeCreated.contains(key);
case UPDATE -> toBeUpdated.contains(key);
case DELETE -> toBeDeleted.contains(key);
default -> false;
};
}

public boolean contains(final T key) {
Expand All @@ -264,25 +208,12 @@ public boolean contains(final T key) {
* @return resource matching the given type
*/
public final Set<T> get(final ResourceOperation type) {
Set<T> result = Set.of();

switch (type) {
case CREATE:
result = toBeCreated;
break;

case UPDATE:
result = toBeUpdated;
break;

case DELETE:
result = toBeDeleted;
break;

default:
}

return result;
return switch (type) {
case CREATE -> toBeCreated;
case UPDATE -> toBeUpdated;
case DELETE -> toBeDeleted;
default -> Set.of();
};
}

public Map<T, ResourceOperation> asMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,38 @@ public void remove() {
@Test
public void removeAll() {
Set<String> keys = new HashSet<>();
keys.add("testKey1");
keys.add("testKey2");
String key1 = "key1";
String key2 = "key2";
keys.add(key1);
keys.add(key2);

assertFalse(propagationByResource.removeAll(ResourceOperation.CREATE, keys));
assertFalse(propagationByResource.removeAll(ResourceOperation.UPDATE, keys));
assertFalse(propagationByResource.removeAll(ResourceOperation.DELETE, keys));
assertFalse(propagationByResource.removeAll(ResourceOperation.NONE, keys));

propagationByResource.add(ResourceOperation.CREATE, key1);
propagationByResource.add(ResourceOperation.UPDATE, key2);
assertTrue(propagationByResource.removeAll(keys));
assertFalse(propagationByResource.contains(key1));
assertFalse(propagationByResource.contains(key2));
}

@Test
public void retainAll() {
Set<String> keys = new HashSet<>();
String key1 = "key1";
String key2 = "key2";
String key3 = "key3";
keys.add(key1);

propagationByResource.add(ResourceOperation.CREATE, key1);
propagationByResource.add(ResourceOperation.UPDATE, key2);
propagationByResource.add(ResourceOperation.DELETE, key3);
assertTrue(propagationByResource.retainAll(keys));
assertTrue(propagationByResource.contains(key1));
assertFalse(propagationByResource.contains(key2));
assertFalse(propagationByResource.contains(key3));
}

@Test
Expand Down