View | Details | Raw Unified | Return to bug 318765
Collapse All | Expand All

(-)src/org/eclipse/fproj/IProjectFacet.java (-18 / +30 lines)
Lines 12-18 Link Here
12
package org.eclipse.fproj;
12
package org.eclipse.fproj;
13
13
14
import java.util.Comparator;
14
import java.util.Comparator;
15
import java.util.List;
16
import java.util.Map;
15
import java.util.Map;
17
import java.util.Set;
16
import java.util.Set;
18
17
Lines 95-108 Link Here
95
    ICategory getCategory();
94
    ICategory getCategory();
96
    
95
    
97
    /**
96
    /**
98
     * Returns the descriptors of all versions of this project facet.
97
     * Returns all versions of this project facet. The returned Set will have unspecified
98
     * traversal order (not sorted).
99
     * 
99
     * 
100
     * @return the descriptors of all versions of this project facet
100
     * @return all versions of this project facet
101
     */
101
     */
102
    
102
    
103
    Set<IProjectFacetVersion> getVersions();
103
    Set<IProjectFacetVersion> getVersions();
104
    
104
    
105
    Set<IProjectFacetVersion> getVersions( String expr )
105
    /**
106
     * Returns the versions of this project facet that match the specified filter. The
107
     * returned Set will have unspecified traversal order (not sorted).
108
     * 
109
     * @param filter an expression that specifies versions to return or null
110
     *   to return all versions
111
     * @return the versions of this project facet that match the specified filter
112
     */
113
    
114
    Set<IProjectFacetVersion> getVersions( String filter )
115
    
116
        throws CoreException;
117
118
    /**
119
     * Returns the versions of this project facet that match the specified filter. The
120
     * result can be sorted, if desired. If the result is sorted, the returned Set
121
     * can be cast to SortedSet.
122
     * 
123
     * @param filter an expression that specifies versions to return or null
124
     *   to return all versions
125
     * @param sortOrder the preference for how the result should be sorted or null
126
     *   to leave the traverse order of the returned set unspecified
127
     * @return the versions of this project facet that match the specified filter
128
     */
129
    
130
    Set<IProjectFacetVersion> getVersions( String filter,
131
                                           SortOrder sortOrder )
106
    
132
    
107
        throws CoreException;
133
        throws CoreException;
108
    
134
    
Lines 161-180 Link Here
161
    IProjectFacetVersion getDefaultVersion();
187
    IProjectFacetVersion getDefaultVersion();
162
188
163
    /**
189
    /**
164
     * Returns a sorted list containing the descriptors of all versions of this 
165
     * project facet. 
166
     * 
167
     * @param ascending whether version descriptors should be sorted in 
168
     *   ascending order
169
     * @return a sorted list containing the descriptors of all versions of this 
170
     *   project facet
171
     */
172
    
173
    List<IProjectFacetVersion> getSortedVersions( boolean ascending )
174
    
175
        throws VersionFormatException, CoreException;
176
    
177
    /**
178
     * Returns the version comparator specified for this project facet. If no 
190
     * Returns the version comparator specified for this project facet. If no 
179
     * version comparator is specified, this method will return an instance of 
191
     * version comparator is specified, this method will return an instance of 
180
     * the {@link DefaultVersionComparator}.
192
     * the {@link DefaultVersionComparator}.
(-)src/org/eclipse/fproj/SortOrder.java (+41 lines)
Added Link Here
1
/******************************************************************************
2
 * Copyright (c) 2010 Oracle
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Konstantin Komissarchik - initial implementation and ongoing maintenance
10
 ******************************************************************************/
11
12
package org.eclipse.fproj;
13
14
/**
15
 * Used for specifying sorting preference in methods capable of returning sorted
16
 * results.
17
 * 
18
 * @author <a href="mailto:konstantin.komissarchik@oracle.com">Konstantin Komissarchik</a>
19
 */
