JsonDataStoreQueue { @Nullable public T pop() { synchronized (storeKey) { List<JsonValue> jsonValues = dataStore.getJsonValue(storeKey).optList().getList(); if (jsonValues.isEmpty()) { return null; } JsonValue value = jsonValues.remove(0); dataStore.put(storeKey, JsonValue.wrapOpt(jsonValues)); return deserializer.apply(value); } } 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 testPop() { queue.add(JsonValue.wrapOpt("neat")); queue.add(JsonValue.wrapOpt("rad")); assertEquals(2, queue.getList().size()); assertEquals("neat", queue.pop().getString()); assertEquals(1, queue.getList().size()); assertEquals("rad", queue.pop().getString()); assertTrue(queue.getList().isEmpty()); }