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 java.util.concurrent.ConcurrentHashMap;
23 import java.util.concurrent.ConcurrentMap;
24
25
26
27
28 public final class DefaultSessionData
29 implements SessionData
30 {
31
32 private final ConcurrentMap<Object, Object> data;
33
34 public DefaultSessionData()
35 {
36 data = new ConcurrentHashMap<Object, Object>();
37 }
38
39 public void set( Object key, Object value )
40 {
41 if ( key == null )
42 {
43 throw new IllegalArgumentException( "key must not be null" );
44 }
45
46 if ( value != null )
47 {
48 data.put( key, value );
49 }
50 else
51 {
52 data.remove( key );
53 }
54 }
55
56 public boolean set( Object key, Object oldValue, Object newValue )
57 {
58 if ( key == null )
59 {
60 throw new IllegalArgumentException( "key must not be null" );
61 }
62
63 if ( newValue != null )
64 {
65 if ( oldValue == null )
66 {
67 return data.putIfAbsent( key, newValue ) == null;
68 }
69 return data.replace( key, oldValue, newValue );
70 }
71 else
72 {
73 if ( oldValue == null )
74 {
75 return !data.containsKey( key );
76 }
77 return data.remove( key, oldValue );
78 }
79 }
80
81 public Object get( Object key )
82 {
83 if ( key == null )
84 {
85 throw new IllegalArgumentException( "key must not be null" );
86 }
87
88 return data.get( key );
89 }
90
91 }