Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 298905 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/wst/common/project/facet/core/util/internal/CollectionsUtil.java (-2 / +4 lines)
Lines 26-32 Link Here
26
{
26
{
27
    private CollectionsUtil() {}
27
    private CollectionsUtil() {}
28
    
28
    
29
    @SuppressWarnings( "unchecked" )
29
    @SuppressWarnings( "rawtypes" )
30
    
30
    private static final Comparator<Comparable<? super Comparable>> INVERTING_COMPARATOR 
31
    private static final Comparator<Comparable<? super Comparable>> INVERTING_COMPARATOR 
31
        = new Comparator<Comparable<? super Comparable>>()
32
        = new Comparator<Comparable<? super Comparable>>()
32
    {
33
    {
Lines 45-51 Link Here
45
     * @return an inverting comparator
46
     * @return an inverting comparator
46
     */
47
     */
47
    
48
    
48
    @SuppressWarnings( "unchecked" )
49
    @SuppressWarnings( { "unchecked", "rawtypes" } )
50
    
49
    public static <T extends Comparable> Comparator<T> getInvertingComparator()
51
    public static <T extends Comparable> Comparator<T> getInvertingComparator()
50
    {
52
    {
51
        return (Comparator<T>) INVERTING_COMPARATOR;
53
        return (Comparator<T>) INVERTING_COMPARATOR;
(-)src/org/eclipse/wst/common/project/facet/core/util/internal/IndexedSet.java (-27 / +73 lines)
Lines 14-19 Link Here
14
import java.util.Collections;
14
import java.util.Collections;
15
import java.util.HashMap;
15
import java.util.HashMap;
16
import java.util.HashSet;
16
import java.util.HashSet;
17
import java.util.Iterator;
17
import java.util.Map;
18
import java.util.Map;
18
import java.util.Set;
19
import java.util.Set;
19
20
Lines 22-77 Link Here
22
 */
23
 */
23
24
24
public final class IndexedSet<K,V>
25
public final class IndexedSet<K,V>
25
26
    extends HashSet<V>
27
    
28
{
26
{
29
    private static final long serialVersionUID = 1L;
27
    private final Set<V> set;
30
    private final Set<V> unmodifiable;
28
    private final Set<V> unmodifiable;
31
    private final Map<K,V> index;
29
    private final Map<K,V> index;
32
    
30
    
33
    public IndexedSet()
31
    public IndexedSet()
34
    {
32
    {
35
        this.unmodifiable = Collections.unmodifiableSet( this );
33
        this.set = new HashSet<V>();
34
        this.unmodifiable = Collections.unmodifiableSet( this.set );
36
        this.index = new HashMap<K,V>();
35
        this.index = new HashMap<K,V>();
37
    }
36
    }
38
    
37
    
39
    public void add( final K key,
38
    public Set<V> getItemSet()
40
                     final V value )
41
    {
39
    {
42
        remove( this.index.get( key ) );
40
        return this.unmodifiable;
43
        add( value );
41
    }
44
        this.index.put( key, value );
42
43
    public V getItemByKey( final K key )
44
    {
45
        return this.index.get( key );
45
    }
46
    }
46
    
47
    
47
    public boolean delete( final K key )
48
    public boolean containsKey( final K key )
48
    {
49
    {
49
        final Object value = this.index.get( key );
50
        return this.index.containsKey( key );
50
        
51
    }
51
        if( value == null )
52
52
        {
53
    public boolean containsItem( final V item )
53
            return false;
54
    {
54
        }
55
        return this.set.contains( item );
55
        else
56
    }
57
58
    public void addItem( final V item )
59
    {
60
        if( item == null )
56
        {
61
        {
57
            remove( value );
62
            throw new IllegalArgumentException();
58
            this.index.remove( key );
59
            return true;
60
        }
63
        }
64
        
65
        this.set.add( item );
61
    }
66
    }
62
    
67
    
63
    public V get( final K key )
68
    public void addItemWithKey( final K key,
69
                                final V item )
64
    {
70
    {
65
        return this.index.get( key );
71
        addItem( item );
72
        addKey( key, item );
66
    }
73
    }
67
    
74
    
68
    public boolean containsKey( final K key )
75
    public void addKey( final K key,
76
                        final V item )
69
    {
77
    {
70
        return this.index.containsKey( key );
78
        if( key == null || item == null )
79
        {
80
            throw new IllegalArgumentException();
81
        }
82
        
83
        if( ! this.set.contains( item ) )
84
        {
85
            throw new IllegalArgumentException();
86
        }
87
        
88
        this.index.put( key, item );
71
    }
89
    }
72
    
90
    
73
    public Set<V> getUnmodifiable()
91
    public boolean removeItem( final V item )
74
    {
92
    {
75
        return this.unmodifiable;
93
        if( this.set.remove( item ) )
94
        {
95
            for( Iterator<Map.Entry<K,V>> itr = this.index.entrySet().iterator(); itr.hasNext(); )
96
            {
97
                final Map.Entry<K,V> entry = itr.next();
98
                
99
                if( entry.getValue() == item )
100
                {
101
                    itr.remove();
102
                }
103
            }
104
        
105
            return true;
106
        }
107
        
108
        return false;
109
    }
110
111
    public boolean removeItemByKey( final K key )
112
    {
113
        final V item = this.index.get( key );
114
        
115
        if( item != null )
116
        {
117
            return removeItem( item );
118
        }
119
        
120
        return false;
76
    }
121
    }
122
    
77
}
123
}
(-)src/org/eclipse/wst/common/project/facet/core/util/internal/PluginUtil.java (-2 / +3 lines)
Lines 184-195 Link Here
184
    }
184
    }
185
185
186
    @SuppressWarnings( "unchecked" )
186
    @SuppressWarnings( "unchecked" )
187
    
187
    public static <T> Class<T> loadClass( final String pluginId,
188
    public static <T> Class<T> loadClass( final String pluginId,
188
                                          final String clname,
189
                                          final String clname,
189
                                          final Class<T> interfc )
190
                                          final Class<T> interfc )
190
    {
191
    {
191
        final Bundle bundle = Platform.getBundle( pluginId );
192
        final Bundle bundle = Platform.getBundle( pluginId );
192
        final Class cl;
193
        final Class<?> cl;
193
194
194
        try
195
        try
195
        {
196
        {
Lines 216-222 Link Here
216
            return null;
217
            return null;
217
        }
218
        }
218
219
219
        return cl;
220
        return (Class<T>) cl;
220
    }
221
    }
221
222
222
    public static <T> T instantiate( final String pluginId,
223
    public static <T> T instantiate( final String pluginId,
(-)src/org/eclipse/wst/common/project/facet/core/util/internal/Versionable.java (-10 / +8 lines)
Lines 49-55 Link Here
49
    
49
    
50
    public Set<T> getVersions()
50
    public Set<T> getVersions()
51
    {
51
    {
52
        return this.versions.getUnmodifiable();
52
        return this.versions.getItemSet();
53
    }
53
    }
54
    
54
    
55
    public Set<T> getVersions( final String expr )
55
    public Set<T> getVersions( final String expr )
Lines 60-66 Link Here
60
        final VersionExpr<T> prepared = new VersionExpr<T>( this, expr, null );
60
        final VersionExpr<T> prepared = new VersionExpr<T>( this, expr, null );
61
        final Set<T> result = new HashSet<T>();
61
        final Set<T> result = new HashSet<T>();
62
         
62
         
63
        for( T ver : this.versions )
63
        for( T ver : this.versions.getItemSet() )
64
        {
64
        {
65
            if( prepared.check( ver ) )
65
            if( prepared.check( ver ) )
66
            {
66
            {
Lines 73-79 Link Here
73
    
73
    
74
    public T getVersion( final String version )
74
    public T getVersion( final String version )
75
    {
75
    {
76
        final T ver = this.versions.get( version );
76
        final T ver = this.versions.getItemByKey( version );
77
        
77
        
78
        if( ver == null )
78
        if( ver == null )
79
        {
79
        {
Lines 87-96 Link Here
87
    
87
    
88
    public T getLatestVersion()
88
    public T getLatestVersion()
89
    {
89
    {
90
        if( this.versions.size() > 0 )
90
        if( this.versions.getItemSet().size() > 0 )
91
        {
91
        {
92
        	// [263113] Versionable no longer compiles as of I20090125-2000
92
            return (T) Collections.max( this.versions.getItemSet() );
93
            return (T) Collections.max( this.versions );
94
        }
93
        }
95
        else
94
        else
96
        {
95
        {
Lines 124-136 Link Here
124
            };
123
            };
125
        }
124
        }
126
125
127
        final List<T> list = new ArrayList<T>( this.versions );
126
        final List<T> list = new ArrayList<T>( this.versions.getItemSet() );
128
        Collections.sort( list, comp );
127
        Collections.sort( list, comp );
129
        
128
        
130
        return list;
129
        return list;
131
    }
130
    }
132
    
131
    
133
    @SuppressWarnings( "unchecked" )
132
    @SuppressWarnings( "unchecked" )
133
    
134
    public Comparator<String> getVersionComparator()
134
    public Comparator<String> getVersionComparator()
135
    
135
    
136
        throws CoreException
136
        throws CoreException
Lines 150-158 Link Here
150
                
150
                
151
                try
151
                try
152
                {
152
                {
153
                    final Class cl 
153
                    final Class<?> cl = bundle.loadClass( this.versionComparatorClass );
154
                        = bundle.loadClass( this.versionComparatorClass );
155
                    
156
                    this.versionComparator = (Comparator<String>) cl.newInstance();
154
                    this.versionComparator = (Comparator<String>) cl.newInstance();
157
                }
155
                }
158
                catch( Exception e )
156
                catch( Exception e )

Return to bug 298905