filtered out null objects

This commit is contained in:
Adrian Cole 2012-01-14 21:09:12 -08:00
parent 9d36c3e4b0
commit c9f980e59e
1 changed files with 14 additions and 9 deletions

View File

@ -18,6 +18,11 @@
*/ */
package org.jclouds.compute.config; package org.jclouds.compute.config;
import static com.google.common.base.Functions.compose;
import static com.google.common.base.Predicates.notNull;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import static com.google.inject.util.Types.newParameterizedType;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import java.util.Set; import java.util.Set;
@ -48,14 +53,11 @@ import org.jclouds.domain.LoginCredentials;
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.Scopes; import com.google.inject.Scopes;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
import com.google.inject.util.Types;
/** /**
* *
@ -77,8 +79,8 @@ public class ComputeServiceAdapterContextModule<S, A, N, H, I, L> extends BaseCo
super.configure(); super.configure();
bind(new TypeLiteral<ComputeServiceContext>() { bind(new TypeLiteral<ComputeServiceContext>() {
}).to( }).to(
(TypeLiteral) TypeLiteral.get(Types.newParameterizedType(ComputeServiceContextImpl.class, (TypeLiteral) TypeLiteral.get(newParameterizedType(ComputeServiceContextImpl.class, syncClientType,
syncClientType, asyncClientType))).in(Scopes.SINGLETON); asyncClientType))).in(Scopes.SINGLETON);
} }
@Override @Override
@ -95,7 +97,8 @@ public class ComputeServiceAdapterContextModule<S, A, N, H, I, L> extends BaseCo
seconds, new Supplier<Set<? extends Location>>() { seconds, new Supplier<Set<? extends Location>>() {
@Override @Override
public Set<? extends Location> get() { public Set<? extends Location> get() {
return ImmutableSet.<Location> copyOf(Iterables.transform(adapter.listLocations(), transformer)); return ImmutableSet.<Location> copyOf(transform(filter(adapter.listLocations(), notNull()),
transformer));
} }
}); });
} }
@ -108,7 +111,7 @@ public class ComputeServiceAdapterContextModule<S, A, N, H, I, L> extends BaseCo
@Override @Override
public Iterable<H> get() { public Iterable<H> get() {
return adapter.listHardwareProfiles(); return filter(adapter.listHardwareProfiles(), notNull());
} }
}, transformer); }, transformer);
@ -122,10 +125,10 @@ public class ComputeServiceAdapterContextModule<S, A, N, H, I, L> extends BaseCo
@Override @Override
public Iterable<I> get() { public Iterable<I> get() {
return adapter.listImages(); return filter(adapter.listImages(), notNull());
} }
}, Functions.compose(addDefaultCredentialsToImage, transformer)); }, compose(addDefaultCredentialsToImage, transformer));
} }
@Singleton @Singleton
@ -139,6 +142,8 @@ public class ComputeServiceAdapterContextModule<S, A, N, H, I, L> extends BaseCo
@Override @Override
public Image apply(Image arg0) { public Image apply(Image arg0) {
if (arg0 == null)
return null;
LoginCredentials credentials = credsForImage.apply(arg0); LoginCredentials credentials = credsForImage.apply(arg0);
return credentials != null ? ImageBuilder.fromImage(arg0).defaultCredentials(credentials).build() : arg0; return credentials != null ? ImageBuilder.fromImage(arg0).defaultCredentials(credentials).build() : arg0;
} }