| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2009, 2013 Ericsson |
| 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 | * Contributors: |
| 10 | * Francois Chouinard - Initial API and implementation |
| 11 | * Francois Chouinard - Updated as per TMF Trace Model 1.0 |
| 12 | * Patrick Tasse - Updated for ranks in experiment location |
| 13 | *******************************************************************************/ |
| 14 | |
| 15 | package org.eclipse.tracecompass.internal.tmf.core.trace; |
| 16 | |
| 17 | import java.nio.ByteBuffer; |
| 18 | |
| 19 | import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation; |
| 20 | |
| 21 | |
| 22 | /** |
| 23 | * The experiment location in TMF. |
| 24 | * <p> |
| 25 | * An experiment location is actually the set of locations of the traces it |
| 26 | * contains. By setting the individual traces to their corresponding locations, |
| 27 | * the experiment can be positioned to read the next chronological event. |
| 28 | * <p> |
| 29 | * It is the responsibility of the user the individual trace locations are valid |
| 30 | * and that they are matched to the correct trace. |
| 31 | * |
| 32 | * @version 1.0 |
| 33 | * @author Francois Chouinard |
| 34 | * |
| 35 | * @see TmfLocationArray |
| 36 | */ |
| 37 | public final class TmfExperimentLocation implements ITmfLocation { |
| 38 | |
| 39 | private final TmfLocationArray fLocation; |
| 40 | |
| 41 | // ------------------------------------------------------------------------ |
| 42 | // Constructors |
| 43 | // ------------------------------------------------------------------------ |
| 44 | |
| 45 | /** |
| 46 | * The standard constructor |
| 47 | * |
| 48 | * @param locations the set of trace locations |
| 49 | */ |
| 50 | public TmfExperimentLocation(TmfLocationArray locations) { |
| 51 | fLocation = locations; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * The copy constructor |
| 56 | * |
| 57 | * @param location the other experiment location |
| 58 | */ |
| 59 | public TmfExperimentLocation(TmfExperimentLocation location) { |
| 60 | this(location.getLocationInfo()); |
| 61 | } |
| 62 | |
| 63 | // ------------------------------------------------------------------------ |
| 64 | // Object |
| 65 | // ------------------------------------------------------------------------ |
| 66 | |
| 67 | @Override |
| 68 | @SuppressWarnings("nls") |
| 69 | public String toString() { |
| 70 | StringBuilder result = new StringBuilder("TmfExperimentLocation ["); |
| 71 | result.append(fLocation.toString()); |
| 72 | result.append("]"); |
| 73 | return result.toString(); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public int hashCode() { |
| 78 | final int prime = 31; |
| 79 | int result = 1; |
| 80 | result = prime * result + ((fLocation != null) ? fLocation.hashCode() : 0); |
| 81 | return result; |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public boolean equals(Object obj) { |
| 86 | if (this == obj) { |
| 87 | return true; |
| 88 | } |
| 89 | if (obj == null) { |
| 90 | return false; |
| 91 | } |
| 92 | if (getClass() != obj.getClass()) { |
| 93 | return false; |
| 94 | } |
| 95 | final TmfExperimentLocation other = (TmfExperimentLocation) obj; |
| 96 | if (fLocation == null) { |
| 97 | if (other.fLocation != null) { |
| 98 | return false; |
| 99 | } |
| 100 | } else if (!fLocation.equals(other.fLocation)) { |
| 101 | return false; |
| 102 | } |
| 103 | return true; |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public TmfLocationArray getLocationInfo() { |
| 108 | return fLocation; |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public void serialize(ByteBuffer bufferOut) { |
| 113 | ITmfLocation[] locations = fLocation.getLocations(); |
| 114 | long[] ranks = fLocation.getRanks(); |
| 115 | for (int i = 0; i < locations.length; ++i) { |
| 116 | locations[i].serialize(bufferOut); |
| 117 | bufferOut.putLong(ranks[i]); |
| 118 | } |
| 119 | } |
| 120 | } |