1 /*******************************************************************************
2 * Copyright (c) 2017 École Polytechnique de Montréal
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
.datastore
.core
.interval
;
12 import java
.util
.Objects
;
13 import java
.util
.StringJoiner
;
15 import org
.eclipse
.jdt
.annotation
.NonNull
;
16 import org
.eclipse
.jdt
.annotation
.Nullable
;
17 import org
.eclipse
.tracecompass
.datastore
.core
.serialization
.ISafeByteBufferWriter
;
20 * Basic implementation of {@link IHTInterval}.
22 * @author Geneviève Bastien
25 public class HTInterval
implements IHTInterval
{
27 private final long fStart
;
28 private final long fEnd
;
31 * The object to use to read a BaseHtObject from the disk
33 public static final IHTIntervalReader
<HTInterval
> INTERVAL_READER
=
34 (buffer
) -> new HTInterval(buffer
.getLong(), buffer
.getLong());
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 HTInterval(long start
, long end
) {
48 throw new IllegalArgumentException();
55 public long getStart() {
60 public long getEnd() {
65 public String
toString() {
66 return (new StringJoiner(", ", "[", "]")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
67 .add(String
.valueOf(fStart
))
68 .add(String
.valueOf(fEnd
))
73 public int getSizeOnDisk() {
74 return 2 * Long
.BYTES
;
78 public void writeSegment(@NonNull ISafeByteBufferWriter buffer
) {
79 buffer
.putLong(fStart
);
84 public int hashCode() {
85 return Objects
.hash(fStart
, fEnd
);
89 public boolean equals(@Nullable Object obj
) {
93 if (obj
.getClass() != getClass()) {
96 HTInterval other
= (HTInterval
) obj
;
97 return (fStart
== other
.fStart
98 && fEnd
== other
.fEnd
);