segstore: add default unhandled methods to ISegmentStore
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Sat, 15 Oct 2016 20:06:55 +0000 (16:06 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 2 Nov 2016 16:53:46 +0000 (12:53 -0400)
This handles common functionalities for all segment stores.
This can be seen as part of the segment store contract.

Anything removing items from a segment store asside from
clear should throw an unsupportedOperationException.

If an implementation decides to support this, that is fine, but
not the expected way the object should behave.

Change-Id: I9d00960ae8826cecc63092245ca7fc447a28defb
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/83305
Reviewed-by: Hudson CI
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
statesystem/org.eclipse.tracecompass.segmentstore.core/src/org/eclipse/tracecompass/internal/segmentstore/core/arraylist/ArrayListStore.java
statesystem/org.eclipse.tracecompass.segmentstore.core/src/org/eclipse/tracecompass/internal/segmentstore/core/arraylist/LazyArrayListStore.java
statesystem/org.eclipse.tracecompass.segmentstore.core/src/org/eclipse/tracecompass/internal/segmentstore/core/treemap/TreeMapStore.java
statesystem/org.eclipse.tracecompass.segmentstore.core/src/org/eclipse/tracecompass/segmentstore/core/ISegmentStore.java

index 60387b953b3d36513bf4e762274e85ecf25c2f99..ee130338b07f3b459dc831964eb0e5ce444ccb2d 100644 (file)
@@ -184,11 +184,6 @@ public class ArrayListStore<@NonNull E extends ISegment> implements ISegmentStor
         }
     }
 
-    @Override
-    public boolean remove(@Nullable Object o) {
-        throw new UnsupportedOperationException();
-    }
-
     @Override
     public boolean addAll(@Nullable Collection<? extends E> c) {
         if (c == null) {
@@ -209,16 +204,6 @@ public class ArrayListStore<@NonNull E extends ISegment> implements ISegmentStor
         }
     }
 
-    @Override
-    public boolean removeAll(@Nullable Collection<?> c) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public boolean retainAll(@Nullable Collection<?> c) {
-        throw new UnsupportedOperationException();
-    }
-
     @Override
     public void clear() {
         fLock.writeLock().lock();
index a9128c7b1773aef6f5c48b968b8ea6f28d658732..d78479dc9972142e829d1333532c008f8e1099d0 100644 (file)
@@ -56,8 +56,6 @@ import com.google.common.collect.Ordering;
  */
 public class LazyArrayListStore<@NonNull E extends ISegment> implements ISegmentStore<E> {
 
-    private static final String ERROR_MESSAGE = "Cannot remove from a segment store"; //$NON-NLS-1$
-
     private final Comparator<E> COMPARATOR = Ordering.from(SegmentComparators.INTERVAL_START_COMPARATOR)
             .compound(SegmentComparators.INTERVAL_END_COMPARATOR);
 
@@ -234,21 +232,6 @@ public class LazyArrayListStore<@NonNull E extends ISegment> implements ISegment
         }
     }
 
-    @Override
-    public boolean removeAll(@Nullable Collection<?> c) {
-        throw new UnsupportedOperationException(ERROR_MESSAGE);
-    }
-
-    @Override
-    public boolean retainAll(@Nullable Collection<?> c) {
-        throw new UnsupportedOperationException(ERROR_MESSAGE);
-    }
-
-    @Override
-    public boolean remove(@Nullable Object o) {
-        throw new UnsupportedOperationException(ERROR_MESSAGE);
-    }
-
     @Override
     public void clear() {
         fLock.lock();
index e9a0965ff1f62b7b70b5ed6cecf7d9ae1e4876f5..ba987fdc21110305717065068e9954b980daab68 100644 (file)
@@ -180,11 +180,6 @@ public class TreeMapStore<@NonNull E extends ISegment> implements ISegmentStore<
         }
     }
 
-    @Override
-    public boolean remove(@Nullable Object o) {
-        throw new UnsupportedOperationException();
-    }
-
     @Override
     public boolean addAll(@Nullable Collection<? extends E> c) {
         if (c == null) {
@@ -205,16 +200,6 @@ public class TreeMapStore<@NonNull E extends ISegment> implements ISegmentStore<
         }
     }
 
-    @Override
-    public boolean removeAll(@Nullable Collection<?> c) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public boolean retainAll(@Nullable Collection<?> c) {
-        throw new UnsupportedOperationException();
-    }
-
     @Override
     public void clear() {
         fLock.writeLock().lock();
index 132f08a9a68f3178e1b285fe6d4720cf9af94c2f..c5779732bc43538149c80152874565e9c490358f 100644 (file)
@@ -22,9 +22,18 @@ import org.eclipse.jdt.annotation.NonNull;
 
 import com.google.common.collect.Lists;
 
+import org.eclipse.jdt.annotation.Nullable;
+
 /**
  * Interface for segment-storing backends.
  *
+ * Common contract (what should not be implemented) for a segment store.
+ * <ol>
+ * <li>no remove</li>
+ * <li>no removeAll</li>
+ * <li>no retainall</li>
+ * </ol>
+ *
  * @param <E>
  *            The type of {@link ISegment} element that will be stored in this
  *            database.
@@ -135,4 +144,19 @@ public interface ISegmentStore<E extends ISegment> extends Collection<E> {
     default void close(boolean deleteFiles) {
 
     }
+
+    @Override
+    default boolean remove(@Nullable Object o) {
+        throw new UnsupportedOperationException("Segment stores does not support \"remove\""); //$NON-NLS-1$
+    }
+
+    @Override
+    default boolean removeAll(@Nullable Collection<?> c) {
+        throw new UnsupportedOperationException("Segment stores does not support \"removeAll\""); //$NON-NLS-1$
+    }
+
+    @Override
+    default boolean retainAll(@Nullable Collection<?> c) {
+        throw new UnsupportedOperationException("Segment stores does not support \"retainAll\""); //$NON-NLS-1$
+    }
 }
This page took 0.02668 seconds and 5 git commands to generate.