20
21
public enum SortOrder
22
{
23
    /**
24
     * No sorting preference. The order of returned items is unspecified.
25
     */
26
    
27
    UNSORTED,
28
    
29
    /**
30
     * The returned items should be sorted in ascending order from lowest to highest.
31
     */
32
    
33
    ASCENDING,
34
    
35
    /**
36
     * The returned items should be sorted in descending order from highest to lowest.
37
     */
38
    
39
    DESCENDING
40
    
41
}
(-)src/org/eclipse/fproj/internal/ProjectFacet.java (-3 / +14 lines)
Lines 21-32 Link Here
21
import java.util.Map;
21
import java.util.Map;
22
import java.util.Set;
22
import java.util.Set;
23
23
24
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.Platform;
25
import org.eclipse.core.runtime.Platform;
25
import org.eclipse.fproj.IActionDefinition;
26
import org.eclipse.fproj.IActionDefinition;
26
import org.eclipse.fproj.ICategory;
27
import org.eclipse.fproj.ICategory;
27
import org.eclipse.fproj.IDefaultVersionProvider;
28
import org.eclipse.fproj.IDefaultVersionProvider;
28
import org.eclipse.fproj.IProjectFacet;
29
import org.eclipse.fproj.IProjectFacet;
29
import org.eclipse.fproj.IProjectFacetVersion;
30
import org.eclipse.fproj.IProjectFacetVersion;
31
import org.eclipse.fproj.SortOrder;
30
import org.eclipse.fproj.runtime.IRuntime;
32
import org.eclipse.fproj.runtime.IRuntime;
31
import org.eclipse.fproj.util.internal.Versionable;
33
import org.eclipse.fproj.util.internal.Versionable;
32
import org.eclipse.osgi.util.NLS;
34
import org.eclipse.osgi.util.NLS;
Lines 139-151 Link Here
139
    
141
    
140
    public IProjectFacetVersion getLatestSupportedVersion( final IRuntime r )
142
    public IProjectFacetVersion getLatestSupportedVersion( final IRuntime r )
141
    {
143
    {
142
        for( IProjectFacetVersion fv : getSortedVersions( false ) )
144
        try
143
        {
145
        {
144
            if( r.supports( fv ) )
146
            for( IProjectFacetVersion fv : getVersions( null, SortOrder.DESCENDING ) )
145
            {
147
            {
146
                return fv;
148
                if( r.supports( fv ) )
149
                {
150
                    return fv;
151
                }
147
            }
152
            }
148
        }
153
        }
154
        catch( CoreException e )
155
        {
156
            // Not expected in this context...
157
            
158
            FacetCorePlugin.log( e );
159
        }
149
        
160
        
150
        return null;
161
        return null;
151
    }
162
    }
(-)src/org/eclipse/fproj/runtime/IRuntimeComponentType.java (-17 / +31 lines)
Lines 12-23 Link Here
12
package org.eclipse.fproj.runtime;
12
package org.eclipse.fproj.runtime;
13
13
14
import java.util.Comparator;
14
import java.util.Comparator;
15
import java.util.List;
16
import java.util.Set;
15
import java.util.Set;
17
16
18
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.core.runtime.IAdaptable;
20
import org.eclipse.fproj.DefaultVersionComparator;
19
import org.eclipse.fproj.DefaultVersionComparator;
20
import org.eclipse.fproj.SortOrder;
21
21
22
/**
22
/**
23
 * Represents the type of a runtime component. A runtime instance is composed of  multiple runtime 
23
 * Represents the type of a runtime component. A runtime instance is composed of  multiple runtime 
Lines 58-71 Link Here
58
    String getPluginId();
58
    String getPluginId();
59
    
59
    
60
    /**
60
    /**
61
     * Returns all of the versions of this runtime component type.
61
     * Returns all versions of this runtime component type. The returned Set will have unspecified
62
     * traversal order (not sorted).
62
     * 
63
     * 
63
     * @return all of the versions of this runtime component type
64
     * @return all versions of this runtime component type
64
     */
65
     */
65
    
66
    
66
    Set<IRuntimeComponentVersion> getVersions();
67
    Set<IRuntimeComponentVersion> getVersions();
67
    
68
    
68
    Set<IRuntimeComponentVersion> getVersions( String expr )
69
    /**
70
     * Returns the versions of this runtime component type that match the specified filter. The
71
     * returned Set will have unspecified traversal order (not sorted).
72
     * 
73
     * @param filter an expression that specifies versions to return or null
74
     *   to return all versions
75
     * @return the versions of this runtime component type that match the specified filter
76
     */
