1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.spi.config.support;
17
18 import java.util.Collection;
19 import java.util.Iterator;
20 import java.util.Map.Entry;
21 import java.util.Properties;
22 import java.util.Set;
23
24 import javax.annotation.concurrent.NotThreadSafe;
25
26 import de.smartics.properties.api.config.domain.Property;
27 import de.smartics.properties.api.config.domain.PropertyCollection;
28 import de.smartics.properties.api.config.domain.PropertyLocation;
29 import de.smartics.util.lang.Arg;
30
31
32
33
34 @NotThreadSafe
35 public final class PropertiesPropertyCollection implements PropertyCollection
36 {
37
38
39
40
41
42
43
44
45
46 private final Properties properties = new Properties();
47
48
49
50
51
52
53
54
55
56
57 public PropertiesPropertyCollection(final Collection<Properties> properties)
58 {
59 Arg.checkNotNull("properties", properties);
60
61 for (final Properties element : properties)
62 {
63 this.properties.putAll(element);
64 }
65 }
66
67
68
69
70
71
72 public PropertiesPropertyCollection(final Properties... properties)
73 {
74 Arg.checkNotNull("properties", properties);
75
76 for (final Properties element : properties)
77 {
78 this.properties.putAll(element);
79 }
80 }
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97 @Override
98 public Iterator<Property> iterator()
99 {
100 final Set<Entry<Object, Object>> entrySet = properties.entrySet();
101 final Iterator<Entry<Object, Object>> i = entrySet.iterator();
102
103 return new Iterator<Property>()
104 {
105 @Override
106 public boolean hasNext()
107 {
108 return i.hasNext();
109 }
110
111 @Override
112 public Property next()
113 {
114 final Entry<Object, Object> entry = i.next();
115 final Object value = entry.getValue();
116
117 if (value instanceof Property)
118 {
119 return (Property) value;
120 }
121 else
122 {
123 return new Property(new PropertyLocation(getClass().getName()),
124 (String) entry.getKey(), entry.getValue());
125 }
126 }
127
128 @Override
129 public void remove()
130 {
131 throw new UnsupportedOperationException("Remove not supported.");
132 }
133 };
134 }
135
136 @Override
137 public void close()
138 {
139 }
140
141
142
143 }