ss: Provide a basic implementation of ISegment
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.segmentstore.core / src / org / eclipse / tracecompass / segmentstore / core / BasicSegment.java
CommitLineData
5a90de55
AM
1/*******************************************************************************
2 * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir
3 *
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 *******************************************************************************/
9
10package org.eclipse.tracecompass.segmentstore.core;
11
12/**
13 * Basic implementation of {@link ISegment}.
14 *
15 * @author Alexandre Montplaisir
16 */
17public class BasicSegment implements ISegment {
18
19 private static final long serialVersionUID = -3257452887960883177L;
20
21 private final long fStart;
22 private final long fEnd;
23
24 /**
25 * Create a new segment.
26 *
27 * The end position should be equal to or greater than the start position.
28 *
29 * @param start
30 * Start position of the segment
31 * @param end
32 * End position of the segment
33 */
34 public BasicSegment(long start, long end) {
35 if (end < start) {
36 throw new IllegalArgumentException();
37 }
38 fStart = start;
39 fEnd = end;
40 }
41
42 @Override
43 public long getStart() {
44 return fStart;
45 }
46
47 @Override
48 public long getEnd() {
49 return fEnd;
50 }
51
52 @Override
53 public long getLength() {
54 return (fEnd - fStart);
55 }
56
57 @Override
58 public String toString() {
59 return new String('[' + String.valueOf(fStart) + ", " + String.valueOf(fEnd) + ']'); //$NON-NLS-1$
60 }
61
62}
This page took 0.036039 seconds and 5 git commands to generate.