Import views plugins
[deliverable/tracecompass.git] / tmf / org.lttng.scope.tmf2.views.ui / src / org / lttng / scope / tmf2 / views / ui / timeline / widgets / timegraph / VerticalPosition.java
1 /*
2 * Copyright (C) 2017 EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 */
9
10 package org.lttng.scope.tmf2.views.ui.timeline.widgets.timegraph;
11
12 import java.util.Objects;
13
14 import org.eclipse.jdt.annotation.Nullable;
15
16 import com.google.common.base.MoreObjects;
17
18 public class VerticalPosition {
19
20 /**
21 * Placeholder for uninitialized vertical positions.
22 */
23 public static final VerticalPosition UNINITIALIZED_VP = new VerticalPosition(0.0, 0.0);
24
25 private static final double EPSILON = 0.00001;
26
27 public final double fTopPos;
28 public final double fBottomPos;
29
30 public VerticalPosition(double topPos, double bottomPos) {
31 fTopPos = topPos;
32 fBottomPos = bottomPos;
33 }
34
35 @Override
36 public int hashCode() {
37 return Objects.hash(fTopPos, fBottomPos);
38 }
39
40 @Override
41 public boolean equals(@Nullable Object obj) {
42 if (this == obj) {
43 return true;
44 }
45 if (obj == null) {
46 return false;
47 }
48 if (getClass() != obj.getClass()) {
49 return false;
50 }
51 VerticalPosition other = (VerticalPosition) obj;
52 return (doubleEquals(fTopPos, other.fTopPos)
53 && doubleEquals(fBottomPos, other.fBottomPos));
54 }
55
56 @Override
57 public String toString() {
58 return MoreObjects.toStringHelper(this)
59 .add("fTopPos", fTopPos) //$NON-NLS-1$
60 .add("fBottomPos", fBottomPos) //$NON-NLS-1$
61 .toString();
62 }
63
64 private static boolean doubleEquals(double d1, double d2) {
65 return (Math.abs(d1 - d2) < EPSILON);
66 }
67 }
This page took 0.032816 seconds and 5 git commands to generate.