### Eclipse Workspace Patch 1.0 #P org.eclipse.fproj Index: src/org/eclipse/fproj/IProjectFacet.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.fproj/core/plugins/org.eclipse.fproj/src/org/eclipse/fproj/IProjectFacet.java,v retrieving revision 1.4 diff -u -r1.4 IProjectFacet.java --- src/org/eclipse/fproj/IProjectFacet.java 13 Jan 2010 17:16:30 -0000 1.4 +++ src/org/eclipse/fproj/IProjectFacet.java 2 Jul 2010 22:29:38 -0000 @@ -12,7 +12,6 @@ package org.eclipse.fproj; import java.util.Comparator; -import java.util.List; import java.util.Map; import java.util.Set; @@ -95,14 +94,41 @@ ICategory getCategory(); /** - * Returns the descriptors of all versions of this project facet. + * Returns all versions of this project facet. The returned Set will have unspecified + * traversal order (not sorted). * - * @return the descriptors of all versions of this project facet + * @return all versions of this project facet */ Set getVersions(); - Set getVersions( String expr ) + /** + * Returns the versions of this project facet that match the specified filter. The + * returned Set will have unspecified traversal order (not sorted). + * + * @param filter an expression that specifies versions to return or null + * to return all versions + * @return the versions of this project facet that match the specified filter + */ + + Set getVersions( String filter ) + + throws CoreException; + + /** + * Returns the versions of this project facet that match the specified filter. The + * result can be sorted, if desired. If the result is sorted, the returned Set + * can be cast to SortedSet. + * + * @param filter an expression that specifies versions to return or null + * to return all versions + * @param sortOrder the preference for how the result should be sorted or null + * to leave the traverse order of the returned set unspecified + * @return the versions of this project facet that match the specified filter + */ + + Set getVersions( String filter, + SortOrder sortOrder ) throws CoreException; @@ -161,20 +187,6 @@ IProjectFacetVersion getDefaultVersion(); /** - * Returns a sorted list containing the descriptors of all versions of this - * project facet. - * - * @param ascending whether version descriptors should be sorted in - * ascending order - * @return a sorted list containing the descriptors of all versions of this - * project facet - */ - - List getSortedVersions( boolean ascending ) - - throws VersionFormatException, CoreException; - - /** * Returns the version comparator specified for this project facet. If no * version comparator is specified, this method will return an instance of * the {@link DefaultVersionComparator}. Index: src/org/eclipse/fproj/SortOrder.java =================================================================== RCS file: src/org/eclipse/fproj/SortOrder.java diff -N src/org/eclipse/fproj/SortOrder.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/fproj/SortOrder.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,41 @@ +/****************************************************************************** + * Copyright (c) 2010 Oracle + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Konstantin Komissarchik - initial implementation and ongoing maintenance + ******************************************************************************/ + +package org.eclipse.fproj; + +/** + * Used for specifying sorting preference in methods capable of returning sorted + * results. + * + * @author Konstantin Komissarchik + */ + +public enum SortOrder +{ + /** + * No sorting preference. The order of returned items is unspecified. + */ + + UNSORTED, + + /** + * The returned items should be sorted in ascending order from lowest to highest. + */ + + ASCENDING, + + /** + * The returned items should be sorted in descending order from highest to lowest. + */ + + DESCENDING + +} Index: src/org/eclipse/fproj/internal/ProjectFacet.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.fproj/core/plugins/org.eclipse.fproj/src/org/eclipse/fproj/internal/ProjectFacet.java,v retrieving revision 1.3 diff -u -r1.3 ProjectFacet.java --- src/org/eclipse/fproj/internal/ProjectFacet.java 13 Jan 2010 17:16:30 -0000 1.3 +++ src/org/eclipse/fproj/internal/ProjectFacet.java 2 Jul 2010 22:29:40 -0000 @@ -21,12 +21,14 @@ import java.util.Map; import java.util.Set; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Platform; import org.eclipse.fproj.IActionDefinition; import org.eclipse.fproj.ICategory; import org.eclipse.fproj.IDefaultVersionProvider; import org.eclipse.fproj.IProjectFacet; import org.eclipse.fproj.IProjectFacetVersion; +import org.eclipse.fproj.SortOrder; import org.eclipse.fproj.runtime.IRuntime; import org.eclipse.fproj.util.internal.Versionable; import org.eclipse.osgi.util.NLS; @@ -139,13 +141,22 @@ public IProjectFacetVersion getLatestSupportedVersion( final IRuntime r ) { - for( IProjectFacetVersion fv : getSortedVersions( false ) ) + try { - if( r.supports( fv ) ) + for( IProjectFacetVersion fv : getVersions( null, SortOrder.DESCENDING ) ) { - return fv; + if( r.supports( fv ) ) + { + return fv; + } } } + catch( CoreException e ) + { + // Not expected in this context... + + FacetCorePlugin.log( e ); + } return null; } Index: src/org/eclipse/fproj/runtime/IRuntimeComponentType.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.fproj/core/plugins/org.eclipse.fproj/src/org/eclipse/fproj/runtime/IRuntimeComponentType.java,v retrieving revision 1.2 diff -u -r1.2 IRuntimeComponentType.java --- src/org/eclipse/fproj/runtime/IRuntimeComponentType.java 22 Dec 2009 23:07:36 -0000 1.2 +++ src/org/eclipse/fproj/runtime/IRuntimeComponentType.java 2 Jul 2010 22:29:40 -0000 @@ -12,12 +12,12 @@ package org.eclipse.fproj.runtime; import java.util.Comparator; -import java.util.List; import java.util.Set; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.fproj.DefaultVersionComparator; +import org.eclipse.fproj.SortOrder; /** * Represents the type of a runtime component. A runtime instance is composed of multiple runtime @@ -58,14 +58,41 @@ String getPluginId(); /** - * Returns all of the versions of this runtime component type. + * Returns all versions of this runtime component type. The returned Set will have unspecified + * traversal order (not sorted). * - * @return all of the versions of this runtime component type + * @return all versions of this runtime component type */ Set getVersions(); - Set getVersions( String expr ) + /** + * Returns the versions of this runtime component type that match the specified filter. The + * returned Set will have unspecified traversal order (not sorted). + * + * @param filter an expression that specifies versions to return or null + * to return all versions + * @return the versions of this runtime component type that match the specified filter + */ + + Set getVersions( String filter ) + + throws CoreException; + + /** + * Returns the versions of this runtime component type that match the specified filter. The + * result can be sorted, if desired. If the result is sorted, the returned Set + * can be cast to SortedSet. + * + * @param filter an expression that specifies versions to return or null + * to return all versions + * @param sortOrder the preference for how the result should be sorted or null + * to leave the traverse order of the returned set unspecified + * @return the versions of this runtime component type that match the specified filter + */ + + Set getVersions( String filter, + SortOrder sortOrder ) throws CoreException; @@ -104,19 +131,6 @@ throws CoreException; /** - * Returns a sorted list containing all of the versions of this runtime - * component type. The sort order is determined by the version comparator. - * - * @param ascending whether versions should be sorted in ascending order - * @return a sorted list containing all of the versions of this runtime - * component type - */ - - List getSortedVersions( boolean ascending ) - - throws CoreException; - - /** * Returns the version comparator specified for this runtime component type. * If no version comparator is specified, this method will return an * instance of the {@link DefaultVersionComparator}. Index: src/org/eclipse/fproj/util/internal/Versionable.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.fproj/core/plugins/org.eclipse.fproj/src/org/eclipse/fproj/util/internal/Versionable.java,v retrieving revision 1.3 diff -u -r1.3 Versionable.java --- src/org/eclipse/fproj/util/internal/Versionable.java 13 Jan 2010 17:16:31 -0000 1.3 +++ src/org/eclipse/fproj/util/internal/Versionable.java 2 Jul 2010 22:29:40 -0000 @@ -11,18 +11,18 @@ package org.eclipse.fproj.util.internal; -import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; -import java.util.List; import java.util.Set; +import java.util.TreeSet; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.fproj.DefaultVersionComparator; import org.eclipse.fproj.IVersion; +import org.eclipse.fproj.SortOrder; import org.eclipse.fproj.internal.FacetCorePlugin; import org.eclipse.osgi.util.NLS; import org.osgi.framework.Bundle; @@ -49,22 +49,77 @@ public Set getVersions() { - return this.versions.getItemSet(); + try + { + return getVersions( null, null ); + } + catch( CoreException e ) + { + // Should not happen in this context... + + FacetCorePlugin.log( e ); + return Collections.emptySet(); + } } - public Set getVersions( final String expr ) + public Set getVersions( final String filter ) + + throws CoreException + + { + return getVersions( filter, null ); + } + + public Set getVersions( final String filter, + final SortOrder sortDirection ) throws CoreException { - final VersionExpr prepared = new VersionExpr( this, expr, null ); - final Set result = new HashSet(); - - for( T ver : this.versions.getItemSet() ) + final Set result; + + if( sortDirection != null && sortDirection != SortOrder.UNSORTED ) + { + final Comparator comp; + + if( sortDirection == SortOrder.ASCENDING ) + { + comp = null; + } + else + { + comp = new Comparator() + { + @SuppressWarnings( "unchecked" ) + public int compare( final T ver1, + final T ver2 ) + { + return ver1.compareTo( ver2 ) * -1; + } + }; + } + + result = new TreeSet( comp ); + } + else { - if( prepared.check( ver ) ) + result = new HashSet(); + } + + if( filter == null ) + { + result.addAll( this.versions.getItemSet() ); + } + else + { + final VersionExpr prepared = new VersionExpr( this, filter, null ); + + for( T ver : this.versions.getItemSet() ) { - result.add( ver ); + if( prepared.check( ver ) ) + { + result.add( ver ); + } } } @@ -102,33 +157,6 @@ return this.versions.containsKey( version ); } - public List getSortedVersions( final boolean ascending ) - { - Comparator comp; - - if( ascending ) - { - comp = null; - } - else - { - comp = new Comparator() - { - @SuppressWarnings( "unchecked" ) - public int compare( final T ver1, - final T ver2 ) - { - return ver1.compareTo( ver2 ) * -1; - } - }; - } - - final List list = new ArrayList( this.versions.getItemSet() ); - Collections.sort( list, comp ); - - return list; - } - @SuppressWarnings( "unchecked" ) public Comparator getVersionComparator() #P org.eclipse.fproj.doc.api Index: guide/migration/migration.txt =================================================================== RCS file: guide/migration/migration.txt diff -N guide/migration/migration.txt --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ guide/migration/migration.txt 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,9 @@ +1. IProjectFacet.getSortedVersions() and IRuntimeComponentType.getSortedVersions() + + The function provided by the getSortedVersions method was consolidated into the getVersions method. A new + variant of the getVersions method takes SortOrder enum as an optional parameter. + + [api] Consolidate getSortedVersions() method with getVersions() method family + https://bugs.eclipse.org/bugs/show_bug.cgi?id=318765 + + \ No newline at end of file #P org.eclipse.fproj.tests Index: src/org/eclipse/fproj/tests/BasicTests.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.fproj/core/tests/plugins/org.eclipse.fproj.tests/src/org/eclipse/fproj/tests/BasicTests.java,v retrieving revision 1.1 diff -u -r1.1 BasicTests.java --- src/org/eclipse/fproj/tests/BasicTests.java 17 Jun 2009 16:35:43 -0000 1.1 +++ src/org/eclipse/fproj/tests/BasicTests.java 2 Jul 2010 22:29:42 -0000 @@ -11,12 +11,14 @@ package org.eclipse.fproj.tests; +import static java.util.Arrays.asList; import static org.eclipse.fproj.tests.support.TestUtils.asSet; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.SortedSet; import junit.framework.Test; import junit.framework.TestCase; @@ -29,6 +31,7 @@ import org.eclipse.fproj.IProjectFacet; import org.eclipse.fproj.IProjectFacetVersion; import org.eclipse.fproj.ProjectFacetsManager; +import org.eclipse.fproj.SortOrder; /** * @author Konstantin Komissarchik @@ -304,23 +307,11 @@ assertEquals( f1.getLatestVersion(), f1v20 ); - final List asc = f1.getSortedVersions( true ); + final SortedSet asc = (SortedSet) f1.getVersions( null, SortOrder.ASCENDING ); + assertEquals( new ArrayList( asc ), asList( f1v10, f1v12, f1v121, f1v13, f1v20 ) ); - assertEquals( asc.size(), 5 ); - assertEquals( asc.get( 0 ), f1v10 ); - assertEquals( asc.get( 1 ), f1v12 ); - assertEquals( asc.get( 2 ), f1v121 ); - assertEquals( asc.get( 3 ), f1v13 ); - assertEquals( asc.get( 4 ), f1v20 ); - - final List desc = f1.getSortedVersions( false ); - - assertEquals( desc.size(), 5 ); - assertEquals( desc.get( 0 ), f1v20 ); - assertEquals( desc.get( 1 ), f1v13 ); - assertEquals( desc.get( 2 ), f1v121 ); - assertEquals( desc.get( 3 ), f1v12 ); - assertEquals( desc.get( 4 ), f1v10 ); + final SortedSet desc = (SortedSet) f1.getVersions( null, SortOrder.DESCENDING ); + assertEquals( new ArrayList( desc ), asList( f1v20, f1v13, f1v121, f1v12, f1v10 ) ); } @SuppressWarnings( "unchecked" ) @@ -362,23 +353,11 @@ assertEquals( f2.getLatestVersion(), f2v47b ); - final List asc = f2.getSortedVersions( true ); + final SortedSet asc = (SortedSet) f2.getVersions( null, SortOrder.ASCENDING ); + assertEquals( new ArrayList( asc ), asList( f2v35, f2v35a, f2v47, f2v47c, f2v47b ) ); - assertEquals( asc.size(), 5 ); - assertEquals( asc.get( 0 ), f2v35 ); - assertEquals( asc.get( 1 ), f2v35a ); - assertEquals( asc.get( 2 ), f2v47 ); - assertEquals( asc.get( 3 ), f2v47c ); - assertEquals( asc.get( 4 ), f2v47b ); - - final List desc = f2.getSortedVersions( false ); - - assertEquals( desc.size(), 5 ); - assertEquals( desc.get( 0 ), f2v47b ); - assertEquals( desc.get( 1 ), f2v47c ); - assertEquals( desc.get( 2 ), f2v47 ); - assertEquals( desc.get( 3 ), f2v35a ); - assertEquals( desc.get( 4 ), f2v35 ); + final SortedSet desc = (SortedSet) f2.getVersions( null, SortOrder.DESCENDING ); + assertEquals( new ArrayList( desc ), asList( f2v47b, f2v47c, f2v47, f2v35a, f2v35 ) ); } public void testVersionExpressions()