segStore: Merge ISegment and ISegment2
[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
3866be8e
GB
12import org.eclipse.jdt.annotation.NonNull;
13import org.eclipse.tracecompass.datastore.core.interval.IHTIntervalReader;
14import org.eclipse.tracecompass.datastore.core.serialization.ISafeByteBufferWriter;
15
5a90de55
AM
16/**
17 * Basic implementation of {@link ISegment}.
18 *
19 * @author Alexandre Montplaisir
20 */
21public class BasicSegment implements ISegment {
22
3866be8e
GB
23 /**
24 * The factory to read an object from a buffer
25 * @since 2.0
26 */
27 public static final IHTIntervalReader<BasicSegment> BASIC_SEGMENT_READ_FACTORY = buffer -> {
28 return new BasicSegment(buffer.getLong(), buffer.getLong());
29 };
30
5a90de55
AM
31 private static final long serialVersionUID = -3257452887960883177L;
32
33 private final long fStart;
34 private final long fEnd;
35
36 /**
37 * Create a new segment.
38 *
39 * The end position should be equal to or greater than the start position.
40 *
41 * @param start
42 * Start position of the segment
43 * @param end
44 * End position of the segment
45 */
46 public BasicSegment(long start, long end) {
47 if (end < start) {
48 throw new IllegalArgumentException();
49 }
50 fStart = start;
51 fEnd = end;
52 }
53
54 @Override
55 public long getStart() {
56 return fStart;
57 }
58
59 @Override
60 public long getEnd() {
61 return fEnd;
62 }
63
3866be8e
GB
64 /**
65 * @since 2.0
66 */
67 @Override
68 public int getSizeOnDisk() {
69 // Save the start and end time
70 return Long.BYTES * 2;
71 }
72
73 /**
74 * @since 2.0
75 */
76 @Override
77 public void writeSegment(@NonNull ISafeByteBufferWriter buffer) {
78 buffer.putLong(getStart());
79 buffer.putLong(getEnd());
80 }
81
5a90de55
AM
82 @Override
83 public String toString() {
84 return new String('[' + String.valueOf(fStart) + ", " + String.valueOf(fEnd) + ']'); //$NON-NLS-1$
85 }
3866be8e 86
5a90de55 87}
This page took 0.04513 seconds and 5 git commands to generate.