mirror of https://github.com/apache/jclouds.git
Issue 550: Refactored the ISO 3166 filtering methods for Providers API.
* core/src/main/java/org/jclouds/providers/ProviderPredicates.java (inIso3166Code): Deleted. (boundedByIso3166Code): Added. * core/src/main/java/org/jclouds/providers/Providers.java (withIso3166Code): Deleted. (boundedByIso3166Code): Added. * core/src/test/java/org/jclouds/providers/ProvidersTest.java (testWithIso3166Code): Deleted. (testBoundedByIso3166Code): Added (testIntersectingIso3166Code): Deleted. (testCollocatedWith): Added.
This commit is contained in:
parent
d320641734
commit
86817b7612
|
@ -99,13 +99,14 @@ public class ProviderPredicates {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all providers that are "in" the given ISO 3166 code.
|
* Returns the providers that are bound to the same location as the given ISO 3166 code.
|
||||||
*
|
*
|
||||||
* @param iso3166Code the ISO 3166 code for the location/region to search for
|
* @param isoCode
|
||||||
|
* the ISO 3166 code to filter providers by
|
||||||
*
|
*
|
||||||
* @return the providers "in" the given ISO 3166 code
|
* @return the providers with the given ISO 3166 code
|
||||||
*/
|
*/
|
||||||
public static Predicate<ProviderMetadata> inIso3166Code(final String iso3166Code) {
|
public static Predicate<ProviderMetadata> boundedByIso3166Code(final String iso3166Code) {
|
||||||
Preconditions.checkNotNull(iso3166Code, "iso3166Code must not be null");
|
Preconditions.checkNotNull(iso3166Code, "iso3166Code must not be null");
|
||||||
|
|
||||||
return new Predicate<ProviderMetadata>() {
|
return new Predicate<ProviderMetadata>() {
|
||||||
|
@ -122,7 +123,7 @@ public class ProviderPredicates {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "inIso3166Code(" + iso3166Code + ")";
|
return "boundedByIso3166Code(" + iso3166Code + ")";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,15 +127,15 @@ public class Providers {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the providers that have the given ISO 3166 code regardless of type.
|
* Returns the providers that are bound to the same location as the given ISO 3166 code.
|
||||||
*
|
*
|
||||||
* @param isoCode
|
* @param isoCode
|
||||||
* the ISO 3166 code to filter providers by
|
* the ISO 3166 code to filter providers by
|
||||||
*
|
*
|
||||||
* @return the providers with the given ISO 3166 code
|
* @return the providers with the given ISO 3166 code
|
||||||
*/
|
*/
|
||||||
public static Iterable<ProviderMetadata> withIso3166Code(String iso3166Code) {
|
public static Iterable<ProviderMetadata> boundedByIso3166Code(String iso3166Code) {
|
||||||
return filter(all(), ProviderPredicates.inIso3166Code(iso3166Code));
|
return filter(all(), ProviderPredicates.boundedByIso3166Code(iso3166Code));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -95,7 +95,7 @@ public class ProvidersTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithIso3166Code() {
|
public void testBoundedByIso3166Code() {
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
Map<String, Integer> expectedResults = new HashMap<String, Integer>() {{
|
Map<String, Integer> expectedResults = new HashMap<String, Integer>() {{
|
||||||
put("US-CA", 2);
|
put("US-CA", 2);
|
||||||
|
@ -107,7 +107,7 @@ public class ProvidersTest {
|
||||||
}};
|
}};
|
||||||
|
|
||||||
for (Map.Entry<String, Integer> result : expectedResults.entrySet()) {
|
for (Map.Entry<String, Integer> result : expectedResults.entrySet()) {
|
||||||
Iterable<ProviderMetadata> providersMetadata = Providers.withIso3166Code(result.getKey());
|
Iterable<ProviderMetadata> providersMetadata = Providers.boundedByIso3166Code(result.getKey());
|
||||||
int providersFound = 0;
|
int providersFound = 0;
|
||||||
|
|
||||||
for (ProviderMetadata providerMetadata : providersMetadata) {
|
for (ProviderMetadata providerMetadata : providersMetadata) {
|
||||||
|
@ -121,7 +121,7 @@ public class ProvidersTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIntersectingIso3166Code() {
|
public void testCollocatedWith() {
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
Map<ProviderMetadata, Integer> expectedResults = new HashMap<ProviderMetadata, Integer>() {{
|
Map<ProviderMetadata, Integer> expectedResults = new HashMap<ProviderMetadata, Integer>() {{
|
||||||
put(testBlobstoreProvider, 1);
|
put(testBlobstoreProvider, 1);
|
||||||
|
|
Loading…
Reference in New Issue