~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/tracecontrol/model/config/TraceChannels.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2011 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
 *******************************************************************************/
 
13
package org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.config;
 
14
 
 
15
import java.util.Collection;
 
16
import java.util.HashMap;
 
17
import java.util.Iterator;
 
18
import java.util.Map;
 
19
import java.util.Set;
 
20
 
 
21
import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.config.TraceChannel;
 
22
import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.config.TraceChannels;
 
23
 
 
24
/**
 
25
 * <b><u>TraceChannels</u></b>
 
26
 * <p>
 
27
 *  This models a collection of trace channels.
 
28
 * </p>
 
29
 */
 
30
public class TraceChannels implements Map<String, TraceChannel>, Cloneable {
 
31
 
 
32
    // ------------------------------------------------------------------------
 
33
    // Attributes
 
34
    // -----------------------------------------------------------------------
 
35
    private Map<String, TraceChannel> fChannels = new HashMap<String, TraceChannel>();
 
36
 
 
37
    // ------------------------------------------------------------------------
 
38
    // Constructors
 
39
    // ------------------------------------------------------------------------
 
40
    
 
41
    // ------------------------------------------------------------------------
 
42
    // Operations
 
43
    // ------------------------------------------------------------------------
 
44
 
 
45
    /*
 
46
     * (non-Javadoc)
 
47
     * @see java.util.Map#size()
 
48
     */
 
49
    @Override
 
50
    public int size() {
 
51
        return fChannels.size();
 
52
    }
 
53
 
 
54
    /*
 
55
     * (non-Javadoc)
 
56
     * @see java.util.Map#isEmpty()
 
57
     */
 
58
    @Override
 
59
    public boolean isEmpty() {
 
60
        return fChannels.isEmpty();
 
61
    }
 
62
 
 
63
    /*
 
64
     * (non-Javadoc)
 
65
     * @see java.util.Map#containsKey(java.lang.Object)
 
66
     */
 
67
    @Override
 
68
    public boolean containsKey(Object key) {
 
69
        return fChannels.containsKey(key);
 
70
    }
 
71
 
 
72
    /*
 
73
     * (non-Javadoc)
 
74
     * @see java.util.Map#containsValue(java.lang.Object)
 
75
     */
 
76
    @Override
 
77
    public boolean containsValue(Object value) {
 
78
        return fChannels.containsValue(value);
 
79
    }
 
80
 
 
81
    /*
 
82
     * (non-Javadoc)
 
83
     * @see java.util.Map#get(java.lang.Object)
 
84
     */
 
85
    @Override
 
86
    public TraceChannel get(Object key) {
 
87
        return fChannels.get(key);
 
88
    }
 
89
 
 
90
    /*
 
91
     * (non-Javadoc)
 
92
     * @see java.util.Map#put(java.lang.Object, java.lang.Object)
 
93
     */
 
94
    @Override
 
95
    public TraceChannel put(String key, TraceChannel value) {
 
96
        return fChannels.put(key, value);
 
97
    }
 
98
 
 
99
    /*
 
100
     * (non-Javadoc)
 
101
     * @see java.util.Map#remove(java.lang.Object)
 
102
     */
 
103
    @Override
 
104
    public TraceChannel remove(Object key) {
 
105
        return fChannels.remove(key);
 
106
    }
 
107
 
 
108
    /*
 
109
     * (non-Javadoc)
 
110
     * @see java.util.Map#putAll(java.util.Map)
 
111
     */
 
112
    @Override
 
113
    public void putAll(Map<? extends String, ? extends TraceChannel> m) {
 
114
        fChannels.putAll(m);
 
115
    }
 
116
 
 
117
    /*
 
118
     * (non-Javadoc)
 
119
     * @see java.util.Map#clear()
 
120
     */
 
121
    @Override
 
122
    public void clear() {
 
123
        fChannels.clear();
 
124
    }
 
125
 
 
126
    /*
 
127
     * (non-Javadoc)
 
128
     * @see java.util.Map#keySet()
 
129
     */
 
130
    @Override
 
131
    public Set<String> keySet() {
 
132
        return fChannels.keySet();
 
133
    }
 
134
 
 
135
    /*
 
136
     * (non-Javadoc)
 
137
     * @see java.util.Map#values()
 
138
     */
 
139
    @Override
 
140
    public Collection<TraceChannel> values() {
 
141
        return fChannels.values();
 
142
    }
 
143
 
 
144
    /*
 
145
     * (non-Javadoc)
 
146
     * @see java.util.Map#entrySet()
 
147
     */
 
148
    @Override
 
149
    public Set<java.util.Map.Entry<String, TraceChannel>> entrySet() {
 
150
        return fChannels.entrySet();
 
151
    }
 
152
    
 
153
    /**
 
154
     * Creates trace channels with given names, put the to the map with a default
 
155
     * trace channel object.
 
156
     * 
 
157
     * @param channelNames
 
158
     */
 
159
    public void putAll(String[] channelNames) {
 
160
        for (int i = 0; i < channelNames.length; i++) {
 
161
            fChannels.put(channelNames[i], new TraceChannel(channelNames[i]));
 
162
        }
 
163
    }
 
164
    
 
165
    /*
 
166
     * (non-Javadoc)
 
167
     * @see java.lang.Object#clone()
 
168
     */
 
169
    @Override
 
170
    public TraceChannels clone() {
 
171
        TraceChannels clone = null;
 
172
        try {
 
173
            clone = (TraceChannels)super.clone();
 
174
 
 
175
            clone.fChannels = new HashMap<String, TraceChannel>();
 
176
            
 
177
            for (Iterator<String> iterator = fChannels.keySet().iterator(); iterator.hasNext();) {
 
178
                String key = (String) iterator.next();
 
179
                clone.fChannels.put(key, (fChannels.get(key)).clone());
 
180
            }
 
181
 
 
182
        } catch (CloneNotSupportedException e) {
 
183
        }
 
184
        return clone;
 
185
    }
 
186
}