don't consider field equivalence when using ofApi

This commit is contained in:
Adrian Cole 2012-04-02 13:30:23 -07:00
parent af3a226b3d
commit d1fdc504c0
2 changed files with 10 additions and 8 deletions

View File

@ -206,22 +206,22 @@ public class ProviderPredicates {
} }
/** /**
* Returns all providers with the given api. * Returns all providers with an instance of the given api.
* *
* @param type * @param apiClass
* the type of the provider to return * the api of the provider to return
* *
* @return the providers with the given api * @return the providers with the given api
*/ */
public static Predicate<ProviderMetadata> api(final ApiMetadata api) { public static Predicate<ProviderMetadata> apiInstanceOf(final Class<? extends ApiMetadata> apiClass) {
Preconditions.checkNotNull(api, "api must be defined"); Preconditions.checkNotNull(apiClass, "api must be defined");
return new Predicate<ProviderMetadata>() { return new Predicate<ProviderMetadata>() {
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean apply(ProviderMetadata providerMetadata) { public boolean apply(ProviderMetadata providerMetadata) {
return providerMetadata.getApi().equals(api); return Predicates.instanceOf(apiClass).apply(providerMetadata.getApi());
} }
/** /**
@ -229,7 +229,7 @@ public class ProviderPredicates {
*/ */
@Override @Override
public String toString() { public String toString() {
return "api(" + api + ")"; return "apiInstanceOf(" + apiClass + ")";
} }
}; };
} }

View File

@ -27,6 +27,7 @@ import java.util.ServiceLoader;
import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.ApiMetadata;
import org.jclouds.apis.ApiType; import org.jclouds.apis.ApiType;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
/** /**
@ -141,7 +142,8 @@ public class Providers {
* @return the providers of the provided api * @return the providers of the provided api
*/ */
public static Iterable<ProviderMetadata> ofApi(ApiMetadata api) { public static Iterable<ProviderMetadata> ofApi(ApiMetadata api) {
return filter(all(), ProviderPredicates.api(api)); Preconditions.checkNotNull(api, "api must be defined");
return filter(all(), ProviderPredicates.apiInstanceOf(api.getClass()));
} }
/** /**