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
* the type of the provider to return
* @param apiClass
* the api of the provider to return
*
* @return the providers with the given api
*/
public static Predicate<ProviderMetadata> api(final ApiMetadata api) {
Preconditions.checkNotNull(api, "api must be defined");
public static Predicate<ProviderMetadata> apiInstanceOf(final Class<? extends ApiMetadata> apiClass) {
Preconditions.checkNotNull(apiClass, "api must be defined");
return new Predicate<ProviderMetadata>() {
/**
* {@inheritDoc}
*/
@Override
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
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.ApiType;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
/**
@ -141,7 +142,8 @@ public class Providers {
* @return the providers of the provided 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()));
}
/**