1 package org.apache.maven.shared.filtering;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.AbstractMap;
23 import java.util.ArrayList;
24 import java.util.Iterator;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Set;
28
29
30
31
32
33
34
35
36 public class CompositeMap
37 extends AbstractMap
38 {
39
40 private List
41
42 private boolean systemPropertiesFirst;
43
44
45
46
47
48 public CompositeMap( List
49 {
50 this( maps, false, false );
51 }
52
53
54
55
56
57
58
59 public CompositeMap( List
60 {
61 this.systemPropertiesFirst = systemPropertiesFirst;
62 if ( systemPropertiesFirst && !useSystemProperties )
63 {
64 throw new IllegalArgumentException( "systemPropertiesFirst can't be true if useSystemProperties is false" );
65 }
66 this.maps = new ArrayList();
67 if ( useSystemProperties && !systemPropertiesFirst )
68 {
69 if ( maps != null )
70 {
71 this.maps.addAll( maps );
72 }
73 this.maps.add( System.getProperties() );
74 }
75 else if ( useSystemProperties && systemPropertiesFirst )
76 {
77 this.maps.add( System.getProperties() );
78 if ( maps != null )
79 {
80 this.maps.addAll( maps );
81 }
82 }
83 else
84 {
85 if ( maps != null )
86 {
87 this.maps.addAll( maps );
88 }
89 }
90 }
91
92 public Object get( Object key )
93 {
94 if ( this.maps != null )
95 {
96 for ( Iterator iterator = this.maps.iterator(); iterator.hasNext(); )
97 {
98 Map map = (Map) iterator.next();
99 Object value = map.get( key );
100 if ( value != null )
101 {
102 return value;
103 }
104 }
105 }
106 return null;
107 }
108
109
110
111
112 public Set entrySet()
113 {
114 throw new UnsupportedOperationException( "Cannot enumerate properties in a composite map" );
115 }
116
117 public List getMaps()
118 {
119 return maps;
120 }
121
122 public void addMap( Map map )
123 {
124
125 this.maps.add( map );
126 }
127
128 public boolean isSystemPropertiesFirst()
129 {
130 return systemPropertiesFirst;
131 }
132
133 public void setSystemPropertiesFirst( boolean systemPropertiesFirst )
134 {
135 this.systemPropertiesFirst = systemPropertiesFirst;
136 }
137
138 }