Merge pull request #787 from andrewgaul/predicates-not-in

Use appropriate Predicates helpers
This commit is contained in:
Adrian Cole 2012-08-16 14:49:01 -07:00
commit 05b15a7302
1 changed files with 4 additions and 11 deletions

View File

@ -30,7 +30,7 @@ import org.jclouds.atmos.reference.AtmosHeaders;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicates;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -42,23 +42,16 @@ import com.google.common.collect.ImmutableMap.Builder;
*/ */
@Singleton @Singleton
public class ParseUserMetadataFromHeaders implements Function<HttpResponse, UserMetadata> { public class ParseUserMetadataFromHeaders implements Function<HttpResponse, UserMetadata> {
private static final Set<String> sysKeys = ImmutableSet.of("atime", "ctime", "gid", "itime", "mtime", "nlink", private static final Set<String> SYS_KEYS = ImmutableSet.of(
"atime", "ctime", "gid", "itime", "mtime", "nlink",
"policyname", "size", "uid", "content-md5", "objectid", "objname", "type"); "policyname", "size", "uid", "content-md5", "objectid", "objname", "type");
private static final Predicate<String> filter = new Predicate<String>() {
@Override
public boolean apply(String arg0) {
return !sysKeys.contains(arg0);
}
};
public UserMetadata apply(HttpResponse from) { public UserMetadata apply(HttpResponse from) {
checkNotNull(from, "http response"); checkNotNull(from, "http response");
Map<String, String> meta = Maps.filterKeys( Map<String, String> meta = Maps.filterKeys(
getMetaMap(checkNotNull(from.getFirstHeaderOrNull(AtmosHeaders.META), AtmosHeaders.META)), getMetaMap(checkNotNull(from.getFirstHeaderOrNull(AtmosHeaders.META), AtmosHeaders.META)),
filter); Predicates.not(Predicates.in(SYS_KEYS)));
Map<String, String> listableMeta = (from.getFirstHeaderOrNull(AtmosHeaders.LISTABLE_META) != null) ? getMetaMap(from Map<String, String> listableMeta = (from.getFirstHeaderOrNull(AtmosHeaders.LISTABLE_META) != null) ? getMetaMap(from
.getFirstHeaderOrNull(AtmosHeaders.LISTABLE_META)) : ImmutableMap.<String, String> of(); .getFirstHeaderOrNull(AtmosHeaders.LISTABLE_META)) : ImmutableMap.<String, String> of();