| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2012, 2013 Ericsson |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are made |
| 5 | * 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 | * Contributors: |
| 10 | * Matthew Khouzam - Initial API and implementation |
| 11 | * Alexandre Montplaisir - Extends TmfLocation |
| 12 | *******************************************************************************/ |
| 13 | package org.eclipse.linuxtools.tmf.core.ctfadaptor; |
| 14 | |
| 15 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
| 16 | import org.eclipse.linuxtools.tmf.core.trace.location.TmfLocation; |
| 17 | |
| 18 | /** |
| 19 | * The nugget of information that is unique to a location in a CTF trace. |
| 20 | * |
| 21 | * It can be copied and used to restore a position in a given trace. |
| 22 | * |
| 23 | * @version 1.0 |
| 24 | * @author Matthew Khouzam |
| 25 | */ |
| 26 | public final class CtfLocation extends TmfLocation { |
| 27 | |
| 28 | // ------------------------------------------------------------------------ |
| 29 | // Attributes |
| 30 | // ------------------------------------------------------------------------ |
| 31 | |
| 32 | /** |
| 33 | * An invalid location |
| 34 | */ |
| 35 | public static final CtfLocationInfo INVALID_LOCATION = new CtfLocationInfo(-1, -1); |
| 36 | |
| 37 | // ------------------------------------------------------------------------ |
| 38 | // Constructors |
| 39 | // ------------------------------------------------------------------------ |
| 40 | |
| 41 | /** |
| 42 | * Basic constructor for CtfLocation. Uses a default index of 0. |
| 43 | * |
| 44 | * @param timestamp |
| 45 | * The timestamp of this location |
| 46 | * @since 2.0 |
| 47 | */ |
| 48 | public CtfLocation(final ITmfTimestamp timestamp) { |
| 49 | this(timestamp.getValue(), 0); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Constructor using timestamp object and index |
| 54 | * |
| 55 | * @param timestamp |
| 56 | * The timestamp of this location |
| 57 | * @param index |
| 58 | * The index of this location for this timestamp |
| 59 | * @since 2.0 |
| 60 | */ |
| 61 | public CtfLocation(final ITmfTimestamp timestamp, long index) { |
| 62 | this(timestamp.getValue(), index); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Constructor using a long value for the timestamp, and an index |
| 67 | * |
| 68 | * @param timestampValue |
| 69 | * The new timestamp |
| 70 | * @param index |
| 71 | * The new index |
| 72 | * @since 2.0 |
| 73 | */ |
| 74 | public CtfLocation(final long timestampValue, final long index) { |
| 75 | super(new CtfLocationInfo(timestampValue, index)); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Constructor using a pre-made locationInfo object |
| 80 | * |
| 81 | * @param locationInfo |
| 82 | * The locationInfo object to use |
| 83 | * @since 2.0 |
| 84 | */ |
| 85 | public CtfLocation(CtfLocationInfo locationInfo) { |
| 86 | super(locationInfo); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Copy constructor |
| 91 | * |
| 92 | * @param location |
| 93 | * Other location to copy |
| 94 | * @since 2.0 |
| 95 | */ |
| 96 | public CtfLocation(final CtfLocation location) { |
| 97 | super(location); |
| 98 | } |
| 99 | |
| 100 | // ------------------------------------------------------------------------ |
| 101 | // TmfLocation |
| 102 | // ------------------------------------------------------------------------ |
| 103 | |
| 104 | /** |
| 105 | * @since 2.0 |
| 106 | */ |
| 107 | @Override |
| 108 | public CtfLocationInfo getLocationInfo() { |
| 109 | return (CtfLocationInfo) super.getLocationInfo(); |
| 110 | } |
| 111 | |
| 112 | // ------------------------------------------------------------------------ |
| 113 | // Object |
| 114 | // ------------------------------------------------------------------------ |
| 115 | |
| 116 | @Override |
| 117 | public String toString() { |
| 118 | if( this.getLocationInfo().equals(CtfLocation.INVALID_LOCATION )) { |
| 119 | return getClass().getSimpleName() + " [INVALID]"; //$NON-NLS-1$ |
| 120 | } |
| 121 | return super.toString(); |
| 122 | } |
| 123 | |
| 124 | } |