1 package org.eclipse.aether;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static java.util.Objects.requireNonNull;
23
24 import java.util.concurrent.ConcurrentHashMap;
25 import java.util.concurrent.ConcurrentMap;
26
27
28
29
30 public final class DefaultSessionData
31 implements SessionData
32 {
33
34 private final ConcurrentMap<Object, Object> data;
35
36 public DefaultSessionData()
37 {
38 data = new ConcurrentHashMap<>();
39 }
40
41 public void set( Object key, Object value )
42 {
43 requireNonNull( key, "key cannot be null" );
44
45 if ( value != null )
46 {
47 data.put( key, value );
48 }
49 else
50 {
51 data.remove( key );
52 }
53 }
54
55 public boolean set( Object key, Object oldValue, Object newValue )
56 {
57 requireNonNull( key, "key cannot be null" );
58
59 if ( newValue != null )
60 {
61 if ( oldValue == null )
62 {
63 return data.putIfAbsent( key, newValue ) == null;
64 }
65 return data.replace( key, oldValue, newValue );
66 }
67 else
68 {
69 if ( oldValue == null )
70 {
71 return !data.containsKey( key );
72 }
73 return data.remove( key, oldValue );
74 }
75 }
76
77 public Object get( Object key )
78 {
79 requireNonNull( key, "key cannot be null" );
80
81 return data.get( key );
82 }
83
84 }