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
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.segmentstore
.core
;
12 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
14 import java
.util
.Comparator
;
16 import org
.eclipse
.jdt
.annotation
.Nullable
;
18 import com
.google
.common
.collect
.Ordering
;
21 * Basic implementation of {@link ISegment}.
23 * @author Alexandre Montplaisir
25 public class BasicSegment
implements ISegment
{
27 private static final long serialVersionUID
= -3257452887960883177L;
29 private static final Comparator
<ISegment
> COMPARATOR
;
31 /* checkNotNull() has to be called separately, or else it breaks the
33 Comparator
<ISegment
> comp
= Ordering
34 .from(SegmentComparators
.INTERVAL_START_COMPARATOR
)
35 .compound(SegmentComparators
.INTERVAL_END_COMPARATOR
);
36 COMPARATOR
= checkNotNull(comp
);
39 private final long fStart
;
40 private final long fEnd
;
43 * Create a new segment.
45 * The end position should be equal to or greater than the start position.
48 * Start position of the segment
50 * End position of the segment
52 public BasicSegment(long start
, long end
) {
54 throw new IllegalArgumentException();
61 public long getStart() {
66 public long getEnd() {
71 public int compareTo(@Nullable ISegment o
) {
73 throw new IllegalArgumentException();
75 return COMPARATOR
.compare(this, o
);
79 public String
toString() {
80 return new String('[' + String
.valueOf(fStart
) + ", " + String
.valueOf(fEnd
) + ']'); //$NON-NLS-1$