~ubuntu-branches/ubuntu/trusty/cobertura/trusty

« back to all changes in this revision

Viewing changes to src/net/sourceforge/cobertura/coveragedata/ClassData.java

  • Committer: Bazaar Package Importer
  • Author(s): Miguel Landaeta
  • Date: 2010-05-11 19:21:46 UTC
  • mfrom: (0.1.4 sid) (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100511192146-j742v5jsl89ztndu
Tags: 1.9.4.1+dfsg-2
* Now Build-Depends on libservlet2.5-java and add a missing Depends
  on the same package. (Closes: #580842). 
* Simplify list of JRE dependences for cobertura and drop JRE dependences for
  libcobertura-java as Java libraries are no longer required to depend on a
  JVM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
 */
50
50
 
51
51
public class ClassData extends CoverageDataContainer
52
 
        implements Comparable, HasBeenInstrumented 
 
52
        implements Comparable<ClassData>, HasBeenInstrumented 
53
53
{
54
54
 
55
55
        private static final long serialVersionUID = 5;
58
58
         * Each key is a line number in this class, stored as an Integer object.
59
59
         * Each value is information about the line, stored as a LineData object.
60
60
         */
61
 
        private Map branches = new HashMap();
 
61
        private Map<Integer,LineData> branches = new HashMap<Integer,LineData>();
62
62
 
63
63
        private boolean containsInstrumentationInfo = false;
64
64
 
65
 
        private Set methodNamesAndDescriptors = new HashSet();
 
65
        private Set<String> methodNamesAndDescriptors = new HashSet<String>();
66
66
 
67
67
        private String name = null;
68
68
 
82
82
        public LineData addLine(int lineNumber, String methodName,
83
83
                        String methodDescriptor)
84
84
        {
85
 
                LineData lineData = getLineData(lineNumber);
86
 
                if (lineData == null)
87
 
                {
88
 
                        lineData = new LineData(lineNumber);
89
 
                        // Each key is a line number in this class, stored as an Integer object.
90
 
                        // Each value is information about the line, stored as a LineData object.
91
 
                        children.put(new Integer(lineNumber), lineData);
92
 
                }
93
 
                lineData.setMethodNameAndDescriptor(methodName, methodDescriptor);
94
 
      
95
 
                // methodName and methodDescriptor can be null when cobertura.ser with 
96
 
                // no line information was loaded (or was not loaded at all).
97
 
                if( methodName!=null && methodDescriptor!=null)
98
 
                        methodNamesAndDescriptors.add(methodName + methodDescriptor);
99
 
                return lineData;
 
85
                lock.lock();
 
86
                try
 
87
                {
 
88
                        LineData lineData = getLineData(lineNumber);
 
89
                        if (lineData == null)
 
90
                        {
 
91
                                lineData = new LineData(lineNumber);
 
92
                                // Each key is a line number in this class, stored as an Integer object.
 
93
                                // Each value is information about the line, stored as a LineData object.
 
94
                                children.put(new Integer(lineNumber), lineData);
 
95
                        }
 
96
                        lineData.setMethodNameAndDescriptor(methodName, methodDescriptor);
 
97
              
 
98
                        // methodName and methodDescriptor can be null when cobertura.ser with 
 
99
                        // no line information was loaded (or was not loaded at all).
 
100
                        if( methodName!=null && methodDescriptor!=null)
 
101
                                methodNamesAndDescriptors.add(methodName + methodDescriptor);
 
102
                        return lineData;
 
103
                }
 
104
                finally
 
105
                {
 
106
                        lock.unlock();
 
107
                }
100
108
        }
101
109
 
102
110
        /**
103
111
         * This is required because we implement Comparable.
104
112
         */
105
 
        public int compareTo(Object o)
 
113
        public int compareTo(ClassData o)
106
114
        {
107
 
                if (!o.getClass().equals(ClassData.class))
108
 
                        return Integer.MAX_VALUE;
109
 
                return this.name.compareTo(((ClassData)o).name);
 
115
                return this.name.compareTo(o.name);
110
116
        }
111
117
 
112
118
        public boolean containsInstrumentationInfo()
113
119
        {
114
 
                return this.containsInstrumentationInfo;
 
120
                lock.lock();
 
121
                try
 
122
                {
 
123
                        return this.containsInstrumentationInfo;
 
124
                }
 
125
                finally
 
126
                {
 
127
                        lock.unlock();
 
128
                }
115
129
        }
116
130
 
117
131
        /**
127
141
                        return false;
128
142
 
129
143
                ClassData classData = (ClassData)obj;
130
 
                return super.equals(obj)
131
 
                        && this.branches.equals(classData.branches)
132
 
                        && this.methodNamesAndDescriptors
133
 
                                .equals(classData.methodNamesAndDescriptors)
134
 
                        && this.name.equals(classData.name)
135
 
                        && this.sourceFileName.equals(classData.sourceFileName);
 
144
                getBothLocks(classData);
 
145
                try
 
146
                {
 
147
                        return super.equals(obj)
 
148
                                && this.branches.equals(classData.branches)
 
149
                                && this.methodNamesAndDescriptors
 
150
                                        .equals(classData.methodNamesAndDescriptors)
 
151
                                && this.name.equals(classData.name)
 
152
                                && this.sourceFileName.equals(classData.sourceFileName);
 
153
                }
 
154
                finally
 
155
                {
 
156
                        lock.unlock();
 
157
                        classData.lock.unlock();
 
158
                }
136
159
        }
137
160
 
138
161
        public String getBaseName()
153
176
                int total = 0;
154
177
                int covered = 0;
155
178
 
156
 
                for (Iterator iter = branches.values().iterator(); iter.hasNext();) {
157
 
                        LineData next = (LineData) iter.next();
158
 
                        if (methodNameAndDescriptor.equals(next.getMethodName() + next.getMethodDescriptor()))
159
 
                        {
160
 
                                total += next.getNumberOfValidBranches();
161
 
                                covered += next.getNumberOfCoveredBranches();
 
179
                lock.lock();
 
180
                try
 
181
                {
 
182
                        for (Iterator<LineData> iter = branches.values().iterator(); iter.hasNext();) {
 
183
                                LineData next = (LineData) iter.next();
 
184
                                if (methodNameAndDescriptor.equals(next.getMethodName() + next.getMethodDescriptor()))
 
185
                                {
 
186
                                        total += next.getNumberOfValidBranches();
 
187
                                        covered += next.getNumberOfCoveredBranches();
 
188
                                }
162
189
                        }
163
 
                }
164
 
                if (total == 0) return 1.0;
165
 
                return (double) covered / total;
 
190
                        if (total == 0) return 1.0;
 
191
                        return (double) covered / total;
 
192
                }
 
193
                finally
 
194
                {
 
195
                        lock.unlock();
 
196
                }
166
197
        }
167
198
 
168
 
        public Collection getBranches() 
 
199
        public Collection<Integer> getBranches() 
169
200
        {
170
 
                return Collections.unmodifiableCollection(branches.keySet());
 
201
                lock.lock();
 
202
                try
 
203
                {
 
204
                        return Collections.unmodifiableCollection(branches.keySet());
 
205
                }
 
206
                finally
 
207
                {
 
208
                        lock.unlock();
 
209
                }
171
210
        }
172
211
 
173
212
        /**
177
216
        public LineData getLineCoverage(int lineNumber) 
178
217
        {
179
218
                Integer lineObject = new Integer(lineNumber);
180
 
                if (!children.containsKey(lineObject)) 
181
 
                {
182
 
                        return null;
183
 
                }
184
 
 
185
 
                return (LineData) children.get(lineObject);
 
219
                lock.lock();
 
220
                try
 
221
                {
 
222
                        if (!children.containsKey(lineObject)) 
 
223
                        {
 
224
                                return null;
 
225
                        }
 
226
        
 
227
                        return (LineData) children.get(lineObject);
 
228
                }
 
229
                finally
 
230
                {
 
231
                        lock.unlock();
 
232
                }
186
233
        }
187
234
 
188
235
        /**
193
240
                int total = 0;
194
241
                int hits = 0;
195
242
 
196
 
                Iterator iter = children.values().iterator();
197
 
                while (iter.hasNext()) 
 
243
                lock.lock();
 
244
                try
198
245
                {
199
 
                        LineData next = (LineData) iter.next();
200
 
                        if (methodNameAndDescriptor.equals(next.getMethodName() + next.getMethodDescriptor())) 
 
246
                        Iterator<CoverageData> iter = children.values().iterator();
 
247
                        while (iter.hasNext()) 
201
248
                        {
202
 
                                total++;
203
 
                                if (next.getHits() > 0) {
204
 
                                        hits++;
 
249
                                LineData next = (LineData) iter.next();
 
250
                                if (methodNameAndDescriptor.equals(next.getMethodName() + next.getMethodDescriptor())) 
 
251
                                {
 
252
                                        total++;
 
253
                                        if (next.getHits() > 0) {
 
254
                                                hits++;
 
255
                                        }
205
256
                                }
206
257
                        }
207
 
                }
208
 
                if (total == 0) return 1d;
209
 
                return (double) hits / total;
 
258
                        if (total == 0) return 1d;
 
259
                        return (double) hits / total;
 
260
                }
 
261
                finally
 
262
                {
 
263
                        lock.unlock();
 
264
                }
210
265
        }
211
266
 
212
267
        private LineData getLineData(int lineNumber)
213
268
        {
214
 
                return (LineData)children.get(new Integer(lineNumber));
215
 
        }
216
 
 
217
 
        public SortedSet getLines()
218
 
        {
219
 
                return new TreeSet(this.children.values());
220
 
        }
221
 
 
222
 
        public Collection getLines(String methodNameAndDescriptor)
223
 
        {
224
 
                Collection lines = new HashSet();
225
 
                Iterator iter = children.values().iterator();
226
 
                while (iter.hasNext())
227
 
                {
228
 
                        LineData next = (LineData)iter.next();
229
 
                        if (methodNameAndDescriptor.equals(next.getMethodName()
230
 
                                        + next.getMethodDescriptor()))
 
269
                lock.lock();
 
270
                try
 
271
                {
 
272
                        return (LineData)children.get(Integer.valueOf(lineNumber));
 
273
                }
 
274
                finally
 
275
                {
 
276
                        lock.unlock();
 
277
                }
 
278
        }
 
279
 
 
280
        public SortedSet<CoverageData> getLines()
 
281
        {
 
282
                lock.lock();
 
283
                try
 
284
                {
 
285
                        return new TreeSet<CoverageData>(this.children.values());
 
286
                }
 
287
                finally
 
288
                {
 
289
                        lock.unlock();
 
290
                }
 
291
        }
 
292
 
 
293
        public Collection<CoverageData> getLines(String methodNameAndDescriptor)
 
294
        {
 
295
                Collection<CoverageData> lines = new HashSet<CoverageData>();
 
296
                lock.lock();
 
297
                try
 
298
                {
 
299
                        Iterator<CoverageData> iter = children.values().iterator();
 
300
                        while (iter.hasNext())
231
301
                        {
232
 
                                lines.add(next);
 
302
                                LineData next = (LineData)iter.next();
 
303
                                if (methodNameAndDescriptor.equals(next.getMethodName()
 
304
                                                + next.getMethodDescriptor()))
 
305
                                {
 
306
                                        lines.add(next);
 
307
                                }
233
308
                        }
234
 
                }
235
 
                return lines;
 
309
                        return lines;
 
310
                }
 
311
                finally
 
312
                {
 
313
                        lock.unlock();
 
314
                }
236
315
        }
237
316
 
238
317
        /**
239
318
         * @return The method name and descriptor of each method found in the
240
319
         *         class represented by this instrumentation.
241
320
         */
242
 
        public Set getMethodNamesAndDescriptors() 
 
321
        public Set<String> getMethodNamesAndDescriptors() 
243
322
        {
244
 
                return methodNamesAndDescriptors;
 
323
                lock.lock();
 
324
                try
 
325
                {
 
326
                        return methodNamesAndDescriptors;
 
327
                }
 
328
                finally
 
329
                {
 
330
                        lock.unlock();
 
331
                }
245
332
        }
246
333
 
247
334
        public String getName() 
255
342
        public int getNumberOfValidBranches() 
256
343
        {
257
344
                int number = 0;
258
 
                for (Iterator i = branches.values().iterator(); 
259
 
                        i.hasNext(); 
260
 
                        number += ((LineData) i.next()).getNumberOfValidBranches())
261
 
                        ;
262
 
                return number;
 
345
                lock.lock();
 
346
                try
 
347
                {
 
348
                        for (Iterator<LineData> i = branches.values().iterator(); 
 
349
                                i.hasNext(); 
 
350
                                number += (i.next()).getNumberOfValidBranches())
 
351
                                ;
 
352
                        return number;
 
353
                }
 
354
                finally
 
355
                {
 
356
                        lock.unlock();
 
357
                }
263
358
        }
264
359
 
265
360
        /**
268
363
        public int getNumberOfCoveredBranches() 
269
364
        {
270
365
                int number = 0;
271
 
                for (Iterator i = branches.values().iterator(); 
272
 
                        i.hasNext(); 
273
 
                        number += ((LineData) i.next()).getNumberOfCoveredBranches())
274
 
                        ;
275
 
                return number;
 
366
                lock.lock();
 
367
                try
 
368
                {
 
369
                        for (Iterator<LineData> i = branches.values().iterator(); 
 
370
                                i.hasNext(); 
 
371
                                number += (i.next()).getNumberOfCoveredBranches())
 
372
                                ;
 
373
                        return number;
 
374
                }
 
375
                finally
 
376
                {
 
377
                        lock.unlock();
 
378
                }
276
379
        }
277
380
 
278
381
        public String getPackageName()
297
400
        public String getSourceFileName()
298
401
        {
299
402
                String baseName;
300
 
                if (sourceFileName != null)
301
 
                        baseName = sourceFileName;
302
 
                else
 
403
                lock.lock();
 
404
                try
303
405
                {
304
 
                        baseName = getBaseName();
305
 
                        int firstDollarSign = baseName.indexOf('$');
306
 
                        if (firstDollarSign == -1 || firstDollarSign == 0)
307
 
                                baseName += ".java";
 
406
                        if (sourceFileName != null)
 
407
                                baseName = sourceFileName;
308
408
                        else
309
 
                                baseName = baseName.substring(0, firstDollarSign)
310
 
                                        + ".java";
311
 
                }
312
 
 
313
 
                String packageName = getPackageName();
314
 
                if (packageName.equals(""))
315
 
                        return baseName;
316
 
                return packageName.replace('.', '/') + '/' + baseName;
 
409
                        {
 
410
                                baseName = getBaseName();
 
411
                                int firstDollarSign = baseName.indexOf('$');
 
412
                                if (firstDollarSign == -1 || firstDollarSign == 0)
 
413
                                        baseName += ".java";
 
414
                                else
 
415
                                        baseName = baseName.substring(0, firstDollarSign)
 
416
                                                + ".java";
 
417
                        }
 
418
        
 
419
                        String packageName = getPackageName();
 
420
                        if (packageName.equals(""))
 
421
                                return baseName;
 
422
                        return packageName.replace('.', '/') + '/' + baseName;
 
423
                }
 
424
                finally
 
425
                {
 
426
                        lock.unlock();
 
427
                }
317
428
        }
318
429
 
319
430
        public int hashCode()
326
437
         */
327
438
        public boolean hasBranch(int lineNumber) 
328
439
        {
329
 
                return branches.containsKey(new Integer(lineNumber));
 
440
                lock.lock();
 
441
                try
 
442
                {
 
443
                        return branches.containsKey(Integer.valueOf(lineNumber));
 
444
                }
 
445
                finally
 
446
                {
 
447
                        lock.unlock();
 
448
                }
330
449
        }
331
450
 
332
451
        /**
337
456
         */
338
457
        public boolean isValidSourceLineNumber(int lineNumber) 
339
458
        {
340
 
                return children.containsKey(new Integer(lineNumber));
 
459
                lock.lock();
 
460
                try
 
461
                {
 
462
                        return children.containsKey(Integer.valueOf(lineNumber));
 
463
                }
 
464
                finally
 
465
                {
 
466
                        lock.unlock();
 
467
                }
341
468
        }
342
469
 
343
470
        public void addLineJump(int lineNumber, int branchNumber) 
344
471
        {
345
 
                LineData lineData = getLineData(lineNumber);
346
 
                if (lineData != null) 
347
 
                {
348
 
                        lineData.addJump(branchNumber);
349
 
                        this.branches.put(new Integer(lineNumber), lineData);
 
472
                lock.lock();
 
473
                try
 
474
                {
 
475
                        LineData lineData = getLineData(lineNumber);
 
476
                        if (lineData != null) 
 
477
                        {
 
478
                                lineData.addJump(branchNumber);
 
479
                                this.branches.put(Integer.valueOf(lineNumber), lineData);
 
480
                        }
 
481
                }
 
482
                finally
 
483
                {
 
484
                        lock.unlock();
350
485
                }
351
486
        }
352
487
 
353
488
        public void addLineSwitch(int lineNumber, int switchNumber, int[] keys) 
354
489
        {
355
 
                LineData lineData = getLineData(lineNumber);
356
 
                if (lineData != null) 
357
 
                {
358
 
                        lineData.addSwitch(switchNumber, keys);
359
 
                        this.branches.put(new Integer(lineNumber), lineData);
 
490
                lock.lock();
 
491
                try
 
492
                {
 
493
                        LineData lineData = getLineData(lineNumber);
 
494
                        if (lineData != null) 
 
495
                        {
 
496
                                lineData.addSwitch(switchNumber, keys);
 
497
                                this.branches.put(Integer.valueOf(lineNumber), lineData);
 
498
                        }
 
499
                }
 
500
                finally
 
501
                {
 
502
                        lock.unlock();
360
503
                }
361
504
        }
362
505
 
363
506
        public void addLineSwitch(int lineNumber, int switchNumber, int min, int max) 
364
507
        {
365
 
                LineData lineData = getLineData(lineNumber);
366
 
                if (lineData != null) 
367
 
                {
368
 
                        lineData.addSwitch(switchNumber, min, max);
369
 
                        this.branches.put(new Integer(lineNumber), lineData);
 
508
                lock.lock();
 
509
                try
 
510
                {
 
511
                        LineData lineData = getLineData(lineNumber);
 
512
                        if (lineData != null) 
 
513
                        {
 
514
                                lineData.addSwitch(switchNumber, min, max);
 
515
                                this.branches.put(Integer.valueOf(lineNumber), lineData);
 
516
                        }
 
517
                }
 
518
                finally
 
519
                {
 
520
                        lock.unlock();
370
521
                }
371
522
        }
372
523
 
383
534
                if (!this.getName().equals(classData.getName()))
384
535
                        return;
385
536
 
386
 
                super.merge(coverageData);
387
 
 
388
 
                // We can't just call this.branches.putAll(classData.branches);
389
 
                // Why not?  If we did a putAll, then the LineData objects from
390
 
                // the coverageData class would overwrite the LineData objects
391
 
                // that are already in "this.branches"  And we don't need to
392
 
                // update the LineData objects that are already in this.branches
393
 
                // because they are shared between this.branches and this.children,
394
 
                // so the object hit counts will be moved when we called
395
 
                // super.merge() above.
396
 
                for (Iterator iter = classData.branches.keySet().iterator(); iter.hasNext();)
 
537
                getBothLocks(classData);
 
538
                try
397
539
                {
398
 
                        Object key = iter.next();
399
 
                        if (!this.branches.containsKey(key))
 
540
                        super.merge(coverageData);
 
541
        
 
542
                        // We can't just call this.branches.putAll(classData.branches);
 
543
                        // Why not?  If we did a putAll, then the LineData objects from
 
544
                        // the coverageData class would overwrite the LineData objects
 
545
                        // that are already in "this.branches"  And we don't need to
 
546
                        // update the LineData objects that are already in this.branches
 
547
                        // because they are shared between this.branches and this.children,
 
548
                        // so the object hit counts will be moved when we called
 
549
                        // super.merge() above.
 
550
                        for (Iterator<Integer> iter = classData.branches.keySet().iterator(); iter.hasNext();)
400
551
                        {
401
 
                                this.branches.put(key, classData.branches.get(key));
 
552
                                Integer key = iter.next();
 
553
                                if (!this.branches.containsKey(key))
 
554
                                {
 
555
                                        this.branches.put(key, classData.branches.get(key));
 
556
                                }
402
557
                        }
403
 
                }
404
 
 
405
 
                this.containsInstrumentationInfo |= classData.containsInstrumentationInfo;
406
 
                this.methodNamesAndDescriptors.addAll(classData
407
 
                                .getMethodNamesAndDescriptors());
408
 
                if (classData.sourceFileName != null)
409
 
                        this.sourceFileName = classData.sourceFileName;
410
 
                }
 
558
        
 
559
                        this.containsInstrumentationInfo |= classData.containsInstrumentationInfo;
 
560
                        this.methodNamesAndDescriptors.addAll(classData
 
561
                                        .getMethodNamesAndDescriptors());
 
562
                        if (classData.sourceFileName != null)
 
563
                                this.sourceFileName = classData.sourceFileName;
 
564
                }
 
565
                finally
 
566
                {
 
567
                        lock.unlock();
 
568
                        classData.lock.unlock();
 
569
                }
 
570
        }
411
571
 
412
572
        public void removeLine(int lineNumber)
413
573
        {
414
 
                Integer lineObject = new Integer(lineNumber);
415
 
                children.remove(lineObject);
416
 
                branches.remove(lineObject);
 
574
                Integer lineObject = Integer.valueOf(lineNumber);
 
575
                lock.lock();
 
576
                try
 
577
                {
 
578
                        children.remove(lineObject);
 
579
                        branches.remove(lineObject);
 
580
                }
 
581
                finally
 
582
                {
 
583
                        lock.unlock();
 
584
                }
417
585
        }
418
586
 
419
587
        public void setContainsInstrumentationInfo()
420
588
        {
421
 
                this.containsInstrumentationInfo = true;
 
589
                lock.lock();
 
590
                try
 
591
                {
 
592
                        this.containsInstrumentationInfo = true;
 
593
                }
 
594
                finally
 
595
                {
 
596
                        lock.unlock();
 
597
                }
422
598
        }
423
599
 
424
600
        public void setSourceFileName(String sourceFileName)
425
601
        {
426
 
                this.sourceFileName = sourceFileName;
 
602
                lock.lock();
 
603
                try
 
604
                {
 
605
                        this.sourceFileName = sourceFileName;
 
606
                }
 
607
                finally
 
608
                {
 
609
                        lock.unlock();
 
610
                }
427
611
        }
428
612
 
429
613
        /**
430
614
         * Increment the number of hits for a particular line of code.
431
615
         *
432
616
         * @param lineNumber the line of code to increment the number of hits.
 
617
         * @param hits how many times the piece was called
433
618
         */
434
 
        public void touch(int lineNumber)
 
619
        public void touch(int lineNumber,int hits)
435
620
        {
436
 
                LineData lineData = getLineData(lineNumber);
437
 
                if (lineData == null)
438
 
                        lineData = addLine(lineNumber, null, null);
439
 
                lineData.touch();
 
621
                lock.lock();
 
622
                try
 
623
                {
 
624
                        LineData lineData = getLineData(lineNumber);
 
625
                        if (lineData == null)
 
626
                                lineData = addLine(lineNumber, null, null);
 
627
                        lineData.touch(hits);
 
628
                }
 
629
                finally
 
630
                {
 
631
                        lock.unlock();
 
632
                }
440
633
        }
441
634
 
442
635
        /**
445
638
         * @param lineNumber The line of code where the branch is
446
639
         * @param branchNumber  The branch on the line to change the hit counter
447
640
         * @param branch The hit counter (true or false)
 
641
         * @param hits how many times the piece was called
448
642
         */
449
 
        public void touchJump(int lineNumber, int branchNumber, boolean branch) {
450
 
                LineData lineData = getLineData(lineNumber);
451
 
                if (lineData == null)
452
 
                        lineData = addLine(lineNumber, null, null);
453
 
                lineData.touchJump(branchNumber, branch);
 
643
        public void touchJump(int lineNumber, int branchNumber, boolean branch,int hits) {
 
644
                lock.lock();
 
645
                try
 
646
                {
 
647
                        LineData lineData = getLineData(lineNumber);
 
648
                        if (lineData == null)
 
649
                                lineData = addLine(lineNumber, null, null);
 
650
                        lineData.touchJump(branchNumber, branch,hits);
 
651
                }
 
652
                finally
 
653
                {
 
654
                        lock.unlock();
 
655
                }
454
656
        }
455
657
 
456
658
        /**
459
661
         * @param lineNumber The line of code where the branch is
460
662
         * @param switchNumber  The switch on the line to change the hit counter
461
663
         * @param branch The hit counter 
 
664
         * @param hits how many times the piece was called  
462
665
         */
463
 
        public void touchSwitch(int lineNumber, int switchNumber, int branch) {
464
 
                LineData lineData = getLineData(lineNumber);
465
 
                if (lineData == null)
466
 
                        lineData = addLine(lineNumber, null, null);
467
 
                lineData.touchSwitch(switchNumber, branch);
 
666
        public void touchSwitch(int lineNumber, int switchNumber, int branch,int hits) {
 
667
                lock.lock();
 
668
                try
 
669
                {
 
670
                        LineData lineData = getLineData(lineNumber);
 
671
                        if (lineData == null)
 
672
                                lineData = addLine(lineNumber, null, null);
 
673
                        lineData.touchSwitch(switchNumber, branch,hits);
 
674
                }
 
675
                finally
 
676
                {
 
677
                        lock.unlock();
 
678
                }
468
679
        }
469
680
 
470
681
}