1 package com.simpligility.maven.plugins.android.phase01generatesources;
2
3 import java.util.Arrays;
4 import java.util.Collection;
5 import java.util.HashMap;
6 import java.util.HashSet;
7 import java.util.Map;
8 import java.util.Set;
9 import java.util.TreeMap;
10
11
12
13
14 final class ConflictingLayoutDetector
15 {
16 private Map<String, Collection<String>> map = new HashMap<String, Collection<String>>();
17
18 public void addLayoutFiles( String packageName, String[] layoutFiles )
19 {
20 map.put( packageName, Arrays.asList( layoutFiles ) );
21 }
22
23 public Collection<ConflictingLayout> getConflictingLayouts()
24 {
25 final Map<String, ConflictingLayout> result = new TreeMap<String, ConflictingLayout>();
26 for ( final String entryA : map.keySet() )
27 {
28 for ( final String entryB : map.keySet() )
29 {
30 if ( entryA.equals( entryB ) )
31 {
32 continue;
33 }
34
35
36 final Set<String> tmp = new HashSet<String>();
37 tmp.addAll( map.get( entryA ) );
38 tmp.retainAll( map.get( entryB ) );
39
40 for ( final String layoutFile : tmp )
41 {
42 if ( !result.containsKey( layoutFile ) )
43 {
44 result.put( layoutFile, new ConflictingLayout( layoutFile ) );
45 }
46 final ConflictingLayout layout = result.get( layoutFile );
47 layout.addPackageName( entryA );
48 layout.addPackageName( entryB );
49 }
50 }
51 }
52
53 return result.values();
54 }
55 }