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
.Collection
;
16 import java
.util
.Collections
;
17 import java
.util
.Comparator
;
18 import java
.util
.Iterator
;
19 import java
.util
.List
;
21 import org
.eclipse
.jdt
.annotation
.NonNull
;
23 import com
.google
.common
.collect
.Lists
;
25 import org
.eclipse
.jdt
.annotation
.Nullable
;
28 * Interface for segment-storing backends.
30 * Common contract (what should not be implemented) for a segment store.
33 * <li>no removeAll</li>
34 * <li>no retainall</li>
38 * The type of {@link ISegment} element that will be stored in this
41 * @author Alexandre Montplaisir
43 public interface ISegmentStore
<E
extends ISegment
> extends Collection
<E
> {
49 * The desired order for the returned iterator
50 * @return An iterator over all the segments in the store in the desired order
53 default Iterable
<E
> iterator(Comparator
<ISegment
> order
){
54 return getIntersectingElements(Long
.MIN_VALUE
, Long
.MAX_VALUE
, order
);
58 * Retrieve all elements that inclusively cross the given position.
61 * The target position. This would represent a timestamp, if the
62 * tree's X axis represents time.
63 * @return The intervals that cross this position
65 default Iterable
<E
> getIntersectingElements(long position
){
66 return getIntersectingElements(position
, position
);
70 * Retrieve all elements that inclusively cross the given position, sorted
71 * in the specified order.
74 * The target position. This would represent a timestamp, if the
75 * tree's X axis represents time.
77 * The desired order for the returned iterator
78 * @return The intervals that cross this position
81 default Iterable
<E
> getIntersectingElements(long position
, Comparator
<ISegment
> order
) {
82 return getIntersectingElements(position
, position
, order
);
86 * Retrieve all elements that inclusively cross another segment. We define
87 * this target segment by its start and end positions.
89 * This effectively means, all elements that respect *both* conditions:
92 * <li>Their end is after the 'start' parameter</li>
93 * <li>Their start is before the 'end' parameter</li>
97 * The target start position
99 * The target end position
100 * @return The elements overlapping with this segment
102 Iterable
<E
> getIntersectingElements(long start
, long end
);
105 * Retrieve all elements that inclusively cross another segment, sorted in
106 * the specified order. We define this target segment by its start and end
110 * The target start position
112 * The target end position
114 * The desired order for the returned iterator
115 * @return The intervals that cross this position
118 default Iterable
<E
> getIntersectingElements(long start
, long end
, Comparator
<ISegment
> order
){
119 List
<E
> list
= Lists
.newArrayList(getIntersectingElements(start
, end
));
120 return new Iterable
<@NonNull E
>() {
122 public Iterator
<@NonNull E
> iterator() {
123 Collections
.sort(list
, order
);
124 return list
.iterator();
130 * Dispose the data structure and release any system resources associated
136 * Method to close off the segment store. This happens for example when we
137 * are done reading an off-line trace. Implementers can use this method to
138 * save the segment store on disk
141 * Whether to delete any file that was created while building the
144 default void close(boolean deleteFiles
) {
149 default boolean remove(@Nullable Object o
) {
150 throw new UnsupportedOperationException("Segment stores does not support \"remove\""); //$NON-NLS-1$
154 default boolean removeAll(@Nullable Collection
<?
> c
) {
155 throw new UnsupportedOperationException("Segment stores does not support \"removeAll\""); //$NON-NLS-1$
159 default boolean retainAll(@Nullable Collection
<?
> c
) {
160 throw new UnsupportedOperationException("Segment stores does not support \"retainAll\""); //$NON-NLS-1$
This page took 0.034426 seconds and 5 git commands to generate.