77
    
78
    Set<IRuntimeComponentVersion> getVersions( String filter )
79
    
80
        throws CoreException;
81
82
    /**
83
     * Returns the versions of this runtime component type that match the specified filter. The
84
     * result can be sorted, if desired. If the result is sorted, the returned Set
85
     * can be cast to SortedSet.
86
     * 
87
     * @param filter an expression that specifies versions to return or null
88
     *   to return all versions
89
     * @param sortOrder the preference for how the result should be sorted or null
90
     *   to leave the traverse order of the returned set unspecified
91
     * @return the versions of this runtime component type that match the specified filter
92
     */
93
    
94
    Set<IRuntimeComponentVersion> getVersions( String filter,
95
                                               SortOrder sortOrder )
69
    
96
    
70
        throws CoreException;
97
        throws CoreException;
71
    
98
    
Lines 104-122 Link Here
104
        throws CoreException;
131
        throws CoreException;
105
    
132
    
106
    /**
133
    /**
107
     * Returns a sorted list containing all of the versions of this runtime
108
     * component type. The sort order is determined by the version comparator. 
109
     * 
110
     * @param ascending whether versions should be sorted in ascending order
111
     * @return a sorted list containing all of the versions of this runtime 
112
     *   component type
113
     */
114
    
115
    List<IRuntimeComponentVersion> getSortedVersions( boolean ascending )
116
    
117
        throws CoreException;
118
    
