Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6cc6828a867274d470e6afdf6c9046f0f7799542 (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
/*******************************************************************************
 * Copyright (c) 2007 Wind River Systems, Inc. and others.
 * 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:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package com.windriver.debug.tcf.ui.model;

import java.util.HashMap;
import java.util.Map;

public class TCFChildren {

    final TCFNode node;
    final Map<String,TCFNode> children = new HashMap<String,TCFNode>();
    
    protected boolean valid;
    
    TCFChildren(TCFNode node) {
        this.node = node;
    }
    
    void dispose() {
        TCFNode a[] = children.values().toArray(new TCFNode[children.size()]);
        for (int i = 0; i < a.length; i++) a[i].dispose();
        assert children.isEmpty();
    }
    
    void dispose(String id) {
        children.remove(id);
    }
    
    void doneValidate(Map<String,TCFNode> new_children) {
        assert !node.disposed;
        assert !valid;
        valid = true;
        if (children.size() > 0) {
            TCFNode[] a = children.values().toArray(new TCFNode[children.size()]);
            for (TCFNode n : a) if (new_children.get(n.id) != n) n.dispose();
        }
        for (TCFNode n : new_children.values()) {
            assert n.parent == node;
            children.put(n.id, n);
        }
        assert children.size() == new_children.size();
    }
    
    boolean validate() {
        doneValidate(new HashMap<String,TCFNode>());
        return true;
    }
    
    void invalidate() {
        assert !node.disposed;
        TCFNode[] a = children.values().toArray(new TCFNode[children.size()]);
        for (int i = 0; i < a.length; i++) a[i].invalidateNode();
        valid = false;
    }
    
    int size() {
        return children.size();
    }
    
    TCFNode[] toArray() {
        return children.values().toArray(new TCFNode[children.size()]);
    }
}

Back to the top