diff --git a/aws/s3/core/src/main/java/org/jclouds/aws/s3/domain/ArrayListBucketResponse.java b/aws/s3/core/src/main/java/org/jclouds/aws/s3/domain/TreeSetListBucketResponse.java similarity index 87% rename from aws/s3/core/src/main/java/org/jclouds/aws/s3/domain/ArrayListBucketResponse.java rename to aws/s3/core/src/main/java/org/jclouds/aws/s3/domain/TreeSetListBucketResponse.java index 24bce9a8c3..6605df87f3 100644 --- a/aws/s3/core/src/main/java/org/jclouds/aws/s3/domain/ArrayListBucketResponse.java +++ b/aws/s3/core/src/main/java/org/jclouds/aws/s3/domain/TreeSetListBucketResponse.java @@ -23,7 +23,6 @@ */ package org.jclouds.aws.s3.domain; -import java.util.List; import java.util.SortedSet; /** @@ -31,7 +30,7 @@ import java.util.SortedSet; * @author Adrian Cole * */ -public class ArrayListBucketResponse extends org.jclouds.rest.BoundedTreeSet +public class TreeSetListBucketResponse extends org.jclouds.rest.BoundedTreeSet implements ListBucketResponse { /** The serialVersionUID */ private static final long serialVersionUID = -4475709781001190244L; @@ -40,8 +39,8 @@ public class ArrayListBucketResponse extends org.jclouds.rest.BoundedTreeSet commonPrefixes; private final boolean truncated; - public ArrayListBucketResponse(String bucketName, List contents, String prefix, - String marker, int maxResults, String delimiter, boolean isTruncated, + public TreeSetListBucketResponse(String bucketName, SortedSet contents, + String prefix, String marker, int maxResults, String delimiter, boolean isTruncated, SortedSet commonPrefixes) { super(contents, prefix, marker, maxResults); this.delimiter = delimiter; diff --git a/aws/s3/core/src/main/java/org/jclouds/aws/s3/xml/ListAllMyBucketsHandler.java b/aws/s3/core/src/main/java/org/jclouds/aws/s3/xml/ListAllMyBucketsHandler.java index 67d60ad403..e2565eda26 100644 --- a/aws/s3/core/src/main/java/org/jclouds/aws/s3/xml/ListAllMyBucketsHandler.java +++ b/aws/s3/core/src/main/java/org/jclouds/aws/s3/xml/ListAllMyBucketsHandler.java @@ -23,29 +23,30 @@ */ package org.jclouds.aws.s3.xml; -import java.util.ArrayList; -import java.util.List; +import java.util.SortedSet; + +import javax.inject.Inject; -import org.jclouds.aws.s3.domain.CanonicalUser; import org.jclouds.aws.s3.domain.BucketMetadata; +import org.jclouds.aws.s3.domain.CanonicalUser; import org.jclouds.http.functions.ParseSax; import org.jclouds.util.DateService; -import javax.inject.Inject; +import com.google.common.collect.Sets; /** * Parses the following XML document: *

- * ListAllMyBucketsResult xmlns="http://doc.s3.amazonaws.com/2006-03-01" + * SortedSetAllMyBucketsResult xmlns="http://doc.s3.amazonaws.com/2006-03-01" * * @see * @author Adrian Cole */ -public class ListAllMyBucketsHandler extends ParseSax.HandlerWithResult> { +public class ListAllMyBucketsHandler extends ParseSax.HandlerWithResult> { - private List buckets = new ArrayList(); + private SortedSet buckets = Sets.newTreeSet(); private BucketMetadata currentS3Bucket; private CanonicalUser currentOwner; private StringBuilder currentText = new StringBuilder(); @@ -57,7 +58,7 @@ public class ListAllMyBucketsHandler extends ParseSax.HandlerWithResult getResult() { + public SortedSet getResult() { return buckets; } diff --git a/aws/s3/core/src/main/java/org/jclouds/aws/s3/xml/ListBucketHandler.java b/aws/s3/core/src/main/java/org/jclouds/aws/s3/xml/ListBucketHandler.java index 5e0d5f229f..a44bc72bc4 100644 --- a/aws/s3/core/src/main/java/org/jclouds/aws/s3/xml/ListBucketHandler.java +++ b/aws/s3/core/src/main/java/org/jclouds/aws/s3/xml/ListBucketHandler.java @@ -23,21 +23,20 @@ */ package org.jclouds.aws.s3.xml; -import java.util.List; import java.util.SortedSet; -import java.util.TreeSet; -import org.jclouds.aws.s3.domain.ArrayListBucketResponse; +import javax.inject.Inject; + import org.jclouds.aws.s3.domain.CanonicalUser; import org.jclouds.aws.s3.domain.ListBucketResponse; import org.jclouds.aws.s3.domain.ObjectMetadata; +import org.jclouds.aws.s3.domain.TreeSetListBucketResponse; import org.jclouds.http.HttpUtils; import org.jclouds.http.functions.ParseSax; import org.jclouds.util.DateService; import org.xml.sax.Attributes; -import com.google.common.collect.Lists; -import javax.inject.Inject; +import com.google.common.collect.Sets; /** * Parses the following XML document: @@ -50,7 +49,7 @@ import javax.inject.Inject; * /> */ public class ListBucketHandler extends ParseSax.HandlerWithResult { - private List contents; + private SortedSet contents; private SortedSet commonPrefixes; private ObjectMetadata currentObjectMetadata; private CanonicalUser currentOwner; @@ -67,12 +66,12 @@ public class ListBucketHandler extends ParseSax.HandlerWithResult(); + this.contents = Sets.newTreeSet(); + this.commonPrefixes = Sets.newTreeSet(); } public ListBucketResponse getResult() { - return new ArrayListBucketResponse(bucketName, contents, prefix, marker, maxResults, + return new TreeSetListBucketResponse(bucketName, contents, prefix, marker, maxResults, delimiter, isTruncated, commonPrefixes); } diff --git a/aws/s3/core/src/test/java/org/jclouds/aws/s3/config/RestS3ConnectionModuleTest.java b/aws/s3/core/src/test/java/org/jclouds/aws/s3/config/RestS3ConnectionModuleTest.java new file mode 100644 index 0000000000..7af19eef14 --- /dev/null +++ b/aws/s3/core/src/test/java/org/jclouds/aws/s3/config/RestS3ConnectionModuleTest.java @@ -0,0 +1,88 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.aws.s3.config; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.aws.s3.handlers.AWSClientErrorRetryHandler; +import org.jclouds.aws.s3.handlers.AWSRedirectionRetryHandler; +import org.jclouds.aws.s3.handlers.ParseAWSErrorFromXmlContent; +import org.jclouds.aws.s3.reference.S3Constants; +import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.http.handlers.DelegatingErrorHandler; +import org.jclouds.http.handlers.DelegatingRetryHandler; +import org.jclouds.util.Jsr330; +import org.testng.annotations.Test; + +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "s3.RestS3ConnectionModuleTest") +public class RestS3ConnectionModuleTest { + + Injector createInjector() { + return Guice.createInjector(new RestS3ConnectionModule(), new ParserModule(), new AbstractModule() { + @Override + protected void configure() { + bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_AWS_ACCESSKEYID)).to( + "user"); + bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_AWS_SECRETACCESSKEY)) + .to("key"); + bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_S3_ENDPOINT)).to( + "http://localhost"); + } + }); + } + + @Test + void testServerErrorHandler() { + DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); + assertEquals(handler.getServerErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class); + } + + @Test + void testClientErrorHandler() { + DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); + assertEquals(handler.getClientErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class); + } + + @Test + void testClientRetryHandler() { + DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class); + assertEquals(handler.getClientErrorRetryHandler().getClass(), + AWSClientErrorRetryHandler.class); + } + + @Test + void testRedirectionRetryHandler() { + DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class); + assertEquals(handler.getRedirectionRetryHandler().getClass(), + AWSRedirectionRetryHandler.class); + } + +} \ No newline at end of file diff --git a/aws/s3/core/src/test/java/org/jclouds/aws/s3/config/S3ContextModuleTest.java b/aws/s3/core/src/test/java/org/jclouds/aws/s3/config/S3ContextModuleTest.java index 7de9b442b8..f9fd05553d 100644 --- a/aws/s3/core/src/test/java/org/jclouds/aws/s3/config/S3ContextModuleTest.java +++ b/aws/s3/core/src/test/java/org/jclouds/aws/s3/config/S3ContextModuleTest.java @@ -26,20 +26,13 @@ package org.jclouds.aws.s3.config; import static org.testng.Assert.assertEquals; import org.jclouds.aws.s3.S3BlobStore; +import org.jclouds.aws.s3.S3Context; +import org.jclouds.aws.s3.config.S3ContextModule.S3ContextImpl; import org.jclouds.aws.s3.domain.BucketMetadata; import org.jclouds.aws.s3.domain.ObjectMetadata; import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.handlers.AWSClientErrorRetryHandler; -import org.jclouds.aws.s3.handlers.AWSRedirectionRetryHandler; -import org.jclouds.aws.s3.handlers.ParseAWSErrorFromXmlContent; import org.jclouds.aws.s3.reference.S3Constants; import org.jclouds.blobstore.BlobStoreMapsModule; -import org.jclouds.concurrent.WithinThreadExecutorService; -import org.jclouds.concurrent.config.ExecutorServiceModule; -import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; -import org.jclouds.http.functions.config.ParserModule; -import org.jclouds.http.handlers.DelegatingErrorHandler; -import org.jclouds.http.handlers.DelegatingRetryHandler; import org.jclouds.util.Jsr330; import org.testng.annotations.Test; @@ -54,7 +47,7 @@ import com.google.inject.TypeLiteral; public class S3ContextModuleTest { Injector createInjector() { - return Guice.createInjector(new RestS3ConnectionModule(), BlobStoreMapsModule.Builder + return Guice.createInjector(new StubS3BlobStoreModule(), BlobStoreMapsModule.Builder .newBuilder(new TypeLiteral() { }, new TypeLiteral() { }, new TypeLiteral() { @@ -70,34 +63,13 @@ public class S3ContextModuleTest { "http://localhost"); super.configure(); } - }, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(), - new ExecutorServiceModule(new WithinThreadExecutorService())); + }); } @Test - void testServerErrorHandler() { - DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); - assertEquals(handler.getServerErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class); - } - - @Test - void testClientErrorHandler() { - DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); - assertEquals(handler.getClientErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class); - } - - @Test - void testClientRetryHandler() { - DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class); - assertEquals(handler.getClientErrorRetryHandler().getClass(), - AWSClientErrorRetryHandler.class); - } - - @Test - void testRedirectionRetryHandler() { - DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class); - assertEquals(handler.getRedirectionRetryHandler().getClass(), - AWSRedirectionRetryHandler.class); + void testContextImpl() { + S3Context handler = createInjector().getInstance(S3Context.class); + assertEquals(handler.getClass(), S3ContextImpl.class); } } \ No newline at end of file diff --git a/aws/s3/core/src/test/java/org/jclouds/aws/s3/internal/StubS3BlobStore.java b/aws/s3/core/src/test/java/org/jclouds/aws/s3/internal/StubS3BlobStore.java index fb920cb90f..3b99b398de 100755 --- a/aws/s3/core/src/test/java/org/jclouds/aws/s3/internal/StubS3BlobStore.java +++ b/aws/s3/core/src/test/java/org/jclouds/aws/s3/internal/StubS3BlobStore.java @@ -36,12 +36,12 @@ import javax.inject.Provider; import org.jclouds.aws.s3.S3BlobStore; import org.jclouds.aws.s3.domain.AccessControlList; -import org.jclouds.aws.s3.domain.ArrayListBucketResponse; import org.jclouds.aws.s3.domain.BucketMetadata; import org.jclouds.aws.s3.domain.CannedAccessPolicy; import org.jclouds.aws.s3.domain.ListBucketResponse; import org.jclouds.aws.s3.domain.ObjectMetadata; import org.jclouds.aws.s3.domain.S3Object; +import org.jclouds.aws.s3.domain.TreeSetListBucketResponse; import org.jclouds.aws.s3.domain.AccessControlList.CanonicalUserGrantee; import org.jclouds.aws.s3.domain.AccessControlList.EmailAddressGrantee; import org.jclouds.aws.s3.domain.AccessControlList.Grant; @@ -61,7 +61,6 @@ import org.joda.time.DateTime; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.google.inject.internal.Nullable; @@ -167,8 +166,8 @@ public class StubS3BlobStore extends StubBlobStore runParseListAllMyBuckets() throws HttpException { - return (List) factory.create( + private SortedSet runParseListAllMyBuckets() throws HttpException { + return (SortedSet) factory.create( injector.getInstance(ListAllMyBucketsHandler.class)).parse( IOUtils.toInputStream(listAllMyBucketsResultOn200)); } @@ -93,11 +93,11 @@ public class S3ParserTest extends PerformanceTest { @Test void testParseListAllMyBucketsParallelResponseTime() throws InterruptedException, ExecutionException { - CompletionService> completer = new ExecutorCompletionService>( + CompletionService> completer = new ExecutorCompletionService>( exec); for (int i = 0; i < LOOP_COUNT; i++) - completer.submit(new Callable>() { - public List call() throws IOException, SAXException, HttpException { + completer.submit(new Callable>() { + public SortedSet call() throws IOException, SAXException, HttpException { return runParseListAllMyBuckets(); } }); @@ -107,13 +107,13 @@ public class S3ParserTest extends PerformanceTest { @Test public void testCanParseListAllMyBuckets() throws HttpException { - List s3Buckets = runParseListAllMyBuckets(); - BucketMetadata container1 = s3Buckets.get(0); + SortedSet s3Buckets = runParseListAllMyBuckets(); + BucketMetadata container1 = s3Buckets.first(); assert container1.getName().equals("adrianjbosstest"); DateTime expectedDate1 = new DateTime("2009-03-12T02:00:07.000Z"); DateTime date1 = container1.getCreationDate(); assert date1.equals(expectedDate1); - BucketMetadata container2 = s3Buckets.get(1); + BucketMetadata container2 = (BucketMetadata) s3Buckets.toArray()[1]; assert container2.getName().equals("adrianjbosstest2"); DateTime expectedDate2 = new DateTime("2009-03-12T02:00:09.000Z"); DateTime date2 = container2.getCreationDate(); diff --git a/mezeo/pcs2/core/src/main/java/org/jclouds/mezeo/pcs2/xml/FileListToContainerMetadataListHandler.java b/mezeo/pcs2/core/src/main/java/org/jclouds/mezeo/pcs2/xml/FileListToContainerMetadataListHandler.java index b351d41be1..e95d466794 100755 --- a/mezeo/pcs2/core/src/main/java/org/jclouds/mezeo/pcs2/xml/FileListToContainerMetadataListHandler.java +++ b/mezeo/pcs2/core/src/main/java/org/jclouds/mezeo/pcs2/xml/FileListToContainerMetadataListHandler.java @@ -24,8 +24,7 @@ package org.jclouds.mezeo.pcs2.xml; import java.net.URI; -import java.util.ArrayList; -import java.util.List; +import java.util.SortedSet; import javax.inject.Inject; @@ -36,13 +35,15 @@ import org.joda.time.DateTime; import org.xml.sax.Attributes; import org.xml.sax.SAXException; +import com.google.common.collect.Sets; + /** * @author Adrian Cole */ public class FileListToContainerMetadataListHandler extends - ParseSax.HandlerWithResult> { + ParseSax.HandlerWithResult> { - private List containerMetadata = new ArrayList(); + private SortedSet containerMetadata = Sets.newTreeSet(); private URI currentUrl; private String currentName; private DateTime currentCreated; @@ -63,7 +64,7 @@ public class FileListToContainerMetadataListHandler extends this.dateParser = dateParser; } - public List getResult() { + public SortedSet getResult() { return containerMetadata; } diff --git a/mezeo/pcs2/core/src/main/java/org/jclouds/mezeo/pcs2/xml/FileListToFileMetadataListHandler.java b/mezeo/pcs2/core/src/main/java/org/jclouds/mezeo/pcs2/xml/FileListToFileMetadataListHandler.java index 9d405de161..67f41f824f 100644 --- a/mezeo/pcs2/core/src/main/java/org/jclouds/mezeo/pcs2/xml/FileListToFileMetadataListHandler.java +++ b/mezeo/pcs2/core/src/main/java/org/jclouds/mezeo/pcs2/xml/FileListToFileMetadataListHandler.java @@ -24,8 +24,7 @@ package org.jclouds.mezeo.pcs2.xml; import java.net.URI; -import java.util.ArrayList; -import java.util.List; +import java.util.SortedSet; import javax.inject.Inject; @@ -34,20 +33,22 @@ import org.jclouds.util.DateService; import org.xml.sax.Attributes; import org.xml.sax.SAXException; +import com.google.common.collect.Sets; + /** * @author Adrian Cole */ public class FileListToFileMetadataListHandler extends -BaseFileMetadataHandler> { +BaseFileMetadataHandler> { - private List containerMetadata = new ArrayList(); + private SortedSet containerMetadata = Sets.newTreeSet(); @Inject public FileListToFileMetadataListHandler(DateService dateParser) { super(dateParser); } - public List getResult() { + public SortedSet getResult() { return containerMetadata; } diff --git a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/xml/FileListToContainerMetadataListHandlerTest.java b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/xml/FileListToContainerMetadataListHandlerTest.java index ae7885334a..2cc589493d 100644 --- a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/xml/FileListToContainerMetadataListHandlerTest.java +++ b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/xml/FileListToContainerMetadataListHandlerTest.java @@ -27,7 +27,7 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.net.URI; -import java.util.List; +import java.util.SortedSet; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.mezeo.pcs2.domain.ContainerMetadata; @@ -35,7 +35,7 @@ import org.jclouds.util.DateService; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSortedSet; /** * Tests behavior of {@code FileListToContainerMetadataListHandler} @@ -58,7 +58,7 @@ public class FileListToContainerMetadataListHandlerTest extends BaseHandlerTest @SuppressWarnings("unchecked") public void testApplyInputStream() { InputStream is = getClass().getResourceAsStream("/test_file_list.xml"); - List list = ImmutableList + SortedSet list = ImmutableSortedSet .of(new ContainerMetadata( "test1", URI @@ -67,7 +67,7 @@ public class FileListToContainerMetadataListHandlerTest extends BaseHandlerTest dateService.fromSeconds(1254008227), "adrian@jclouds.org", true, false, 1, 1024)); - List result = (List) factory.create( + SortedSet result = (SortedSet) factory.create( injector.getInstance(FileListToContainerMetadataListHandler.class)).parse(is); assertEquals(result, list); diff --git a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/xml/FileListToFileMetadataListHandlerTest.java b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/xml/FileListToFileMetadataListHandlerTest.java index 781a646325..f051bb400c 100644 --- a/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/xml/FileListToFileMetadataListHandlerTest.java +++ b/mezeo/pcs2/core/src/test/java/org/jclouds/mezeo/pcs2/xml/FileListToFileMetadataListHandlerTest.java @@ -27,7 +27,7 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.net.URI; -import java.util.List; +import java.util.SortedSet; import javax.ws.rs.core.MediaType; @@ -37,10 +37,10 @@ import org.jclouds.util.DateService; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSortedSet; /** - * Tests behavior of {@code FileListToFileMetadataListHandler} + * Tests behavior of {@code FileSortedSetToFileMetadataSortedSetHandler} * * @author Adrian Cole */ @@ -60,7 +60,7 @@ public class FileListToFileMetadataListHandlerTest extends BaseHandlerTest { @SuppressWarnings("unchecked") public void testApplyInputStream() { InputStream is = getClass().getResourceAsStream("/test_file_list.xml"); - List list = ImmutableList.of(new FileMetadata("more", URI + SortedSet list = ImmutableSortedSet.of(new FileMetadata("more", URI .create("https://pcsbeta.mezeo.net/v2/files/5C81DADC-AAEE-11DE-9D55-B39340AEFF3A"), dateService.fromSeconds(1254005157), dateService.fromSeconds(1254005158), dateService.fromSeconds(1254005159), "adrian@jclouds.org", false, false, 1, 254288, @@ -72,7 +72,7 @@ public class FileListToFileMetadataListHandlerTest extends BaseHandlerTest { dateService.fromSeconds(1254000182), "adrian@jclouds.org", false, true, 3, 5, MediaType.TEXT_PLAIN, false)); - List result = (List) factory.create( + SortedSet result = (SortedSet) factory.create( injector.getInstance(FileListToFileMetadataListHandler.class)).parse(is); assertEquals(result, list); diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseBlobMetadataListFromJsonResponse.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseBlobMetadataListFromJsonResponse.java index d95fe9bbd9..95240e25d6 100644 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseBlobMetadataListFromJsonResponse.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseBlobMetadataListFromJsonResponse.java @@ -27,7 +27,9 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.lang.reflect.Type; -import java.util.List; +import java.util.SortedSet; + +import javax.inject.Inject; import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.http.HttpUtils; @@ -35,24 +37,24 @@ import org.jclouds.http.functions.ParseJson; import org.joda.time.DateTime; import com.google.common.base.Function; -import com.google.common.collect.Lists; +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; -import javax.inject.Inject; /** * This parses {@link BlobMetadata} from a gson string. * * @author Adrian Cole */ -public class ParseBlobMetadataListFromJsonResponse extends ParseJson> { +public class ParseBlobMetadataListFromJsonResponse extends ParseJson> { @Inject public ParseBlobMetadataListFromJsonResponse(Gson gson) { super(gson); } - public static class CloudFilesMetadata { + public static class CloudFilesMetadata implements Comparable { public CloudFilesMetadata() { } @@ -61,25 +63,30 @@ public class ParseBlobMetadataListFromJsonResponse extends ParseJson apply(InputStream stream) { - Type listType = new TypeToken>() { + public SortedSet apply(InputStream stream) { + Type listType = new TypeToken>() { }.getType(); try { - List list = gson.fromJson(new InputStreamReader(stream, "UTF-8"), + SortedSet list = gson.fromJson(new InputStreamReader(stream, "UTF-8"), listType); - return Lists.transform(list, new Function() { - public BlobMetadata apply(CloudFilesMetadata from) { - BlobMetadata metadata = new BlobMetadata(from.name); - metadata.setSize(from.bytes); - metadata.setLastModified(from.last_modified); - metadata.setContentType(from.content_type); - metadata.setETag(HttpUtils.fromHexString(from.hash)); - return metadata; - } - }); + return Sets.newTreeSet(Iterables.transform(list, + new Function() { + public BlobMetadata apply(CloudFilesMetadata from) { + BlobMetadata metadata = new BlobMetadata(from.name); + metadata.setSize(from.bytes); + metadata.setLastModified(from.last_modified); + metadata.setContentType(from.content_type); + metadata.setETag(HttpUtils.fromHexString(from.hash)); + return metadata; + } + })); } catch (UnsupportedEncodingException e) { throw new RuntimeException("jclouds requires UTF-8 encoding", e); diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerCDNMetadataListFromGsonResponse.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerCDNMetadataListFromGsonResponse.java index 1fe951f55e..3a5dc6a36f 100644 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerCDNMetadataListFromGsonResponse.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerCDNMetadataListFromGsonResponse.java @@ -27,21 +27,22 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.lang.reflect.Type; -import java.util.List; +import java.util.SortedSet; + +import javax.inject.Inject; import org.jclouds.http.functions.ParseJson; import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; -import javax.inject.Inject; /** * This parses {@link ContainerCDNMetadata} from a gson string. * * @author James Murty */ -public class ParseContainerCDNMetadataListFromGsonResponse extends ParseJson> +public class ParseContainerCDNMetadataListFromGsonResponse extends ParseJson> { @Inject @@ -49,8 +50,8 @@ public class ParseContainerCDNMetadataListFromGsonResponse extends ParseJson apply(InputStream stream) { - Type listType = new TypeToken>() { + public SortedSet apply(InputStream stream) { + Type listType = new TypeToken>() { }.getType(); try { return gson.fromJson(new InputStreamReader(stream, "UTF-8"), listType); diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerListFromJsonResponse.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerListFromJsonResponse.java index 6905a343e0..e80f4e953a 100755 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerListFromJsonResponse.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseContainerListFromJsonResponse.java @@ -27,29 +27,30 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.lang.reflect.Type; -import java.util.List; +import java.util.SortedSet; + +import javax.inject.Inject; import org.jclouds.http.functions.ParseJson; import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; -import javax.inject.Inject; /** * This parses {@link ContainerMetadata} from a gson string. * * @author Adrian Cole */ -public class ParseContainerListFromJsonResponse extends ParseJson> { +public class ParseContainerListFromJsonResponse extends ParseJson> { @Inject public ParseContainerListFromJsonResponse(Gson gson) { super(gson); } - public List apply(InputStream stream) { - Type listType = new TypeToken>() { + public SortedSet apply(InputStream stream) { + Type listType = new TypeToken>() { }.getType(); try { return gson.fromJson(new InputStreamReader(stream, "UTF-8"), listType);