119
    /**
120
     * Returns the version comparator specified for this runtime component type.
134
     * Returns the version comparator specified for this runtime component type.
121
     * If no version comparator is specified, this method will return an 
135
     * If no version comparator is specified, this method will return an 
122
     * instance of the {@link DefaultVersionComparator}.
136
     * instance of the {@link DefaultVersionComparator}.
(-)src/org/eclipse/fproj/util/internal/Versionable.java (-37 / +65 lines)
Lines 11-28 Link Here
11
11
12
package org.eclipse.fproj.util.internal;
12
package org.eclipse.fproj.util.internal;
13
13
14
import java.util.ArrayList;
15
import java.util.Collections;
14
import java.util.Collections;
16
import java.util.Comparator;
15
import java.util.Comparator;
17
import java.util.HashSet;
16
import java.util.HashSet;
18
import java.util.List;
19
import java.util.Set;
17
import java.util.Set;
18
import java.util.TreeSet;
20
19
21
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IStatus;
21
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.Platform;
22
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.fproj.DefaultVersionComparator;
23
import org.eclipse.fproj.DefaultVersionComparator;
25
import org.eclipse.fproj.IVersion;
24
import org.eclipse.fproj.IVersion;
25
import org.eclipse.fproj.SortOrder;
26
import org.eclipse.fproj.internal.FacetCorePlugin;
26
import org.eclipse.fproj.internal.FacetCorePlugin;
27
import org.eclipse.osgi.util.NLS;
27
import org.eclipse.osgi.util.NLS;
28
import org.osgi.framework.Bundle;
28
import org.osgi.framework.Bundle;
Lines 49-70 Link Here
49
    
49
    
50
    public Set<T> getVersions()
50
    public Set<T> getVersions()
51
    {
51
    {
52
        return this.versions.getItemSet();
52
        try
53
        {
54
            return getVersions( null, null );
55
        }
56
        catch( CoreException e )
57
        {
58
            // Should not happen in this context...
59
            
60
            FacetCorePlugin.log( e );
61
            return Collections.emptySet();
62
        }
53
    }
63
    }
54
    
64
    
55
    public Set<T> getVersions( final String expr )
65
    public Set<T> getVersions( final String filter )
66
    
67
        throws CoreException
68
        
69
    {
70
        return getVersions( filter, null );
71
    }
72
        
73
    public Set<T> getVersions( final String filter,
74
                               final SortOrder sortDirection )
56
    
75
    
57
        throws CoreException
76
        throws CoreException
58
        
77
        
59
    {
78
    {
60
        final VersionExpr<T> prepared = new VersionExpr<T>( this, expr, null );
79
        final Set<T> result;
61
        final Set<T> result = new HashSet<T>();
80
        
62
         
81
        if( sortDirection != null && sortDirection != SortOrder.UNSORTED )
63
        for( T ver : this.versions.getItemSet() )
82
        {
83
            final Comparator<T> comp;
84
            
85
            if( sortDirection == SortOrder.ASCENDING )
86
            {
87
                comp = null;
88
            }
89
            else
90
            {
91
                comp = new Comparator<T>()
92
                {
93
                    @SuppressWarnings( "unchecked" )
94
                    public int compare( final T ver1,
95
                                        final T ver2 )
96
                    {
97
                        return ver1.compareTo( ver2 ) * -1;
98
                    }
99
                };
100
            }
101
            
102
            result = new TreeSet<T>( comp );
103
        }
104
        else
64
        {
105
        {
65
            if( prepared.check( ver ) )
106
            result = new HashSet<T>();
107
        }
108
        
109
        if( filter == null )
110
        {
111
            result.addAll( this.versions.getItemSet() );
112
        }
113
        else
114
        {
115
            final VersionExpr<T> prepared = new VersionExpr<T>( this, filter, null );
116
             
117
            for( T ver : this.versions.getItemSet() )
66
            {
118
            {
67
                result.add( ver );
119
                if( prepared.check( ver ) )
120
                {
121
                    result.add( ver );
122
                }
68
            }
123
            }
69
        }
124
        }
70
        
125
        
Lines 102-134 Link Here
102
        return this.versions.containsKey( version );
157
        return this.versions.containsKey( version );
103
    }
158
    }
104
159
105
    public List<T> getSortedVersions( final boolean ascending )
106
    {
107
        Comparator<T> comp;
108
        
109
        if( ascending )
110
        {
111
            comp = null;
112
        }
113
        else
114
        {
115
            comp = new Comparator<T>()
116
            {
117
                @SuppressWarnings( "unchecked" )
118
                public int compare( final T ver1,
119
                                    final T ver2 )
120
                {
121
                    return ver1.compareTo( ver2 ) * -1;
122
                }
123
            };
124
        }
125
126
        final List<T> list = new ArrayList<T>( this.versions.getItemSet() );
127
        Collections.sort( list, comp );
128
        
129
        return list;
130
    }
131
    
132
    @SuppressWarnings( "unchecked" )
160
    @SuppressWarnings( "unchecked" )
133
    
161
    
134
    public Comparator<String> getVersionComparator()
162
    public Comparator<String> getVersionComparator()
(-)guide/migration/migration.txt (+9 lines)
Added Link Here
1
1. IProjectFacet.getSortedVersions() and IRuntimeComponentType.getSortedVersions()
2
3
   The function provided by the getSortedVersions method was consolidated into the getVersions method. A new
4
   variant of the getVersions method takes SortOrder enum as an optional parameter.
5
   
6
   [api] Consolidate getSortedVersions() method with getVersions() method family
7
   https://bugs.eclipse.org/bugs/show_bug.cgi?id=318765
8
   
9
   
(-)src/org/eclipse/fproj/tests/BasicTests.java (-32 / +11 lines)
Lines 11-22 Link Here
11
11
12
package org.eclipse.fproj.tests;
12
package org.eclipse.fproj.tests;
13
13
14
import static java.util.Arrays.asList;
14
import static org.eclipse.fproj.tests.support.TestUtils.asSet;
15
import static org.eclipse.fproj.tests.support.TestUtils.asSet;
15
16
16
import java.util.ArrayList;
17
import java.util.ArrayList;
17
import java.util.Collections;
18
import java.util.Collections;
18
import java.util.Comparator;
19
import java.util.Comparator;
19
import java.util.List;
20
import java.util.List;
21
import java.util.SortedSet;
20
22
21
import junit.framework.Test;
23
import junit.framework.Test;
22
import junit.framework.TestCase;
24
import junit.framework.TestCase;
Lines 29-34 Link Here
29
import org.eclipse.fproj.IProjectFacet;
31
import org.eclipse.fproj.IProjectFacet;
30
import org.eclipse.fproj.IProjectFacetVersion;
32
import org.eclipse.fproj.IProjectFacetVersion;
31
import org.eclipse.fproj.ProjectFacetsManager;
33
import org.eclipse.fproj.ProjectFacetsManager;
34
import org.eclipse.fproj.SortOrder;
32
35
33
/**
36
/**
34
 * @author <a href="mailto:kosta@bea.com">Konstantin Komissarchik</a>
37
 * @author <a href="mailto:kosta@bea.com">Konstantin Komissarchik</a>
Lines 304-326 Link Here
304
307
305
        assertEquals( f1.getLatestVersion(), f1v20 );
308
        assertEquals( f1.getLatestVersion(), f1v20 );
306
        
309
        
307
        final List asc = f1.getSortedVersions( true );
310
        final SortedSet<IProjectFacetVersion> asc = (SortedSet<IProjectFacetVersion>) f1.getVersions( null, SortOrder.ASCENDING );
311
        assertEquals( new ArrayList<IProjectFacetVersion>( asc ), asList( f1v10, f1v12, f1v121, f1v13, f1v20 ) );
308
        
312
        
309
        assertEquals( asc.size(), 5 );
313
        final SortedSet<IProjectFacetVersion> desc = (SortedSet<IProjectFacetVersion>) f1.getVersions( null, SortOrder.DESCENDING );
310
        assertEquals( asc.get( 0 ), f1v10 );
314
        assertEquals( new ArrayList<IProjectFacetVersion>( desc ), asList( f1v20, f1v13, f1v121, f1v12, f1v10 ) );
311
        assertEquals( asc.get( 1 ), f1v12 );
312
        assertEquals( asc.get( 2 ), f1v121 );
313
        assertEquals( asc.get( 3 ), f1v13 );
314
        assertEquals( asc.get( 4 ), f1v20 );
315
        
316
        final List desc = f1.getSortedVersions( false );
317
        
318
        assertEquals( desc.size(), 5 );
319
        assertEquals( desc.get( 0 ), f1v20 );
320
        assertEquals( desc.get( 1 ), f1v13 );
321
        assertEquals( desc.get( 2 ), f1v121 );
322
        assertEquals( desc.get( 3 ), f1v12 );
323
        assertEquals( desc.get( 4 ), f1v10 );
324
    }
315
    }
325
316
326
    @SuppressWarnings( "unchecked" )
317
    @SuppressWarnings( "unchecked" )
Lines 362-384 Link Here
362
        
353
        
363
        assertEquals( f2.getLatestVersion(), f2v47b );
354
        assertEquals( f2.getLatestVersion(), f2v47b );
364
        
355
        
365
        final List asc = f2.getSortedVersions( true );
356
        final SortedSet<IProjectFacetVersion> asc = (SortedSet<IProjectFacetVersion>) f2.getVersions( null, SortOrder.ASCENDING );
357
        assertEquals( new ArrayList<IProjectFacetVersion>( asc ), asList( f2v35, f2v35a, f2v47, f2v47c, f2v47b ) );
366
        
358
        
367
        assertEquals( asc.size(), 5 );
359
        final SortedSet<IProjectFacetVersion> desc = (SortedSet<IProjectFacetVersion>) f2.getVersions( null, SortOrder.DESCENDING );
368
        assertEquals( asc.get( 0 ), f2v35 );
360
        assertEquals( new ArrayList<IProjectFacetVersion>( desc ), asList( f2v47b, f2v47c, f2v47, f2v35a, f2v35 ) );
369
        assertEquals( asc.get( 1 ), f2v35a );
370
        assertEquals( asc.get( 2 ), f2v47 );
371
        assertEquals( asc.get( 3 ), f2v47c );
372
        assertEquals( asc.get( 4 ), f2v47b );
373
        
374
        final List desc = f2.getSortedVersions( false );
375
        
376
        assertEquals( desc.size(), 5 );
377
        assertEquals( desc.get( 0 ), f2v47b );
378
        assertEquals( desc.get( 1 ), f2v47c );
379
        assertEquals( desc.get( 2 ), f2v47 );
380
        assertEquals( desc.get( 3 ), f2v35a );
381
        assertEquals( desc.get( 4 ), f2v35 );
382
    }
361
    }
383
    
362
    
384
    public void testVersionExpressions()
363
    public void testVersionExpressions()

Return to bug 318765