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
.internal
.provisional
.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
.internal
.provisional
.datastore
.core
.serialization
.ISafeByteBufferWriter
;
20 * Basic implementation of {@link IHTInterval}.
22 * @author Geneviève Bastien
24 public class HTInterval
implements IHTInterval
{
26 private final long fStart
;
27 private final long fEnd
;
30 * The object to use to read a BaseHtObject from the disk
32 public static final IHTIntervalReader
<HTInterval
> INTERVAL_READER
=
33 (buffer
) -> new HTInterval(buffer
.getLong(), buffer
.getLong());
36 * Create a new segment.
38 * The end position should be equal to or greater than the start position.
41 * Start position of the segment
43 * End position of the segment
45 public HTInterval(long start
, long end
) {
47 throw new IllegalArgumentException();
54 public long getStart() {
59 public long getEnd() {
64 public String
toString() {
65 return (new StringJoiner(", ", "[", "]")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
66 .add(String
.valueOf(fStart
))
67 .add(String
.valueOf(fEnd
))
72 public int getSizeOnDisk() {
73 return 2 * Long
.BYTES
;
77 public void writeSegment(@NonNull ISafeByteBufferWriter buffer
) {
78 buffer
.putLong(fStart
);
83 public int hashCode() {
84 return Objects
.hash(fStart
, fEnd
);
88 public boolean equals(@Nullable Object obj
) {
92 if (obj
.getClass() != getClass()) {
95 HTInterval other
= (HTInterval
) obj
;
96 return (fStart
== other
.fStart
97 && fEnd
== other
.fEnd
);