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
= checkNotNull(Ordering
30 .from(SegmentComparators
.INTERVAL_START_COMPARATOR
)
31 .compound(SegmentComparators
.INTERVAL_END_COMPARATOR
));
33 private final long fStart
;
34 private final long fEnd
;
37 * Create a new segment.
39 * The end position should be equal to or greater than the start position.
42 * Start position of the segment
44 * End position of the segment
46 public BasicSegment(long start
, long end
) {
48 throw new IllegalArgumentException();
55 public long getStart() {
60 public long getEnd() {
65 public long getLength() {
66 return (fEnd
- fStart
);
70 public int compareTo(@Nullable ISegment o
) {
72 throw new IllegalArgumentException();
74 return COMPARATOR
.compare(this, o
);
78 public String
toString() {
79 return new String('[' + String
.valueOf(fStart
) + ", " + String
.valueOf(fEnd
) + ']'); //$NON-NLS-1$