Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PropertiesPropertyCollection |
|
|
1.7142857142857142;1.714 | ||||
PropertiesPropertyCollection$1 |
|
|
1.7142857142857142;1.714 |
1 | /* |
|
2 | * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
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 | * Implementation of {@link PropertyCollection} based on properties. |
|
33 | */ |
|
34 | @NotThreadSafe |
|
35 | public final class PropertiesPropertyCollection implements PropertyCollection |
|
36 | { |
|
37 | // ********************************* Fields ********************************* |
|
38 | ||
39 | // --- constants ------------------------------------------------------------ |
|
40 | ||
41 | // --- members -------------------------------------------------------------- |
|
42 | ||
43 | /** |
|
44 | * The properties to iterate over. |
|
45 | */ |
|
46 | 0 | private final Properties properties = new Properties(); |
47 | ||
48 | // ****************************** Initializer ******************************* |
|
49 | ||
50 | // ****************************** Constructors ****************************** |
|
51 | ||
52 | /** |
|
53 | * Constructor to add properties via a collection. |
|
54 | * |
|
55 | * @param properties the properties to iterate over. |
|
56 | */ |
|
57 | public PropertiesPropertyCollection(final Collection<Properties> properties) |
|
58 | 0 | { |
59 | 0 | Arg.checkNotNull("properties", properties); |
60 | ||
61 | 0 | for (final Properties element : properties) |
62 | { |
|
63 | 0 | this.properties.putAll(element); |
64 | } |
|
65 | 0 | } |
66 | ||
67 | /** |
|
68 | * Constructor to add properties. |
|
69 | * |
|
70 | * @param properties the properties to iterate over. |
|
71 | */ |
|
72 | public PropertiesPropertyCollection(final Properties... properties) |
|
73 | 0 | { |
74 | 0 | Arg.checkNotNull("properties", properties); |
75 | ||
76 | 0 | for (final Properties element : properties) |
77 | { |
|
78 | 0 | this.properties.putAll(element); |
79 | } |
|
80 | 0 | } |
81 | ||
82 | // ****************************** Inner Classes ***************************** |
|
83 | ||
84 | // ********************************* Methods ******************************** |
|
85 | ||
86 | // --- init ----------------------------------------------------------------- |
|
87 | ||
88 | // --- get&set -------------------------------------------------------------- |
|
89 | ||
90 | // --- business ------------------------------------------------------------- |
|
91 | ||
92 | /** |
|
93 | * {@inheritDoc} |
|
94 | * |
|
95 | * @see java.lang.Iterable#iterator() |
|
96 | */ |
|
97 | @Override |
|
98 | public Iterator<Property> iterator() |
|
99 | { |
|
100 | 0 | final Set<Entry<Object, Object>> entrySet = properties.entrySet(); |
101 | 0 | final Iterator<Entry<Object, Object>> i = entrySet.iterator(); |
102 | // CHECKSTYLE:OFF |
|
103 | 0 | return new Iterator<Property>() // NOPMD CHECKSTYLE:ON |
104 | 0 | { |
105 | @Override |
|
106 | public boolean hasNext() |
|
107 | { |
|
108 | 0 | return i.hasNext(); |
109 | } |
|
110 | ||
111 | @Override |
|
112 | public Property next() |
|
113 | { |
|
114 | 0 | final Entry<Object, Object> entry = i.next(); |
115 | 0 | final Object value = entry.getValue(); |
116 | ||
117 | 0 | if (value instanceof Property) |
118 | { |
|
119 | 0 | return (Property) value; |
120 | } |
|
121 | else |
|
122 | { |
|
123 | 0 | return new Property(new PropertyLocation(getClass().getName()), |
124 | (String) entry.getKey(), entry.getValue()); |
|
125 | } |
|
126 | } |
|
127 | ||
128 | @Override |
|
129 | public void remove() |
|
130 | { |
|
131 | 0 | throw new UnsupportedOperationException("Remove not supported."); |
132 | } |
|
133 | }; |
|
134 | } |
|
135 | ||
136 | @Override |
|
137 | public void close() |
|
138 | { |
|
139 | 0 | } |
140 | ||
141 | // --- object basics -------------------------------------------------------- |
|
142 | ||
143 | } |