1 package org.apache.maven.internal.impl;
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.AbstractSet;
24 import java.util.Iterator;
25 import java.util.Map;
26 import java.util.NoSuchElementException;
27 import java.util.Set;
28
29 class PropertiesAsMap extends AbstractMap<String, String>
30 {
31
32 private final Map<Object, Object> properties;
33
34 PropertiesAsMap( Map<Object, Object> properties )
35 {
36 this.properties = properties;
37 }
38
39 @Override
40 public Set<Entry<String, String>> entrySet()
41 {
42 return new AbstractSet<Entry<String, String>>()
43 {
44 @Override
45 public Iterator<Entry<String, String>> iterator()
46 {
47 Iterator<Entry<Object, Object>> iterator = properties.entrySet().iterator();
48 return new Iterator<Entry<String, String>>()
49 {
50 Entry<Object, Object> next;
51
52 @Override
53 public boolean hasNext()
54 {
55 while ( next == null && iterator.hasNext() )
56 {
57 Entry<Object, Object> e = iterator.next();
58 if ( PropertiesAsMap.matches( e ) )
59 {
60 next = e;
61 break;
62 }
63 }
64 return next != null;
65 }
66
67 @Override
68 public Entry<String, String> next()
69 {
70 if ( next == null )
71 {
72 throw new NoSuchElementException();
73 }
74 return new Entry<String, String>()
75 {
76 @Override
77 public String getKey()
78 {
79 return (String) next.getKey();
80 }
81
82 @Override
83 public String getValue()
84 {
85 return (String) next.getValue();
86 }
87
88 @Override
89 public String setValue( String value )
90 {
91 return (String) next.setValue( value );
92 }
93 };
94 }
95 };
96 }
97
98 @Override
99 public int size()
100 {
101 return (int) properties.entrySet()
102 .stream().filter( PropertiesAsMap::matches )
103 .count();
104 }
105 };
106 }
107
108 private static boolean matches( Entry<Object, Object> entry )
109 {
110 return entry.getKey() instanceof String
111 && entry.getValue() instanceof String;
112 }
113 }