| 1 | /********************************************************************** |
| 2 | * Copyright (c) 2012 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 | * Bernd Hufmann - Initial API and implementation |
| 11 | **********************************************************************/ |
| 12 | package org.eclipse.linuxtools.lttng.ui.views.control.model.impl; |
| 13 | |
| 14 | import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceInfo; |
| 15 | |
| 16 | /** |
| 17 | * <b><u>TraceInfo</u></b> |
| 18 | * <p> |
| 19 | * Implementation of the base trace information interface (ITraceInfo) to |
| 20 | * store common data. |
| 21 | * </p> |
| 22 | */ |
| 23 | public class TraceInfo implements ITraceInfo { |
| 24 | |
| 25 | // ------------------------------------------------------------------------ |
| 26 | // Attributes |
| 27 | // ------------------------------------------------------------------------ |
| 28 | /** |
| 29 | * The name of the element. |
| 30 | */ |
| 31 | private String fName = null; |
| 32 | |
| 33 | // ------------------------------------------------------------------------ |
| 34 | // Constructors |
| 35 | // ------------------------------------------------------------------------ |
| 36 | /** |
| 37 | * Constructor |
| 38 | * @param name - name of trace element |
| 39 | */ |
| 40 | public TraceInfo(String name) { |
| 41 | if (name == null) { |
| 42 | throw new IllegalArgumentException(); |
| 43 | } |
| 44 | fName = name; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Copy constructor |
| 49 | * @param other - the instance to copy |
| 50 | */ |
| 51 | public TraceInfo(TraceInfo other) { |
| 52 | if (other == null) { |
| 53 | throw new IllegalArgumentException(); |
| 54 | } else { |
| 55 | fName = String.valueOf(other.fName); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // ------------------------------------------------------------------------ |
| 60 | // Accessors |
| 61 | // ------------------------------------------------------------------------ |
| 62 | /* |
| 63 | * (non-Javadoc) |
| 64 | * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceInfo#getName() |
| 65 | */ |
| 66 | @Override |
| 67 | public String getName() { |
| 68 | return fName; |
| 69 | } |
| 70 | |
| 71 | /* |
| 72 | * (non-Javadoc) |
| 73 | * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceInfo#setName(java.lang.String) |
| 74 | */ |
| 75 | @Override |
| 76 | public void setName(String name) { |
| 77 | fName = name; |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * (non-Javadoc) |
| 82 | * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceInfo#formatString() |
| 83 | */ |
| 84 | @Override |
| 85 | public String formatString() { |
| 86 | return toString(); |
| 87 | } |
| 88 | |
| 89 | /* |
| 90 | * (non-Javadoc) |
| 91 | * @see java.lang.Object#hashCode() |
| 92 | */ |
| 93 | @Override |
| 94 | public int hashCode() { |
| 95 | final int prime = 31; |
| 96 | int result = 1; |
| 97 | result = prime * result + ((fName == null) ? 0 : fName.hashCode()); |
| 98 | return result; |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | * (non-Javadoc) |
| 103 | * @see java.lang.Object#equals(java.lang.Object) |
| 104 | */ |
| 105 | @Override |
| 106 | public boolean equals(Object obj) { |
| 107 | if (this == obj) { |
| 108 | return true; |
| 109 | } |
| 110 | if (obj == null) { |
| 111 | return false; |
| 112 | } |
| 113 | if (getClass() != obj.getClass()) { |
| 114 | return false; |
| 115 | } |
| 116 | TraceInfo other = (TraceInfo) obj; |
| 117 | if (fName == null) { |
| 118 | if (other.fName != null) { |
| 119 | return false; |
| 120 | } |
| 121 | } else if (!fName.equals(other.fName)) { |
| 122 | return false; |
| 123 | } |
| 124 | return true; |
| 125 | } |
| 126 | /* |
| 127 | * (non-Javadoc) |
| 128 | * @see java.lang.Object#toString() |
| 129 | */ |
| 130 | @SuppressWarnings("nls") |
| 131 | @Override |
| 132 | public String toString() { |
| 133 | StringBuffer output = new StringBuffer(); |
| 134 | output.append("[TraceInfo("); |
| 135 | output.append("Name="); |
| 136 | output.append(getName()); |
| 137 | output.append(")]"); |
| 138 | return output.toString(); |
| 139 | } |
| 140 | } |