Normand Briere
2019-12-25 3d30e720e6f012f2d9996b136154dd551844998a
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
/**
 *
 * @author nbriere
 */
public class GroupLeaf extends Composite
{
    static final long serialVersionUID =  // for wader: -6036608125951558970L;
                                -1647706059469889079L;
    
    GroupLeaf()
    {
        this("Loop");
    }
 
    GroupLeaf(String name)
    {
        super(name);
        
        addChild(new cGroup(name + "Leaf"));
    }
 
    Object3D deepCopy()
    {
        Composite comp = new GroupLeaf();
        deepCopySelf(comp);
        return comp;
    }
 
    public int Size()
    {
        return size();
    }
    
    public int size()
    {
        ////GraphreeD.trace("SIZE " + count + this + " = ", super.size() - 1);
        
        if (count == 1) // 2)
            return 1; // 2;
        
        if (true)
            return super.size() - 1; // ???
        
        //System.err.println("COUNT = " + count);
        //assert (count >= 0);
        if (count <= 1)
        {
        //System.err.println("SIZE = " + 1);
            return 1; // Math.min(Size(),1);
        } else
        {
        //System.err.println("SIZE = " + (Size() - 1));
            return Size() - 1;
        }
    }
 
    public Object3D get(int i)
    {
        //GraphreeD.trace("GET " + this + " = ", i);
        
        if (count <= 1)
        {
            //assert (i==0);
            if (i != 0)
            {
                new Exception().printStackTrace();
                //return null;
            }
            
            return super.get(0);
        }
        else
        {
            if (i+1 >= Size()+1)
                return new Object3D("BUG");
            
            return super.get(i+1);
        }
    }
    
    public Object3D reserve(int i)
    {
        Object3D child;
        
        //GraphreeD.tracein("RESERVE2 " + this + " = ", i);
        
        if (count <= 1)
        {
            if (super.size() == 0)
                assert (i==0);
            
            child = super.get(0);
            //Applet3D.tracein("RESERVE ", child);
 
            child.count--;
            //assert (child.count >= 0);
 
        }
        else
        {
            if (i+1 >= Size()+1)
                return new Object3D("BUG");
            
            child = super.get(i+1);
            //Applet3D.tracein("RESERVE ", child);
 
            child.count--;
            //assert (child.count >= 0);
        }
        
        //Applet3D.trace("CHILD = ", child);
        return child;
    }
 
    public void release(int i)
    {
        //GraphreeD.traceout("RELEASE " + this + " = ", i);
        
        if (count <= 1)
        {
//            assert (i==0);
            
        //Applet3D.traceout("RELEASE " + this + " = ", i);
        //Applet3D.trace("CHILD = ", super.get(0));
            super.get(0).count++;
        }
        else
        {
        //Applet3D.traceout("RELEASE " + this + " = ", i);
        //Applet3D.trace("CHILD = ", super.get(i+1));
            super.get(i+1).count++;
        }
    }
}