Commit | Line | Data |
---|---|---|
8c8bf09f ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009 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 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.event; | |
14 | ||
15 | /** | |
16 | * <b><u>TmfEventField</u></b> | |
17 | * <p> | |
18 | * A basic event field. | |
19 | * | |
20 | * TODO: Add support for field hierarchy. | |
21 | */ | |
22 | public class TmfEventField { | |
23 | ||
24 | // ------------------------------------------------------------------------ | |
25 | // Attributes | |
26 | // ------------------------------------------------------------------------ | |
27 | ||
28 | private final TmfEventContent fParent; | |
29 | private final String fFieldId; | |
30 | private Object fValue; | |
31 | ||
32 | // ------------------------------------------------------------------------ | |
33 | // Constructors | |
34 | // ------------------------------------------------------------------------ | |
35 | ||
36 | @SuppressWarnings("unused") | |
37 | private TmfEventField() { | |
38 | throw new AssertionError(); | |
39 | } | |
40 | ||
41 | /** | |
42 | * @param parent | |
43 | * @param id | |
44 | * @param value | |
45 | */ | |
46 | public TmfEventField(TmfEventContent parent, String id, Object value) { | |
47 | if (id == null) { | |
48 | throw new IllegalArgumentException(); | |
49 | } | |
50 | fParent = parent; | |
51 | fFieldId = id; | |
52 | fValue = value; | |
53 | } | |
54 | ||
55 | /** | |
56 | * @param other | |
57 | */ | |
58 | public TmfEventField(TmfEventField other) { | |
59 | if (other == null) | |
60 | throw new IllegalArgumentException(); | |
61 | fParent = other.fParent; | |
62 | fFieldId = other.fFieldId; | |
63 | fValue = other.fValue; | |
64 | } | |
65 | ||
66 | // ------------------------------------------------------------------------ | |
67 | // Accessors | |
68 | // ------------------------------------------------------------------------ | |
69 | ||
70 | /** | |
71 | * @return | |
72 | */ | |
73 | public TmfEventContent getParent() { | |
74 | return fParent; | |
75 | } | |
76 | ||
77 | /** | |
78 | * @return | |
79 | */ | |
80 | public String getId() { | |
81 | return fFieldId; | |
82 | } | |
83 | ||
84 | /** | |
85 | * @return | |
86 | */ | |
87 | public Object getValue() { | |
88 | return fValue; | |
89 | } | |
90 | ||
91 | /** | |
92 | * @param value new field value | |
93 | */ | |
94 | protected void setValue(Object value) { | |
95 | fValue = value; | |
96 | } | |
97 | ||
98 | // ------------------------------------------------------------------------ | |
99 | // Object | |
100 | // ------------------------------------------------------------------------ | |
101 | ||
102 | @Override | |
103 | public int hashCode() { | |
104 | int result = 17; | |
105 | result = 37 * result + fFieldId.hashCode(); | |
106 | result = 37 * result + fValue.hashCode(); | |
107 | return result; | |
108 | } | |
109 | ||
110 | @Override | |
111 | public boolean equals(Object other) { | |
112 | if (!(other instanceof TmfEventField)) | |
113 | return false; | |
114 | TmfEventField o = (TmfEventField) other; | |
115 | return fParent.equals(o.fParent) && fFieldId.equals(o.fFieldId) && fValue.equals(o.fValue); | |
116 | } | |
117 | ||
118 | @Override | |
119 | public String toString() { | |
120 | return "[TmfEventField(" + fFieldId + ":" + fValue.toString() + ")]"; | |
121 | } | |
122 | ||
123 | } |