blob: e6b5adea15e5c4c4e652d24ed7374515c2f23286 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/*******************************************************************************
* Copyright (c) 2010 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.ote.ui.message.tree;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.osee.ote.message.MessageSink;
/**
* Builds a simple tree out of messages. All nodes under the root are messages. Each node under each message is a
* message element
*
* @author Ken J. Aguilar
*/
public class MessageTreeBuilder implements MessageSink {
private ArrayList<String> lastAddedMsgNode;
private int numElements = 0;
private int numMessages = 0;
private final HashMap<String, ArrayList<String>> msgs = new HashMap<String, ArrayList<String>>(200000);
public void clear() {
numMessages = numElements = 0;
msgs.clear();
lastAddedMsgNode = null;
}
@Override
public void absorbElement(final String elementName) {
if (lastAddedMsgNode == null) {
throw new IllegalStateException("no message exists for " + elementName);
}
lastAddedMsgNode.add(elementName);
numElements++;
}
@Override
public void absorbMessage(String messageName) {
lastAddedMsgNode = new ArrayList<String>(64);
msgs.put(messageName, lastAddedMsgNode);
numMessages++;
}
@Override
public void absorbProvider(String providerName) {
// We don't care about absorbing this yet
// In the future it would be nice to have this
// information stored and related to the messages
// that are from this provider for display
// to the users
}
public int getNumElements() {
return numElements;
}
public int getNumMessages() {
return numMessages;
}
public Collection<Map.Entry<String, ArrayList<String>>> getMessages() {
return msgs.entrySet();
}
}
|