1 package org.apache.maven.surefire.report;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.surefire.api.util.internal.ClassMethod;
23
24 import java.util.Map;
25 import java.util.concurrent.ConcurrentHashMap;
26 import java.util.concurrent.atomic.AtomicInteger;
27
28 import static java.util.Objects.requireNonNull;
29
30
31
32
33
34 public final class ClassMethodIndexer
35 {
36 private final AtomicInteger classIndex = new AtomicInteger( 1 );
37 private final AtomicInteger methodIndex = new AtomicInteger( 1 );
38 private final Map<ClassMethod, Long> testIdMapping = new ConcurrentHashMap<>();
39 private final ThreadLocal<Long> testLocalMapping = new ThreadLocal<>();
40
41 public long indexClassMethod( String clazz, String method )
42 {
43 ClassMethod key = new ClassMethod( requireNonNull( clazz ), method );
44 return testIdMapping.computeIfAbsent( key, cm ->
45 {
46 Long classId = testIdMapping.get( new ClassMethod( requireNonNull( clazz ), null ) );
47 long c = classId == null ? ( ( (long) classIndex.getAndIncrement() ) << 32 ) : classId;
48 int m = method == null ? 0 : methodIndex.getAndIncrement();
49 long id = c | m;
50 testLocalMapping.set( id );
51 return id;
52 } );
53 }
54
55 public long indexClass( String clazz )
56 {
57 return indexClassMethod( clazz, null );
58 }
59
60 public Long getLocalIndex()
61 {
62 return testLocalMapping.get();
63 }
64 }