1 /*******************************************************************************
2 * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.segmentstore
.core
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Collection
;
17 import java
.util
.Comparator
;
18 import java
.util
.List
;
20 import org
.eclipse
.jdt
.annotation
.Nullable
;
22 import com
.google
.common
.collect
.Lists
;
25 * Interface for segment-storing backends.
27 * Common contract (what should not be implemented) for a segment store.
30 * <li>no removeAll</li>
31 * <li>no retainall</li>
35 * The type of {@link ISegment} element that will be stored in this
38 * @author Alexandre Montplaisir
40 public interface ISegmentStore
<E
extends ISegment
> extends Collection
<E
> {
46 * The desired order for the returned iterator
47 * @return An iterator over all the segments in the store in the desired order
50 default Iterable
<E
> iterator(Comparator
<ISegment
> order
){
51 return getIntersectingElements(0, Long
.MAX_VALUE
, order
);
55 * Retrieve all elements that inclusively cross the given position.
58 * The target position. This would represent a timestamp, if the
59 * tree's X axis represents time.
60 * @return The intervals that cross this position
62 default Iterable
<E
> getIntersectingElements(long position
){
63 return getIntersectingElements(position
, position
);
67 * Retrieve all elements that inclusively cross the given position, sorted
68 * in the specified order.
71 * The target position. This would represent a timestamp, if the
72 * tree's X axis represents time.
74 * The desired order for the returned iterator
75 * @return The intervals that cross this position
78 default Iterable
<E
> getIntersectingElements(long position
, Comparator
<ISegment
> order
) {
79 return getIntersectingElements(position
, position
, order
);
83 * Retrieve all elements that inclusively cross another segment. We define
84 * this target segment by its start and end positions.
86 * This effectively means, all elements that respect *both* conditions:
89 * <li>Their end is after the 'start' parameter</li>
90 * <li>Their start is before the 'end' parameter</li>
94 * The target start position
96 * The target end position
97 * @return The elements overlapping with this segment
99 Iterable
<E
> getIntersectingElements(long start
, long end
);
102 * Retrieve all elements that inclusively cross another segment, sorted in
103 * the specified order. We define this target segment by its start and end
107 * The target start position
109 * The target end position
111 * The desired order for the returned iterator
112 * @return The intervals that cross this position
115 default Iterable
<E
> getIntersectingElements(long start
, long end
, Comparator
<ISegment
> order
) {
116 Iterable
<E
> ret
= getIntersectingElements(start
, end
);
118 if (ret
instanceof ArrayList
<?
>) {
120 * No point in copying the intersecting elements into a new
121 * ArrayList if they are already in a new ArrayList.
123 list
= (List
<E
>) ret
;
125 list
= Lists
.newArrayList(ret
);
132 * Dispose the data structure and release any system resources associated
138 * Method to close off the segment store. This happens for example when we
139 * are done reading an off-line trace. Implementers can use this method to
140 * save the segment store on disk
143 * Whether to delete any file that was created while building the
146 default void close(boolean deleteFiles
) {
151 default boolean remove(@Nullable Object o
) {
152 throw new UnsupportedOperationException("Segment stores does not support \"remove\""); //$NON-NLS-1$
156 default boolean removeAll(@Nullable Collection
<?
> c
) {
157 throw new UnsupportedOperationException("Segment stores does not support \"removeAll\""); //$NON-NLS-1$
161 default boolean retainAll(@Nullable Collection
<?
> c
) {
162 throw new UnsupportedOperationException("Segment stores does not support \"retainAll\""); //$NON-NLS-1$
This page took 0.045307 seconds and 5 git commands to generate.