JsonDataStoreQueue { public void apply(Function<List<T>, List<T>> listOperation) { synchronized (storeKey) { List<T> values = getList(); values = listOperation.apply(values); dataStore.put(storeKey, JsonValue.wrapOpt(values)); } } JsonDataStoreQueue(@NonNull PreferenceDataStore dataStore,
                              @NonNull String storeKey,
                              @NonNull Function<T, ? extends JsonSerializable> serializer,
                              @NonNull Function<JsonValue, T> deserializer); void removeAll(); void addAll(@NonNull List<T> values); void add(@NonNull T value); @Nullable T pop(); @Nullable T peek(); @NonNull List<T> getList(); void apply(Function<List<T>, List<T>> listOperation);  }
@Test public void testApply() { queue.add(JsonValue.wrapOpt("neat")); queue.add(JsonValue.wrapOpt("rad")); queue.apply(new Function<List<JsonValue>, List<JsonValue>>() { @Override public List<JsonValue> apply(List<JsonValue> input) { return Arrays.asList(JsonValue.wrapOpt("what?")); } }); assertEquals(1, queue.getList().size()); assertEquals("what?", queue.peek().getString()); }